Wise货币转换器MCP服务器
模型上下文协议(MCP)服务器,使用Wise API提供货币转换。
先决条件
您需要一个Wise API密钥才能使用此服务器。从获取API密钥 明智的API.
特性
- 转换货币:使用实时或历史Wise汇率在不同货币之间转换金额
- 列出货币:获取所有支持的货币代码列表
- 速率缓存:内置缓存可最大限度地减少API调用
- 交叉费率计算:当直接汇率不可用时,自动回退到基于美元的交叉汇率计算
安装
npm install
npm run build配置
API密钥设置
将Wise API键设置为环境变量:
export WISE_API_KEY="your-api-key-here"或者复制示例环境文件并添加密钥:
cp .env.example .env
# Edit .env and add your API key安全说明:永远不要将API密钥提交给版本控制。这 .gitignore 文件已配置为排除 .env 文件夹。
用法
作为MCP服务器
服务器在stdio上运行,可以与任何MCP客户端一起使用:
node dist/index.js可用工具
1. convert_currency
将金额从一种货币转换为另一种货币。
参数:
source_currency(字符串,必填):源货币代码(例如,美元、欧元、英镑)amount(数字,必填):要转换的金额target_currency(字符串,必填):目标货币代码date(字符串,可选):YYYY-MM-DD格式的历史汇率日期
示例响应:
{
"source_currency": "USD",
"source_amount": 100,
"target_currency": "EUR",
"target_amount": 92.45,
"exchange_rate": 0.9245,
"date": "2024-01-15"
}2. list_currencies
返回所有支持的货币代码列表。
示例响应:
{
"currencies": ["USD", "EUR", "GBP", "JPY", ...],
"total": 40
}使用Claude Desktop进行配置
要将此MCP服务器与Claude Desktop一起使用,请将其添加到配置文件中:
macOS
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"wise-currency": {
"command": "node",
"args": ["/path/to/wise-currency-converter-mcp/dist/index.js"],
"env": {
"WISE_API_KEY": "your-api-key-here"
}
}
}
}视窗
编辑 %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"wise-currency": {
"command": "node",
"args": ["C:\\path\\to\\wise-currency-converter-mcp\\dist\\index.js"],
"env": {
"WISE_API_KEY": "your-api-key-here"
}
}
}
}支持的货币
该服务器支持40种主要的世界货币,包括:
- 美元、欧元、英镑、日元、澳大利亚、加拿大、瑞士、加拿大、韩国、新西兰
- MXN、SGD、HKD、no、KRW、TRY、RUB、INR、BRL、ZAR
- 还有20多个。..
测试
测试服务器功能:
# Run the test script
WISE_API_KEY="your-api-key" node test.js发展
# Install dependencies
npm install
# Build the project
npm run build
# Watch for changes during development
npm run dev
# Run the server directly for testing
WISE_API_KEY="your-api-key" node dist/index.js项目结构
wise-currency-converter-mcp/
├── src/
│ ├── index.ts # MCP server implementation
│ ├── wise-client.ts # Wise API client with caching
│ └── types.ts # TypeScript type definitions
├── dist/ # Compiled JavaScript output
├── test.js # Test script for validation
├── .env.example # Example environment configuration
├── .gitignore # Git ignore rules
├── package.json # Node.js dependencies
└── tsconfig.json # TypeScript configuration建筑
- TypeScript:完全类型安全和更好的IDE支持
- MCP-SDK:用于服务器实现的官方模型上下文协议SDK
- 明智的API:实时汇率和历史汇率
- 缓存:1分钟的TTL缓存,以减少API调用
- 错误处理:优雅地回退到交叉速率计算
- 安全:存储在环境变量中的API密钥,已清理错误日志记录
故障排除
API关键问题
- 确保在环境中正确设置了API密钥
- 检查API密钥是否具有进行费率查询所需的权限
- 如果未检测到API密钥,服务器将发出警告
连接问题
- 验证Wise API终结点是否可访问
- 检查网络连接
- 查看控制台输出中的错误消息
许可证
麻省理工学院
