MCP Server (self-hosted)¶
TradeServer includes a built-in Model Context Protocol (MCP) server that exposes its full trading API as structured tools consumable by AI agents and large language models (LLMs).
This allows you to connect any MCP-compatible AI client — such as Claude, Cursor, or a custom agent — directly to your TradeServer instance and automate tasks using natural language or programmatic tool calls.
Using TradeServer Cloud?
This page covers the self-hosted setup, which authenticates with an API key you create in your own instance. On HaasOnline TradeServer Cloud there is no API key — your agent authorizes through the browser in one click. See AI Agent Access (MCP) under TradeServer Cloud.
What is MCP?¶
Model Context Protocol is an open standard for connecting AI systems to external data sources and tools. Instead of building custom integrations for each AI client, TradeServer exposes a single MCP endpoint that any compliant client can discover and call.
With MCP, an AI agent can:
- List and manage your trading bots
- Create, edit, and compile HaasScripts
- Run backtests and retrieve results
- Execute and monitor Labs (parameter optimization)
- Query wallet balances and portfolio values
- Check market data availability
Endpoints¶
The MCP server is hosted on the same REST server as the regular TradeServer API.
| Endpoint | Method | Description |
|---|---|---|
/mcp |
POST |
JSON-RPC 2.0 endpoint — spec-compliant MCP interface |
/mcp/tools |
GET |
Returns a human-readable list of all available tools |
/mcp/execute |
POST |
Simplified execute endpoint — accepts {"name": "...", "args": {...}} |
JSON-RPC 2.0 example¶
POST /mcp
Content-Type: application/json
Authorization: Bearer <your-api-key>
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "list_bots",
"arguments": {}
}
}
Direct execute example¶
POST /mcp/execute
Content-Type: application/json
Authorization: Bearer <your-api-key>
{
"name": "get_bot",
"args": {
"botid": "abc123"
}
}
Setup¶
1. Open MCP Settings¶
In the TradeServer interface, open the Menu (top right) → Settings → MCP (AI Agent Access).

2. Create an API Key¶
In the API Keys section, click the + button to generate a new key. Give it a descriptive label (e.g. Claude Desktop) so you can identify it later.
Your key is displayed as a UUID — copy it now, as it will be partially masked after you leave the page.
Warning
Keep your API key secret. Anyone with the key has full access to your bots, scripts, and exchange accounts via the MCP interface.
3. Connect Your AI Client¶
The settings page includes ready-to-use config snippets for Claude Code, Cursor, Windsurf, Zed, and others. Select your client from the tabs at the top of the MCP settings page, copy the snippet shown, and paste it into your terminal or client config file.
Info
If TradeServer is not running on the same machine as your AI client, replace 127.0.0.1:8080 in the snippet with your server's hostname or IP address and the configured port.
Authentication¶
All MCP requests require a valid API key passed as a Bearer token in the Authorization header:
Protocol Details¶
| Property | Value |
|---|---|
| Protocol version | 2025-11-25 |
| Server name | HaasOnline Trade Server |
| Server version | 1.0.0 |
| Transport | HTTP (JSON-RPC 2.0) |
Treat what your agent reads as untrusted
Your agent reads text you did not necessarily write — script source, bot names, logs — and anyone who can get text in front of it can attempt to plant instructions for it to follow. Leave tool confirmation enabled in your client, and read what it proposes before approving, particularly anything that deletes or overwrites. See Treat what your agent reads as untrusted — the guidance is the same for both deployments.
Available Tools¶
The MCP server exposes 46 tools across eight functional areas:
| Category | Tools |
|---|---|
| System | 1 |
| HaasScript Management | 7 |
| Backtest Execution | 12 |
| Trading Bots | 8 |
| Exchange Accounts | 1 |
| Labs (Parameter Optimization) | 10 |
| Markets & Price Data | 3 |
| Wallet & Portfolio | 4 |
See the Tools Reference for the complete list with parameters and descriptions.