Public.com MCP服务器
一个MCP(模型上下文协议)服务器,为AI助手提供对Public.com股票和期权交易API的访问。
特性
- 实时市场数据 -股票和加密货币报价、买卖价差、交易量
- 期权分析 -链,赎罪,希腊语(δ,γ,θ,维加,ρ,IV)
- 投资组合管理 -查看头寸、股权、购买力、交易历史
- 下订单 -单腿和多腿订单,带安全防护装置
- 交易前分析 -交易前成本估算的飞行前计算
先决条件
- Node.js 18+或 包子 运行时
- 具有API访问权限的Public.com帐户
- 来自的API密钥 Public.com设置
安装
通过npm
npm install -g public-com-mcp通过npx(无需安装)
npx public-com-mcp来源
git clone https://github.com/Gajesh2007/public-com-mcp.git
cd public-com-mcp
bun install配置
编辑 .env 使用您的凭据:
# Required - your API secret key
PUBLIC_API_SECRET_KEY=your-api-secret-key
# Optional - default account ID (use get_accounts to find yours)
PUBLIC_DEFAULT_ACCOUNT_ID=
# Safety - set to "true" to enable live trading (default: false)
ENABLE_TRADING=false用法
使用克劳德桌面
添加到您的Claude桌面配置(~/Library/Application Support/Claude/claude_desktop_config.json):
使用npx(最简单):
{
"mcpServers": {
"public-stocks": {
"command": "npx",
"args": ["public-com-mcp"],
"env": {
"PUBLIC_API_SECRET_KEY": "your-api-key"
}
}
}
}使用全局安装:
{
"mcpServers": {
"public-stocks": {
"command": "public-com-mcp",
"env": {
"PUBLIC_API_SECRET_KEY": "your-api-key"
}
}
}
}使用Bun(来源):
{
"mcpServers": {
"public-stocks": {
"command": "bun",
"args": ["run", "/path/to/public-com-mcp/src/index.ts"]
}
}
}独立
# Via npx
npx public-com-mcp
# Via global install
public-com-mcp
# From source with Bun
bun run src/index.ts发展
# Run with hot reload
bun run dev
# Build for distribution
bun run build
# Run tests
bun test可用工具
市场数据
| 工具 | 说明 |
|---|---|
get_quote | 获取单个交易品种的实时报价 |
get_quotes | 多个交易品种的批量报价(最多50个) |
get_instrument | 获得交易品种的交易能力 |
search_instruments | 搜索/筛选可用仪器 |
选项
| 工具 | 说明 |
|---|---|
get_option_expirations | 列出可用的到期日期 |
get_option_chain | 到期的完整期权链 |
get_option_greeks | 希腊期权合约 |
账户
| 工具 | 说明 |
|---|---|
get_accounts | 列出您的交易账户 |
get_portfolio | 带有头寸的投资组合快照 |
get_account_history | 交易历史 |
订单
| 工具 | 说明 |
|---|---|
preflight_order | 放置前估算成本 |
preflight_multileg | 估算多腿策略成本 |
place_order | 下单单腿订单\* |
place_multileg_order | 位置选项分散\* |
cancel_order | 取消待处理订单\* |
get_order | 检查订单状态 |
\*需要 ENABLE_TRADING=true
示例提示
一旦连接到克劳德,你可以问:
- “AAPL目前的价格是多少?”
- “显示下周五到期的SPY期权链”
- “对于2月份到期的AAPL 250电话,希腊人有什么看法?”
- “我的投资组合里有什么?”
- “购买10股NVDA需要多少钱?”
安全
默认情况下,交易被禁用。 这 place_order, place_multileg_order,以及 cancel_order 除非满足以下条件,否则工具将无法执行 ENABLE_TRADING=true 设置在您的环境中。
当交易被禁用时,您仍然可以:
- 查看实时报价和市场数据
- 分析期权链和希腊
- 查看您的投资组合和账户历史记录
- 运行飞行前计算以估算订单成本
项目结构
src/
├── index.ts # Entry point (stdio transport)
├── server.ts # MCP server configuration
├── client/
│ ├── types.ts # TypeScript type definitions
│ ├── auth.ts # API token management
│ └── public-api.ts # HTTP client for Public.com
├── tools/
│ ├── market-data.ts # Quote & instrument tools
│ ├── options.ts # Options chain & Greeks
│ ├── account.ts # Portfolio & history
│ └── orders.ts # Order placement (guarded)
└── schemas/
└── index.ts # Zod validation schemas许可证
麻省理工学院
免责声明
该软件按原样提供。交易股票和期权涉及风险。在启用实时交易之前,始终验证订单。作者不对任何经济损失负责。
