库存工具MCP服务器
提供财务分析和股票市场实用工具的MCP(模型上下文协议)服务器。设计用于与人工智能助手一起执行技术分析、投资组合计算和市场数据操作。
特性
- 退货分析 -计算总回报、夏普比率、波动率和最大提款
- 波动性分析 -滚动波动率、VaR、CVaR和波动机制分类
- 库存比较 -通过相关性分析和排名比较多只股票
- 库存筛选 -按财务标准(市盈率、市值、行业等)筛选股票
- 投资组合指标 -投资组合绩效、权重和贝塔系数计算
- 技术水平 -枢轴点、斐波那契回撤和移动平均线支撑/阻力
- 移动平均值 -SMA和EMA计算与当前价格的距离
- 轴心点 -标准、Woodie和Camarilla枢轴计算
安装
需要Python 3.10-3.12和 紫外线.
# Clone the repository
cd stock_tools_mcp
# Install dependencies
uv sync
# Install with dev dependencies (for testing)
uv sync --extra dev用法
运行服务器
# Using uv (recommended)
uv run stock-tools-mcp-server
# Using the launcher script (Unix/macOS)
./launch-stock-tools.sh
# Using the Python launcher (cross-platform)
python launch.py
# With SSE transport
uv run stock-tools-mcp-server --sse
# With streamable HTTP transport
uv run stock-tools-mcp-server --streamableMCP客户端配置
添加到MCP客户端配置中。使用 launch.py 因为它可以定位 uv 即使PATH不可用(从AI助手启动时很常见):
{
"mcpServers": {
"stock-tools": {
"command": "python3",
"args": ["/path/to/stock_tools_mcp/launch.py"]
}
}
}直接使用紫外线的替代方案(需要PATH中的紫外线):
{
"mcpServers": {
"stock-tools": {
"command": "uv",
"args": ["run", "--directory", "/path/to/stock_tools_mcp", "stock-tools-mcp-server"]
}
}
}配置
通过环境变量进行配置:
| 变量 | 默认值 | 描述 |
|---|---|---|
STOCK_TOOLS_DEBUG | false | 启用调试模式 |
STOCK_TOOLS_LOG_LEVEL | INFO | 日志级别(调试、信息、警告、错误) |
STOCK_TOOLS_RISK_FREE_RATE | 0.02 | 夏普比率的无风险利率(2%) |
STOCK_TOOLS_TRADING_DAYS | 252 | 年化交易日数 |
STOCK_TOOLS_PORT | 8003 | 用于SSE/流式传输的服务器端口 |
STOCK_TOOLS_MAX_DATA_POINTS | 50 | 时间序列中返回的最大数据点 |
MCP_TRANSPORT | stdio | 传输协议(stdio、sse、流式传输) |
例子:
STOCK_TOOLS_DEBUG=true STOCK_TOOLS_LOG_LEVEL=DEBUG uv run stock-tools-mcp-server可用工具
计算回报
根据价格序列计算股票回报和绩效指标。
prices = [100.0, 102.0, 101.0, 105.0, 108.0]
periods = [3, 5] # Optional: specific period returns回报:总回报、平均日回报、波动率、夏普比率、最大提款、期回报。
分析挥发性
计算波动性和风险指标。
prices = [100.0, 102.0, ...] # At least window+1 prices
window = 20 # Rolling window size回报:当前/历史波动率、VaR(95%)、CVaR、波动机制(高/正常/低)。
比较股票
并排比较多只股票。
stock_data = {
"AAPL": [150.0, 152.0, 155.0, ...],
"MSFT": [300.0, 305.0, 310.0, ...]
}回报:每只股票的指标、相关矩阵、按回报和夏普比率排名。
screen_stocks
根据财务标准过滤库存。
criteria = {
"stocks": [
{"symbol": "AAPL", "sector": "Technology", "market_cap": 3000000000000, ...}
],
"min_market_cap": 1000000000000,
"max_pe_ratio": 30.0,
"sectors": ["Technology", "Healthcare"]
}计算投资组合计量
分析投资组合绩效。
holdings = {"AAPL": 10, "MSFT": 5}
prices = {"AAPL": [...], "MSFT": [...]}
benchmark_prices = [...] # Optional: for beta calculation回报:总回报、波动率、夏普比率、最大回撤、贝塔系数、投资组合权重。
计算技术水平
计算支撑位和阻力位。
prices = [100.0, 102.0, ...]
method = "pivot" # or "fibonacci", "moving_average"计算移动平均值
计算给定时间段的SMA和EMA。
prices = [100.0, 102.0, ...]
periods = [5, 10, 20, 50, 200] # Optional, these are defaults计算积分
根据OHLC数据计算枢轴点。
high = 110.0
low = 100.0
close = 105.0回报:标准、Woodie和Camarilla枢轴水平。
发展
运行测试
# Run all tests
uv run pytest
# Run with verbose output
uv run pytest -v
# Run specific test file
uv run pytest tests/test_server.py
# Run specific test
uv run pytest -k "test_basic_returns"项目结构
stock_tools_mcp/
├── server.py # Main MCP server implementation
├── launch.py # Cross-platform launcher
├── launch-stock-tools.sh # Unix launcher script
├── pyproject.toml # Project configuration
├── uv.lock # Dependency lock file
├── shared/
│ ├── __init__.py
│ └── types.py # MCPResponse type definition
└── tests/
├── __init__.py
├── conftest.py # Test fixtures
└── test_server.py # Test suite (41 tests)许可证
专有-奥尼克斯研发
