Questrade MCP服务器
A. 模型上下文协议 服务器 Questrade个人交易API。查询您的投资组合,查找交易品种,检查 通过任何兼容MCP的AI助手查看订单、余额和订单。
采用面向结果的工具设计,服务于用户意图,而不是1:1的REST 端点镜像。每个工具在内部协调多个API调用以返回 完整的答案,最大限度地减少代理往返和上下文窗口的使用。
快速开始
1.安装Deno
curl -fsSL https://deno.land/install.sh | sh或者看看 代诺.com 对于其他安装方法。
2.获取Questrade刷新令牌
- 登录到 Questrade API枢纽
- 注册个人应用程序(或使用现有应用程序)
- 生成刷新令牌——复制它以进行下一步
3.添加到您的MCP客户端
克劳德桌面版 (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"questrade": {
"command": "deno",
"args": ["run", "-A", "jsr:@mathuran/questrade-mcp"],
"env": {
"QUESTRADE_REFRESH_TOKEN": ""
}
}
}
}克劳德代码 (.mcp.json 在项目根目录中,或 ~/.claude/mcp.json 全球):
{
"mcpServers": {
"questrade": {
"command": "deno",
"args": ["run", "-A", "jsr:@mathuran/questrade-mcp"],
"env": {
"QUESTRADE_REFRESH_TOKEN": ""
}
}
}
}光标 (设置>MCP服务器>添加):
{
"mcpServers": {
"questrade": {
"command": "deno",
"args": ["run", "-A", "jsr:@mathuran/questrade-mcp"],
"env": {
"QUESTRADE_REFRESH_TOKEN": ""
}
}
}
}重新启动MCP客户端,并要求它“显示我的投资组合”以验证连接。
工具
| 工具 | 说明 |
|---|---|
get_portfolio | 完整的投资组合概述——账户、头寸和余额在一次通话中 |
get_positions | 在特定账户中持有的头寸 |
get_balances | 账户的现金余额和购买力 |
lookup_symbol | 按名称/股票代码搜索,返回交易品种详细信息+实时报价 |
get_quotes | 按交易品种ID批量报价 |
get_price_history | 历史OHLCV蜡烛数据 |
get_option_chain | 带有可选实时报价的期权链 |
get_orders | 带有状态/日期过滤器的订单历史记录 |
get_account_activity | 综合活动+执行时间表 |
交易工具(place_order, cancel_order)已实现但已禁用-- 服务器是 只读 目前。
运作原理
启动服务器时:
- 确认
QUESTRADE_REFRESH_TOKEN已设置(从env var或.env文件) - 使用Questrade的OAuth2 API进行身份验证
- 运行烟雾测试以验证连接
- 开始在stdio上监听MCP请求
令牌是一次性使用的——每次刷新都会产生一个新的令牌对。服务器 将令牌持久化到适合平台的配置目录并自动刷新 在到期之前或401响应时。
令牌存储
| 平台 | 路径 |
|---|---|
| macOS | ~/Library/Application Support/questrade-mcp/token.json |
| Linux | ~/.config/questrade-mcp/token.json |
| 窗户 | %APPDATA%/questrade-mcp/token.json |
如果a token.json 存在于当前工作目录中,它具有优先级 (为了与源代码运行设置向后兼容)。
发展
从源代码运行
git clone https://github.com/mathuransadagopan/questrade-mcp.git
cd questrade-mcp
cp .env.example .env
# Edit .env with your refresh token
deno task start开发模式(自动重新加载)
deno task dev使用MCP检查员进行测试
npx @modelcontextprotocol/inspector deno run -A src/main.ts项目结构
src/
├── main.ts # Entry point — .env loading + dispatch
├── main-stdio.ts # Stdio transport setup + smoke test
├── env.ts # Environment validation
├── auth.ts # OAuth token lifecycle (refresh, persist, auto-renew)
├── client-factory.ts # Questrade HTTP client (auto-auth, retry on 401)
├── server.ts # MCP server factory + tool registration
├── log.ts # Stderr logger
└── tools/
├── portfolio.ts # get_portfolio, get_positions, get_balances
├── market.ts # lookup_symbol, get_quotes, get_price_history, get_option_chain
└── trading.ts # get_orders, get_account_activity