book
Checkout our new book! Hands on AI Trading with Python, QuantConnect, and AWS Learn More arrow

MCP Server

Key Concepts

Introduction

The QuantConnect Model Context Protocol (MCP) server is a bridge that connects the QuantConnect API to an MCP client application on your local machine. With this setup, you can prompt a Large Language Model (LLM) and have it interact with our API on your behalf. This server equips the LLM with tools to create projects, run backtests, deploy live algorithms, and more. Our MCP integration can supercharge your existing workflow on QuantConnect and can even unlock quant trading to non-programmers. Simply prompt the LLM in layperson language and let it do the heavy lifting for you.

Example Conversation

The following example conversation with Claude Desktop demonstrates how the server equips an LLM with the ability to create trading strategies, backtest them, and deploy them to live trading:

Getting Started

To connect local MCP client applications (like Claude Desktop) to the QC MCP Server, see the Getting Started guide for one of the supported MCP clients.

Tools

The server provides the following tools:

Account

  • read_account - Read the organization account status.

Projects

  • create_project - Create a new project in your default organization.
  • read_project - List the details of a project or a set of recent projects.
  • list_projects - List the details of all projects.
  • update_project - Update a project's name or description.
  • delete_project - Delete a project.

Project Collaboration

  • create_project_collaborator - Add a collaborator to a project.
  • read_project_collaborators - List all collaborators on a project.
  • update_project_collaborator - Update collaborator information in a project.
  • delete_project_collaborator - Remove a collaborator from a project.
  • lock_project_with_collaborators - Lock a project so you can edit it.

Project Nodes

  • read_project_nodes - Read the available and selected nodes of a project.
  • update_project_nodes - Update the active state of the given nodes to true.

Compile

  • create_compile - Asynchronously create a compile job request for a project.
  • read_compile - Read a compile packet job result.

Files

  • create_file - Add a file to a given project.
  • read_file - Read a file from a project, or all files in the project if no file name is provided.
  • update_file_name - Update the name of a file.
  • update_file_contents - Update the contents of a file.
  • patch_file - Apply a patch (unified diff) to a file in a project.
  • delete_file - Delete a file in a project

Backtests

  • create_backtest - Create a new backtest request and get the backtest Id.
  • read_backtest - Read the results of a backtest.
  • list_backtests - List all the backtests for the project.
  • read_backtest_chart - Read a chart from a backtest.
  • read_backtest_orders - Read out the orders of a backtest.
  • read_backtest_insights - Read out the insights of a backtest.
  • update_backtest - Update the name or note of a backtest.
  • delete_backtest - Delete a backtest from a projec

Optimization

  • estimate_optimization_time - Estimate the execution time of an optimization with the specified parameters.
  • create_optimization - Create an optimization with the specified parameters.
  • read_optimization - Read an optimization.
  • list_optimizations - List all the optimizations for a project.
  • update_optimization - Update the name of an optimization.
  • abort_optimization - Abort an optimization.
  • delete_optimization - Delete an optimization.

Live Trading

  • authorize_connection - Authorize an external connection with a live brokerage or data provider.
  • create_live_algorithm - Create a live algorithm.
  • read_live_algorithm - Read details of a live algorithm.
  • list_live_algorithms - List all your past and current live trading deployments.
  • read_live_chart - Read a chart from a live algorithm.
  • read_live_logs - Get the logs of a live algorithm.
  • read_live_portfolio - Read out the portfolio state of a live algorithm.
  • read_live_orders - Read out the orders of a live algorithm.
  • read_live_insights - Read out the insights of a live algorithm.
  • stop_live_algorithm - Stop a live algorithm.
  • liquidate_live_algorithm - Liquidate and stop a live algorithm.

Live Commands

  • create_live_command - Send a command to a live trading algorithm.
  • broadcast_live_command - Broadcast a live command to all live algorithms in an organization.

Object Store

  • upload_object - Upload files to the Object Store.
  • read_object_properties - Get Object Store properties of a specific organization and key.
  • read_object_store_file_job_id - Create a job to download files from the Object Store and then read the job Id.
  • read_object_store_file_download_url - Get the URL for downloading files from the Object Store.
  • list_object_store_files - List the Object Store files under a specific directory in an organization.
  • delete_object - Delete the Object Store file of a specific organization and key.

Lean Versions

  • read_lean_versions - Returns a list of LEAN versions with basic information for each version.

MCP Server Versions

  • read_mcp_server_version - Returns the version of the QC MCP Server that's running.
  • read_latest_mcp_server_version - Returns the latest version of the QC MCP Server released.

AI

  • check_initialization_errors - Run a backtest for a few seconds to initialize the algorithm and get initialization errors if any.
  • complete_code - Show the code completion for a specific text input.
  • enhance_error_message - Show additional context and suggestions for error messages.
  • update_code_to_pep8 - Update Python code to follow PEP8 style.
  • check_syntax - Check the syntax of a code.
  • search_quantconnect - Search for content in QuantConnect.

Prompt Ideas

The following prompts are some ideas on how you can leverage the LLM’s knowledge to improve your workflow:

  • Are there any new strategies out there being discussed online?
  • How do you think we can improve the Sharpe ratio of this strategy?
  • Review my live algorithms. Are there any you think we should stop trading?
  • Add Option hedging to my strategy.

Workflow

The MCP integration supports multiple workflows, ranging from exclusively using the LLM for everything all the way to just prompting the LLM to supplement your activity on our other platforms. The following sections contain several examples of common workflows.

LLM-Focused Workflow

An LLM-focused workflow might look like this:

  1. Open Docker Desktop and your MCP client application.
  2. Issue prompts to investigate new trading ideas, create projects, run backtests, analyze backtest performance, and manage live algorithms.
  3. When you’re finished, shut down the client and Docker Desktop.

The advantage of this workflow is it doesn’t require you to be an expert in programming or financial markets. It leverages the knowledge of the pre-trained LLM to fill your knowledge gaps. The downside to this workflow is LLMs aren’t perfect, so you may need to intervene if it starts hallucinating or if it struggles to implement sophisticated trading logic.

Multi-Platform Workflow

A multi-platform workflow might look like this:

  1. Open Cloud Platform, Docker Desktop, and your MCP client application.
  2. Create a new project in the Algorithm Lab and run a backtest.
  3. Prompt the client application to add a trailing stop order to the project.
  4. Deploy an optimization in the Algorithm Lab.
  5. Prompt the client application to interpret the optimization results and offer suggestions for improvement.
  6. When you’re finished, close the Cloud Platform, client application, and Docker Desktop.

The advantage of this workflow is you can continue using the Cloud Platform, Local Platform, and CLI as you usually would while leveraging the power of LLMs to perform tedious tasks and brainstorm solutions.

Quotas

There are no quotas on the QuantConnect API, but the client you use may have quotas. For more information about the quotas, see the Quotas section for one of the supported MCP clients.

Troubleshooting

The following sections explain some issues you may encounter and how to resolve them.

No Tools Available

When you open your MCP client, it can take up to 30 seconds for the MCP server to start up and for the client to connect to it. Before you start entering prompts, check Docker Desktop to ensure the container is running and check the client to ensure it’s connected.

If the client can’t discover the tools after 30 seconds, follow these steps:

  1. Shut down the client application.
  2. If the server doesn’t automatically shut down in Docker Desktop, click the trash icon to shut it down.
  3. Docker Desktop container page showing the MCP server is still running.
  4. Restart the client application.

Connection Error Code -32000

The docker run ... command in the configuration file also accepts a --name option, which sets the name of the Docker container when the MCP Server starts running. If your computer tries to start up two MCP Server containers with the same name, this -32000 error occurs. To avoid the error, remove the --name option and its value from the configuration file. For an example of a working configuration file, see the Getting Started guide for one of the supported MCP clients.

Service Outages

The MCP server relies on the QuantConnect API and the client application. To check the status of the QuantConnect API, see our Status page. To check the status of your client and the LLM, see their status page.

Examples

The following examples demonstrate the MCP server.

Example 1: Hello World

To test the server and client are working and connected, enter the following prompt into the client application:

> Create a QuantConnect project.

The client should call the create_project tool.

Example 2: Search QuantConnect, Create Projects, and Fix Errors

The following video shows this conversation with Claude Desktop in real-time:

Example 3: Brainstorm Ideas, Add Project Descriptions, and Add Collaborators

The following video shows this conversation with Claude Desktop in real-time:

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: