使用说明
Upstox MCP服务器
模型上下文协议(MCP)服务器,用于将Upstox交易功能与AI助手和应用程序集成。
概述
此MCP服务器提供与Upstox交易API交互的工具和资源,允许AI助手帮助进行交易操作、市场数据检索和投资组合管理。
特性
- 🔧 交易工具:执行交易和管理订单
- 📊 市场数据:访问实时和历史市场数据
- 💼 投资组合管理:查看和管理您的交易组合
- 🔒 安全认证:使用Upstox OAuth进行安全的API访问
先决条件
- Python 3.12或更高版本
- Upstox交易账户
- Upstox API证书
安装
选项1:从PyPI安装(发布时)
pip install upstox-mcp-server
选项2:从源代码安装
-
克隆存储库:
git clone https://github.com/YOUR_USERNAME/upstox-mcp-server.git cd upstox-mcp-server -
安装依赖项:
使用紫外线(推荐):
uv sync或者使用pip:
pip install -e . -
为了发展:
# Using uv uv sync --dev # Or using pip pip install -e ".[dev]"
快速设置
1.获取您的Upstox API证书
- 访问 Upstox开发人员控制台
- 创建一个新应用程序以获取您的API凭据
- 记下API密钥、API机密和重定向URI
2.选择您的客户
这 config/ 目录包含常用MCP客户端的现成配置文件:
-
克劳德桌面:复制
config/claude_desktop_config.json致:- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 窗户:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- macOS:
-
光标IDE:使用
config/cursor_config.json作为光标设置的参考 -
Continue.dev:复制
config/continue_config.json向~/.continue/config.json -
Zed编辑:合并
config/zed_settings.json使用现有设置文件
3.设置您的凭据
替换所选配置文件中的占位符值:
{
"UPSTOX_API_KEY": "your_actual_api_key",
"UPSTOX_API_SECRET": "your_actual_api_secret",
"UPSTOX_REDIRECT_URI": "your_actual_redirect_uri"
}
4.重新启动客户端
重新启动MCP客户端以加载新配置。
配置
1. Upstox API 设置
- 访问 Upstox开发人员控制台
- 创建一个新应用程序以获取您的API凭据
- 记下你的:
- API密钥
- API秘密
- 重定向URI
2.环境变量
创建一个 .env 项目目录中的文件:
UPSTOX_API_KEY=your_api_key_here
UPSTOX_API_SECRET=your_api_secret_here
UPSTOX_REDIRECT_URI=your_redirect_uri_here
用法
运行MCP服务器
单独模式
upstox-mcp-server
或者使用Python模块:
python -m mcpserver
客户端集成
Upstox MCP服务器可以与各种兼容MCP的客户端集成。以下是常见客户端的配置示例:
1.克劳德桌面
适用于macOS (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"upstox": {
"command": "upstox-mcp-server",
"env": {
"UPSTOX_API_KEY": "your_api_key_here",
"UPSTOX_API_SECRET": "your_api_secret_here",
"UPSTOX_REDIRECT_URI": "your_redirect_uri_here"
}
}
}
}
对于Windows (%APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"upstox": {
"command": "upstox-mcp-server",
"env": {
"UPSTOX_API_KEY": "your_api_key_here",
"UPSTOX_API_SECRET": "your_api_secret_here",
"UPSTOX_REDIRECT_URI": "your_redirect_uri_here"
}
}
}
}
对于Linux (~/.config/Claude/claude_desktop_config.json):
{
"mcpServers": {
"upstox": {
"command": "upstox-mcp-server",
"env": {
"UPSTOX_API_KEY": "your_api_key_here",
"UPSTOX_API_SECRET": "your_api_secret_here",
"UPSTOX_REDIRECT_URI": "your_redirect_uri_here"
}
}
}
}
2.光标IDE
Cursor通过其设置支持MCP。将此添加到光标设置中:
方法1:通过光标设置UI
- 打开光标设置(Cmd/Ctrl+,)
- 搜索“MCP”或“模型上下文协议”
- 添加具有以下详细信息的新MCP服务器:
- 名字:
upstox - 命令:
upstox-mcp-server - 环境变量:
UPSTOX_API_KEY=your_api_key_here UPSTOX_API_SECRET=your_api_secret_here UPSTOX_REDIRECT_URI=your_redirect_uri_here
- 名字:
方法2:通过配置文件
添加到游标配置文件(~/.cursor/config.json 或类似):
{
"mcp": {
"servers": {
"upstox": {
"command": "upstox-mcp-server",
"env": {
"UPSTOX_API_KEY": "your_api_key_here",
"UPSTOX_API_SECRET": "your_api_secret_here",
"UPSTOX_REDIRECT_URI": "your_redirect_uri_here"
}
}
}
}
}
3.Continue.dev(VS代码扩展)
将其添加到“继续”配置文件中(~/.continue/config.json):
{
"models": [
{
"title": "GPT-4 with Upstox",
"provider": "openai",
"model": "gpt-4",
"apiKey": "your_openai_api_key"
}
],
"contextProviders": [
{
"name": "mcp",
"params": {
"serverName": "upstox",
"command": "upstox-mcp-server",
"env": {
"UPSTOX_API_KEY": "your_api_key_here",
"UPSTOX_API_SECRET": "your_api_secret_here",
"UPSTOX_REDIRECT_URI": "your_redirect_uri_here"
}
}
}
]
}
4.Zed编辑
对于Zed编辑器,将其添加到您的设置文件中(~/.config/zed/settings.json):
{
"assistant": {
"mcp_servers": {
"upstox": {
"command": "upstox-mcp-server",
"env": {
"UPSTOX_API_KEY": "your_api_key_here",
"UPSTOX_API_SECRET": "your_api_secret_here",
"UPSTOX_REDIRECT_URI": "your_redirect_uri_here"
}
}
}
}
}
5.自定义MCP客户端
对于自定义实现或其他MCP客户端,请使用以下通用配置:
服务器命令: upstox-mcp-server
运输: stdio
环境变量:
UPSTOX_API_KEY=your_api_key_here
UPSTOX_API_SECRET=your_api_secret_here
UPSTOX_REDIRECT_URI=your_redirect_uri_here
6.Docker集成
您还可以在Docker容器中运行MCP服务器以实现一致的部署:
Docker 文件:
FROM python:3.12-slim
WORKDIR /app
COPY . .
RUN pip install -e .
CMD ["upstox-mcp-server"]
Docker Compose (docker-compose.yml):
version: '3.8'
services:
upstox-mcp-server:
build: .
environment:
- UPSTOX_API_KEY=${UPSTOX_API_KEY}
- UPSTOX_API_SECRET=${UPSTOX_API_SECRET}
- UPSTOX_REDIRECT_URI=${UPSTOX_REDIRECT_URI}
volumes:
- ./logs:/app/logs
restart: unless-stopped
配置提示
环境变量管理
选项1:使用.env文件
创建一个 .env 项目目录中的文件:
UPSTOX_API_KEY=your_api_key_here
UPSTOX_API_SECRET=your_api_secret_here
UPSTOX_REDIRECT_URI=your_redirect_uri_here
选项2:系统环境变量
# Add to your shell profile (.bashrc, .zshrc, etc.)
export UPSTOX_API_KEY="your_api_key_here"
export UPSTOX_API_SECRET="your_api_secret_here"
export UPSTOX_REDIRECT_URI="your_redirect_uri_here"
选项3:客户特定环境 大多数MCP客户端允许您直接在其配置文件中设置环境变量,如上述示例所示。
客户端集成故障排除
-
服务器未启动:
- 确保
upstox-mcp-server已安装并位于您的PATH中 - 检查Python 3.12+是否可用
- 验证环境变量是否设置正确
- 确保
-
权限问题:
# Make sure the server executable has proper permissions chmod +x $(which upstox-mcp-server) -
环境变量未加载:
- 为.env文件使用绝对路径
- 确保变量赋值中没有多余的空格
- 检查特定于客户端的文档,了解环境变量语法
-
测试服务器:
# Test the server directly upstox-mcp-server --help # Run in debug mode UPSTOX_DEBUG=true upstox-mcp-server
高级配置
对于生产部署,请考虑:
-
日志记录配置:
LOG_LEVEL=INFO LOG_FILE=/var/log/upstox-mcp-server.log -
速率限制:
UPSTOX_RATE_LIMIT=100 # requests per minute -
超时设置:
UPSTOX_TIMEOUT=30 # seconds
使用MCP客户端
使用上述“客户端集成”部分中提供的配置,服务器可以与任何兼容MCP的客户端集成。
可用工具
目前可用:
helloWorld:基本连接测试
未来版本中将添加更多Upstox专用工具。
发展
建立开发环境
-
克隆并安装:
git clone https://github.com/YOUR_USERNAME/upstox-mcp-server.git cd upstox-mcp-server uv sync --dev -
运行测试:
pytest -
代码格式化:
black src/ isort src/ -
类型检查:
mypy src/
项目结构
upstox-mcp-server/
├── src/
│ └── mcpserver/
│ ├── __init__.py
│ ├── __main__.py # Entry point
│ └── server.py # Main server implementation
├── config/ # Ready-to-use client configurations
│ ├── claude_desktop_config.json
│ ├── cursor_config.json
│ ├── continue_config.json
│ └── zed_settings.json
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker container definition
├── pyproject.toml # Project configuration
├── README.md # This file
├── uv.lock # Dependency lock file
├── .env.example # Environment variables template
└── .gitignore # Git ignore patterns
贡献
- 分叉存储库
- 创建要素分支:
git checkout -b feature-name - 进行更改并添加测试
- 运行测试套件:
pytest - 格式代码:
black src/ && isort src/ - 提交您的更改:
git commit -am 'Add feature' - 推到分支:
git push origin feature-name - 提交拉取请求
安全
- 从不将API凭据提交到版本控制
- 使用环境变量进行敏感配置
- 遵循Upstox API安全最佳实践
- 通过GitHub Issues报告安全漏洞
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
免责声明
此软件用于教育目的。交易涉及风险。请自行决定使用。作者不对任何经济损失负责。
支持
- 📚 Upstox API文件
- 🔧 MCP规范
- 🐛 报告问题
- 💬 讨论
备注:替换 YOUR_USERNAME 在上面的URL中显示您的实际GitHub用户名。