CoinGecko Server
一个用于CoinGecko Pro API的人工智能MCP服务器(兼容OpenAI函数调用)。
简介
CoinGecko Server 是一个 MCP(模型上下文协议)服务器,可与 CoinGecko Pro API 交互,同时兼容 OpenAI 函数调用。
核心功能
- 获取加密货币列表及详情
- 查询历史价格、市值和交易量数据
- 获取 OHLC(开盘、最高、最低、收盘)K线数据
- 维护本地币种缓存(支持刷新)
安装
npm install coingecko-server
配置
- 创建
.env
文件:
COINGECKO_API_KEY=your_api_key_here
使用方法
在 Claude Desktop 中使用
- 安装 Claude Desktop
- 修改配置文件:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
{
"mcpServers": {
"coingecko": {
"command": "node",
"args": ["/path/to/coingecko-server/build/index.js"],
"env": {
"COINGECKO_API_KEY": "your-api-key-here"
}
}
}
}
- 重启 Claude Desktop
- 可用工具:
get-coins
: 获取币种列表find-coin-ids
: 查找币种IDget-historical-data
: 获取历史数据get-ohlc-data
: 获取K线数据refresh-cache
: 刷新缓存
与 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
);
console.log(history);
}
注意事项
- 请遵守 CoinGecko Pro API 的请求限制
- 使用 MIT 许可证
数据类型参考
// OHLC数据
interface OHLCData {
timestamp: number;
open: number;
high: number;
low: number;
close: number;
}
// 历史数据
interface HistoricalData {
prices: [number, number][];
market_caps: [number, number][];
total_volumes: [number, number][];
}
// 币种信息
interface CoinInfo {
id: string;
symbol: string;
name: string;
platforms?: Record<string, string>;
}