MCP 212交易服务器
具有多账户支持的用于交易的模型上下文协议(MCP)服务器212。
设置
自动引导(推荐)
运行:
./setup.sh什么 setup.sh 做:
- 安装依赖项(
uv如果可用,否则pip) - 配置多帐户
.env交互式(isa,invest,或两者皆有) - 可以更新Claude Desktop MCP配置(可选提示)
手动设置(可选)
- 安装依赖项:
uv sync- 创建本地env文件:
cp .env.template .env- 编辑
.env随着isa,invest或两者皆有。 - 运行服务器:
uv run python main.py环境配置
支持的帐户别名固定为:
isainvest
您可以配置两者的任意组合。
两个账户:
212_ACCOUNTS=isa,invest
212_DEFAULT_ACCOUNT=isa
212_ISA_API_KEY_ID=...
212_ISA_API_KEY_SECRET=...
212_ISA_API_BASE_LIVE_URL=https://live.trading212.com/api/v0/
212_INVEST_API_KEY_ID=...
212_INVEST_API_KEY_SECRET=...
212_INVEST_API_BASE_LIVE_URL=https://live.trading212.com/api/v0/仅限ISA:
212_ACCOUNTS=isa
212_DEFAULT_ACCOUNT=isa
212_ISA_API_KEY_ID=...
212_ISA_API_KEY_SECRET=...
212_ISA_API_BASE_LIVE_URL=https://live.trading212.com/api/v0/仅投资:
212_ACCOUNTS=invest
212_DEFAULT_ACCOUNT=invest
212_INVEST_API_KEY_ID=...
212_INVEST_API_KEY_SECRET=...
212_INVEST_API_BASE_LIVE_URL=https://live.trading212.com/api/v0/MCP资源
所有资源都是帐户范围的:
trading212://accounts/{account}/infotrading212://accounts/{account}/balancetrading212://accounts/{account}/portfoliotrading212://accounts/{account}/portfolio/{ticker}trading212://accounts/{account}/orderstrading212://accounts/{account}/orders/{order_id}trading212://accounts/{account}/piestrading212://accounts/{account}/pies/{pie_id}trading212://accounts/{account}/dividendstrading212://accounts/{account}/metadata/exchangestrading212://accounts/{account}/metadata/instruments/tickerstrading212://accounts/{account}/metadata/instruments/{ticker}
使用 {account} 作为要么 isa 或 invest.
MCP工具
突变工具需要 account (isa 或 invest):
place_market_order(account, ticker, quantity, extended_hours)place_limit_order(account, ticker, quantity, limit_price, time_validity)place_stop_order(account, ticker, quantity, stop_price, time_validity)place_stop_limit_order(account, ticker, quantity, stop_price, limit_price, time_validity)cancel_order(account, order_id)create_pie(account, name, dividend_destination, instrument_shares, end_date, goal)update_pie(account, pie_id, name, dividend_destination, instrument_shares, end_date, goal)delete_pie(account, pie_id)
其他工具:
list_accounts()read_resource(uri)mcp_capabilities()
read_resource 兼容性别名(也支持):
trading212://accounts/{account}/account/overview->帐户信息trading212://accounts/{account}/account/info->帐户信息trading212://accounts/{account}/account/balance->账户余额
Claude桌面集成(可选)
本节仅适用于Claude Desktop用户。\ 如果您使用另一个MCP客户端,则可以跳过此步骤,直接配置您的客户端以运行此服务器。
选项A:让安装脚本更新Claude配置
./setup.sh --update-claude-config auto这将保持您现有的非-212-trading 仅MCP条目和更新 mcpServers["212-trading"].
选项B:手动输入Claude配置
将此服务器添加到 mcpServers 在Claude桌面配置中:
{
"command": "uv",
"args": ["--directory", "/ABS/PATH/TO/mcp-server-212-trading", "run", "main.py"]
}克劳德的第二个账户接线
如果克劳德已经运行了这个仓库(uv --directory run main.py),仅更新 .env:
212_ACCOUNTS=isa,invest
212_DEFAULT_ACCOUNT=isa
212_INVEST_API_KEY_ID=
212_INVEST_API_KEY_SECRET=
212_INVEST_API_BASE_LIVE_URL=https://live.trading212.com/api/v0/然后重新启动Claude Desktop并使用:
account=invest用于工具trading212://accounts/invest/...资源
帮助克劳德正确使用它
与Claude聊天时,让它按照以下顺序进行:
- 呼叫
list_accounts() - 挑选
isa或invest - 仅使用
trading212://accounts/{account}/...资源 - 包括
account在每次不断变化的工具调用中
有用的入门信息:
Before doing anything, call list_accounts(). Then use account=isa (or account=invest) explicitly in every tool call and trading212://accounts/{account}/... resource URI.测试
uv run pytest