CrazyrabbitLTC_mcp Coingecko Server

CrazyrabbitLTC_mcp Coingecko Server

🚀 CoinGecko 服务器

CoinGecko 服务器是一个模型上下文协议(MCP)服务器和 OpenAI 函数调用服务,用于与 CoinGecko Pro API 交互,可助力用户获取各类加密货币数据。

🚀 快速开始

CoinGecko 服务器为用户提供了便捷的方式与 CoinGecko Pro API 进行交互。通过以下步骤,你可以快速搭建并使用该服务器。

✨ 主要特性

  • 分页列出支持的加密货币,方便用户按页查看不同加密货币信息。
  • 按名称或符号查找 Coin ID,能快速定位特定加密货币。
  • 提供历史价格、市值和交易量数据,助力用户进行市场分析。
  • 提供 OHLC(开盘价、最高价、最低价、收盘价)烛台数据,满足专业交易分析需求。
  • 具有刷新功能的本地硬币缓存,可提高数据获取效率。

📦 安装指南

在项目中安装 CoinGecko 服务器,可使用以下命令:

npm install coingecko-server

🔧 环境设置

在项目根目录中创建一个 .env 文件,并设置 CoinGecko API 密钥:

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

该服务器提供的工具如下:

  • get-coins:获取分页的加密货币列表
  • find-coin-ids:按名称或符号查找 CoinGecko ID
  • get-historical-data:获取历史价格、市值和交易量数据
  • get-ohlc-data:获取 OHLC 烛台数据
  • 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",
});

如果 (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
);
}

数据类型说明

OHLCData

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

HistoricalData

interface HistoricalData {
prices: [number, number][];
market_caps: [number, number][];
total_volumes: [number, number][];
}

CoinInfo

interface CoinInfo {
id: string;
symbol: string;
name: string;
platforms?: Record<string, string>;
}

📚 详细文档

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

📄 许可证

本项目采用 MIT 许可证。

  • 0 关注
  • 0 收藏,17 浏览
  • system 提出于 2025-09-21 16:45

相似服务问题

相关AI产品