维护MCP服务器
A. 模型上下文协议(MCP) 暴露的服务器 Uphold的 公共加密货币API作为Claude等人工智能助手的工具。
此服务器提供对汇率、支持的资产和国家信息的实时访问,无需身份验证。
什么是MCP?
模型上下文协议(MCP)是一个开放标准,使AI助手能够安全地与外部数据源和工具进行交互。它为AI模型提供了一种标准化的方法:
- 从API访问实时数据
- 执行工具和功能
- 在对话中保持上下文
架构图
flowchart TD
A[AI Application
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
UpholdClient class]
H -->|HTTPS| I[Uphold Public API
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 devAPI 参考
此服务器使用Uphold的公共API终结点:
| 端点 | 描述 |
|---|---|
GET /v0/ticker/:currency | 特定货币的汇率(也支持配对格式,如 BTCUSD) |
GET /v0/assets | 所有支持的资产 |
GET /v0/countries | 所有支持的国家 |
有关更多详细信息,请参阅 支持API文档.
故障排除
服务器未出现在Claude中
- 检查路径:确保配置中的路径是绝对正确的
- 验证构建:确保你跑过了
npm run build和那个dist/文件夹存在 - 检查环境变量:确保
UPHOLD_API_BASE_URL已在配置中设置 - 检查日志:在Claude Desktop的开发人员控制台或Claude Code的输出中查找错误
- 重启:配置更改后重新启动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许可证
麻省理工学院
