Skip to main content
Glama

visualize_circuit

Retrieve a stored quantum circuit by ID and display it as an interactive HTML diagram with a structured gate list for review and narration.

Instructions

Visualize a stored circuit as HTML and a structured gate list for narration.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
circuit_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the visualize_circuit tool. Retrieves a circuit by ID from the store, renders its text diagram as HTML, extracts gate-level structure (name, qubits, clbits), and returns a JSON dict with HTML and circuit metadata.
    def visualize_circuit(circuit_id: str) -> str:
        try:
            circuit = get_circuit(circuit_id)
        except CircuitNotFoundError as e:
            return json.dumps(mcp_error(str(e)))
    
        html = f"<pre>{str(circuit.draw('text'))}</pre>"
    
        gates = []
        for inst in circuit.data:
            gate: dict = {"name": inst.operation.name,
                          "qubits": [circuit.find_bit(q).index for q in inst.qubits]}
            if inst.clbits:
                gate["clbits"] = [circuit.find_bit(c).index for c in inst.clbits]
            gates.append(gate)
    
        return json.dumps({
            "html": html,
            "circuit": {
                "name": circuit.name,
                "n_qubits": circuit.num_qubits,
                "depth": circuit.depth(),
                "gates": gates,
            },
        })
  • Registers visualize_circuit as an MCP tool on the FastMCP server with a description.
    mcp.tool(
        description="Visualize a stored circuit as HTML and a structured gate list for narration.",
    )(visualize_circuit)
  • Helper function used by visualize_circuit to return an error dict when CircuitNotFoundError occurs.
    def mcp_error(message: str) -> dict[str, bool | str]:
        logger.warning("mcp_error: %s", message)
        return {"isError": True, "content": message}
  • Retrieves a stored QuantumCircuit by ID; raises CircuitNotFoundError if missing.
    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]
Behavior2/5

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

No annotations are provided, and the description does not disclose behavioral traits such as whether the operation is read-only, any side effects, or prerequisites (e.g., circuit must exist). This leaves uncertainty about its safety and failure modes.

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 a single, efficient sentence with no unnecessary words. It front-loads the key action and outputs.

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

Completeness3/5

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

Given the presence of an output schema and no annotations, the description is adequate but incomplete. It fails to specify error conditions, the format of the gate list, or prerequisite existence checks for the circuit.

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

Parameters2/5

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

The single parameter 'circuit_id' has 0% schema description coverage, and the description does not add any meaning beyond the schema's title. No guidance on what constitutes a valid circuit_id or how to obtain it.

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 verb 'visualize' and resource 'stored circuit', and specifies the output as HTML and a gate list for narration. This distinguishes it from siblings 'create_circuit' and 'run_simulation'.

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?

No explicit when-to-use or when-not-to-use guidance is provided. Usage is implied by the context of having a stored circuit to visualize, but alternatives like run_simulation are not differentiated.

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