Skip to content

MCP Setup via an AI Agent

Connect DQC to Codex, Claude Code, Cursor, or another MCP client by pasting one prompt into your agent.

LOCAL MCP SERVER

Let your agent handle setup

It checks your Python environment, installs missing dependencies, connects DQC, and verifies the tools are ready.

Copy, paste into your agent, and send.

Your agent checks for an existing DQC installation automatically.

View the full setup prompt
## Task: install and connect the memq-dqc MCP server

You are setting up the memq-dqc MCP server for the user. memq-dqc is a
Python library for distributed quantum compilation (PyPI package
`memq-dqc`). Its MCP server ships as the optional `mcp` extra and runs
locally over stdio via the `memq-dqc-mcp` command.

Work through the steps in order. Run the commands yourself; do not ask the
user to run them. Keep narration brief: one short progress sentence, then a
short final summary of the environment, server command, and verification.
Do not print full config files, dependency logs, or documentation. Show the
relevant command and error if something fails. Tool output may still be
visible in the client's interface; do not repeat it in your prose.

### Rules

- Web browsing is not required. For Codex, Claude Code, and Cursor, use the
  client-specific instructions below and local CLI `--help` if needed.
  Do not browse the web or fetch external documentation for this setup.
  Package managers may download the required packages and dependencies.
- Never use `sudo`, and never install into the system Python.
- Ask the user before installing `uv` or any other tool.
- When editing a client config file, back it up first and merge the new
  entry into it. Never remove or overwrite other entries.
- If a step fails in a way this file does not cover, stop and tell the user
  what failed, including the command and its output.
- Use the paths and shell for the user's OS. On Windows, executables live in
  `Scripts\` with an `.exe` suffix rather than in `bin/`.

### Step 1: MCP client

The user selected Codex. Set up this client only.

### Step 2: Detect an existing installation

Check for an existing installation yourself; do not first ask the user
whether memq-dqc is installed.

1. If memq-dqc tools are already available, call `list_algorithms`. If it
   succeeds, report that DQC is connected and stop without changing config.
2. Inspect only the selected client's memq-dqc configuration entry. If
   present, test its configured command and arguments with `--help`. Reuse
   a working server, including a development installation or uvx command.
3. If the user supplied an environment or executable path, check that first.
   Otherwise check the current project's `.venv`, the active Python
   environment, `python`/`python3` on PATH, and an existing `~/.memq-dqc`
   virtualenv. Do not scan unrelated directories or print environment
   variables or credentials. For each available interpreter, run:

```bash
<python> -c "import sys, importlib.metadata as m; print(sys.executable); print(m.version('memq-dqc'))"
```

If a single suitable installation is found, follow Path A. Prefer the
configured server or user-specified environment over other candidates.
Ask which environment to use only if multiple candidates remain ambiguous.
If none is found, follow Path B.

memq-dqc needs Python 3.11 or newer. Check `<python> --version` before
installing into an environment.

### Path A: memq-dqc is already installed

Find the absolute path of the server executable:

```bash
<python> -c "import sysconfig; print(sysconfig.get_path('scripts'))"
```

The server is `<that directory>/memq-dqc-mcp`. Test it:

```bash
<absolute path>/memq-dqc-mcp --help
```

If this works, reuse it without installing or upgrading anything. Clients
launch the absolute command without activating the environment.

If the server or MCP dependency is missing, add the extra to that same
virtualenv. For a PyPI installation:

```bash
<python> -m pip install --upgrade "memq-dqc[mcp]"
```

For a uv-managed project, use `uv add "memq-dqc[mcp]"`. For an editable
local checkout, preserve the development installation and add the MCP
extra from that checkout rather than replacing it with a PyPI release.
Never install into system Python; use Path B's isolated environment instead.
Re-test the server's `--help` after any install.

The client command is the absolute server path, with no arguments.
Go to Step 3.

### Path B: memq-dqc is not installed

Check for uv with `uv --version`.

**If uv is available**, use `uvx`, which needs no install into the user's
Python. Run this once to download and cache everything; it can take a
minute or two, and doing it now keeps the client from timing out on first
launch:

```bash
uvx --from "memq-dqc[mcp]" memq-dqc-mcp --help
```

The client command is `uvx` with the arguments
`--from memq-dqc[mcp] memq-dqc-mcp`. Go to Step 3.

**If uv is not available**, ask the user which they prefer:

1. Install uv (see https://docs.astral.sh/uv/getting-started/installation/),
   then follow the uv instructions above.
2. Use a dedicated virtualenv instead. With a Python 3.11+ interpreter:

    ```bash
    python3 -m venv ~/.memq-dqc
    ~/.memq-dqc/bin/python -m pip install "memq-dqc[mcp]"
    ~/.memq-dqc/bin/memq-dqc-mcp --help
    ```

    The client command is the absolute path of
    `~/.memq-dqc/bin/memq-dqc-mcp` with `~` expanded, and no arguments.

### Step 3: Register the server in Codex

Use the server name `memq-dqc` and the command and arguments from Path A or
Path B. Back up the existing Codex config (normally `~/.codex/config.toml`,
or `config.toml` in the configured CODEX_HOME directory) before registration.
Check `codex mcp list` first. If an entry named memq-dqc already exists,
inspect it and reuse it if correct; ask before replacing a different entry.
Preserve every other configured server.

```bash
codex mcp add memq-dqc -- <command> <args...>
```

### Step 4: Verify in Codex

Run `codex mcp list` and `codex mcp get memq-dqc` to confirm the registered
stdio command. Restart the Codex session to load the server, then check
`/mcp` and call the memq-dqc `list_algorithms` tool to verify it responds.
If a new session is required, explain that handoff rather than claiming
that the current session already has the tools.

### Present setup and results

Once installation and registration have succeeded, print this banner once
in the user-facing terminal. Color only the three small memQ lines purple
with ANSI `\033[35m`, then reset with `\033[0m` before DQC.
Use the already available Python interpreter to print it; do not install
figlet or another dependency. Keep ANSI codes out of MCP server stdout.
If terminal output is unavailable or does not support color, show the
plain banner once in your final response as a fenced text block instead.

```text
        ▄ ▄ ▄  ▄▄▄  ▄ ▄ ▄  ▄▄▄
        █▀█▀█  █▄   █▀█▀█  █ █
        █ █ █  █▄▄  █ █ █  ▀▀█▄

██████╗    ██████╗   ██████╗
██╔══██╗  ██╔═══██╗ ██╔════╝
██║  ██║  ██║   ██║ ██║
██║  ██║  ██║▄▄ ██║ ██║
██████╔╝  ╚██████╔╝ ╚██████╗
╚═════╝    ╚══▀▀═╝   ╚═════╝
```

Follow it with a compact Markdown table showing the Python environment,
server executable, and verified status. Distinguish "Registered; restart
required" from "Connected; tool call verified". Do not claim connectivity
until an actual MCP tool call succeeds. If setup fails, show the error
instead of the success banner. End with the next step and one prompt:
"Use memq-dqc to compile qft_n10 on 10_qubits/n2_pair_nn and report the
e-bit cost."

For subsequent DQC requests, keep results easy to scan:

- Use a short summary table for compilation, verification, and scheduling.
  Include only returned values: partitioner, e-bit cost, verification
  method/result, makespan with documented units, and saved files as relevant.
- Use one row per partitioner in comparisons, showing e-bit cost,
  makespan, and status. Retain failed rows with their error rather than
  inventing results. Note that randomized methods can vary.
- Save circuit and schedule outputs to files instead of dumping long QASM
  or JSON into the conversation, unless the user asks to see them.
- Keep explanations to one or two sentences. Describe statevector
  verification as an ideal measured-output distribution check and
  schedules as timing estimates.

### Troubleshooting

| Symptom | Fix |
|---|---|
| `memq-dqc ... does not provide the extra 'mcp'` | The installed release predates the MCP server. Re-run the install with `--upgrade`. |
| `Requires-Python >=3.11` or a resolver error naming Python | The environment's Python is too old. Use a 3.11+ interpreter. |
| The client times out the first time it starts the server | Run the `--help` command from Path A or B once, then restart the client. |
| The `hypergraph` partitioner fails on Windows | Expected. KaHyPar has no Windows build; every other partitioner works. |