Trading 212 MCP Server
Trading 212 MCP 服务器
通过 MCP 为 Claude 提供安全的 Trading 212 公共 API 访问
构建于:
项目概述
本项目将 Trading 212 公共 API 的功能公开为 MCP 工具,以便 Claude Desktop 可以安全地查询账户、市场、订单、历史记录和派息(Pie)数据。它面向那些希望通过自然语言访问其投资组合工作流,而无需构建自定义 UI 的用户。其核心价值在于模块化的、基于功能的 TypeScript 架构,具有结构化错误处理、严格的环境处理以及以工具为先的 MCP 集成。
Related MCP server: Trading 212 MCP Server
主要功能
Claude 就绪的 MCP 工具 - 通过 MCP 直接在 Claude Desktop 中使用 Trading 212 操作。
兼容公共 API 的身份验证 - 支持使用 API 密钥 + API 密钥秘密的 Trading 212 基本身份验证。
完整的派息(Pie)覆盖 - 包括列出、按 ID 获取、创建、更新、复制和删除派息操作。
包含订单工作流 - 待处理订单、订单详情、下单/取消限价单、市价单、止损单和止损限价单。
历史记录 + 导出操作 - 基于游标的历史订单、股息、交易以及 CSV 导出请求/列表端点。
类型化错误模型 - 一致的身份验证、验证、速率限制、未找到和 API 错误处理。
快速入门演示
在本地运行,然后使用 MCP Inspector 检查工具:
npx @modelcontextprotocol/inspector对于 stdio 模式,将 Inspector 命令配置为:
bun run src/server.ts技术栈
语言: TypeScript (严格模式)
运行时: Bun 1.x (兼容 Node.js 18+)
MCP:
@modelcontextprotocol/sdk验证/模式:
zod配置:
dotenv测试: Bun 测试运行器 (
bun test src)
安装与设置
先决条件
Bun 1.0+
Node.js 18+
Trading 212 公共 API 凭据 (
TRADING212_API_KEY,TRADING212_API_SECRET)Claude Desktop (用于 MCP 集成)
设置
克隆仓库
git clone https://github.com/razeevascx/212mcp.git导航至项目
cd 212mcp安装依赖
bun install配置环境
cp .env.example .env在
.env中设置凭据TRADING212_API_KEY=your_api_key_here TRADING212_API_SECRET=your_api_secret_here ENVIRONMENT=live TRANSPORT=stdio LOG_LEVEL=info DEBUG=false构建项目
bun run build启动服务器
bun run start
验证
您应该在终端输出中看到
Trading 212 MCP Server running。在 Claude Desktop 中,打开 MCP 工具并确认已列出 Trading 212 工具。
Claude Desktop 配置
使用此 MCP 服务器配置:
{
"mcpServers": {
"trading212": {
"command": "/absolute/path/to/212mcp/start.sh"
}
}
}创建 start.sh 并使其可执行:
#!/bin/bash
set -euo pipefail
set -a
source /absolute/path/to/212mcp/.env
set +a
exec bun run /absolute/path/to/212mcp/src/server.tsMCP 工具
账户
fetch_account_cashfetch_account_metadata
证券
search_exchangesearch_instrument
投资组合 / 持仓
fetch_open_positions(可选ticker过滤器)
订单
fetch_all_ordersfetch_orderplace_limit_orderplace_market_orderplace_stop_orderplace_stop_limit_ordercancel_order
历史记录
fetch_historical_order_datafetch_paid_out_dividendsfetch_transaction_listfetch_exports_listrequest_export_csv
派息(Pies)
fetch_piesfetch_piecreate_pieupdate_pieduplicate_piedelete_pie
服务器实用工具
get_server_health
API 使用说明
身份验证: Trading 212 公共 API 使用基本身份验证 (
API_KEY:API_SECRET),由BaseClient处理。环境路由:
ENVIRONMENT=demo|live映射到 Trading 212 演示/实时基础 URL。分页: 历史记录端点使用
limit+cursor并返回nextPagePath。速率限制: API 受到速率限制;
429被呈现为RATE_LIMIT_EXCEEDED。
开发
脚本
bun run build— 编译 TypeScriptbun run start— 启动 MCP 服务器bun run dev— 监视模式bun test src— 运行src中的测试
故障排除
缺少凭据: 设置
TRADING212_API_KEY和TRADING212_API_SECRET。身份验证错误: 重新生成 API 凭据并重启服务器。
Claude 无法连接: 验证 Bun 安装、命令路径和 Claude MCP 配置。
启动时,服务器会验证身份验证配置,如果凭据不完整,将快速失败。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Connect Claude, ChatGPT, Codex, Claude Code or another MCP client to your real multi-broker investment portfolio. Fortunest tracks stocks, ETFs and crypto across brokers and exchanges; its MCP server lets your agent read holdings, returns, allocation, risk, trades and tax lots, calculated by Fortunest rather than guessed by the model. Reads run on their own; every change waits for your approval in the Fortunest app, and no tool places an order or moves money. Sign-in is OAuth 2.1 and needs Fortunest Pro (14-day trial, no card). A free demo that needs no account is listed as Fortunest demo.
Connect brokerage accounts to AI assistants: holdings, orders, asset lookup, and approved trading.
Build and backtest investing strategies from your AI assistant. Remote MCP with OAuth sign-in.
OpenFinance gives any AI agent easy trading across every major market through one hosted MCP server. Trade crypto spot and perpetuals on Hyperliquid with market, limit and TWAP orders, leverage and margin control. Trade stocks, indices, commodities, forex and pre-IPO names as Hyperliquid HIP-3 perps. Trade Polymarket prediction markets with odds, order books, positions, PnL and trader leaderboards. Swap and bridge across 40+ EVM chains and Solana with Relay and Jupiter, find memecoins across 200+ chains, launch tokens on Robinhood Chain and Solana, and buy crypto with card, bank or UPI. Write actions are designed to ask for your confirmation first. Connect with OAuth (sign in to OpenFinance and approve) or an API key. Works with Claude, ChatGPT, Cursor, VS Code, Codex and any MCP client. No install. Home: https://openfinance.tech/agents · Docs: https://docs.openfinance.tech · GitHub: https://github.com/openfinance-tech/mcp
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI assistants to interact with Trading 212 investment accounts for portfolio tracking, account management, and real-time order execution. It supports managing investment pies, analyzing historical data, and monitoring market performance across multiple instrument types.232MIT
- AlicenseNot gradedqualityBmaintenanceExposes Trading 212 trading account, instruments, orders, history, and pies as MCP tools. Allows placing and canceling real orders (defaults to demo/paper environment).Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to read a Trading 212 portfolio (balances, positions, orders, history) and place trades via the public API, supporting both demo and live environments.MIT
- FlicenseNot gradedqualityCmaintenanceExposes Trading212 account data (summary, portfolio, cash, order history, dividends) as MCP tools, intended for direct connection to Claude.ai.-