Skip to main content
Glama

create_circuit

Create a quantum circuit using a preset (bell, ghz_3, superposition, deutsch_jozsa, random_4) or by providing an OpenQASM 2.0 string.

Instructions

Create a quantum circuit from a named preset or an OpenQASM 2.0 string. Provide exactly one of: preset (bell|ghz_3|superposition|deutsch_jozsa|random_4) or qasm.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
presetNo
qasmNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function that executes the create_circuit tool logic. Accepts a 'preset' name or a 'qasm' string, builds a QuantumCircuit, stores it, and returns its ID, qubit count, and name.
    def create_circuit(preset: str | None = None, qasm: str | None = None) -> str:
        if (preset is None) == (qasm is None):
            return json.dumps(mcp_error("Provide exactly one of 'preset' or 'qasm'"))
    
        if preset is not None:
            try:
                circuit = get_preset(preset)
                name = preset
            except PresetNotFoundError as e:
                return json.dumps(mcp_error(str(e)))
        else:
            try:
                circuit = qasm2.loads(qasm)
                name = "custom"
            except Exception as e:
                return json.dumps(mcp_error(f"QASM parse error: {e}"))
    
        circuit_id = store_circuit(circuit)
        return json.dumps({"circuit_id": circuit_id, "n_qubits": circuit.num_qubits, "name": name})
  • Registration of create_circuit as an MCP tool on the FastMCP server with a description explaining the two modes (preset or OpenQASM 2.0).
    mcp.tool(
        description=(
            "Create a quantum circuit from a named preset or an OpenQASM 2.0 string. "
            "Provide exactly one of: preset (bell|ghz_3|superposition|deutsch_jozsa|random_4) or qasm."
        )
    )(create_circuit)
  • Preset circuit definitions (bell, ghz_3, superposition, deutsch_jozsa, random_4) and the get_preset lookup function used by create_circuit.
    import logging
    import numpy as np
    from qiskit import QuantumCircuit
    
    logger = logging.getLogger(__name__)
    
    
    class PresetNotFoundError(Exception):
        """Raised when preset name is not in the registry."""
    
    
    def bell() -> QuantumCircuit:
        circuit = QuantumCircuit(2, 2)
        circuit.h(0)
        circuit.cx(0, 1)
        circuit.measure([0, 1], [0, 1])
        return circuit
    
    
    def ghz_3() -> QuantumCircuit:
        circuit = QuantumCircuit(3, 3)
        circuit.h(0)
        circuit.cx(0, 1)
        circuit.cx(1, 2)
        circuit.measure([0, 1, 2], [0, 1, 2])
        return circuit
    
    
    def superposition() -> QuantumCircuit:
        circuit = QuantumCircuit(1, 1)
        circuit.h(0)
        circuit.measure(0, 0)
        return circuit
    
    
    def deutsch_jozsa() -> QuantumCircuit:
        circuit = QuantumCircuit(3, 3)
        circuit.x(2)
        circuit.h([0, 1, 2])
        circuit.cz(0, 2)
        circuit.cz(1, 2)
        circuit.h([0, 1])
        circuit.measure([0, 1, 2], [0, 1, 2])
        return circuit
    
    
    def random_4() -> QuantumCircuit:
        rng = np.random.default_rng(seed=42)
        circuit = QuantumCircuit(4, 4)
        for q in range(4):
            circuit.rx(float(rng.uniform(0, 2 * np.pi)), q)
            circuit.ry(float(rng.uniform(0, 2 * np.pi)), q)
        circuit.cx(0, 1)
        circuit.cx(2, 3)
        circuit.cx(1, 2)
        circuit.measure([0, 1, 2, 3], [0, 1, 2, 3])
        return circuit
    
    
    _PRESETS = {
        "bell": bell,
        "ghz_3": ghz_3,
        "superposition": superposition,
        "deutsch_jozsa": deutsch_jozsa,
        "random_4": random_4,
    }
    
    
    def get_preset(name: str) -> QuantumCircuit:
        if name not in _PRESETS:
            raise PresetNotFoundError(
                f"Unknown preset: {name!r}. Available: {list(_PRESETS)}"
            )
        return _PRESETS[name]()
  • In-memory circuit store used by create_circuit to save the built QuantumCircuit and return a unique circuit_id.
    import uuid
    import logging
    from qiskit import QuantumCircuit
    
    logger = logging.getLogger(__name__)
    
    _circuits: dict[str, QuantumCircuit] = {}
    
    
    class CircuitNotFoundError(Exception):
        """Raised when circuit_id is not found in the store."""
    
    
    def store_circuit(circuit: QuantumCircuit) -> str:
        circuit_id = str(uuid.uuid4())
        _circuits[circuit_id] = circuit
        logger.debug("stored circuit %s (%d qubits)", circuit_id, circuit.num_qubits)
        return circuit_id
    
    
    def get_circuit(circuit_id: str) -> QuantumCircuit:
        if circuit_id not in _circuits:
            raise CircuitNotFoundError(f"Circuit not found: {circuit_id!r}")
        return _circuits[circuit_id]
  • The mcp_error helper used by create_circuit to format error responses as JSON.
    def mcp_error(message: str) -> dict[str, bool | str]:
        logger.warning("mcp_error: %s", message)
        return {"isError": True, "content": message}
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry full burden. It only states 'create', which implies mutation, but does not disclose side effects, permissions, rate limits, or whether the operation is reversible. Minimal behavioral context beyond the action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, front-loaded with purpose, and contains no unnecessary words. Every sentence adds value, making it highly concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that an output schema exists (implied), the description need not explain return values. It covers the essential parameter modes and preset list. However, it lacks error handling guidance (e.g., what happens if both or neither are provided) and interaction with sibling tools, but the description remains adequate for a simple creation tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 0% description coverage, so the description compensates by specifying that exactly one parameter must be provided and listing the preset options. It clarifies that qasm is an OpenQASM 2.0 string, adding semantic value. However, it does not detail the format or constraints further.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool creates a quantum circuit from a named preset or an OpenQASM 2.0 string, listing specific preset options. This distinguishes it from siblings (run_simulation, visualize_circuit) which perform different actions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for circuit creation but does not explicitly state when to use this tool over alternatives or provide exclusions. It lacks guidance on prerequisites or context for using presets versus QASM.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Narashiman24/qiskit-sim-mcp-demo'

If you have feedback or need assistance with the MCP directory API, please join our Discord server