✅ 官方Alpha Vantage MCP服务器
](https://smithery.ai/server/@calvernaz/alphavantage) 
用于股票市场数据的MCP服务器API、Alphavantage API。
MCP服务器URL: https://mcp.alphavantage.co
PyPi: https://pypi.org/project/alphavantage-mcp/
配置
获取API密钥
- 注册一个 免费Alphavantage API密钥
- 将API键添加到环境变量中,作为
ALPHAVANTAGE_API_KEY
安装
选项1:使用uvx(推荐)
使用AlphaVantage MCP服务器的最简单方法是 uvx:
# Run directly without installation
uvx alphavantage-mcp
# Or with specific arguments
uvx alphavantage-mcp --server http --port 8080选项2:使用pip
pip install alphavantage-mcp
alphavantage-mcp选项3:来源
git clone https://github.com/calvernaz/alphavantage.git
cd alphavantage
uv run alphavantage服务器模式
AlphaVantage服务器可以在两种不同的模式下运行:
标准服务器(默认)
这是用于Claude Desktop等工具的标准MCP服务器模式。
alphavantage
# or explicitly:
alphavantage --server stdio流式HTTP服务器
此模式通过HTTP流提供实时更新。
alphavantage --server http --port 8080具有OAuth 2.1身份验证的流式HTTP服务器
此模式将OAuth 2.1身份验证添加到HTTP服务器,遵循MCP安全访问规范。
alphavantage --server http --port 8080 --oauthOAuth配置
使用时 --oauth 标志,服务器需要通过环境变量配置OAuth 2.1:
所需的环境变量:
export OAUTH_AUTHORIZATION_SERVER_URL="https://your-auth-server.com/realms/your-realm"
export OAUTH_RESOURCE_SERVER_URI="https://your-mcp-server.com"可选环境变量:
# Token validation method (default: jwt)
export OAUTH_TOKEN_VALIDATION_METHOD="jwt" # or "introspection"
# For JWT validation
export OAUTH_JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----"
export OAUTH_JWT_ALGORITHM="RS256" # default
# For token introspection validation
export OAUTH_INTROSPECTION_ENDPOINT="https://your-auth-server.com/realms/your-realm/protocol/openid-connect/token/introspect"
export OAUTH_INTROSPECTION_CLIENT_ID="your-client-id"
export OAUTH_INTROSPECTION_CLIENT_SECRET="your-client-secret"
# Optional: Required scopes (space-separated)
export OAUTH_REQUIRED_SCOPES="mcp:access mcp:read"
# Optional: Enable session binding for additional security (default: true)
export OAUTH_SESSION_BINDING_ENABLED="true"OAuth功能
OAuth实现提供:
- OAuth 2.0受保护的资源元数据 端点(
/.well-known/oauth-protected-resource) - 承载令牌身份验证 对于所有MCP请求
- JWT与代币反思 验证方法
- MCP安全最佳实践 顺从:
- 令牌受众验证(防止令牌传递攻击) - 使用安全会话ID防止会话劫持 - 用户绑定会话以提高安全性 - 401响应的正确WWW-Authenticate标头
示例:Keycloak配置
使用Keycloak进行测试:
# Keycloak OAuth configuration
export OAUTH_AUTHORIZATION_SERVER_URL="https://keycloak.example.com/realms/mcp-realm"
export OAUTH_RESOURCE_SERVER_URI="https://mcp.example.com"
export OAUTH_TOKEN_VALIDATION_METHOD="introspection"
export OAUTH_INTROSPECTION_ENDPOINT="https://keycloak.example.com/realms/mcp-realm/protocol/openid-connect/token/introspect"
export OAUTH_INTROSPECTION_CLIENT_ID="mcp-server"
export OAUTH_INTROSPECTION_CLIENT_SECRET="your-keycloak-client-secret"
export OAUTH_REQUIRED_SCOPES="mcp:access"
# Start server with OAuth
alphavantage --server http --port 8080 --oauthOAuth客户端流
启用OAuth后,MCP客户端必须:
- 发现 授权服务器通过
GET /.well-known/oauth-protected-resource - 注册 使用授权服务器(如果使用动态客户端注册)
- 获取访问令牌 从授权服务器
- 包括令牌 在请求中:
Authorization: Bearer - 处理401/403响应 并根据需要刷新令牌
选项:
--server:从中选择stdio(默认)或http服务器模式--port:指定流式HTTP服务器的端口(默认值:8080)--oauth:启用OAuth 2.1身份验证(需要--server http)
📊 遥测
AlphaVantage MCP服务器包括可选的普罗米修斯指标,用于监控和可观察性。
启用遥测
设置以下环境变量以启用遥测:
# Enable telemetry (default: true)
export MCP_TELEMETRY_ENABLED=true
# Server identification (optional)
export MCP_SERVER_NAME=alphavantage
export MCP_SERVER_VERSION=1.0.0
# Metrics server port (default: 9464)
export MCP_METRICS_PORT=9464指标端点
启用遥测后,Prometheus指标可在以下网址获得:
http://localhost:9464/metrics可用指标
服务器为每次工具调用收集以下指标:
mcp_tool_calls_total-工具调用总数(按工具和结果标记)mcp_tool_latency_seconds-工具执行延迟直方图mcp_tool_request_bytes-请求有效载荷大小直方图mcp_tool_response_bytes-响应有效载荷大小直方图mcp_tool_active_concurrency-主动并发工具调用量表mcp_tool_errors_total-按类型(超时、输入错误、连接、未知)列出的错误总数
遥测使用示例
# Start server with telemetry enabled
export MCP_TELEMETRY_ENABLED=true
export MCP_SERVER_NAME=alphavantage-prod
export ALPHAVANTAGE_API_KEY=your_api_key
alphavantage --server http --port 8080
# View metrics
curl http://localhost:9464/metrics🚀 AWS无服务器部署
使用无状态MCP模式在AWS Lambda上部署AlphaVantage MCP服务器,以实现生产就绪、可扩展的部署。
快速部署AWS
cd deploy/aws-stateless-mcp-lambda
export ALPHAVANTAGE_API_KEY=your_api_key_here
./deploy.sh特征:
- ✅ 无状态MCP模式 -非常适合Lambda的执行模型
- ✅ 自动缩放 -使用AWS Lambda+API网关处理任何负载
- ✅ 成本效益高 -仅按请求付费(典型使用约1-5美元/月)
- ✅ 生产准备就绪 -基于AWS官方样本模式
- ✅ OAuth 2.1支持 -安全访问的可选身份验证
📖 完整文档: 看 AWS部署指南 有关完整的设置说明、测试、监控和故障排除。
使用Claude Desktop
选项1:使用uvx(推荐)
将此添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"alphavantage": {
"command": "uvx",
"args": ["alphavantage-mcp"],
"env": {
"ALPHAVANTAGE_API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}选项2:来源
如果克隆了存储库,请使用以下配置:
{
"mcpServers": {
"alphavantage": {
"command": "uv",
"args": [
"--directory",
"/alphavantage",
"run",
"alphavantage"
],
"env": {
"ALPHAVANTAGE_API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}以流式HTTP模式运行服务器
使用uvx:
{
"mcpServers": {
"alphavantage": {
"command": "uvx",
"args": ["alphavantage-mcp", "--server", "http", "--port", "8080"],
"env": {
"ALPHAVANTAGE_API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}来源:
{
"mcpServers": {
"alphavantage": {
"command": "uv",
"args": [
"--directory",
"/alphavantage",
"run",
"alphavantage",
"--server",
"http",
"--port",
"8080"
],
"env": {
"ALPHAVANTAGE_API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}📺 演示视频
观看Alpha Vantage MCP服务器的快速演示:

🔧 开发与出版
发布到PyPI
此项目包括用于发布到PyPI和TestPyPI的脚本:
# Publish to TestPyPI (for testing)
python scripts/publish.py --test
# Publish to PyPI (production)
python scripts/publish.py
# Use uv publish instead of twine
python scripts/publish.py --test --use-uv脚本使用 twine 默认情况下(推荐),但也可以使用 uv publish 随着 --use-uv 旗帜。
GitHub操作
该存储库包括一个用于自动发布的GitHub Actions工作流:
- 可信发布:使用PyPA与OpenID Connect的官方发布操作
- 手动触发:可以通过TestPyPI与PyPI的选项手动触发
- Twine回退:支持可信发布和基于线的发布
要设置发布,请执行以下操作:
- 用于可信发布 (推荐):
- 使用GitHub存储库在PyPI/TestPyPI上配置可信发布 - 无需秘密-使用OpenID Connect
- 用于基于令牌的发布:
- 添加 PYPI_API_TOKEN 和 TEST_PYPI_API_TOKEN 存储库的秘密 - 在工作流调度中使用“使用绳索”选项
🤝 贡献
我们欢迎社区的贡献!要开始,请查看我们的 贡献 设置说明指南, 开发技巧和指南。
