MCP Integration
Connect SimuTrade (simutrade.ai) via Model Context Protocol (MCP) for autonomous AI trading agents.
What is MCP?
Model Context Protocol (MCP) is an open standard that allows AI models to securely interact with external tools and data sources. SimuTrade provides a fully compatible MCP server that exposes trading capabilities as MCP tools, enabling AI agents to autonomously manage simulated portfolios. Tool descriptions in the server are written so that AI agents know when to call each tool and what parameters to provide (e.g. always pass reason for orders and risk rules; call simutrade_get_investment_thinking before decisions).
MCP Server
Pre-built MCP server with all trading tools available out of the box.
Stdio & SSE Transport
Supports both stdio (local) and SSE (remote) transport protocols.
Secure by Default
API key authentication with granular permissions for each tool.
Quick Setup with Claude Desktop
The fastest way to get started is with Claude Desktop. Add the SimuTrade MCP server to your Claude Desktop configuration:
安装 MCP 服务(任选其一)
方式 A(推荐):若 simutrade-mcp 已发布到 npm,可直接用 npx 运行,无需克隆仓库(维护者发布方式见下方):
npx -y simutrade-mcp方式 B:全局安装后直接调用命令:
npm install -g simutrade-mcp方式 C:从仓库本地运行(适用于开发者):
git clone https://github.com/YaoLang/simutrade.git && cd simutrade/server/mcp-server && npm install配置 MCP 客户端
在 Claude Desktop、Cursor、或其他支持 MCP 的应用中添加配置。需提供 API Key(在 simutrade.ai 后台创建)和 API 地址。
Claude Desktop 配置文件:macOS ~/Library/Application Support/Claude/claude_desktop_config.json,Windows %APPDATA%\Claude\claude_desktop_config.json
配置示例(npx / 全局安装,无需本地路径):
{
"mcpServers": {
"simutrade": {
"command": "npx",
"args": ["-y", "simutrade-mcp"],
"env": {
"TRADESIM_API_KEY": "ts_live_你的API密钥",
"TRADESIM_BASE_URL": "https://api.simutrade.ai/v1"
}
}
}
}或全局安装后:
{
"mcpServers": {
"simutrade": {
"command": "simutrade-mcp",
"env": {
"TRADESIM_API_KEY": "ts_live_你的API密钥",
"TRADESIM_BASE_URL": "https://api.simutrade.ai/v1"
}
}
}
}或从本地路径运行:
{
"mcpServers": {
"simutrade": {
"command": "node",
"args": ["/path/to/simutrade/server/mcp-server/index.js"],
"env": {
"TRADESIM_API_KEY": "ts_live_你的API密钥",
"TRADESIM_BASE_URL": "https://api.simutrade.ai/v1"
}
}
}
}生产环境用 https://api.simutrade.ai/v1,本地开发用 http://localhost:8080/v1。
Restart Claude Desktop
Restart Claude Desktop to load the MCP server. You should see SimuTrade listed in the available tools. Now you can trade through conversation!
Recommended Workflow for AI
So that your decisions align with the account's strategy and humans can review clearly:
- Before any trade or risk decision: Call
simutrade_get_investment_thinkingto read the overall investment thinking. Ensure your action matches the documented direction (strategy, risk preference, symbols). - When placing orders: Always pass
reasoninsimutrade_place_order(strategy, signals, target/stop). Humans see this in Dashboard and Investment Thinking timeline. - When creating risk rules: Always pass
reasoninsimutrade_create_risk_control_rule. Usesimutrade_update_risk_control_ruleorsimutrade_delete_risk_control_ruleto adjust or remove rules. - When strategy or view changes: Call
simutrade_update_investment_thinkingwith a clear narrative (market view, strategy, risk, preferences) so humans and AI stay aligned.
Investment Thinking (Overall Strategy Document)
Each account has one "investment thinking" document: the same content is shown to humans on the Dashboard and Investment Thinking page, and to the AI via MCP. The AI should read it before decisions and update it when strategy changes.
simutrade_get_investment_thinking{ content, updatedAt }. Call before any trade or risk decision so your action follows the documented direction.simutrade_update_investment_thinkingcontent (string, required). Replaces the full document. Use when initializing or when strategy/market view changes. Markdown supported.Response format
Every tool returns a content array with one text item containing JSON (stringified). The examples below show the structure of that JSON. On failure, the server returns a text message and isError: true. There are no tools that return empty or missing responses.
MCP Tools Reference
The SimuTrade MCP server exposes the following tools:
simutrade_get_quoteGet real-time price quote for a stock or cryptocurrency
Input Parameters
{
"symbol": "AAPL" // Trading symbol (e.g., AAPL, 0700.HK, BTC-USD)
}Response
{
"symbol": "AAPL",
"name": "Apple Inc.",
"price": 189.84,
"change": 2.34,
"changePercent": 1.25,
"volume": 52340000,
"high": 191.05,
"low": 187.45
}simutrade_place_orderPlace a buy/sell order. Provide 'reason' with your decision rationale so it appears in the dashboard and timeline.
Input Parameters
{
"symbol": "AAPL", // Trading symbol
"side": "buy", // "buy" or "sell"
"type": "market", // "market", "limit", or "stop"
"quantity": 10, // Shares/units to trade
"price": 185.00, // For limit/stop orders only
"reason": "Signal X triggered; risk/reward 1:2. Stop at 180." // Optional but recommended: your decision rationale
}Response
{
"id": "ord-abc123",
"symbol": "AAPL",
"side": "buy",
"type": "market",
"status": "pending",
"quantity": 10,
"createdAt": "2026-02-20T15:30:00Z"
}simutrade_get_portfolioGet portfolio summary with all positions
Input Parameters
{} // No parameters requiredResponse
{
"summary": {
"totalValue": 145678.90,
"cashBalance": 53922.70,
"holdingsValue": 91756.20,
"todayPnL": 1245.30,
"totalPnL": 5678.90
},
"totalPositions": 1,
"positions": [
{ "symbol": "AAPL", "quantity": 50, "currentPrice": 189.84, "marketValue": 9492.00, "unrealizedPnL": 732.00 }
]
}simutrade_list_ordersList recent orders, optionally filtered by status
Input Parameters
{
"status": "pending", // Optional: "pending", "filled", "cancelled"
"limit": 10 // Optional: number of orders
}Response
{
"orders": [
{ "id": "ord-abc123", "symbol": "AAPL", "side": "buy", "status": "pending" }
],
"total": 1
}simutrade_cancel_orderCancel a pending order by ID
Input Parameters
{
"order_id": "ord-abc123" // Order ID to cancel
}Response
{
"id": "ord-abc123",
"status": "cancelled",
"cancelledAt": "2026-02-20T15:35:00Z"
}simutrade_get_market_historyGet historical OHLCV data for charting and analysis
Input Parameters
{
"symbol": "AAPL", // Trading symbol
"interval": "1d", // "1m", "5m", "15m", "1h", "1d"
"limit": 30 // Number of candles
}Response
{
"symbol": "AAPL",
"interval": "1d",
"limit": 30,
"candles": [
{ "time": "2026-02-20", "open": 188.5, "high": 191.0, "low": 187.4, "close": 189.8, "volume": 52340000 }
]
}simutrade_create_risk_control_ruleCreate a risk control rule with structured risk metrics and AI metadata (stop loss, take profit, trailing stop, or position limit)
Input Parameters
{
"rule_type": "stop_loss", // "stop_loss" | "take_profit" | "trailing_stop" | "position_limit"
"config": {
"type": "percentage", // "absolute" | "percentage"
"percentage": 5.0, // Stop loss: 5% below entry
"enabled": true
},
"symbol": "AAPL", // Optional: for position-level rules
"reason": "Based on RSI overbought at 72, setting 5% stop loss to protect profits", // Optional: human-readable explanation
"max_loss": 5000.0, // Optional: maximum loss amount
"max_loss_percent": 5.0, // Optional: maximum loss percentage
"risk_reward_ratio": 2.0, // Optional: risk-reward ratio
"volatility": 0.15, // Optional: volatility metric (15%)
"metadata": { // Optional: AI metadata and extended information
"ai": {
"confidence": 0.85,
"model": "claude-3.5-sonnet",
"reasoning": "Based on RSI indicator (72) showing overbought, MACD divergence signal",
"decision_factors": ["RSI overbought", "MACD divergence", "Price near resistance"]
},
"strategy": {
"id": "strategy-001",
"name": "Trend Following Strategy",
"params": {"maPeriod": 20, "stopLossPercent": 5}
},
"market": {
"trend": "up",
"support": 180.0,
"resistance": 195.0,
"current_price": 189.84
}
}
}Response
{
"rule": {
"id": "rule-abc123",
"rule_type": "stop_loss",
"symbol": "AAPL",
"config": { "type": "percentage", "percentage": 5.0, "enabled": true },
"reason": "Based on RSI overbought at 72, setting 5% stop loss to protect profits",
"max_loss": 5000.0,
"max_loss_percent": 5.0,
"risk_reward_ratio": 2.0,
"volatility": 0.15,
"metadata": { "ai": {...}, "strategy": {...}, "market": {...} },
"is_active": true,
"created_at": "2026-02-20T15:35:00Z"
}
}simutrade_list_risk_control_rulesList risk control rules with optional filters
Input Parameters
{
"symbol": "AAPL", // Optional: filter by symbol
"rule_type": "stop_loss", // Optional: filter by type
"is_active": true // Optional: filter by active status
}Response
{
"totalRules": 1,
"rules": [
{
"id": "rule-abc123",
"ruleType": "stop_loss",
"symbol": "AAPL",
"config": { "type": "percentage", "percentage": 5.0 },
"actionOnTrigger": "auto_sell",
"isActive": true
}
]
}simutrade_list_risk_control_executionsList risk control execution records showing when rules were triggered
Input Parameters
{
"rule_id": "rule-abc123", // Optional: filter by rule ID
"status": "triggered", // Optional: "triggered" | "executed" | "cancelled"
"limit": 50 // Number of records (default: 50)
}Response
{
"executions": [
{
"id": "exec-xyz789",
"rule_id": "rule-abc123",
"triggered_at": "2026-02-20T15:40:00Z",
"trigger_price": 180.50,
"current_price": 180.45,
"status": "triggered",
"details": { "stopPrice": 180.50, "lossPercent": -5.2 }
}
],
"total": 1
}simutrade_list_positionsList current holdings (positions). Use to check what you hold before selling or setting position-level risk rules.
Input Parameters
{} // No parametersResponse
{
"totalPositions": 1,
"positions": [
{ "symbol": "AAPL", "quantity": 50, "avgCost": 185.2, "currentPrice": 189.84, "marketValue": 9492, "unrealizedPnL": 732, "unrealizedPnLPercent": 2.51 }
]
}simutrade_get_orderGet a single order by ID (decisionReason, fill price/quantity, status). Use after place_order to confirm or for复盘.
Input Parameters
{
"order_id": "ord-abc123" // Order ID from place_order response
}Response
{
"order": {
"id": "ord-abc123",
"symbol": "AAPL",
"side": "buy",
"status": "filled",
"quantity": 10,
"filledQuantity": 10,
"filledPrice": 189.84,
"decisionReason": "Momentum breakout; target 195, stop 180.",
"createdAt": "2026-02-20T15:30:00Z"
}
}simutrade_update_risk_control_ruleUpdate an existing rule (config, reason, is_active, metadata). Use to adjust stop/target or disable without deleting.
Input Parameters
{
"rule_id": "rule-abc123", // Required
"config": { "percentage": 6 }, // Optional
"reason": "Adjusted to 6% after volatility increase", // Optional
"is_active": false // Optional: enable/disable
}Response
{
"rule": { "id": "rule-abc123", "config": {...}, "reason": "...", "is_active": true }
}simutrade_delete_risk_control_rulePermanently delete a risk control rule by ID.
Input Parameters
{
"rule_id": "rule-abc123" // Required
}Response
{
"success": true,
"deleted": "rule-abc123"
}simutrade_get_investment_thinkingGet the account's overall investment thinking (same as humans see). Call before any trade or risk decision to align with documented strategy.
Input Parameters
{} // No parametersResponse
{
"content": "# Strategy\nMarket view, risk preference...",
"updatedAt": "2026-02-20T15:00:00Z"
}simutrade_update_investment_thinkingUpdate the overall investment thinking document. Use when initializing or when strategy/market view changes. Markdown supported.
Input Parameters
{
"content": "# Overall strategy\nMarket view, strategy logic, risk preference, position/symbol preferences. Full document; replaces previous."
}Response
{
"content": "...",
"updatedAt": "2026-02-20T15:30:00Z"
}Risk Control Module
The risk control module provides automated risk management through MCP tools. Rules are automatically checked every 30 seconds by the system. When a rule is triggered, an execution record is created with status "triggered". The system only records and alerts - it does not automatically execute trades.
Rule Levels
Rule Types
Available MCP Tools
simutrade_create_risk_control_rule- Create a new risk control rule (always provide reason)simutrade_list_risk_control_rules- List rules with optional filters (symbol, rule_type, is_active)simutrade_list_risk_control_executions- View execution history when rules were triggeredsimutrade_update_risk_control_rule- Update config, reason, or is_active for an existing rulesimutrade_delete_risk_control_rule- Permanently delete a rule by ID
Example: Creating a stop loss rule
// Create a 5% stop loss for AAPL position with structured risk metrics
const rule = await client.callTool("simutrade_create_risk_control_rule", {
rule_type: "stop_loss",
config: {
type: "percentage",
percentage: 5.0,
enabled: true
},
symbol: "AAPL",
reason: "Based on RSI overbought at 72, setting 5% stop loss to protect profits",
max_loss: 5000.0,
max_loss_percent: 5.0,
risk_reward_ratio: 2.0,
volatility: 0.15,
metadata: {
ai: {
confidence: 0.85,
model: "claude-3.5-sonnet",
reasoning: "RSI indicator shows overbought condition",
decision_factors: ["RSI overbought", "MACD divergence"]
}
}
});
// Check execution history
const executions = await client.callTool("simutrade_list_risk_control_executions", {
rule_id: rule.id,
status: "triggered",
limit: 10
});Custom MCP Client
You can also connect to SimuTrade MCP from your own application using the MCP SDK:
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
// Connect to the SimuTrade MCP server
const transport = new StdioClientTransport({
command: "node",
args: ["./server/mcp-server/index.js"],
env: {
TRADESIM_API_KEY: process.env.TRADESIM_API_KEY,
TRADESIM_BASE_URL: "https://api.simutrade.ai/v1",
},
});
const client = new Client({
name: "my-trading-bot",
version: "1.0.0",
});
await client.connect(transport);
// List available tools
const tools = await client.listTools();
console.log("Available tools:", tools.map(t => t.name));
// Get a quote
const quote = await client.callTool("simutrade_get_quote", {
symbol: "AAPL",
});
console.log("AAPL price:", quote);
// Place an order (include reason for human review in dashboard/timeline)
const order = await client.callTool("simutrade_place_order", {
symbol: "AAPL",
side: "buy",
type: "market",
quantity: 10,
reason: "Momentum breakout above 185; target 195, stop 180.",
});
console.log("Order placed:", order);集成到其他应用 / 不在本机运行
本 MCP 可被任何支持 MCP 的应用集成(Claude Desktop、Cursor、自建 AI Agent 等)。若要在服务器或其他机器上运行,有两种方式:
方式 1:Stdio(客户端在哪,MCP 就跟在哪)
若你的客户端(如交易机器人、自建 Agent)部署在云服务器上,MCP 会作为其子进程在同一台服务器上运行。只需在服务器上安装 Node.js,用 npx / 全局安装 / 本地路径任一方式启动即可。
方式 2:SSE 远程连接(已上线)
通过 URL 直接连接,无需在本地或服务器上运行 MCP 进程。适用于支持 HTTP/SSE 传输的 MCP 客户端(如 MCP Inspector、自建 SDK 应用)。
Remote SSE Transport
适用于支持 HTTP + SSE 的 MCP 客户端。使用 API Key 作为 Bearer Token 鉴权。
SSE 端点 URL:
- 生产环境:
https://api.simutrade.ai/v1/mcp/sse或https://mcp.simutrade.ai/sse - 本地开发:
http://localhost:8080/v1/mcp/sse
客户端配置示例(支持 url 的 MCP 客户端):
{
"mcpServers": {
"simutrade": {
"url": "https://api.simutrade.ai/v1/mcp/sse",
"headers": {
"Authorization": "Bearer ts_live_你的API密钥"
}
}
}
}或使用 mcp.simutrade.ai 子域名:
{
"mcpServers": {
"simutrade": {
"url": "https://mcp.simutrade.ai/sse",
"headers": {
"Authorization": "Bearer ts_live_你的API密钥"
}
}
}
}连接时需在 Headers 中携带 Authorization: Bearer <API密钥>,密钥需在 simutrade.ai 后台创建并具有 read + trade 权限。
维护者:发布 simutrade-mcp 到 npm
若要让用户使用 npx simutrade-mcp 或 npm install -g simutrade-mcp,需先将包发布到 npm:
cd server/mcp-server
npm login # 首次需要
npm publishTroubleshooting
Claude Desktop doesn't show SimuTrade tools
Ensure the config file path is correct and restart Claude Desktop completely (quit and relaunch). Check that your API key is valid.
Getting 'UNAUTHORIZED' errors
Verify your API key is correct and has the required permissions (read + trade). Check that the key is not revoked.
MCP server fails to start
Ensure Node.js v18+ is installed. Try running 'npx simutrade-mcp' directly in terminal to see error messages.
SSE connection returns 401 or session not found
Ensure Authorization: Bearer <api_key> header is sent with the initial GET request. For POST /messages, the sessionId from the endpoint event must be included in the query string. API key must have read + trade permissions.