印度证券交易所MCP服务器
该服务器通过模型上下文协议(MCP)提供对印度证券交易所(BSE&NSE)实时市场数据的访问,由 印度API.
🚀 快速开始
先决条件
- Python 3.8+
- pip(Python包安装程序)
- API印度API密钥:注册地址: https://indianapi.in/ 并获得股票市场API的API密钥
安装
备注:此包尚未发布到PyPI。请暂时使用源代码安装。
选项1:从源代码快速安装(推荐)
git clone https://github.com/GirishKumarDV/Live-NSE-BSE-MCP.git
cd Live-NSE-BSE-MCP
pip install -e .选项2:开发安装
git clone https://github.com/GirishKumarDV/Live-NSE-BSE-MCP.git
cd Live-NSE-BSE-MCP
pip install -r requirements.txt
pip install -e .选项3:手动执行(无需安装)
如果您不想安装该软件包:
git clone https://github.com/GirishKumarDV/Live-NSE-BSE-MCP.git
cd Live-NSE-BSE-MCP
pip install -r requirements.txt
# Run directly with: python -m ise_mcp.server重要:由于包尚未在PyPI上,请使用模块执行(python -m ise_mcp.server)或者从源代码安装以使控制台脚本工作。
配置
- 获取API密钥:
- 访问 https://indianapi.in/ - 注册一个免费帐户 - 导航至股票市场API部分 - 订阅以获取您的API密钥
- 配置环境变量:
# Copy the example environment file
cp env.example .env
# Edit .env and add your IndianAPI key
# ISE_API_KEY=your_indianapi_key_here用法
HTTP服务器模式(适用于Cursor、VSCode、Dify等web客户端)
安装后,您可以通过多种方式运行服务器:
方法1:模块执行(推荐)
# From the project root directory
python -m ise_mcp.server方法2:使用批处理脚本(Windows)
# Use the provided batch script (note the .\ prefix for PowerShell)
.\ise-mcp-server.bat
# Or with environment variables
$env:ISE_HTTP_PORT=9000; .\ise-mcp-server.bat方法三:开发模式
# If not installed, run as module from parent directory
cd ..
python -m ise_mcp.server备注:来自PyPI的控制台脚本(ise-mcp-server)尚未提供。请改用模块执行或批处理脚本。
服务器将于启动 http://localhost:8000 默认情况下。
标准模式(适用于Claude Desktop等直接MCP客户端)
方法1:模块执行(推荐)
# From the project root directory
python -m ise_mcp.stdio_server方法2:使用批处理脚本(Windows)
# Use the existing batch script (note the .\ prefix for PowerShell)
.\ise-mcp-stdio.bat备注:来自PyPI的控制台脚本(ise-mcp-stdio)尚未提供。请改用模块执行或批处理脚本。
重要:不要直接运行服务器文件(例如。, python server.py)因为这将导致导入错误。始终使用控制台脚本或模块执行。
🔧 配置
服务器使用环境变量进行配置。创建一个 .env 项目根目录中的文件,包含以下变量:
# Required: API Key from IndianAPI (https://indianapi.in/)
ISE_API_KEY=your_indianapi_key_here
# Optional: API Base URL (default: https://stock.indianapi.in/)
ISE_API_BASE_URL=https://stock.indianapi.in/
# Optional: Server configuration
ISE_HTTP_HOST=0.0.0.0
ISE_HTTP_PORT=8000
ISE_REQUEST_TIMEOUT=30
ISE_LOG_LEVEL=INFO重要:The ISE_API_KEY 是必需的,没有它服务器将无法启动。请确保添加您的 .env 文件到 .gitignore 以防止提交敏感信息。
🌐 客户端集成
Claude桌面集成
Claude Desktop使用stdio传输进行直接MCP通信。
步骤1:安装服务器
由于该包尚未安装在PyPI上,请从源代码安装:
git clone https://github.com/GirishKumarDV/Live-NSE-BSE-MCP.git
cd Live-NSE-BSE-MCP
pip install -e .步骤2:配置Claude桌面
视窗:编辑 %APPDATA%\Claude\claude_desktop_config.json macOS:编辑 ~/Library/Application Support/Claude/claude_desktop_config.json
根据您的设置选择以下配置方法之一:
选项1:使用虚拟环境Python(最可靠)
如果您有一个安装了依赖项的虚拟环境:
{
"mcpServers": {
"ise-mcp": {
"command": "C:\\path\\to\\your\\project\\venv\\Scripts\\python.exe",
"args": ["-m", "ise_mcp.stdio_server"],
"cwd": "C:\\path\\to\\your\\project",
"env": {
"ISE_API_KEY": "your_indianapi_key_here"
}
}
}
}选项2:使用PYTHONPATH(推荐回退)
{
"mcpServers": {
"ise-mcp": {
"command": "python",
"args": ["-m", "ise_mcp.stdio_server"],
"cwd": "C:\\path\\to\\your\\project",
"env": {
"ISE_API_KEY": "your_indianapi_key_here",
"PYTHONPATH": "C:\\path\\to\\your\\project"
}
}
}
}选项3:使用批处理脚本(Windows)
{
"mcpServers": {
"ise-mcp": {
"command": "C:\\path\\to\\your\\project\\ise-mcp-stdio.bat",
"cwd": "C:\\path\\to\\your\\project",
"env": {
"ISE_API_KEY": "your_indianapi_key_here"
}
}
}
}选项4:直接执行文件
{
"mcpServers": {
"ise-mcp": {
"command": "python",
"args": ["ise_mcp/stdio_server.py"],
"cwd": "C:\\path\\to\\your\\project",
"env": {
"ISE_API_KEY": "your_indianapi_key_here",
"PYTHONPATH": "C:\\path\\to\\your\\project"
}
}
}
}选项5:使用PowerShell(如果执行策略允许)
{
"mcpServers": {
"ise-mcp": {
"command": "powershell",
"args": ["-Command", "cd 'C:\\path\\to\\your\\project'; python -m ise_mcp.stdio_server"],
"env": {
"ISE_API_KEY": "your_indianapi_key_here"
}
}
}
}选项6:全局安装后
如果您已使用全局安装了该软件包 pip install -e .:
{
"mcpServers": {
"ise-mcp": {
"command": "python",
"args": ["-m", "ise_mcp.stdio_server"],
"env": {
"ISE_API_KEY": "your_indianapi_key_here"
}
}
}
}macOS/Linux等价物:
对于macOS/Linux,将Windows路径替换为Unix风格的路径:
C:\\path\\to\\your\\project成为/path/to/your/projectvenv\\Scripts\\python.exe成为venv/bin/python- 使用正斜杠
/而不是反睫毛\\
笔记:
- 替换
C:\\path\\to\\your\\project使用您的实际项目路径 - 替换
your_indianapi_key_here使用来自的实际API密钥 印度API - 按顺序尝试选项- 选项1 (虚拟环境)最可靠
- 如果一个不起作用,试试下一个选项
步骤3:重新启动克劳德桌面
保存配置后,重新启动Claude Desktop。您应该在聊天中看到ISE MCP工具。
测试Claude集成
配置后,您可以询问Claude:
- “向我展示印度市场的趋势股票”
- “为信实工业获取数据”
- “今天涨幅最大的是什么?”
VSCode集成
VSCode可以使用HTTP传输连接到MCP服务器。
步骤1:安装MCP扩展
在VSCode中安装MCP兼容扩展,或使用内置的MCP支持(如果可用)。
步骤2:启动HTTP服务器
首先克隆并设置服务器:
# Clone the repository
git clone https://github.com/GirishKumarDV/Live-NSE-BSE-MCP.git
cd Live-NSE-BSE-MCP
# Install dependencies
pip install -r requirements.txt
# Start the server
python -m ise_mcp.server步骤3:配置VSCode
添加到您的VSCode设置.json:
{
"mcp.servers": {
"ise-mcp": {
"url": "http://localhost:8000/jsonrpc",
"type": "http"
}
}
}步骤4:设置环境变量
确保您的 ISE_API_KEY 已设置:
# In your terminal before starting VSCode
export ISE_API_KEY=your_indianapi_key_here
code .光标集成
Cursor通过HTTP传输支持MCP。
步骤1:启动HTTP服务器
首先克隆并设置服务器:
# Clone the repository
git clone https://github.com/GirishKumarDV/Live-NSE-BSE-MCP.git
cd Live-NSE-BSE-MCP
# Install dependencies
pip install -r requirements.txt
# Start the server
python -m ise_mcp.server步骤2:配置游标
在光标中,转到设置→ 扩展→ MCP并添加:
- 服务器URL:
http://localhost:8000/jsonrpc - 服务器类型:HTTP JSON-RPC
步骤3:环境设置
请确保您的API密钥已在 .env 文件:
ISE_API_KEY=your_indianapi_key_here测试游标集成
您现在可以询问Cursor的AI:
- “使用ISE MCP获取TCS的库存数据”
- “给我看看NSE上最活跃的股票”
其他MCP客户端
HTTP传输(Web客户端)
对于任何基于HTTP的MCP客户端:
- 统一资源定位符:
http://localhost:8000/jsonrpc - 类型:HTTP JSON-RPC 2.0
- 内容类型:
application/json
标准运输(命令行)
对于基于stdio的MCP客户端:
# Clone and setup first
git clone https://github.com/GirishKumarDV/Live-NSE-BSE-MCP.git
cd Live-NSE-BSE-MCP
pip install -r requirements.txt
# Direct stdio connection
python -m ise_mcp.stdio_server
# Or with environment variables
ISE_API_KEY=your_key python -m ise_mcp.stdio_serverDify集成
Dify可以使用HTTP传输进行连接:
- 统一资源定位符:
http://localhost:8000/jsonrpc - 类型:HTTP上的MCP
- 标头:
Content-Type: application/json
可用工具
服务器提供以下工具用于访问印度股市数据:
市场数据工具
get_stock_data-获取特定公司的详细财务数据get_trending_stocks-获取涨幅最大和跌幅最大的热门股票get_52_week_high_low-获取过去52周内价格最高和最低的股票get_nse_most_active-按交易量获取NSE上最活跃的股票get_bse_most_active-按交易量获取BSE上最活跃的股票get_price_shockers-获取价格发生重大变化的股票
研究工具
search_industry-搜索特定行业内的公司get_analyst_recommendations-获取分析师的目标价格和建议get_stock_forecasts-获取股票的详细预测信息get_historical_data-使用各种过滤器获取历史股票数据get_historical_stats-获取股票的历史统计数据
投资工具
search_mutual_funds-搜索共同基金get_mutual_funds-获取包含资产净值和回报的最新共同基金数据get_commodities-获取实时商品期货数据
🔗 API终点
健康检查
GET http://localhost:8000/health服务器信息
GET http://localhost:8000/infoMCP JSON-RPC
POST http://localhost:8000/jsonrpc📝 示例用法
获取股票数据
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_stock_data",
"arguments": {
"name": "Reliance"
}
},
"id": 1
}获取热门股票
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_trending_stocks",
"arguments": {}
},
"id": 2
}🛠️ 开发与测试
运行测试
该项目包括几个功能不同方面的测试文件:
1.工具测试
# Test individual MCP tools functionality
python tests/test_tools.py2.连接测试
# Test basic HTTP connections and API responses
python tests/test_connection.py3.清洁工具测试
# Test tool validation and clean responses
python tests/test_clean_tools.py4.VSCode集成测试
# Test VSCode MCP integration
python tests/test_vscode_connection.py5.运行所有测试
# If you have pytest installed (recommended)
pytest tests/
# Or run all test files manually
python tests/test_tools.py && python tests/test_connection.py && python tests/test_clean_tools.py && python tests/test_vscode_connection.py使用不同客户端进行测试
卷曲测试
# Start the HTTP server
python -m ise_mcp.server
# Test health endpoint
curl http://localhost:8000/health
# Test server info
curl http://localhost:8000/info
# Test MCP tool call
curl -X POST http://localhost:8000/jsonrpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_trending_stocks",
"arguments": {}
},
"id": 1
}'使用Python客户端进行测试
# Use the included Python client
cd client
python simple_mcp_client.py
# Or run the basic usage example
cd examples
python basic_usage.py调试模式
将日志级别设置为DEBUG .env 文件:
ISE_LOG_LEVEL=DEBUG开发工作流程
- 设置开发环境:
git clone https://github.com/GirishKumarDV/Live-NSE-BSE-MCP.git
cd Live-NSE-BSE-MCP
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
pip install -e .- 创建配置:
cp env.example .env
# Edit .env and add your API key- 运行测试:
python tests/test_tools.py- 启动开发服务器:
python -m ise_mcp.server🔒 安全
- 环境变量:所有敏感配置都存储在环境变量中
- API密钥保护:API密钥从未在响应中记录或公开
- 跨域资源共享:为跨源请求设置适当的CORS标头
- 输入验证:所有工具输入都根据JSON模式进行验证
📦 发布到PyPI
当前状态:此包尚未发布到PyPI。用户必须从源安装。
用户应使用中描述的方法从源代码安装 安装 部分。
开发安装
# Clone and install in development mode
git clone https://github.com/GirishKumarDV/Live-NSE-BSE-MCP.git
cd Live-NSE-BSE-MCP
pip install -e ".[dev]"
# Run tests
pytest tests/
# Format code
black .
# Type check
mypy ise_mcp/🐛 故障排除
常见问题
- 相对导入错误 (
attempted relative import with no known parent package):
- 问题:跑步 python server.py 或 python stdio_server.py 直接 - 解决方案:使用模块执行(python -m ise_mcp.server, python -m ise_mcp.stdio_server)或从源代码安装 pip install -e .
- 服务器无法启动:
- 检查你的 ISE_API_KEY 从 印度API 设置在 .env 文件 - 验证API密钥是否有效且未过期
- API错误:
- 验证您的IndianAPI密钥是否有效,是否有足够的配额 - 检查您是否已在IndianAPI上订阅API股票市场
- 连接问题:
- 确保服务器在正确的主机/端口上运行 - 检查端口8000是否可用 - 验证防火墙设置
- CORS错误:
- 服务器包含CORS标头,但请检查您的客户端配置 - 确保您向正确的端点发出请求
- 未找到模块:
- 确保您已安装了以下软件包 pip install -e . 从项目目录 - 检查虚拟环境是否已激活 - 注意:PyPI安装(pip install ise-mcp-server)尚未提供
- 导入错误:
- 检查Python版本兼容性(需要Python 3.8+) - 确保安装了所有依赖项: pip install -r requirements.txt
安装问题
错误: No module named 'ise_mcp'
# Solution 1: Install the package
pip install -e .
# Solution 2: Run from correct directory
cd /path/to/Live-NSE-BSE-MCP
python -m ise_mcp.server错误: ModuleNotFoundError: No module named 'mcp'
# Install MCP dependency
pip install mcp>=1.0.0
# Or install all requirements
pip install -r requirements.txt客户端集成问题
克劳德桌面未检测到服务器
- 检查配置文件位置:
- 视窗: %APPDATA%\Claude\claude_desktop_config.json - macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
- 验证JSON语法是否有效
- 完全重新启动克劳德桌面
- 检查控制台日志中的错误消息
VSCode/游标连接问题
- 确保HTTP服务器正在运行:
python -m ise_mcp.server - 测试服务器运行状况:
curl http://localhost:8000/health - 检查MCP扩展是否正确安装
- 验证是否设置了环境变量
错误处理
服务器以JSON-RPC格式提供详细的错误消息:
-32600:无效请求-32601:未找到方法-32602:无效参数-32603:内部错误
交通特定问题
HTTP传输
- 检查端口8000是否可用:
netstat -an | grep 8000 - 验证防火墙设置
- 测试用
curl http://localhost:8000/health - 检查服务器日志中的错误消息
标准运输
- 确保没有其他输出到stdout
- 检查是否设置了环境变量
- 验证MCP客户端配置
- 测试stdio连接:
echo '{"jsonrpc":"2.0","method":"ping","id":1}' | python -m ise_mcp.stdio_server
发展问题
测试失败
# Check if server is running
curl http://localhost:8000/health
# Verify API key is set
echo $ISE_API_KEY
# Run individual tests
python tests/test_connection.py
python tests/test_tools.py调试服务器问题
- 启用调试登录
.env:
ISE_LOG_LEVEL=DEBUG- 检查服务器日志以获取详细的错误信息
- 使用curl手动测试API端点
- 验证IndianAPI服务状态
📚 相关项目
🤝 贡献
- 分叉存储库
- 创建要素分支
- 进行更改
- 如果适用,添加测试
- 提交拉取请求
📄 许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
🔗 链接
- 印度API市场:
- API印度股票:
- 模型上下文协议:
- MCP规范:
______________________________________________________________________
