sentinel
Sentinel Execution MCP
一个以生产级算法交易控制平面形式提供的 MCP 服务器——让 Claude 能够通过自然语言管理观察列表、分类市场状态、验证风险并提交模拟订单。
这是什么
Sentinel 是一个包含两个包的单仓库(monorepo):
包 | 语言 | 职责 |
| Python 3.12 / FastAPI | 所有交易逻辑:风险检查、状态分类、订单生命周期、审计日志、策略治理 |
| TypeScript / Node 20 | 轻量 MCP 服务器,通过 HTTP 将 40+ 个工具路由到引擎。此处不包含任何交易逻辑。 |
Claude(或任何兼容 MCP 的代理)与 MCP 服务器通信。MCP 服务器与引擎通信。引擎拥有数据库和缓存。
Related MCP server: Alpaca MCP Server
架构
Claude Desktop (or any MCP agent)
│
│ MCP protocol (stdio or SSE)
▼
┌─────────────────────────┐
│ MCP Server │ TypeScript · Zod validation · tool routing
│ (packages/mcp) │
└────────────┬────────────┘
│ HTTP REST (localhost:8100)
▼
┌─────────────────────────┐
│ Engine API │ Python · FastAPI · all trading logic
│ (packages/engine) │
└──────────┬──────────────┘
│
┌───────┴────────┐
▼ ▼
PostgreSQL Redis
(orders, (kill switch,
positions, rate limits,
strategies, cache)
audit log)如果引擎不可用,每个 MCP 工具调用都会立即返回错误。没有回退或部分执行。
快速开始(Docker——推荐)
最快的启动方式。需要 Docker 和 Node.js 20+。
# 1. Clone and configure
git clone https://github.com/rohith1125/sentinel-execution-mcp.git
cd sentinel-execution-mcp
cp .env.example .env # defaults work out of the box — no edits needed
# 2. Start Postgres + Redis + engine (runs migrations automatically)
docker compose -f docker/docker-compose.yml up -d db redis engine
# Wait ~10 seconds, then verify the engine is healthy:
curl http://localhost:8100/health
# {"status": "ok", "provider": "mock", ...}
# 3. Build the MCP server (one-time)
cd packages/mcp
npm install
npm run build然后将 Sentinel 添加到 Claude Desktop(参见下面的 连接 Claude Desktop)并重启 Claude。就这样——全部 40 个工具即可使用。
手动设置(不使用 Docker)
如果本地已有 Postgres 和 Redis 在运行,请使用此方式。
前置条件:
依赖 | 最低版本 | 说明 |
Python | 3.12 | 引擎运行时——使用 |
Node.js | 20 | MCP 服务器运行时 |
PostgreSQL | 15+ | 主数据存储 |
Redis | 7+ | 紧急停止开关和缓存 |
1. 克隆并配置
git clone https://github.com/rohith1125/sentinel-execution-mcp.git
cd sentinel-execution-mcp
cp .env.example .env
# Default values work for local paper-trading development — no edits required2. 设置引擎
cd packages/engine
python3.12 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -e ".[dev]"3. 运行数据库迁移
# From packages/engine with the venv active
alembic upgrade head4. 启动引擎
uvicorn sentinel.api:app --reload --port 8100验证它正在运行:
curl http://localhost:8100/health
# {"status": "ok", "env": "paper"}5. 构建并启动 MCP 服务器
打开第二个终端:
cd packages/mcp
npm install
npm run build
npm run dev # stdio transport — for direct Claude Desktop integration连接 Claude Desktop
将以下内容添加到你的 Claude Desktop 配置文件中。
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
在终端中运行以下命令获取正确路径:
echo "$(pwd)/packages/mcp/dist/index.js"然后将其粘贴到配置中:
{
"mcpServers": {
"sentinel": {
"command": "node",
"args": ["/absolute/path/to/sentinel-execution-mcp/packages/mcp/dist/index.js"],
"env": {
"ENGINE_BASE_URL": "http://localhost:8100",
"APP_ENV": "paper"
}
}
}
}保存后重启 Claude Desktop。你应该会在聊天输入框中看到一个锤子图标(🔨)——点击它确认 Sentinel 的 40 个工具已加载。
MCP 工具参考
Sentinel 提供 40+ 个工具,涵盖九个类别。MCP 服务器名称为 sentinel。
类别 | 工具 | 描述 |
观察列表 |
| 将代码添加到交易观察列表,可选择分配给某个分组 |
| 移除代码;它们将不再出现在策略扫描中 | |
| 列出活跃代码,可选择按分组过滤 | |
| 获取单个代码的详细信息 | |
| 列出所有已命名的观察列表分组 | |
| 更新代码的备注或分组分配 | |
市场数据 |
| 一个或多个代码的最新报价和交易数据 |
| 可配置时间框架的 OHLCV K 线历史 | |
| 代码的实时买卖价差 | |
| 检查市场数据提供商的连接状态 | |
状态 |
| 使用 ATR、ADX、RSI、布林带宽度、Hurst 指数、VWAP 和价格效率对当前市场状态进行分类 |
| 检索代码的历史状态快照 | |
策略 |
| 跨一个或多个策略扫描观察列表以寻找信号 |
| 针对特定策略评估单个代码 | |
| 列出所有已注册策略及其当前状态 | |
风险 / 紧急停止 |
| 在提交前对拟议交易运行全部 13+ 项风险检查 |
| 获取所有紧急停止开关的当前状态 | |
| 全局、按策略或按代码启用紧急停止开关 | |
| 禁用紧急停止开关(需要明确原因) | |
| 当前总敞口和净敞口摘要 | |
| 当前每日回撤与配置限额的对比 | |
投资组合 |
| 完整账户概览:价值、现金、权益、盈亏、购买力 |
| 所有未平仓头寸及未实现盈亏 | |
| 已平仓头寸历史及已实现盈亏 | |
执行 |
| 提交模拟交易订单(市价、限价、止损、止损限价) |
| 按 ID 取消待处理或部分成交的订单 | |
| 获取特定订单的当前状态 | |
| 按状态、代码或日期范围过滤列出订单 | |
| 触发引擎状态与券商之间的手动对账 | |
治理 |
| 以 |
| 推进策略:草稿 → 研究 → 回测 → 模拟 → 实盘 | |
| 立即暂停实盘或模拟策略 | |
| 列出所有策略及其当前生命周期状态 | |
| 检查策略是否满足晋升条件 | |
审计 |
| 按审计事件 ID 提供交易决策的完整人类可读解释 |
| 最近的审计事件,可按代码或策略过滤 | |
| 已完成交易历史及结果 | |
| 指定时间窗口内的原始决策日志条目 | |
| 汇总统计:胜率、平均盈亏、Sharpe 代理指标 | |
| 按日期范围将审计记录导出为 CSV |
包含参数模式的完整工具文档:docs/mcp-tools.md
环境变量
引擎(packages/engine/.env)
变量 | 默认值 | 说明 |
|
|
|
|
| PostgreSQL 连接字符串 |
|
| Redis 连接字符串 |
|
|
|
| (空) | 当 |
| (空) | 当 |
|
| 实时交易请使用 |
|
| 最大仓位大小,按账户权益的比例计算(5%) |
|
| 每日硬性亏损上限(2%),一旦超出则停止交易 |
|
| 所有仓位的最大总敞口(80%) |
|
| 可同时持有的最大持仓数量 |
|
| 单笔交易的最大风险(1%) |
|
| 模拟交易模式下的模拟成交延迟 |
|
| 以基点计算的模拟滑点 |
|
| 仅为本地开发设置 为 |
| (空) | 使用 |
| (空) | 其他客户端密钥记录的 JSON 数组 |
MCP Server(packages/mcp/.env)
变量 | 默认值 | 说明 |
|
| 当前引擎服务的基础 URL |
完整的注释参考请参见仓库根目录下的 .env.example。
示例工作流程(模拟交易)
# 1. Add symbols
watchlist.add(symbols=["NVDA", "MSFT", "AAPL"], group="tech")
# 2. Classify regime
regime.evaluate(symbol="NVDA", timeframe="1Day")
# 3. Scan for signals
strategy.scan(group="tech", strategy="momentum_v1")
# 4. Validate before submitting
risk.validate_trade(symbol="NVDA", side="buy", qty=10, order_type="market")
# 5. Submit paper order
execution.paper_order(symbol="NVDA", side="buy", qty=10, order_type="market")
# 6. Review portfolio
portfolio.status()
# 7. Inspect the audit trail
audit.recent_events(symbol="NVDA", limit=1)
audit.explain_trade(audit_event_id="evt-...")运行测试
引擎(Python)
cd packages/engine
source .venv/bin/activate
pytest tests/ -vMCP Server(TypeScript)
cd packages/mcp
pnpm test完整 CI(lint + 类型检查 + 测试)
# From repo root
make check仓库结构
sentinel-execution-mcp/
├── packages/
│ ├── engine/ # Python FastAPI trading engine
│ │ ├── sentinel/ # Application source
│ │ ├── tests/ # Pytest test suite
│ │ └── alembic/ # Database migrations
│ └── mcp/ # TypeScript MCP server
│ └── src/
│ └── tools/ # One file per tool category
├── docker/ # Dockerfiles and docker-compose
├── docs/ # Architecture, tool reference, risk model
├── scripts/ # Setup and reset helpers
└── .env.example # Annotated environment variable reference安全免责声明
除非您完全了解每个组件,否则本软件仅供模拟交易和研究使用。使用真实的 Alpaca 凭据设置 APP_ENV=live 将会以真实资金进行真实交易。硬编码的风险限额是保守的默认值,请在使用前确认它们符合您自己的风险承受能力。作者对财务损失不承担任何责任。
许可证
MIT。请参阅 LICENSE。
This server cannot be deployed
Maintenance
Related MCP Connectors
Trade Robinhood through natural language in Claude Code.
Global stock research, ML forecasts, valuation signals, screeners & portfolio tracking in Claude
Trade Papertrade BTC and ETH perps from Claude, ChatGPT, Codex, Cursor and any MCP client.
1Unified financial infrastructure connecting AI agents directly to trade live/demo brokerage accounts, Web3 non-custodial wallets, real-time market data across equities, ETFs, crypto, forex, options, DeFi swaps, and prediction markets, institutional research feeds, and algorithmic strategy backtesters.
Related MCP Servers
- AlicenseBqualityFmaintenanceEnables AI assistants like Claude to interact with Paper's trading platform API using natural language, allowing users to manage accounts, portfolios, trades, and access market data through conversational requests.2310 npm24MIT
- AlicenseNot gradedqualityDmaintenanceEnables natural language trading operations through Alpaca's Trading API, supporting stocks, options, crypto, portfolio management, and real-time market data access through AI assistants like Claude.MIT
- AlicenseBqualityAmaintenanceProvides 32 trading analysis tools for AI-powered market analysis, including real-time data, technical indicators, options Greeks, scanners, and Interactive Brokers portfolio management, all accessible via natural language in Claude Desktop.36376MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants like Claude to run backtests, fetch market data, list strategies, and analyze trading algorithms via natural language.1,106GPL 3.0