返回 MCP 目录
public公开dns本地运行

CoinGecko MCP Server

CoinGecko Server是一个提供加密货币数据交互的MCP服务和OpenAI函数调用接口的项目。

article

README

🚀 CoinGecko 服务器

CoinGecko 服务器是一个模型上下文协议(MCP)服务器和 OpenAI 函数调用服务,用于与 CoinGecko Pro API 进行交互,为用户提供加密货币相关的数据服务。

🚀 快速开始

安装

npm install coingecko-server

环境配置

在项目根目录中创建一个 .env 文件:

COINGECKO_API_KEY=your_api_key_here

与Claude Desktop一起使用

Claude Desktop 完全支持 MCP 功能。要使用此服务器,可按以下步骤操作:

  1. 安装 Claude Desktop
  2. 添加到您的 Claude Desktop 配置中:
    • 在 macOS 上:~/Library/Application Support/Claude/claude_desktop_config.json
    • 在 Windows 上:%APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "coingecko": {
      "command": "node",
      "args": ["/path/to/coingecko-server/build/index.js"],
      "env": {
        "COINGECKO_API_KEY": "your-api-key-here"
      }
    }
  }
}
  1. 重启 Claude Desktop

与 OpenAI 函数调用一起使用

import { CoinGeckoService } from 'coingecko-server';
import OpenAI from 'openai';

const openai = new OpenAI();
const coinGeckoService = new CoinGeckoService(process.env.COINGECKO_API_KEY);

// 获取函数定义
const functions = CoinGeckoService.getOpenAIFunctionDefinitions();

// 示例:获取历史数据
const response = await openai.chat.completions.create({
  model: "gpt-4-turbo-preview",
  messages: [{ role: "user", content: "获取过去一周的比特币价格历史" }],
  functions: [functions[2]], // get_historical_data 函数
  function_call: "auto",
});

if (response.choices[0].message.function_call) {
  const args = JSON.parse(response.choices[0].message.function_call.arguments);
  const history = await coinGeckoService.getHistoricalData(
    args.id,
    args.vs_currency,
    args.from,
    args.to,
    args.interval
  );
}

✨ 主要特性

  • 分页列出支持的加密货币
  • 通过名称或符号查找 Coin ID
  • 历史价格、市值和成交量数据
  • OHLC(开盘价、最高价、最低价、收盘价)烛台数据
  • 具有刷新功能的本地硬币缓存

该服务器提供以下工具:

  • get-coins:获取分页支持的硬币列表
  • find-coin-ids:查找加密货币名称或符号对应的 CoinGecko ID
  • get-historical-data:获取历史价格、市值和成交量数据
  • get-ohlc-data:获取 OHLC 烛台数据
  • refresh-cache:刷新本地硬币列表缓存

📚 详细文档

数据类型

OHLCData

interface OHLCData {
  open: number;
  high: number;
  low: number;
  close: number;
  volume?: number;
  timestamp: string;
}

HistoricalData

interface HistoricalData {
  [key: string]: OHLCData[];
}

CoinInfo

interface CoinInfo {
  id: string;
  symbol: string;
  name: string;
  priceUsd: string;
  marketCapUsd: string;
  volumeUsd24Hr: string;
  latestUpdate: string;
}

速率限制

有关 API 调用的速率限制,请参考 CoinGecko Pro API 文档

📄 许可证

该库在 MIT 许可证下发布。

help

运行方式说明

cloud

托管运行

托管运行通常表示这个 MCP Server 由服务方环境承载,用户一般按页面提供的连接方式或授权流程接入,不需要在本地长期启动一个 MCP 进程

  1. 打开服务方连接页
  2. 完成授权或复制端点
  3. 在 MCP 客户端中连接
terminal

本地运行 / 其它方式

本地运行通常需要用户在自己的电脑或服务器上安装依赖,把 server_config 复制到 MCP 客户端,并按 env_schema 补齐环境变量、密钥或其它配置

  1. 复制 server_config
  2. 安装所需依赖
  3. 补齐环境变量后重启客户端