使用说明
mcp芬兰中心
模型上下文协议(MCP)服务器提供对以下内容的全面访问 Finnhub 金融市场数据API。专为Claude Desktop等人工智能助手打造,可无缝访问实时市场数据、技术指标、基本面和替代数据。
特性
- 15个MCP工具 覆盖100多个Finnhub API端点
- 实时市场数据:报价、蜡烛、报价数据、BBO
- 技术分析:50多个指标、模式、支撑/阻力
- 基础:财务、收益、股息、指标
- 替代数据:ESG评分、社会情绪、供应链
- 多资产支持:股票、加密货币、外汇、ETF、债券
- 基于项目的存储 具有自动CSV/JSON导出功能
- 后台作业处理 对于大型数据集
- 智能输出处理 使用令牌估计
- 可配置工具 -只启用您需要的功能
- AI友好错误 -带指导的结构化错误响应
- 内置帮助 -每个工具都支持
operation="help"为了发现
快速开始
先决条件
- Python 3.11或更高版本
- Finnhub API密钥 (免费版可用)
- 克劳德桌面版 或兼容的MCP客户端
安装
选项1:从PyPI安装(即将推出)
pip install mcp-finnhub
选项2:从源代码安装
git clone https://github.com/cfdude/mcp-finnhub.git
cd mcp-finnhub
pip install -e .
配置
- 创建
.env项目根目录中的文件:
# Required
FINNHUB_API_KEY=your_api_key_here
FINNHUB_STORAGE_DIR=/path/to/storage
# Optional - Tool configuration
FINNHUB_ENABLE_TECHNICAL_ANALYSIS=true
FINNHUB_ENABLE_STOCK_MARKET_DATA=true
FINNHUB_ENABLE_NEWS_SENTIMENT=true
# ... enable/disable other tools as needed
# Optional - Performance tuning
FINNHUB_RATE_LIMIT_RPM=300 # Requests per minute (30 free, 300 premium)
FINNHUB_REQUEST_TIMEOUT=30 # Request timeout in seconds
FINNHUB_SAFE_TOKEN_LIMIT=75000 # Conservative token limit
- 通过添加以下内容配置Claude Desktop以使用mcp finnhub
claude_desktop_config.json:
{
"mcpServers": {
"finnhub": {
"command": "mcp-finnhub",
"env": {
"FINNHUB_API_KEY": "your_api_key_here",
"FINNHUB_STORAGE_DIR": "/Users/yourname/finnhub-data"
}
}
}
}
- 重新启动克劳德桌面
第一个查询
问克劳德:
“给我AAPL的最新报价”
克劳德将使用 finnhub_stock_market_data 工具与 get_quote 获取苹果实时股票报价的操作。
可用工具
核心交易与分析(3个工具)
finnhub_stock_market_data-报价、蜡烛、报价数据、BBO、市场状况finnhub_technical_analysis-50+指标(RSI、MACD、SMA)、模式、信号finnhub_news_sentiment-公司新闻、市场新闻、情绪评分
基础与分析(5个工具)
finnhub_stock_fundamentals-财务、收益、股息、指标finnhub_stock_estimates-收入/每股收益估算、价格目标finnhub_stock_ownership-内幕交易、机构持股finnhub_alternative_data-ESG评分、社会情绪、供应链finnhub_sec_filings-美国证券交易委员会文件、收益记录
多资产数据(4个工具)
finnhub_crypto_data-加密货币交易所、符号、配置文件、蜡烛finnhub_forex_data-外汇汇率、蜡烛、交易所finnhub_calendar_data-IPO日历、收益日历、经济事件finnhub_market_events-市场假期、分析师上调/下调评级
管理工具(3个工具)
finnhub_project_create-创建项目工作区finnhub_project_list-列出所有具有统计信息的项目finnhub_job_status-检查后台作业状态
示例工作流
技术分析工作流程
User: "Analyze TSLA using RSI and MACD indicators"
Claude uses:
1. finnhub_technical_analysis → get_indicator (operation=get_indicator, symbol=TSLA, indicator=rsi)
2. finnhub_technical_analysis → get_indicator (operation=get_indicator, symbol=TSLA, indicator=macd)
3. Analyzes both indicators and provides trading insights
基础研究工作流程
User: "Research MSFT - get financials, earnings, and analyst estimates"
Claude uses:
1. finnhub_stock_fundamentals → get_basic_financials (operation=get_basic_financials, symbol=MSFT)
2. finnhub_stock_fundamentals → get_earnings (operation=get_earnings, symbol=MSFT)
3. finnhub_stock_estimates → get_earnings_estimates (operation=get_earnings_estimates, symbol=MSFT)
4. Summarizes financial health and analyst outlook
多资产组合工作流
User: "Create a project called 'my-portfolio', get quotes for AAPL, BTC-USD, and EUR/USD"
Claude uses:
1. finnhub_project_create → create (operation=create, project=my-portfolio)
2. finnhub_stock_market_data → get_quote (operation=get_quote, symbol=AAPL, project=my-portfolio)
3. finnhub_crypto_data → get_crypto_profile (operation=get_crypto_profile, symbol=BINANCE:BTCUSDT)
4. finnhub_forex_data → get_forex_rates (operation=get_forex_rates, base=EUR, project=my-portfolio)
5. All data saved to /storage/my-portfolio/ with CSV exports
工具配置
控制哪些工具可用于减少上下文窗口的使用:
# Disable tools you don't need
FINNHUB_ENABLE_CRYPTO=false
FINNHUB_ENABLE_FOREX=false
FINNHUB_ENABLE_ALTERNATIVE_DATA=false
# Core tools (always recommended)
FINNHUB_ENABLE_STOCK_MARKET_DATA=true
FINNHUB_ENABLE_TECHNICAL_ANALYSIS=true
FINNHUB_ENABLE_NEWS_SENTIMENT=true
速率限制
- 免费版:60个请求/分钟
- 基本层:150个请求/分钟(49.99美元/月)
- 高级级别:300个请求/分钟
- 企业层:自定义限制
mcp-finnhub通过指数退避和重试逻辑自动处理速率限制。
AI代理功能
帮助/发现
每个工具都支持 operation="help" 发现可用操作:
finnhub_stock_fundamentals(operation="help")
# Returns all operations with required/optional params and examples
结构化错误
错误返回可操作的JSON,而不是堆栈跟踪:
{
"error": "invalid_operation",
"message": "Operation 'get_data' not found",
"valid_operations": ["get_basic_financials", "get_dividends", ...],
"tool": "finnhub_stock_fundamentals"
}
存储结构
项目存储在子目录中:
FINNHUB_STORAGE_DIR/
├── my-portfolio/
│ ├── .project.json # Project metadata
│ ├── candles/ # Historical price data
│ ├── quotes/ # Real-time quotes
│ ├── news/ # News articles
│ ├── fundamentals/ # Financial data
│ ├── technical/ # Technical indicators
│ └── jobs/ # Background job results
└── research-tech/
└── ...
发展
设置
# Clone repository
git clone https://github.com/cfdude/mcp-finnhub.git
cd mcp-finnhub
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest --cov=mcp_finnhub --cov-report=term-missing
# Lint and format
ruff check --fix .
ruff format .
本地运行
# Set environment variables
export FINNHUB_API_KEY=your_api_key
export FINNHUB_STORAGE_DIR=/tmp/finnhub-data
# Run with STDIO transport (default, for Claude Desktop)
mcp-finnhub
# Run with HTTP streaming (recommended for persistent/remote connections)
mcp-finnhub --transport http --port 8000
# Run with SSE transport (deprecated, use HTTP instead)
mcp-finnhub --transport sse --port 8000
# Custom host binding for network access
mcp-finnhub --transport http --host 0.0.0.0 --port 8125
运输选项
| 运输 | 用例 | 命令 |
|---|---|---|
stdio |
Claude Desktop,本地MCP客户端 | mcp-finnhub (默认) |
http |
远程连接、持久服务器、Claude Code | mcp-finnhub --transport http --port 8000 |
sse |
旧式SSE客户端(已弃用) | mcp-finnhub --transport sse --port 8000 |
作为持久服务运行
对于HTTP传输,您可以将服务器作为后台服务运行:
# Using nohup (simple)
nohup mcp-finnhub --transport http --port 8000 > finnhub.log 2>&1 &
# Using systemd (Linux)
# See docs/DEPLOYMENT.md for service file examples
MCP检验员测试
# Install MCP inspector
npm install -g @modelcontextprotocol/inspector
# Test the server
mcp-inspector mcp-finnhub
建筑
- FastMCP服务器:基于MCP SDK的FastMCP构建,支持多传输
- 服务器上下文:依赖注入容器管理客户端和实用程序
- 多运输:STDIO(默认)、HTTP流和SSE传输
- 异步作业处理:大型数据集操作的后台工作人员
- 类型安全:所有API请求/响应的Pydantic模型
看 建筑.md 详细的设计文档。
api参考
看 API毫米 查看完整的工具文档和示例。
故障排除
“身份验证失败”错误
- 验证您的
FINNHUB_API_KEY是正确的 - 检查您的API密钥是否已过期
- 确保您没有超过费率限制
“找不到工具”错误
- 检查您的配置中是否启用了该工具
- 验证工具名称是否完全匹配(区分大小写)
存储权限错误
- 确保
FINNHUB_STORAGE_DIR存在并且可写 - 检查文件系统权限
速率限制错误
- 减少
FINNHUB_RATE_LIMIT_RPM在您的配置中 - 升级到高级级别以获得更高的限额
贡献
欢迎投稿!拜托:
- 克隆该仓库
- 创建要素分支
- 添加新功能的测试
- 确保所有测试通过
- 提交拉取请求
许可证
MIT许可证-请参阅 许可证 详情
致谢
支持
- 问题: GitHub问题
- 文档: docs/
- 芬兰API文件: finnhub.io/docs/api
由以下材料制成❤️ AI助手生态系统
