Skip to main content

FlagQuantum MCP Server

An MCP server that gives any MCP-compatible agent local access to the FlagQuantum SDK: build, compile, route, serialize and plan quantum circuits, with no credentials, no network access and no hardware submission.

Part of FlagQuantum/mcp-servers.

What it does

Nine read-only tools over stdio:

Tool What it answers
analyze_circuit_tool Gate counts, depth, wire usage, two-qubit gate count
serialize_circuit_tool Canonical IR JSON plus its content hash
deserialize_circuit_tool Is this IR valid, and does it round-trip unchanged?
optimize_circuit_tool What did target-independent optimization change?
route_circuit_tool What does this circuit cost on a line / ring / grid / custom topology?
compare_topologies_tool Which connectivity is cheapest for this circuit?
emit_openqasm_tool OpenQASM 2.0 or 3.0 text
emit_qcis_tool QCIS text
plan_execution_tool How would the SDK execute this — which mode, device, how much memory?

Three resources: flagquantum://version, flagquantum://gate-set, flagquantum://ir-schema.

Three prompts: build_and_analyze_circuit, compile_for_topology, export_circuit.

Install

pip install flagquantum-mcp-server

This pulls flagquantum, which depends on torch.

Claude Code

claude mcp add flagquantum -- uvx flagquantum-mcp-server

Claude Desktop / Cline

{
  "mcpServers": {
    "flagquantum": {
      "command": "uvx",
      "args": ["flagquantum-mcp-server"]
    }
  }
}

MCP Inspector

npx @modelcontextprotocol/inspector uvx flagquantum-mcp-server

Circuit formats

Two input formats are accepted, both of them FlagQuantum's own serialization.

ir (canonical) — FlagQuantum IR JSON, as produced by CircuitIR.to_json(). Versioned, hashable, and rejected if it carries unknown fields:

{
  "kind": "flagquantum.circuit_ir",
  "version": "1.0",
  "n_wires": 2,
  "dtype": "complex64",
  "shape": [4],
  "instructions": [
    {"opcode": "h", "wires": [0], "params": {}, "matrix": null, "metadata": {}},
    {"opcode": "cx", "wires": [0, 1], "params": {}, "matrix": null, "metadata": {}}
  ],
  "observables": [],
  "measurements": [],
  "metadata": {}
}

qir (convenience) — the compact gate list from Circuit.to_qir(), easier to write by hand:

[{"name": "h", "index": [0]}, {"name": "cx", "index": [0, 1]}]

Either format can be passed to any tool; serialize_circuit_tool converts qir into canonical ir.

Limits

Every bound is overridable by environment variable, so a deployment can tighten them without a code change:

Variable Default Bounds
FLAGQUANTUM_MCP_MAX_QUBITS 24 Circuit width
FLAGQUANTUM_MCP_MAX_GATES 10000 Instruction count
FLAGQUANTUM_MCP_MAX_IR_BYTES 262144 Serialized circuit payload
FLAGQUANTUM_MCP_MAX_QASM_CHARS 1000000 Emitted program size
FLAGQUANTUM_MCP_MAX_COMPARE_TOPOLOGIES 4 Topologies per comparison

Errors

Tools do not raise across the MCP boundary. A failure comes back as:

{"status": "error", "error": {"code": "LIMIT_EXCEEDED", "message": "..."}}

Codes: INVALID_INPUT, LIMIT_EXCEEDED, UNSUPPORTED_FORMAT, SDK_UNAVAILABLE, INTERNAL_ERROR.

What this server deliberately does not do

  • No execution. Nothing runs a circuit, locally or remotely. Planning is plan_execution_tool; running is the caller's step, through fq.run.
  • No hardware, no credentials, no network. FlagQuantum's own release 0.2.0 ships no remote-submission entry point, and this adapter adds none.
  • No noise models. A NoiseModel is a live SDK object rather than a serializable value, and every tool here takes and returns JSON.
  • No in-tree coupling. This package must never be imported by the FlagQuantum repository. That project's long-horizon architecture contract names "the main repository has no production MCP transport dependency" as a retirement condition, and its tests/team/services/test_service_boundaries.py fails if mcp or fastmcp becomes importable on the core path. Keeping the gateway out of tree is what that contract asks for.

Which contracts this rests on

FlagQuantum publishes a frozen stable_exports snapshot (34 names, each with a named verification test) and separately describes flagquantum.compiler as its "stable expert compiler interface". This server uses both, in two tiers:

Tier Surface Tools
Frozen snapshot Circuit, CircuitIR, Instruction, IR_VERSION, ExecutionOptions, ExecutionPlan, plan, … analyze, serialize, deserialize, plan
Public module (__all__) flagquantum.compiler: CouplingMap, optimize, route_to_topology optimize, route, compare
Public submodule (no __all__) flagquantum.compiler.openqasm.emit_openqasm, flagquantum.compiler.qcis.emit_qcis emit_openqasm, emit_qcis

The third tier is the weakest: those two functions are public but are not re-exported from flagquantum.compiler. They are resolved through a helper that turns a relocation into a named error rather than an AttributeError inside a tool call, and tests/test_api_contract.py pins both paths so a move fails the build instead of failing a user.

The dependency is pinned to flagquantum>=0.2,<0.3. It is a version range, never a git URL: a URL in the dependency table makes every environment that installs a different upstream revision unresolvable.

Development

python3 -m venv .venv
.venv/bin/python -m pip install -e ".[dev]"
.venv/bin/ruff check .
.venv/bin/ruff format --check .
.venv/bin/mypy --config-file ../mypy.ini src
.venv/bin/pytest -m "not integration"

See the repository README and CONTRIBUTING.md.

License

Apache-2.0.

Release files for flagquantum-mcp-server 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flagquantum-mcp-server 0.1.0
File Size Uploaded
flagquantum_mcp_server-0.1.0.tar.gz 35.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flagquantum-mcp-server 0.1.0
File Interpreter ABI Platform
flagquantum_mcp_server-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 67.1 kB

Release files / flagquantum_mcp_server-0.1.0.tar.gz

Download URL flagquantum_mcp_server-0.1.0.tar.gz
Size 35.4 kB
Tags Source
SHA-256 checksum
How to use checksums
720962959c18c5474d04b069d7d5fd23cbe3e8d2b16ac8415a16ebeaee49aff1
BLAKE2b-256 checksum
How to use checksums
c26b286d786d18299316d8da9b52ff4bac758eccd579ff13711f35d72577553c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / flagquantum_mcp_server-0.1.0-py3-none-any.whl

Download URL flagquantum_mcp_server-0.1.0-py3-none-any.whl
Size 31.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b664d2d1dce44f0a00cd80035d1cae4077fd4d74a81ebf81b5557e2d0b44cdc6
BLAKE2b-256 checksum
How to use checksums
c0f88e135c1757f40a3617bd2a0734226b0f03146affe7fd816a5f23542a0a0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page