印度股票分析服务器

一个全面的印度股票分析服务器,提供实时股票数据、基本面分析、历史数据、股票搜索和市场概览等功能,专为印度NSE和BSE交易所优化。

  • by parthashirolkar
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 parthashirolkar/stock-analysis-mcp

使用说明

印度股票分析MCP服务器

一个全面的模型上下文协议(MCP)服务器,用于分析在BSE和NSE交易所上市的印度股票。采用FastMCP构建,由雅虎金融API提供支持。

特性

  • 实时股票数据:当前价格、每日变化、交易量和市值
  • 基本面:市盈率、净资产收益率、债务权益比和其他关键指标
  • 历史数据:OHLC数据用于跨多个时间段的技术分析
  • 股票发现:按公司名称或股票代码搜索印度股票
  • 市场概述:NIFTY 50、SENSEX和其他主要印度指数
  • 新闻整合:情绪分析的最新新闻文章(由法学硕士处理)
  • 市场现状:实时市场交易时间和交易状态
  • 印度市场优化:专门用于NSE(.NS)和BSE(.BO)交换

先决条件

  • Python 3.13或更高版本
  • 紫外线 (推荐包管理器)
  • Claude Desktop(用于MCP集成)

安装

1.克隆存储库

git clone <repository-url>
cd stock-analysis-mcp

2.安装依赖项

# Using uv (recommended)
uv sync

# Or using pip
pip install -e .

3.验证安装

uv run python -c "import server; print('MCP server installed successfully')"

Claude桌面配置

1.查找配置文件

查找您的Claude Desktop配置文件:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • 视窗: %APPDATA%\Claude\claude_desktop_config.json

2.添加MCP服务器配置

{
  "mcpServers": {
    "indian-stock-analysis": {
      "command": "uv",
      "args": [
        "--directory",
        "/ABSOLUTE/PATH/TO/stock-analysis-mcp",
        "run",
        "server.py"
      ]
    }
  }
}

重要:替换 /ABSOLUTE/PATH/TO/stock-analysis-mcp 使用项目目录的实际绝对路径。

3.重新启动克劳德桌面

完全退出并重新启动Claude Desktop以加载新的MCP服务器。

4.验证连接

在Claude Desktop中查找工具图标。您应该看到可用的印度股票分析工具。

可用工具

1. stock_quote

获取当前股票价格和基本交易信息。

参数:

  • ticker (必填):印度股票代码(例如“RELIANCE”、“TCS”、“INFY”)

示例用法:

What's the current price of Reliance Industries?
Show me the stock quote for TCS

样本输出:

Current Stock Quote for RELIANCE (NSE):

Price Information:
* Current Price: ₹2,845.50
* Daily Change: +1.2% (₹33.80)
* Day's Range: ₹2,812.00 - ₹2,855.90
* Opening Price: ₹2,815.00
* Previous Close: ₹2,811.70

Trading Data:
* Volume: 15,234,567
* Market Cap: ₹19,82,123 Cr
* Currency: INR

2. company_fundamentals

为公司获取全面的基本面分析数据。

参数:

  • ticker (必填):印度股票代码

示例用法:

Show me the fundamentals for Infosys
What are the financial metrics for HDFC Bank?

样本输出:

Fundamental Analysis for INFOSYS LTD (INFY):

Company Information:
* Name: Infosys Limited
* Sector: Technology
* Industry: IT Services
* Exchange: NSE
* Website: https://www.infosys.com

Valuation Metrics:
* P/E Ratio: 28.5
* P/B Ratio: 8.2
* Market Cap: ₹6,45,789 Cr

Financial Metrics:
* EPS: ₹68.5
* ROE: 29.8%
* Dividend Yield: 2.1%

3. stock_news

获取特定股票的最新新闻文章。

参数:

  • ticker (必填):印度股票代码
  • limit (可选):最大文章数(默认值:5)

示例用法:

Show me recent news about Tata Motors
What are the latest news articles for ICICI Bank?

4. search_indian_stocks

按公司名称或股票代码搜索印度股票。

参数:

  • query (必填):搜索查询-公司名称或部分股票代码
  • limit (可选):最大结果数(默认值:10)

示例用法:

Search for banking stocks
Find companies with "tata" in the name

5. market_overview

获取当前印度市场指数和行业表现。

示例用法:

What's the current market overview?
Show me NIFTY and SENSEX performance

样本输出:

Indian Market Overview:

Market Indices:
* NIFTY 50: ₹21,834.25 (+0.8%)
* SENSEX: ₹72,156.85 (+0.6%)
* NIFTY BANK: ₹46,789.30 (+1.2%)
* NIFTY IT: ₹29,456.20 (-0.3%)

Market Status: Open
Market is currently open for trading
Current Time: 2024-01-15 14:30:25 IST

可用资源

1. indian-stock://market-status

当前印度市场状况和交易时间。

访问方式: MCP客户端资源接口

2. indian-stock://popular-stocks

经常分析的印度股票列表及其基本信息。

访问方式: MCP客户端资源接口

使用示例

投资组合分析工作流程

User: "Show me fundamentals of Reliance Industries"
[Uses company_fundamentals tool]

User: "What's current market status?"
[Uses market_overview tool]

User: "Get recent news about Reliance"
[Uses stock_news tool]

User: "How has Reliance performed technically over the past 6 months?"
[Uses technical_analysis tool]

库存发现工作流程

User: "Search for technology companies"
[Uses search_indian_stocks tool]

User: "Show me the current price of TCS"
[Uses stock_quote tool]

User: "What are TCS's financial metrics?"
[Uses company_fundamentals tool]

市场研究工作流程

User: "What's today's market overview?"
[Uses market_overview tool]

User: "Find banking stocks with good fundamentals"
[Uses search_indian_stocks tool + company_fundamentals tool]

User: "Show me technical analysis for top performers"
[Uses technical_analysis tool]

发展

项目结构

stock-analysis-mcp/
├── server.py              # Main MCP server with FastMCP tools
├── stock_analyzer.py      # Core data fetching and processing
├── pyproject.toml         # Project configuration and dependencies
├── main.py               # Entry point
└── README.md             # This file

代码质量

  • 用途 颈毛 用于linting和代码格式化
  • 遵循Python类型提示和async/await模式
  • 全面的错误处理
  • 结构化日志记录到stderr(MCP安全)

在本地运行服务器

# Start the MCP server
uv run python server.py

# The server will listen for JSON-RPC messages on stdin/stdout

添加新工具

  1. 添加数据提取功能 stock_analyzer.py
  2. 在中创建工具功能 server.py 随着 @mcp.tool() 装饰器
  3. 遵循现有的错误处理和返回格式模式

故障排除

常见问题

服务器未显示在Claude Desktop中

  • 验证中的绝对路径 claude_desktop_config.json
  • 完全退出并重新启动Claude Desktop
  • 检查是否安装了依赖项: uv sync

找不到自动收报机的数据

  • 确保股票代码有效(尝试使用.NS或.BO后缀)
  • 检查市场是否开放
  • 验证股票是否在NSE或BSE上市

获取数据时出错

  • 检查网络连接
  • 雅虎财经API可能有利率限制
  • 几分钟后重试

市场时机考虑因素

  • 市场交易时间:印度标准时间周一至周五上午9:15-下午3:30
  • 上市前:上午9:15之前数据可能有限
  • 周末:没有可用的实时数据
  • 假期:印度市场假期影响数据可用性

数据限制

  • 实时数据受雅虎财经API限制
  • 某些基本数据可能并非适用于所有股票
  • 历史数据的准确性取决于雅虎财经的数据质量
  • 新闻文章的可用性因库存和来源而异

贡献

  1. 克隆该仓库
  2. 创建要素分支: git checkout -b feature-name
  3. 进行更改并确保它们通过linting: uv run ruff check .
  4. 提交您的更改: git commit -m "feat: add new feature"
  5. 推到分支: git push origin feature-name
  6. 打开拉取请求

支持

对于问题和疑问:

  • 检查上面的故障排除部分
  • 在存储库上打开问题
  • 查看Claude Desktop集成的MCP文档

免责声明:此工具仅为教育目的提供财务信息。不是财务建议。在做出投资决策之前,始终咨询合格的金融专业人士。