Skip to main content

MCP server for IBM Quantum computing services through Qiskit IBM Runtime

Project description

Qiskit IBM Runtime MCP Server

A comprehensive Model Context Protocol (MCP) server that provides AI assistants with access to IBM Quantum computing services through Qiskit IBM Runtime. This server enables quantum circuit creation, execution, and management directly from AI conversations.

Features

  • Quantum Backend Management: List and inspect available quantum backends
  • Job Management: Monitor, cancel, and retrieve job results
  • Account Management: Easy setup and configuration of IBM Quantum accounts

Prerequisites

Installation

This project recommends using uv for virtual environments and dependencies management. If you don't have uv installed, check out the instructions in https://docs.astral.sh/uv/getting-started/installation/

Setting up the Project with uv

  1. Initialize or sync the project:

    # This will create a virtual environment and install dependencies
    uv sync
    
  2. Get your IBM Quantum token (if you don't have saved credentials):

  3. Configure your credentials (choose one method):

    Option A: Environment Variable (Recommended)

    # Copy the example environment file
    cp .env.example .env
    
    # Edit .env and add your IBM Quantum API token
    export IBM_QUANTUM_TOKEN="your_token_here"
    

    Option B: Save Credentials Locally

    from qiskit_ibm_runtime import QiskitRuntimeService
    
    # Save your credentials (one-time setup)
    QiskitRuntimeService.save_account(
        channel="ibm_quantum_platform",
        token="your_token_here",
        overwrite=True
    )
    

    This stores your credentials in ~/.qiskit/qiskit-ibm.json

    Option C: Pass Token Directly

    # Provide token when setting up the account
    await setup_ibm_quantum_account(token="your_token_here")
    

    Token Resolution Priority: The server looks for credentials in this order:

    1. Explicit token passed to setup_ibm_quantum_account()
    2. IBM_QUANTUM_TOKEN environment variable
    3. Saved credentials in ~/.qiskit/qiskit-ibm.json

Quick Start

Running the Server

uv run qiskit-ibm-runtime-mcp-server

The server will start and listen for MCP connections.

Basic Usage Examples

Async Usage (MCP Server)

# 1. Setup IBM Quantum Account (optional if credentials already configured)
# Will use saved credentials or environment variable if token not provided
await setup_ibm_quantum_account()  # Uses saved credentials/env var
# OR
await setup_ibm_quantum_account(token="your_token_here")  # Explicit token

# 2. List Available Backends (no setup needed if credentials are saved)
backends = await list_backends()
print(f"Available backends: {len(backends['backends'])}")

# 3. Get the least busy backend
backend = await least_busy_backend()
print(f"Least busy backend: {backend}")

# 4. Get backend's properties
backend_props = await get_backend_properties("backend_name")
print(f"Backend_name properties: {backend_props}")

# 5. List recent jobs
jobs = await list_my_jobs(10)
print(f"Last 10 jobs: {jobs}")

# 6. Get job status
job_status = await get_job_status("job_id")
print(f"Job status: {job_status}")

# 7. Cancel job
cancelled_job = await cancel_job("job_id")
print(f"Cancelled job: {cancelled_job}")

Sync Usage (DSPy, Scripts, Jupyter)

For frameworks that don't support async operations:

from qiskit_ibm_runtime_mcp_server.sync import (
    setup_ibm_quantum_account_sync,
    list_backends_sync,
    least_busy_backend_sync,
    get_backend_properties_sync,
    list_my_jobs_sync,
    get_job_status_sync,
    cancel_job_sync
)

# Optional: Setup account if not already configured
# Will automatically use IBM_QUANTUM_TOKEN env var or saved credentials
setup_ibm_quantum_account_sync()  # No token needed if already configured

# Use synchronously without async/await - no setup needed if credentials saved
backends = list_backends_sync()
print(f"Available backends: {backends['total_backends']}")

# Get least busy backend
backend = least_busy_backend_sync()
print(f"Least busy: {backend['backend_name']}")

# Works in Jupyter notebooks and DSPy agents
jobs = list_my_jobs_sync(limit=5)
print(f"Recent jobs: {len(jobs['jobs'])}")

DSPy Integration Example:

import dspy
import os
from dotenv import load_dotenv
from qiskit_ibm_runtime_mcp_server.sync import (
    setup_ibm_quantum_account_sync,
    list_backends_sync,
    least_busy_backend_sync,
    get_backend_properties_sync
)

# Load environment variables (includes IBM_QUANTUM_TOKEN)
load_dotenv()

# The agent will automatically use saved credentials or environment variables
# No need to explicitly pass tokens to individual functions
agent = dspy.ReAct(
    YourSignature,
    tools=[
        setup_ibm_quantum_account_sync,  # Optional - only if you need to verify setup
        list_backends_sync,
        least_busy_backend_sync,
        get_backend_properties_sync
    ]
)

result = agent(user_request="What QPUs are available?")

API Reference

Tools

setup_ibm_quantum_account(token: str = "", channel: str = "ibm_quantum_platform")

Configure IBM Quantum account with API token.

Parameters:

  • token (optional): IBM Quantum API token. If not provided, the function will:
    1. Check for IBM_QUANTUM_TOKEN environment variable
    2. Use saved credentials from ~/.qiskit/qiskit-ibm.json
  • channel: Service channel (default: "ibm_quantum_platform")

Returns: Setup status and account information

Note: If you already have saved credentials or have set the IBM_QUANTUM_TOKEN environment variable, you can call this function without parameters or skip it entirely and use other functions directly.

list_backends()

Get list of available quantum backends.

Returns: Array of backend information including:

  • Name, status, queue length
  • Number of qubits, coupling map
  • Simulator vs. hardware designation

least_busy_backend()

Get the current least busy IBM Quantum backend available Returns: The backend with the fewest number of pending jobs

get_backend_properties(backend_name: str)

Get detailed properties of specific backend.

Returns: Complete backend configuration including:

  • Hardware specifications
  • Gate set and coupling map
  • Current operational status
  • Queue information

list_my_jobs(limit: int = 10)

Get list of recent jobs from your account.

Parameters:

  • limit: The N of jobs to retrieve

get_job_status(job_id: str)

Check status of submitted job.

Parameters:

  • job_id: The ID of the job to get its status

Returns: Current job status, creation date, backend info

cancel_job(job_id: str)

Cancel a running or queued job.

Parameters:

  • job_id: The ID of the job to cancel

Resources

ibm_quantum://status

Get current service status and connection info.

Security Considerations

  • Store IBM Quantum tokens securely: Never commit tokens to version control
  • Use environment variables for production deployments: Set IBM_QUANTUM_TOKEN environment variable
  • Credential Priority: The server automatically resolves credentials in this order:
    1. Explicit token parameter (highest priority)
    2. IBM_QUANTUM_TOKEN environment variable
    3. Saved credentials in ~/.qiskit/qiskit-ibm.json (lowest priority)
  • Token Validation: The server rejects placeholder values like <PASSWORD>, <TOKEN>, etc., to prevent accidental credential corruption
  • Implement rate limiting for production use: Monitor API request frequency
  • Monitor quantum resource consumption: Track job submissions and backend usage

Contributing

Contributions are welcome! Areas for improvement:

  • Support for Primitives
  • Support for error mitigation/correction/cancellation techniques
  • Other qiskit-ibm-runtime features

Other ways of testing and debugging the server

Note: to launch the MCP inspector you will need to have node and npm

  1. From a terminal, go into the cloned repo directory

  2. Switch to the virtual environment

    source .venv/bin/activate
    
  3. Run the MCP Inspector:

    npx @modelcontextprotocol/inspector uv run qiskit-ibm-runtime-mcp-server
    
  4. Open your browser to the URL shown in the console message e.g.,

    MCP Inspector is up and running at http://localhost:5173
    

Testing

This project includes comprehensive unit and integration tests.

Running Tests

Quick test run:

./run_tests.sh

Manual test commands:

# Install test dependencies
uv sync --group dev --group test

# Run all tests
uv run pytest

# Run only unit tests
uv run pytest -m "not integration"

# Run only integration tests
uv run pytest -m "integration"

# Run tests with coverage
uv run pytest --cov=src --cov-report=html

# Run specific test file
uv run pytest tests/test_server.py -v

Test Structure

  • tests/test_server.py - Unit tests for server functions
  • tests/test_integration.py - Integration tests
  • tests/conftest.py - Test fixtures and configuration

Test Coverage

The test suite covers:

  • ✅ Service initialization and account setup
  • ✅ Backend listing and analysis
  • ✅ Job management and monitoring
  • ✅ Error handling and validation
  • ✅ Integration scenarios
  • ✅ Resource and tool handlers

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qiskit_ibm_runtime_mcp_server-0.1.0.tar.gz (127.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qiskit_ibm_runtime_mcp_server-0.1.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file qiskit_ibm_runtime_mcp_server-0.1.0.tar.gz.

File metadata

File hashes

Hashes for qiskit_ibm_runtime_mcp_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 14a51b8e381908e56260674752237b02bf53ecd855b225183292d4bee75bd8ef
MD5 efc5070c0003d8c813b0acb4b4f7131d
BLAKE2b-256 6d3357cc718a50ae62684a4b970070cd257f1d035a2e0a12bf935fd58ccf8354

See more details on using hashes here.

File details

Details for the file qiskit_ibm_runtime_mcp_server-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for qiskit_ibm_runtime_mcp_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21a31f8d8e75b85131de236fdeb745dfd4ab000918476e87804dff2e639fd434
MD5 fb78a00cd162e8b09834d5a2e6ebac33
BLAKE2b-256 e0f6e4de5d203c3616ae35d8950b550b0b6a4da9b37de8a59fa280d5b39e75a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page