Connecting Claude Code to NinjaTrader 8: A Setup Guide for the NinjaTrader MCP Server

Configure the open-source Model Context Protocol (MCP) server for NinjaTrader to query account status, compile indicators, and streamline your NinjaScript C# coding workflow directly from the terminal.


Writing NinjaScript C# code can be slow. The cycle of writing code, copying it to NinjaTrader, hitting compile, finding compiler errors, and copy-pasting them back into Claude is a massive bottleneck.

The Model Context Protocol (MCP) changes this workflow. Instead of pasting code chunks manually, you can connect your AI assistant directly to your local NinjaTrader 8 desktop client.

Here is how to configure the open-source NinjaTrader MCP server to read data, check compiler output, and speed up your indicator and strategy development.


What is the Model Context Protocol (MCP)?

The Model Context Protocol is an open-source standard created by Anthropic that allows LLMs to interact with external tools and databases safely. Rather than relying on separate custom plugins for every tool, MCP provides a unified API. You can read the full specification at the Model Context Protocol Website.

By running a local MCP server, you expose a secure gateway that AI clients like Claude Code, Claude Desktop, or Cursor can query.

When you ask a question like “Why is my indicator lagging?”, the AI can call a local tool to check your time sync, read your NinjaTrader logs, or inspect the C# source file.


How the NinjaTrader MCP Server Works

The ozmnf4/ninjatrader-mcp repository is an open-source server that implements this standard for trading. The server is listed in the directory at mcpmarket.com/server/ninjatrader-ninjascript.

It operates in two distinct execution modes:

Connects directly to your local NinjaTrader 8 Desktop installation. This is done by running a lightweight NinjaScript Add-On that opens a local HTTP port. In this mode, the AI can read indicator data, query charts, and access local log outputs.

Cloud Mode

Utilizes the official NinjaTrader Ecosystem API to access account values, margins, and orders. This mode is useful for tracking performance across accounts but does not have direct access to your local C# indicator files.


Step-by-Step Installation and Configuration

To get started, make sure you have Node.js (version 18 or higher) and NinjaTrader 8 installed on your machine.

Step 1: Clone the Server Repository

Open your terminal and clone the repository to a folder on your system:

git clone https://github.com/ozmnf4/ninjatrader-mcp.git ~/ninjatrader-mcp
cd ~/ninjatrader-mcp
npm install

Step 2: Configure the Environment Variables

Copy the template configuration file:

cp .env.example .env

Open the newly created .env file in your code editor. For local developer integration, set the mode to local:

NINJATRADER_MODE=local
NINJATRADER_LOCAL_URL=http://localhost:7890

If you are using Cloud Mode, you will need to add your API credentials:

NINJATRADER_MODE=cloud
NINJATRADER_API_KEY=your_ecosystem_api_key_here

Step 3: Install the NinjaTrader Add-On

For Local Mode, you must install the helper Add-On that starts the local HTTP listener.

  1. Copy the C# Add-On file located in the cloned repository under templates/AddOnMcpServer.cs.
  2. Paste this file into your local NinjaTrader folder at Documents/NinjaTrader 8/bin/Custom/AddOns/.
  3. Open NinjaTrader 8, click Tools > Edit NinjaScript > Add-On, and compile the scripts (or press F5 on any chart).
  4. Verify that you see a log message confirming the HTTP server is listening on port 7890.

Add the NinjaTrader server to your global Claude config file. For Claude Code, edit ~/.claude/.mcp.json. For Windows users, the file is usually located in your user directory:

{
  "mcpServers": {
    "ninjatrader": {
      "command": "node",
      "args": ["C:/path/to/ninjatrader-mcp/src/server.js"]
    }
  }
}

Make sure to replace C:/path/to/ninjatrader-mcp/ with the exact absolute path where you cloned the folder.

Step 5: Test the Connection

Restart Claude Code and run a quick diagnostics check by asking:

“Verify if the NinjaTrader MCP server is connected.”

The assistant will run the nt_health_check tool to verify that the local HTTP port is active and communicating.


Developer Workflows: What You Can Do

Once connected, your AI assistant is no longer just guessing when it writes NinjaScript code. It has active context.

1. Auto-Fixing C# Compilation Errors

If your script fails to compile, you can tell the AI: “Read the compilation log from my NinjaTrader logs and fix the syntax errors in my custom indicator.”

The AI will pull the compilation errors, open the .cs file, correct the syntax, and save the file back to your directory. All you have to do is compile again.

2. Validating Account State and Drawdowns

You can ask: “Check my active account balances and list current open positions.”

This runs local calls to fetch account values and open risk parameters, providing a quick summary inside your console.


Execution Risk: Why You Need Dedicated Trade Managers

While the NinjaTrader MCP server is excellent for developer workflows and analytics, allowing an AI assistant to handle trade execution or manage active risk triggers carries massive danger.

LLMs can experience latency, network delays, or parsing errors. A delay of 500 milliseconds during a high-volatility news event can result in severe slippage or a blown account.

For execution and session control, you should rely on platform-native trade managers.

For example, Nexus Chart Trader runs directly inside the NinjaTrader 8 core engine as a compiled C# assembly. It enforces your daily loss locks, news event halts, and profit protector rules with zero external API dependencies or network latency.

Use AI to code the indicators, but use a dedicated, compiled tool to execute and protect your capital.


Frequently Asked Questions

Can Claude place live trades through the MCP server?

Yes, the MCP server contains order routing tools. However, this is highly discouraged for automated execution due to the latency of processing natural language. It should only be used for utility scripts or testing in simulated accounts.

Does this require a paid NinjaTrader developer license?

No. The local HTTP listener runs inside the standard NinjaTrader 8 desktop client, which is free to download and use for simulation and development.

How do I troubleshoot connection timeouts?

If the server fails to connect, check that your Windows Firewall is not blocking port 7890. You can test if the NinjaScript Add-On is running by opening http://localhost:7890 in your web browser.


Helpful Resources

Upgrade your NinjaTrader 8 setup.

Nexus Indicator designs professional, institutional-grade utilities, risk management tools, and trade copier panels for serious futures and prop firm traders.