Skip to main content
Glama
README.md
<div align="center">

# ◆ QuantConnect MCP Server

[![Python](https://img.shields.io/badge/Python-3.12%2B-blue.svg)](https://python.org)
[![FastMCP](https://img.shields.io/badge/FastMCP-4.x-green.svg)](https://gofastmcp.com)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![PyPI Downloads](https://static.pepy.tech/badge/quantconnect-mcp)](https://pepy.tech/projects/quantconnect-mcp)

**Give your AI assistant the QuantConnect cloud: write LEAN algorithms, compile, backtest, optimize, and manage live trading through the Model Context Protocol.**

</div>

<details open>
<summary>Demo: Claude</summary>

<div align="center">
  <video width="832" src="https://github.com/user-attachments/assets/61e96e0e-05b2-482b-8fe3-ccf078d64cc5"></video>
</div>

</details>

## ◈ What it does

61 tools that cover the [QuantConnect REST API v2](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference):

- **Research loop**: create projects and files, check syntax, compile (the tool waits for the build), backtest, and read statistics, orders, insights, charts, and full reports.
- **Optimization**: estimate cost, then run grid-search parameter sweeps on typed parameter ranges and constraints.
- **Live trading**: deploy, monitor portfolio, orders, logs, and charts, send commands, liquidate, and stop.
- **Object Store**: list, inspect, upload, download, and delete organization data.
- **LEAN coding help**: QuantConnect's AI tools for syntax checks, error explanations, documentation search, and code completion.

Every request is validated in CI against QuantConnect's published OpenAPI spec.

## ◈ Quick start

You need [uv](https://docs.astral.sh/uv/) (it fetches Python 3.12+ and the server for you) and a QuantConnect account.

1. Get your **User ID** and **API token** from [quantconnect.com/settings](https://www.quantconnect.com/settings/).
2. Add the server to your MCP client. For Claude Desktop, Claude Code, Cursor, and most clients:

```json
{
  "mcpServers": {
    "quantconnect": {
      "command": "uvx",
      "args": ["quantconnect-mcp"],
      "env": {
        "QUANTCONNECT_USER_ID": "123456",
        "QUANTCONNECT_API_TOKEN": "your-api-token"
      }
    }
  }
}
```

With Claude Code you can run `claude mcp add quantconnect -e QUANTCONNECT_USER_ID=123456 -e QUANTCONNECT_API_TOKEN=your-api-token -- uvx quantconnect-mcp`.

3. Ask for something: *"Create a Python project with an EMA crossover on SPY, backtest it over 2020 to 2024, and summarize the Sharpe ratio and drawdown."*

### Claude Desktop extension

The 1.0 release does not ship a prebuilt `.dxt`, and the bundles attached to 0.x releases contain the old server, so build it from a checkout:

```bash
git clone https://github.com/taylorwilsdon/quantconnect-mcp && cd quantconnect-mcp
npx @anthropic-ai/dxt pack . quantconnect-mcp.dxt
```

Double-click the file and enter your credentials under **Settings > Extensions > QuantConnect MCP**. The extension starts the server with `uv run`, so uv must be installed.

## ◈ Configuration

All settings come from environment variables. Credentials are never accepted through tool calls, so they stay out of model transcripts.

The server does not read a `.env` file on its own, because MCP clients start it from inside your project and that project's `.env` is not meant for it. To keep settings in a file, copy [`.env.example`](.env.example) and pass it explicitly, for example `uv run --env-file .env quantconnect-mcp`.

| Variable | Default | Purpose |
|----------|---------|---------|
| `QUANTCONNECT_USER_ID` | required | Your QuantConnect user ID |
| `QUANTCONNECT_API_TOKEN` | required | Your QuantConnect API token |
| `QUANTCONNECT_ORGANIZATION_ID` | your preferred org | Organization for new projects, the Object Store, and broadcasts |
| `QUANTCONNECT_API_URL` | `https://www.quantconnect.com/api/v2/` | API base URL; change it only to point at a proxy or mock |
| `REQUEST_TIMEOUT` | `60` | Seconds to wait for a QuantConnect response |
| `MCP_TRANSPORT` | `stdio` | `stdio` or `streamable-http` |
| `MCP_HOST` | `127.0.0.1` | HTTP bind address |
| `MCP_PORT` | `8000` | HTTP port |
| `MCP_PATH` | `/mcp` | HTTP endpoint path |
| `MCP_AUTH_TOKEN` | unset | Bearer token that HTTP clients must send |
| `LOG_LEVEL` | `INFO` | `DEBUG`, `INFO`, `WARNING`, or `ERROR` (logs go to stderr) |

Blank optional variables count as unset. If a required variable is missing or a value is invalid, the server exits at startup and names the offending variables.

The API client keeps one pooled connection, retries failed connections, and retries once on HTTP 429 after waiting for `Retry-After` (capped at 30 seconds).

## ◈ Security model

These tools can deploy algorithms and liquidate positions on real brokerage accounts. The server is built around that fact:

- **Credentials** live only in the server environment and are held as secrets in memory.
- **HTTP transport** binds to `127.0.0.1` by default. Binding anywhere else requires `MCP_AUTH_TOKEN`, or the server refuses to start. Clients send `Authorization: Bearer <token>`.
- **Tool annotations** mark every tool as read-only, mutating, or destructive, so clients can require confirmation for deletes, liquidation, live deployment, and live commands.
- **Errors** come back as proper MCP tool errors with QuantConnect's message. Unexpected internal failures are masked.

### Running over HTTP

```bash
export MCP_AUTH_TOKEN=$(openssl rand -hex 32)
MCP_TRANSPORT=streamable-http uvx quantconnect-mcp
```

The endpoint is `http://127.0.0.1:8000/mcp`. Point a client at it with the token:

```json
{
  "mcpServers": {
    "quantconnect": {
      "type": "http",
      "url": "http://127.0.0.1:8000/mcp",
      "headers": { "Authorization": "Bearer your-mcp-auth-token" }
    }
  }
}
```

### Docker

```bash
docker build -t quantconnect-mcp .
docker run -p 8000:8000 \
  -e QUANTCONNECT_USER_ID -e QUANTCONNECT_API_TOKEN -e MCP_AUTH_TOKEN \
  quantconnect-mcp
```

The image serves HTTP on `0.0.0.0:8000` as a non-root user, so it will not start without `MCP_AUTH_TOKEN`.

## ◈ Tools

| Area | Tools |
|------|-------|
| Account | `validate_quantconnect_auth`, `get_auth_status`, `read_account`, `read_lean_versions`, `authorize_connection` |
| Projects | `create_project`, `read_project`, `update_project`, `delete_project`, `create_project_collaborator`, `read_project_collaborators`, `update_project_collaborator`, `delete_project_collaborator`, `read_project_nodes`, `update_project_nodes` |
| Files | `create_file`, `read_file`, `update_file_content`, `update_file_name`, `delete_file` |
| Compile | `compile_project`, `read_compilation_result` |
| Backtests | `create_backtest`, `read_backtest`, `list_backtests`, `read_backtest_chart`, `read_backtest_orders`, `read_backtest_insights`, `read_backtest_report`, `update_backtest`, `delete_backtest` |
| Optimizations | `estimate_optimization_time`, `create_optimization`, `read_optimization`, `list_optimizations`, `update_optimization`, `abort_optimization`, `delete_optimization` |
| Live trading | `create_live_algorithm`, `read_live_algorithm`, `list_live_algorithms`, `read_live_logs`, `read_live_chart`, `read_live_portfolio`, `read_live_orders`, `read_live_insights`, `liquidate_live_algorithm`, `stop_live_algorithm`, `create_live_command`, `broadcast_live_command` |
| Object Store | `list_object_store`, `read_object_store_properties`, `get_object_store_download`, `upload_object_store_object`, `delete_object_store_object` |
| LEAN coding help | `check_syntax`, `initialize_backtest`, `enhance_error`, `search_quantconnect`, `complete_code`, `convert_to_pep8` |

Each tool returns QuantConnect's response payload. A few behaviors are worth knowing:

- **Compiling**: `compile_project` polls until the build reaches `BuildSuccess` or `BuildError` and reports progress. After about two minutes it fails with the compile ID so you can check later with `read_compilation_result`. Pass `wait=false` to return immediately.
- **Paging**: page limits are enforced before the request is sent. Backtest orders and all insights allow 99 items per call, live orders 1,000, and live logs 250 lines. `end` is exclusive.
- **Charts**: `read_backtest_chart` and `read_live_chart` need `start` and `end` as Unix timestamps. Charts, orders, and reports can answer with a loading status while QuantConnect generates them; call again.
- **Optimizations**: grid search only. `target` and constraints use `SharpeRatio`, `CompoundingAnnualReturn`, `ProbabilisticSharpeRatio`, or `Drawdown`. `create_optimization` spends QuantConnect Credit and needs the `estimated_cost` from `estimate_optimization_time`.
- **Live deployment**: `create_live_algorithm` takes a `brokerage` object with an `id`, for example `{"id": "QuantConnectBrokerage"}` for paper trading. `authorize_connection` returns an OAuth URL for Alpaca, TradeStation, Charles Schwab, or tastytrade that a person must open in a browser.
- **Object Store**: uploads store text. Downloads take two steps: call `get_object_store_download` with `keys` to start a job, then with the returned `job_id` until the response has a URL.

## ◈ Upgrading from 0.x

1.0 is a rewrite on FastMCP 4. Tool names are unchanged except as noted below; see [CHANGELOG.md](CHANGELOG.md) for every signature change.

- Removed `configure_quantconnect_auth`, `clear_quantconnect_auth`, `test_quantconnect_api`, and `get_auth_headers_info`. Set credentials through the environment; the server no longer starts without them.
- HTTP now binds to `127.0.0.1` instead of `0.0.0.0`, and any other bind address requires `MCP_AUTH_TOKEN`. Existing Docker and remote deployments must set a token and send it as a bearer header.
- `MCP_TRANSPORT` accepts only `stdio` and `streamable-http`. The generic `PORT` variable is no longer read; set `MCP_PORT`.
- The entry point moved from `quantconnect_mcp.main` to `quantconnect_mcp.server`. The `quantconnect-mcp` command is unchanged, and `python -m quantconnect_mcp` now works.
- Failed calls now return MCP errors instead of `{"status": "error"}` payloads, and successful calls return the API payload directly.
- Optimization tools take typed `parameters` (`name`, `min`, `max`, `step`), a `target`, and a `target_to`.
- `create_live_algorithm` takes one `brokerage` object in place of `brokerage_id` and `brokerage_config`, `update_file_name` takes `name` and `new_name`, and `update_project_collaborator` requires both `write` and `live_control`.
- New tools: the Object Store, the LEAN coding help set, `read_backtest_report`, `read_lean_versions`, `create_live_command`, and `broadcast_live_command`.
- The install is much smaller: pandas, numpy, scipy, scikit-learn, matplotlib, and the other unused scientific packages are gone. Runtime dependencies are fastmcp, httpx2, pydantic, and pydantic-settings.
- The analytics features previously described in this README (PCA, cointegration, universe screening, portfolio optimization) were never implemented and are no longer advertised.

## ◈ Development

```bash
git clone https://github.com/taylorwilsdon/quantconnect-mcp && cd quantconnect-mcp
uv sync
uv run pytest            # tool, client, server, and OpenAPI contract tests
uv run ruff check && uv run ruff format --check
uv run mypy              # strict
uv run pre-commit install   # optional: run ruff and mypy on commit
```

CI runs the same checks on Python 3.12 and 3.13.

The layout is small on purpose:

```
quantconnect_mcp/
  settings.py   configuration (pydantic-settings)
  client.py     signed, pooled QuantConnect API client
  server.py     FastMCP server, bearer auth, entry point
  tools/        one module per API area, one short function per tool
```

To add a tool, write an async function in the matching `tools/` module, decorate it with `@tool(annotations=...)`, take `qc: QuantConnectClient = CLIENT`, add it to that module's `TOOLS`, and add a row to `tests/cases.py`. The contract test checks the payload against `tests/fixtures/quantconnect-openapi.yaml`, which is vendored from [QuantConnect/Documentation](https://github.com/QuantConnect/Documentation).

To release, run `uv run release.py`: it bumps the version in `pyproject.toml`, `manifest.json`, and `uv.lock`, tags, pushes, and drafts a GitHub release. Publishing that draft triggers the workflow that uploads to PyPI through trusted publishing.

## ◈ License

MIT. See [LICENSE](LICENSE).

TDQS

B3.4/5.0

Scored across 50 tools

Disambiguation4/5

Most tools have distinct purposes targeting specific resources (projects, backtests, optimizations, live algorithms, files, collaborators, authentication) with clear action verbs. However, some overlap exists between read_backtest and read_backtest_chart/read_backtest_insights/read_backtest_orders, which could cause confusion about which tool to use for specific backtest data retrieval.

Naming Consistency5/5

Excellent consistency throughout with a clear verb_noun pattern (create_project, read_backtest, update_file_content, delete_optimization, list_live_algorithms). All tools use snake_case exclusively, and verbs are appropriately chosen for their operations (create, read, update, delete, list, abort, authorize, configure, etc.).

Tool Count2/5

With 50 tools, this is an extremely large surface that feels heavy and overwhelming for the QuantConnect domain. While the domain is complex (algorithm development, backtesting, optimization, live trading), many tools could potentially be consolidated (e.g., multiple backtest/live read operations) or organized differently. The count will likely cause cognitive overload for agents.

Completeness5/5

The tool surface provides comprehensive coverage of the QuantConnect platform, including full CRUD operations for projects, files, backtests, optimizations, live algorithms, and collaborators. It covers authentication management, compilation, deployment, monitoring, and data retrieval across all major workflow stages with no apparent gaps.

Maintenance

ActivityMaintained
ResponsivenessLimited data