CoinGecko金融数据接口添加福利群:解决AI开发者的「MCP实战痛点」一个用于与 CoinGecko Pro API 交互的模型上下文协议(MCP)服务器和 OpenAI 函数调用服务。
npm install coingecko-server
在你的项目根目录下创建一个 .env 文件:
COINGECKO_API_KEY=your_api_key_here
Claude Desktop 提供了对 MCP 特性的全面支持。要使用此服务器:
添加到你的 Claude Desktop 配置中:
~/Library/Application Support/Claude/claude_desktop_config.json%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"
}
}
}
}

服务器提供了以下工具:
get-coins: 获取支持的币种分页列表find-coin-ids: 查找币名/符号对应的 CoinGecko IDget-historical-data: 获取历史价格、市值和交易量数据get-ohlc-data: 获取 OHLC K线数据refresh-cache: 刷新本地币种列表缓存import { CoinGeckoService } from 'coingecko-server';
import OpenAI from 'openai';
const openai = new OpenAI();
const coinGeckoService = new CoinGeckoService(process.env.COINGECKO_API_KEY);
// Get function definitions
const functions = CoinGeckoService.getOpenAIFunctionDefinitions();
// Example: Get historical data
const response = await openai.chat.completions.create({
model: "gpt-4-turbo-preview",
messages: [{ role: "user", content: "Get Bitcoin's price history for the last week" }],
functions: [functions[2]], // get_historical_data function
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
);
}

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>;
}

请参考 CoinGecko Pro API 文档 以获取当前的速率限制和使用指南。
MIT