MCP货币转换器
一个MCP(模型上下文协议)服务器,提供货币和报价转换工具。 巴西API专为集成Claude AI和其他兼容的助手而开发。
🎯 目标
该项目允许人工智能助手查看历史报价并使用巴西API数据实时进行货币转换。该项目提供两个接口:
- MCP服务器直接与 Claude AI 和其他助手集成
- API REST Express用于快速开发和测试
🚀 功能
可用的MCP工具:
get_exchange_rate_at_date
- 在特定日期获取货币报价 - 可用时优先考虑 PTAX 费率 - 提供购买和销售费用
convert_currency_at_date
- 在BRL和外币之间转换值 - 双向转换支持 (BRL)↔ 外币) - 根据方向使用适当的费率(买入/卖出)
支持的货币:
查看巴西 API 端点以查看支持的货币:
curl --location 'https://brasilapi.com.br/api/cambio/v1/moedas'📋 要求
- Node.js 18+
- pnpm (推荐) 或 npm
- TypeScript
🛠️ 安装
- 克隆仓库 :
git clone
cd conversor-moeda-mcp- 安装依赖关系 :
pnpm install
# ou
npm install- 编译工程 :
pnpm run build
# ou
npm run build🏃 如何本地旋转
选项 1:API Express(推荐用于开发)
# Iniciar a API Express na porta 3000
pnpm run dev:api
# Ou em produção
pnpm run start:apiAPI可在: http://localhost:3000
可用的端点 :
GET /health-健康检查POST /api/get-exchange-rate-at-date- 获取报价POST /api/convert-currency-at-date- 货币转换器GET /api-docs- 交互式 Swagger 文档GET /swagger.jsonOpenAPI JSON 规格
选项2:MCP Server
# Iniciar o MCP Server
pnpm run dev:mcp
# Ou em produção
pnpm run start:mcp🔌 如何连接MCP
没有克劳德桌面应用程序
- 查找配置文件 :
- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - 视窗: %APPDATA%\Claude\claude_desktop_config.json
- 添加 MCP 配置 :
{
"mcpServers": {
"conversor-moeda": {
"command": "node",
"args": [
"C:\\caminho\\para\\conversor-moeda-mcp\\build\\index.js"
],
"env": {}
}
}
}- 替换路径 :
- 变质的 C:\\caminho\\para\\conversor-moeda-mcp\\build\\index.js 通过编译文件的实际路径 - 使用双条 \\ 在 Windows 或 简单 栏 / 没有macOS/Linux
- 重新设计克劳德桌面
连接检查
重新启动 Claude 后,您应该看到可用的工具:
- 🔨
get_exchange_rate_at_date - 🔨
convert_currency_at_date
📖 使用范例
API Express(HTTP)
获取美元报价:
curl -X POST http://localhost:3000/api/get-exchange-rate-at-date \
-H "Content-Type: application/json" \
-d '{"currency":"USD","date":"2024-01-15"}'转换器100美元兑巴西雷亚尔:
curl -X POST http://localhost:3000/api/convert-currency-at-date \
-H "Content-Type: application/json" \
-d '{
"amount": 100,
"currency": "USD",
"date": "2024-01-15",
"direction": "to_brl"
}'📚 Swagger 文档
API 包括完整的交互式 Swagger 文档:
- 界面Web:
http://localhost:3000/api-docs - JSON规范:
http://localhost:3000/swagger.json
克劳德·艾(MCP)
连接 MCP 后,您可以提出以下问题:
- “2024年1月15日美元的报价是什么?”
- “使用昨天的报价将500美元转换为雷亚尔”
- “2023年12月10日,1000欧元的价格是多少?”
🏗️ 项目结构
├── src/
│ ├── services/
│ │ └── currency.ts # Lógica de negócio
│ ├── index.ts # MCP Server
│ └── server.ts # API Express
├── docs/
│ ├── DEVELOPMENT.md # Guia de desenvolvimento
│ └── REFACTORING_SUMMARY.md
├── build/ # Código compilado
└── package.json🚀 可用脚本
# Desenvolvimento
pnpm run dev:api # API Express + Swagger em http://localhost:3000/api-docs
pnpm run dev:mcp # MCP Server + watch mode
# Produção
pnpm run start:api # API Express + Swagger
pnpm run start:mcp # MCP Server
# Utilidades
pnpm run build # Compilar TypeScript
pnpm run test # Executar testes📝 日期格式
- 总是使用格式
YYYY-MM-DD - 例如:
2024-01-152024年1月15日 - 巴西API从2020年开始提供数据
🔍 故障排除
MCP 不出现在 Claude 中:
- 检查路径是否在
claude_desktop_config.json正确 - 请确认
pnpm run build已执行 - 重新设计克劳德桌面
- 在 Claude 控制台中检查错误日志
🚧 路线图
- \[ \] 添加工具/端点列出支持的货币
API无响应:
- 确认端口 3000 未使用
- 验证se
pnpm run dev:api没有显示错误 - 健康检查:
curl http://localhost:3000/health
未找到报价 :
- 验证数据格式(YYYY-MM-DD)
- 确认日期不是周末/节假日
- 最近日期测试( 更可靠的数据)
🤝 贡献
欢迎捐款!请:
- 分叉工程
- 为您的功能创建一个分支 (
git checkout -b feature/AmazingFeature) - 提交您的更改(
git commit -m 'Add some AmazingFeature') - 推动一个分支(
git push origin feature/AmazingFeature) - 打开 Pull Request
📄 许可证
这个项目是MIT许可的。查看文件 许可证 了解更多详情。
