加密货币API服务

一个提供实时加密货币汇率、支持资产和国家信息的API服务,无需认证即可访问,适用于AI助手等应用。

  • by josecarlosbrandao
  • TypeScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 josecarlosbrandao/uphold-mcp-server

使用说明

维护MCP服务器

A. 模型上下文协议(MCP) 暴露的服务器 Uphold的 公共加密货币API作为Claude等人工智能助手的工具。

此服务器提供对汇率、支持的资产和国家信息的实时访问,无需身份验证。

什么是MCP?

模型上下文协议(MCP)是一个开放标准,使AI助手能够安全地与外部数据源和工具进行交互。它为AI模型提供了一种标准化的方法:

  • 从API访问实时数据
  • 执行工具和功能
  • 在对话中保持上下文

架构图

flowchart TD
    A[AI Application<br/>Claude Desktop, Claude Code, etc.]

    A -->|JSON-RPC over stdio| B[MCP Server: uphold-mcp]

    B --> C[Tool Registry]

    C --> D[get-ticker-by-currency]
    C --> E[get-ticker-pair]
    C --> F[get-assets]
    C --> G[get-countries]

    B --> H[API Client Layer<br/>UpholdClient class]

    H -->|HTTPS| I[Uphold Public API<br/>https://api.uphold.com/v0]

    I --> J["/ticker/:currency"]
    I --> K["/assets"]
    I --> L["/countries"]

    style A fill:#e1f5ff
    style B fill:#fff4e1
    style C fill:#f0f0f0
    style H fill:#f0f0f0
    style I fill:#e1ffe1

项目结构

uphold-mcp-server/
├── src/
│   ├── server.ts           # Entry point with StdioServerTransport
│   ├── client.ts           # Uphold API client class
│   ├── types.ts            # TypeScript types and error classes
│   ├── utils/
│   │   ├── logger.ts       # Pino logger configuration
│   │   └── http-client.ts  # HTTP request utility
│   └── tools/
│       ├── index.ts        # Tool registry
│       ├── tickers.ts      # Ticker tools (2 tools)
│       ├── assets.ts       # Assets tool
│       └── countries.ts    # Countries tool
├── test/                   # Vitest test files
│   ├── client.test.ts
│   ├── types.test.ts
│   ├── utils/
│   │   ├── http-client.test.ts
│   │   └── logger.test.ts
│   └── tools/
│       ├── index.test.ts
│       ├── tickers.test.ts
│       ├── assets.test.ts
│       └── countries.test.ts
├── package.json            # Dependencies & npm scripts
├── tsconfig.json           # TypeScript config
├── vitest.config.ts        # Vitest configuration
└── README.md               # This file

安装

先决条件

  • Node.js 24.12.0或更高版本
  • npm或纱线

设置

# Clone or download the project
cd uphold-mcp-server

# Install dependencies
npm install

# Build the TypeScript code
npm run build

# Run tests
npm test

可用工具

工具名称 描述 参数
get-ticker-by-currency 获取特定货币对所有其他货币的汇率 currency:货币代码(例如“BTC”、“USD”)
get-ticker-pair 获取特定货币对的汇率 pair:货币对(例如“BTCUSD”)
get-assets 获取所有支持的加密货币和法定货币 无
get-countries 获取Uphold可用的所有国家/地区 无

工具示例

按货币获取股票代码

获取比特币的所有配对:

Input: { "currency": "BTC" }

返回所有BTC交易对。

获取股票对

获取特定配对率:

Input: { "pair": "ETHUSD" }

退货:

{
  "ask": "2650.00",
  "bid": "2645.00",
  "currency": "USD",
  "pair": "ETHUSD"
}

获取资产

返回所有支持的资产:

[
  {
    "code": "BTC",
    "name": "Bitcoin",
    "status": "open",
    "type": "cryptocurrency"
  },
  {
    "code": "USD",
    "name": "US Dollar",
    "status": "open",
    "type": "fiat"
  },
  ...
]

获取国家

支持退货的国家:

[
  {
    "code": "US",
    "name": "United States",
    "currency": "USD"
  },
  ...
]

环境变量

服务器需要以下环境变量:

变量 必填 默认 描述
UPHOLD_API_BASE_URL 是 - 井口API的基本URL(例如。, https://api.uphold.com/v0)
LOG_LEVEL 没有 info 日志记录级别(debug, info, warn, error)

示例 .env 文件

UPHOLD_API_BASE_URL=https://api.uphold.com/v0
LOG_LEVEL=info

注: 如果发生以下情况,服务器将在启动时抛出错误 UPHOLD_API_BASE_URL 未设置。

配置

编辑 ~/.claude.json 在理想中 project:

{
  "mcpServers": {

    "uphold": {
      "command": "node",
      "args": [
        "/Users/jose.goncalves/Repos/uphold-mcp-server/dist/server.js"
      ],
      "env": {
        "UPHOLD_API_BASE_URL": "https://api.uphold.com/v0"
      }
    }
  }
}

验证安装

配置后,您可以验证服务器是否已加载:

# List configured MCP servers
claude mcp list

发展

在本地运行

# Set required environment variable
export UPHOLD_API_BASE_URL=https://api.uphold.com/v0

# Run in development mode with hot reload
npm run dev

# Build for production
npm run build

# Run production build
npm start

测试

该项目使用 Vitest 用于具有全面测试覆盖率的测试。

测试设置: 测试使用中定义的环境变量 test/setup.ts.确保 UPHOLD_API_BASE_URL 在运行测试之前设置。

# Run tests once
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with UI
npm run test:ui

# Run tests with coverage report
npm run test:coverage

手动测试工具

您可以使用MCP检查器或通过发送JSON-RPC消息来测试服务器:

# Using MCP Inspector (if installed)
npx @modelcontextprotocol/inspector node dist/server.js

项目脚本

脚本 描述
npm run build 将TypeScript编译为JavaScript
npm run start 运行已编译的服务器
npm run dev 使用tsx在开发模式下运行
npm test 运行一次测试
npm run test:watch 在监视模式下运行测试
npm run test:ui 使用Vitest UI运行测试
npm run test:coverage 使用覆盖率报告运行测试

日志记录

服务器使用 皮诺 用于开发具有漂亮打印功能的结构化测井。日志被发送到stderr,以避免干扰stdout上的MCP协议。

您可以使用以下命令控制日志级别 LOG_LEVEL 环境变量:

LOG_LEVEL=debug npm run dev

API 参考

此服务器使用Uphold的公共API终结点:

端点 描述
GET /v0/ticker/:currency 特定货币的汇率(也支持配对格式,如 BTCUSD)
GET /v0/assets 所有支持的资产
GET /v0/countries 所有支持的国家

有关更多详细信息,请参阅 支持API文档.

故障排除

服务器未出现在Claude中

  1. 检查路径:确保配置中的路径是绝对正确的
  2. 验证构建:确保你跑过了 npm run build 和那个 dist/ 文件夹存在
  3. 检查环境变量:确保 UPHOLD_API_BASE_URL 已在配置中设置
  4. 检查日志:在Claude Desktop的开发人员控制台或Claude Code的输出中查找错误
  5. 重启:配置更改后重新启动Claude Desktop或终端会话

缺少环境变量错误

如果你看到 UPHOLD_API_BASE_URL environment variable is not set,确保您已配置 env MCP服务器配置中的块:

"env": {
  "UPHOLD_API_BASE_URL": "https://api.uphold.com/v0"
}

API错误

  • 429请求太多:持有有费率限制。请稍候,然后重试。
  • 网络错误:检查您的互联网连接和防火墙设置。

TypeScript错误

# Clean and rebuild
rm -rf dist/
npm run build

权限错误

# Ensure the script is executable (Unix/macOS)
chmod +x dist/server.js

许可证

麻省理工学院

链接