CoinGecko MCP Server

CoinGecko MCP Server

🚀 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 许可证下发布。

  • 0 关注
  • 0 收藏,15 浏览
  • system 提出于 2025-09-22 01:42

相似服务问题

相关AI产品