Skip to content

Fix double-quoted error messages in KeyError handlers #6

@DeDuckProject

Description

@DeDuckProject

Summary

When a tool call fails due to an unknown circuit_id, the error field in the JSON response contains extra quotes:

{"success": false, "error": "\"No circuit found with id 'abc'\"}

Expected:

{"success": false, "error": "No circuit found with id 'abc'"}

Root Cause

All KeyError handlers across the tool modules use str(exc) to serialize the exception:

except KeyError as exc:
    return json.dumps({"success": False, "error": str(exc)})

str(KeyError("message")) returns the repr of its first argument, which adds surrounding quotes to strings. Using exc.args[0] instead returns the raw message.

Affected Files

  • src/stim_mcp_server/tools/circuit_management.py
  • src/stim_mcp_server/tools/simulation.py
  • src/stim_mcp_server/tools/analysis.py
  • src/stim_mcp_server/tools/visualization.py

Fix

Replace str(exc) with exc.args[0] in every except KeyError handler, e.g.:

except KeyError as exc:
    return json.dumps({"success": False, "error": exc.args[0]})

Notes

  • Pre-existing issue (present in original server.py before modularization)
  • Non-blocking: existing tests pass because the circuit_id substring is still present inside the quoted string
  • Found during QA of feature/generate-circuit-modularize

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions