How to set up the Capital.com MCP Server

Have more questions? Submit a request

The Capital.com MCP Server lets you connect an AI assistant – such as Claude Code, Codex, Claude Desktop, Cursor, or Windsurf – to your trading account. Once set up, you can use natural language to analyse markets, check account information, review open positions and working orders, and preview and place trades from your AI assistant.

This guide walks you through each step, from creating your API credentials and installing the server, to connecting your chosen AI assistant and reviewing and confirming each trade before execution. You don’t need to be a developer, but you should feel comfortable following technical instructions. We recommend starting in demo mode before switching to a live account.

What is the Capital.com MCP Server?

The Capital.com MCP (Model Context Protocol) Server is a free, open-source tool that lets you connect an AI assistant to your trading account using your Capital.com API credentials and two-factor authentication (2FA). It acts as a bridge between your account and the AI, so the assistant can access market and account data and respond to your instructions in real time.

Once connected, your AI assistant can:

  • Search available markets (such as forex, shares, commodities, and indices).
  • Show your open positions, working orders, and account information.
  • Pull historical prices and client sentiment data.
  • Preview and execute trades, with explicit confirmation required before execution.

You remain fully responsible for any trading decisions made using the MCP Server. Always review trade previews carefully before confirming.

Which AI assistants can I use?

This guide covers setup for Claude Code, Codex, Claude Desktop, Cursor and Windsurf.

AI assistant Setup difficulty What to expect
Claude Code Easy Runs from Terminal after installation. No config file is needed, but you do need Terminal access.
Codex Easy Set up in Codex settings using the same server command, arguments and environment variables as Claude Desktop.
Claude Desktop Moderate Requires editing one configuration file on your computer
Cursor Moderate Set up in Cursor settings using the same server command, arguments and environment variables as Claude Desktop.
Windsurf Moderate Requires editing one configuration file on your computer.

If you are unsure where to start, Claude Code may be a practical option if you are comfortable using Terminal. Claude Desktop may suit you better if you would prefer to edit a configuration file.

Step 1. Create your API credentials

First, generate API credentials inside your Capital.com account. This may take around two minutes.

  1. Log in to your Capital.com account.
  2. Enable two-factor authentication (2FA).
  3. Go to Settings → API Integrations → Generate New Key.
  4. Give your key a label, for example: MCP Server.
  5. Create a custom API password. This is separate from your usual Capital.com login password.
  6. Enter your 2FA code and generate the key.
  7. Copy the API key immediately. It won’t be shown again.

You will need the following values in the next steps:

Variable name What it is
CAP_API_KEY The API key you generated
CAP_API_PASSWORD The custom API password you created
CAP_IDENTIFIER The email address linked to your Capital.com account
CAP_ENV Set this to demo while testing*

*Practise on a demo account before live trading.

Important: these credentials provide access to your trading account. Keep them private. Don’t share them or paste them into chat interfaces, and don’t store them in public documents. Anyone with access to these details may be able to access your account via the API.

Step 2. Install the Capital.com MCP Server

This is a one-time installation. You have two options – option A is recommended for most users.

Option A. One-click install (recommended)

The MCP Server includes a bundle file that lets Claude Desktop handle the installation for you – no terminal or config file editing required.

Before you begin: make sure uv is installed (for example, via brew install uv on Mac) and that you have Node.js installed for the pack command.

  1. In your terminal, clone the repository and build the bundle:

git clone https://github.com/capital-com-sv/capital-mcp

cd capital-mcp

npx @anthropic-ai/mcpb pack . capital-mcp.mcpb

  1. Open capital-mcp.mcpb by double-clicking it, or drag it into Claude Desktop.
  2. Claude Desktop will prompt you for your API credentials. Enter them, then click ‘Install’.
  3. Restart Claude Desktop and verify the connection by asking: 'What Capital.com tools are available?'
Option B. Manual install

Use this if you prefer not to use the bundle, or if you are connecting to Codex, Cursor, or Windsurf.

Terminal (Mac)

1. Download the server files

cd ~/Desktop

git clone https://github.com/capital-com-sv/capital-mcp

cd capital-mcp

2. Create an isolated Python environment and install dependencies

python3 -m venv venv

source venv/bin/activate

pip install -e ".[dev]"

3. Find your Python path

You’ll need this in the next step:

which python

This should return a file path similar to:

/Users/you/Desktop/capital-mcp/venv/bin/python

Copy and save this path. You’ll paste it into your AI assistant settings in Step 3.

Tip: On Mac, you can drag a file from Finder into the Terminal window to display its full path.

4. Check the server starts correctly

python -m capital_mcp.server

If no errors appear, the installation is complete. If you see an error, resolve it now – error messages are usually easier to diagnose at this stage than inside an AI assistant interface..

Command Prompt (Windows)

  1. Download the server files

cd %USERPROFILE%\Desktop

git clone  https://gitlab.itcapital.io/integrations/capital.com-public-api-mcp.git

cd capital.com-public-api-mcp

This downloads the repository to your Desktop and opens the project folder.

  1. Create a virtual environment and install dependencies

py -m venv venv

venv\Scripts\activate.bat

pip install -e ".[dev]"

This creates a virtual environment to keep the project’s dependencies separate from the rest of your system. Activating it makes sure the packages are installed in that environment.

  1. Find your Python path

You’ll need this in the next step:

where python

You should see something like:

C:\Users\you\Desktop\capital.com-public-api-mcp\venv\Scripts\python.exe

Copy and save this path. You’ll paste it into your AI assistant settings in Step 3.

  1. Check the server starts correctly

python -m capital_mcp.server

If no errors appear, the installation is complete. If you see an error, resolve it now before continuing.

Step 3. Connect your AI assistant

All three AI assistants need the same core information. Collect the following before you begin:

What you need Where to get it
Your venv Python path From the which python or where python command in step 2
Your four API credentials From step 1
Claude Code setup 

In your terminal, run:

claude mcp add capital-com -- /path/to/capital-mcp/venv/bin/python -m capital_mcp.server

Replace /path/to/capital-mcp/venv/bin/python with the Python path you copied in Step 2.

To confirm the connection, ask Claude: 'What Capital.com tools are available?' You should see 36 tools listed.

Codex setup 

Go to Codex → Settings → MCP Servers → Add Server and complete the fields below.

Command

Paste your venv Python path, for example:

/Users/you/Desktop/capital.com-public-api-mcp/venv/bin/python

Arguments

Add these as two separate entries – do not combine them:

  1. -m
  2. capital_mcp.server

Environment variables

Add each variable individually:

Variable Value
CAP_ENV demo
CAP_API_KEY your API key
CAP_IDENTIFIER your email address
CAP_API_PASSWORD your custom API password
CAP_ALLOW_TRADING false

Working directory

Set the working directory to ~/code.

Save your settings and restart Codex.

Type /mcp in the chat – you should see capital-com listed.

To confirm the connection, send these three messages:

Check my Capital.com session status

Login to my Capital.com account

List my accounts

If all three return valid responses, the server is connected correctly.

Claude Desktop setup

Terminal (Mac)

Open Terminal and run the following commands to create the configuration file:

mkdir -p ~/Library/Application\ Support/Claude

nano ~/Library/Application\ Support/Claude/claude_desktop_config.json

Command Prompt (Windows)

Open Command Prompt (CMD) and run:

mkdir "%APPDATA%\Claude"

notepad "%APPDATA%\Claude\claude_desktop_config.json"

Terminal (Mac) and Command Prompt (Windows)

Paste the template below into the file and replace every ALL CAPS placeholder with your actual values:

{

  "mcpServers": {

    "capital-com": {

      "command": "/PASTE/YOUR/VENV/PYTHON/PATH",

      "args": ["-m", "capital_mcp.server"],

      "env": {

        "CAP_ENV": "demo",

        "CAP_API_KEY": "PASTE_API_KEY",

        "CAP_IDENTIFIER": "PASTE_YOUR_EMAIL",

        "CAP_API_PASSWORD": "PASTE_API_PASSWORD",

        "CAP_ALLOW_TRADING": "false",

        "CAP_ALLOWED_EPICS": ""

      }

    }

  }

}

Save the file: press Ctrl + O, then Enter, then Ctrl + X. Restart Claude Desktop.

To confirm the connection, ask Claude: ‘What Capital.com tools are available?’’

You should see 36 tools listed. If fewer tools appear, check the troubleshooting section below.

Cursor setup

Go to Settings → Extensions → MCP → Configure and add:

{

  "capital-com": {

    "command": "/path/to/venv/bin/python",

    "args": ["-m", "capital_mcp.server"],

    "env": {

      "CAP_ENV": "demo",

      "CAP_API_KEY": "your_api_key",

      "CAP_IDENTIFIER": "your_email",

      "CAP_API_PASSWORD": "your_password",

      "CAP_ALLOW_TRADING": "false"

    }

  }

}

Restart Cursor and test the connection with:

List my accounts

If the command returns your account information, the integration is working as expected.

Windsurf setup

Create or edit the file at ~/.windsurf/mcp/servers.json and add:

{

  "mcpServers": {

    "capital-com": {

      "command": "/path/to/capital-mcp/venv/bin/python",

      "args": ["-m", "capital_mcp.server"],

      "env": {

        "CAP_ENV": "demo",

        "CAP_API_KEY": "your_api_key_here",

        "CAP_IDENTIFIER": "your_email@example.com",

        "CAP_API_PASSWORD": "your_custom_password"

      }

    }

  }

}

Replace all placeholder values with your actual credentials from step 1.

Restart Windsurf and test the connection with: ‘List my accounts’.

How to trade with the MCP Server

Every trade placed through the MCP Server follows a mandatory three-step process. The server enforces this process and does not allow you to bypass it.

Step 1 – Preview your trade

Ask your AI assistant to preview a trade. It will return a proposal and a unique preview_id.

Example:

Preview buying 1.5 [instrument] with stop at 24.50

Step 2 –  Review the proposal

Read the details returned by the AI carefully before taking any further action. Check the instrument, size, direction, and risk parameters to ensure they match your intention.

If your requested size is below the broker minimum or above the broker maximum for that instrument, the server will return an error. Adjust the size and create a new preview.

Step 3 –  Confirm execution

If you want to proceed, send a second message to confirm:

Execute position with preview_id abc123 confirm=true

A trade cannot be placed without a valid preview_id from a completed preview. The server requires both steps before execution.

Each preview ID can only be used once. After a trade is confirmed and executed, the preview expires immediately. To place another trade, start a new preview.

Before switching to a live account

Confirm all of the following:

  • All testing completed in demo mode (CAP_ENV = demo).
  • CAP_ALLOW_TRADING kept as false throughout the setup.
  • Session login, account listing, and market data all functioning correctly
  • Full preview and execution flow successfully tested in demo account.
  • You have consciously decided to switch CAP_ENV to live and CAP_ALLOW_TRADING to true.

To restrict which markets the server can trade, add a comma-separated list of instrument codes to CAP_ALLOWED_EPICS. Leave it empty to allow access to all available markets on your account.

Troubleshooting: common errors and fixes {#errors}

Error message Most likely cause How to fix it
Session expired or invalid Using login password instead of your custom API password, or a CAP_ENV mismatch Double-check that CAP_API_PASSWORD is your custom API password. Confirm that CAP_ENV matches your account type (demo or live).
Rate limit exceeded Too many requests sent in a short period Wait 30–60 seconds and try again. If the issue persists, reduce the frequency of automated requests.
zsh: event not found API password contains an exclamation mark (!) Wrap the value in single quotes, for example: 'yourPassword!Here'
Server won't start Installation issue or incorrect Python path Run python -m capital_mcp.server directly in Terminal to view the full error message. Check that your Python path points to the virtual environment (venv), not the system Python installation.
Fewer than 36 tools in Claude Server not starting correctly Run tail -f ~/Library/Logs/Claude/mcp-server-capital-com.log to review the log output. Confirm your Python path points to the venv and that your configuration file contains valid JSON formatting.

What can I ask my AI assistant? 

Once connected, you can get started with some example prompts:

Check your account

Check my session status

Login to my account

List my accounts

Research markets

Search for bitcoin markets

Show me [instrument] market details

Get 1-hour historical prices for [instrument]

What is client sentiment on [instrument]?

Review your portfolio

Show my open positions

List my working orders

Review my portfolio exposure

Place a trade (start in demo mode)

Create a trade proposal for [instrument] with 1% risk

Preview buying 1.5 [instrument] with stop at 24.50

Execute position with preview_id abc-123 confirm=true

Close position DEAL_ID confirm=true

Instrument codes are case-sensitive. Use uppercase epics (e.g. SILVER, not silver) to avoid errors.

Always review trade previews carefully before confirming execution. AI-generated outputs are tools to support your analysis. They do not replace your judgement or remove the risks associated with CFD trading.

FAQ

Do I need a live Capital.com account to use the MCP Server?

No. The MCP Server works with a demo account. You may wish to set up and test in demo mode before connecting to a live account.

Is my Capital.com login password the same as CAP_API_PASSWORD?

No. They are two separate passwords. CAP_API_PASSWORD is a custom password you create when generating your API key. Using your login password in this field is a common setup mistake and will cause authentication to fail.

Can the AI place a trade without my permission?

No. Every trade requires a preview step followed by a separate explicit confirmation message containing confirm=true. The server will not execute a trade without both steps. You must explicitly confirm each trade before execution.

What is CAP_ALLOW_TRADING and should I turn it on?

CAP_ALLOW_TRADING is a setting that controls whether the server can execute trades. Keep it set to false during setup and testing. Only change it to true once you have fully verified the connection in demo mode and understand the risks of live CFD trading.

What does CAP_ALLOWED_EPICS do?

It restricts the server to trading specific instruments. If you leave it empty, all markets available on your account can be accessed. Add a comma-separated list of instrument epic codes to limit trading to selected only.

I set everything up but Claude shows fewer than 36 tools. What is wrong?

The server is not starting correctly. Run tail -f ~/Library/Logs/Claude/mcp-server-capital-com.log to review the log output. Common causes include a JSON syntax error in the configuration file or a Python path pointing to the system Python instead of the virtual environment.

Disclaimer – Use of Capital.com Public API with Third-Party Tools

Third-Party Integration

This page describes how clients may connect the Capital.com Public API to third-party software, tools, or integrations, including those powered by artificial intelligence or large language models ('LLMs'). Any such third-party software, tool, or integration is independent of Capital.com and does not form part of Capital.com's services. Capital.com does not control, develop, endorse, or accept any liability for any third-party software, its functionality, outputs, or any outcomes arising from its use. Any use of third-party tools or integrations in connection with the Capital.com Public API is entirely at your own risk. You are responsible for reviewing the terms, privacy policies, and data-handling practices of any third-party tool you choose to use.

Use of the Public API

Your use of the Capital.com Public API is entirely at your own discretion and risk. Capital.com  makes the Public API available for informational and trading purposes but does not recommend, endorse, or encourage any particular use, integration, or trading strategy. You are solely responsible for how you access and use the API, including the parameters of any orders submitted, the configuration of any connected tools or systems, and the interpretation of any data received. Capital.com accepts no liability for losses or unintended outcomes arising from your use of the API, whether accessed directly or through third-party tools. API availability, functionality, and specifications may be modified, rate-limited, suspended, or discontinued at any time without prior notice. Your use of the Public API is subject to Capital.com 's Terms and Conditions and Electronic Trading Terms, which you should read carefully before using the API.

Execution-Only Service and No Investment Advice

Capital.com provides its services on an execution-only basis. Trading financial instruments involves significant risk of loss. Nothing on this page, in the Public API, or in any third-party software or integration constitutes investment advice, a personal recommendation, or a solicitation to buy or sell any financial instrument. This includes any output, signal, suggestion, or analysis generated by AI, LLM-based, or other automated tools. All trading decisions, including any automated or algorithmic activity, are made at your own risk and remain your sole responsibility.

Risks of Automated and Algorithmic Trading

Use of the Public API in connection with automated or algorithmic trading tools carries additional risks, including but not limited to: rapid execution of orders without human review or intervention; system errors, software failures, or connectivity issues; execution at prices materially different from those expected; and unintended or erroneous orders resulting from misconfigured tools or parameters. Capital.com is not responsible for any losses arising from such risks or from the interaction between its systems and any third-party tools. Past performance and any outputs generated by automated tools are not indicative of future results.

Prohibited Use

Use of the Public API and any connected tools must not be used to manipulate the Capital.com platform, exploit pricing or latency, engage in market abuse, or obtain any unfair advantage. Capital.com reserves the right to restrict, suspend, or terminate API access and/or your account where it reasonably considers that such misuse has occurred or is likely to occur. Clients must not permit any third party to exercise discretionary control over their account.

Your Responsibilities

You are responsible for ensuring that your use of the Capital.com platform, the Public API, and any third-party tools or integrations complies with Capital.com's Terms and Conditions, Electronic Trading Terms, and all applicable laws and regulations in your jurisdiction. You should carefully consider whether automated trading tools are appropriate for your circumstances, experience, and risk tolerance before using them. Capital.com strongly recommends that you test any automated tools or integrations thoroughly using a Demo account before connecting them to a live trading environment.

Articles in this section

Was this article helpful?
0 out of 0 found this helpful