加密货币数据分析平台

MCP Crypto Server是一个高性能的加密货币市场数据和分析平台,提供实时市场数据、历史数据分析、LLM集成和市场新闻聚合功能。

  • by yanqinghao
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 yanqinghao/my-mcp-server

使用说明

MCP加密服务器

一个高性能的加密货币市场数据和分析平台,集成了FastMCP、CCXT、TimescaleDB和RSS提要。

概述

MCP Crypto Server是一个强大的平台,提供实时加密货币市场数据、高级分析、LLM驱动的见解和加密货币新闻聚合。基于模型上下文协议(MCP),它能够与人工智能应用程序无缝集成,同时通过CCXT提供强大的加密货币交换连接,通过TimescaleDB提供时间序列数据存储,并通过RSS提要提供实时新闻更新。

主要特点

  • 实时市场数据:从多个交易所访问实时加密货币市场数据
  • 历史数据分析:查询和分析历史价格和交易量数据
  • LLM集成:利用人工智能进行市场趋势分析和洞察
  • MCP协议支持:使用模型上下文协议轻松与AI应用程序集成
  • 可扩展体系结构:以优化的性能处理高请求量
  • TimescaleDB存储:高效的时间序列数据存储和查询
  • 多交换支持:通过CCXT连接到各种加密货币交易所
  • 加密新闻聚合:从多个加密RSS源收集和分析新闻
  • 新闻情绪分析:基于人工智能的加密新闻情绪分析
  • 自定义RSS源订阅:配置和管理新闻源

建筑

┌─────────────────────────────────────────────────────────────────┐
│                      MCP Client Applications                     │
│   (Claude Desktop, Custom AI Applications, Analysis Tools)       │
└───────────────────────────────┬─────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────┐
│                        FastMCP Server                            │
├─────────────┬─────────────────────┬────────────────┬────────────┤
│  Resources  │        Tools        │    Prompts     │  Schemas   │
│             │                     │                │            │
│ Market Data │  Market Analysis    │ Trading Rec.   │ Input/     │
│ Symbols     │  Price Data         │ Market Trend   │ Output     │
│ Historical  │  LLM Analysis       │ Analysis       │ Validation │
│ News Feed   │  News Analysis      │ News Impact    │            │
└─────────────┴─────────────────────┴────────────────┴────────────┘
                    │                      │
       ┌────────────┼──────────────────────┘
       │            │                │
       ▼            ▼                ▼
┌─────────────┐ ┌────────────┐ ┌────────────────────┐
│  Exchange   │ │    RSS     │ │  Database Service  │
│  Service    │ │  Service   │ │                    │
│             │ │            │ │    TimescaleDB     │
│     CCXT    │ │ Feed Parser│ │    Time-series     │
└─────────────┘ └────────────┘ └────────────────────┘

技术栈

  • FastMCP:基于模型上下文协议的服务器框架
  • 仓储管理系统:加密货币交易所连接库
  • TimescaleDB:PostgreSQL的时间序列数据库扩展
  • python:核心编程语言
  • 紫外线:用于依赖管理的高性能Python包管理器
  • 馈送分析器:RSS源解析库
  • NLTK/spaCy:新闻分析的自然语言处理

项目结构

mcp-crypto-server/
├── main.py                   # Main entry point with FastMCP server definition
├── config/                   # Configuration directory
│   ├── __init__.py
│   ├── settings.py           # Application settings and configuration
│   └── logging_config.py     # Logging configuration
├── resources/                # MCP resources
│   ├── __init__.py
│   ├── market_data.py        # Market data resources
│   ├── symbols.py            # Cryptocurrency symbols resources
│   ├── schemas.py            # Schema resources for the client
│   └── news.py               # News feed resources and endpoints
├── tools/                    # MCP tools
│   ├── __init__.py
│   ├── market_analysis.py    # Market analysis tools
│   ├── price_data.py         # Price retrieval tools
│   ├── llm_analysis.py       # LLM integration for data analysis
│   └── news_analysis.py      # News analysis and sentiment tools
├── services/                 # Service integrations
│   ├── __init__.py
│   ├── exchange_service.py   # Exchange API integration
│   ├── database_service.py   # Database service for storing data
│   ├── llm_service.py        # LLM service integration
│   └── news_service.py       # RSS feed management and processing
├── models/                   # Data models
│   ├── __init__.py
│   ├── market_data.py        # Data models for market data
│   ├── analysis.py           # Models for analysis results
│   └── news.py               # Models for news data and analysis
├── utils/                    # Utility functions
│   ├── __init__.py
│   ├── formatters.py         # Data formatting utilities
│   ├── validators.py         # Input validation utilities
│   └── feed_utils.py         # RSS feed utility functions
├── prompts/                  # MCP prompts
│   ├── __init__.py
│   ├── analysis_prompts.py   # Prompt templates for analysis
│   └── news_prompts.py       # Prompt templates for news analysis
├── pyproject.toml            # Project configuration and dependencies
└── uv.lock                   # Lock file for dependencies managed by uv

安装

先决条件

  • Python 3.9+
  • Docker和Docker Compose
  • uv包管理器

设置

  1. 克隆存储库:

    git clone https://github.com/yourusername/mcp-crypto-server.git
    cd mcp-crypto-server
    
  2. 如果你还没有安装uv:

    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  3. 创建虚拟环境并安装依赖项:

    uv venv
    uv pip sync
    
  4. 使用Docker设置TimescaleDB:

    docker-compose up -d timescaledb
    
  5. 配置环境变量:

    cp .env.example .env
    # Edit .env with your configuration settings
    

配置

编辑 config/settings.py 自定义应用程序的文件:

  • 数据库连接参数
  • Exchange API密钥和设置
  • MCP服务器配置
  • LLM服务设置
  • RSS源订阅设置
  • 新闻源配置
  • 日志记录级别和输出

配置RSS源

该系统附带了预定义的加密新闻源,但您可以对其进行自定义:

# In config/settings.py

RSS_FEEDS = [
    {
        "name": "CoinDesk",
        "url": "https://www.coindesk.com/arc/outboundfeeds/rss/",
        "update_interval": 900,  # 15 minutes
        "categories": ["news", "markets", "business"]
    },
    {
        "name": "Cointelegraph",
        "url": "https://cointelegraph.com/rss",
        "update_interval": 600,  # 10 minutes
        "categories": ["news", "analysis"]
    },
    # Add your custom RSS feeds here
]

用法

启动服务器

uv run python main.py

服务器将默认启动,并可通过MCP客户端进行连接。

MCP能力

服务器公开了以下MCP功能:

工具

  • market_analysis -分析市场趋势并提供技术指标
  • price_data -获取特定加密货币的实时或历史价格数据
  • llm_analysis -生成人工智能驱动的市场洞察和预测
  • news_analysis -分析新闻情绪及其对特定货币的影响
  • news_summary -生成最近加密货币新闻的摘要

资源

  • symbols://list -获取所有可用的加密货币符号
  • market_data://{symbol} -获取特定交易品种的实时市场数据
  • historical_data://{symbol}?timeframe={timeframe}&start={start}&end={end} -使用参数获取历史数据
  • news://recent -获取所有来源的最新消息
  • news://{source} -从特定来源获取新闻
  • news://by-coin/{symbol} -获取与特定加密货币相关的新闻

提示

  • analyze_market_trend -用于分析市场趋势的预定义提示
  • generate_trading_recommendation -根据当前市场数据生成交易建议
  • analyze_news_impact -分析最近的新闻如何影响加密货币价格

在MCP客户端上使用新闻功能

from mcp import Client

# Get recent news for a specific cryptocurrency
client = Client("http://localhost:8000")
news_response = await client.query(
    inputs=[{"symbol": "BTC/USD"}],
    resources=["news://by-coin/BTC"]
)
print(news_response.outputs)

# Analyze news sentiment and potential market impact
analysis_response = await client.query(
    inputs=[{"symbol": "BTC/USD", "timeframe": "24h"}],
    tools=["news_analysis"]
)
print(analysis_response.outputs)

发展

添加新交易所

  1. 更新 services/exchange_service.py 添加新交换配置的文件
  2. 执行所需的任何交易所特定处理
  3. 更新中的可用符号 resources/symbols.py

添加新的RSS源

  1. 更新 config/settings.py 添加新订阅源配置的文件
  2. 如果提要需要特殊解析,请扩展 services/news_service.py 使用自定义处理程序
  3. (可选)在中添加特定于源的端点 resources/news.py
# Example of adding a custom parser in services/news_service.py

def parse_custom_feed(feed_data, source_config):
    """Custom parser for a specific news source"""
    articles = []
    for entry in feed_data.entries:
        # Custom parsing logic
        articles.append({
            "title": entry.title,
            "url": entry.link,
            "published": parse_date(entry.published),
            "summary": entry.summary,
            "source": source_config["name"]
        })
    return articles

创建自定义工具

  1. 在中添加新文件 tools/ 目录
  2. 使用FastMCP装饰器实现您的工具逻辑:
    @mcp.tool()
    def your_tool_name(param1: str, param2: int) -> dict:
        """Tool description"""
        # Implementation
        return result
    

添加新资源

  1. 在相应的资源文件中创建资源函数:
    @mcp.resource("resource://{parameter}")
    def get_resource(parameter: str) -> str:
        """Resource description"""
        # Implementation
        return data
    

使用uv管理依赖关系

该项目使用uv进行快速高效的依赖关系管理:

  1. 添加新的依赖关系:

    uv add package_name
    
  2. 更新所有依赖关系:

    uv pip sync
    
  3. 生成锁文件:

    uv pip compile -o uv.lock
    

性能注意事项

  • 该应用程序利用TimescaleDB的时间序列优化来实现高效的历史数据查询
  • 考虑根据数据量使用具有适当块间隔的TimescaleDB超表
  • 为频繁访问的数据实施适当的缓存策略
  • 对于RSS提要,根据源更新频率调整轮询间隔,以尽量减少不必要的请求
  • 考虑为RSS提要更新实现后台任务调度程序,以避免阻塞主应用程序线程
  • 通过在负载均衡器后部署多个实例进行水平扩展

许可证

MIT许可证

致谢