Emercoin MCP服务器

一个提供HTTP/JSON访问所有Emercoin CLI功能的综合模型上下文协议(MCP)服务器,具有集成格式化实用程序。

  • by Jeff-Bouchard
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 jeff-bouchard/emercoin-mcp-server

使用说明

Emercoin MCP服务器v0.2

一个全面的模型上下文协议(MCP)服务器,通过集成的格式化实用程序提供对所有Emercoin CLI功能的HTTP/JSON访问。

特性

  • 完全RPC覆盖:按类别组织的所有100+Emercoin RPC端点
  • 格式化集成:内置支持 emercoin-format.py 和 emercoin-value.py 公用事业
  • 多种API样式:基于类别的路由、通用RPC调用和传统兼容性
  • 增强的错误处理:带有stderr输出和退出代码的详细错误响应
  • 自动发现: /endpoints route按类别列出所有可用方法
  • 健康监测:带终点计数的全面健康检查
  • CORS支持:启用了跨源请求
  • 高性能:用途 spawn 为了更好的流程管理

先决条件

  • Node.js 14.0.0或更高版本
  • Python 3(用于格式化工具)
  • 启用RPC运行的Emercoin守护进程(emercoind)
  • emercoin-cli在PATH中或通过环境变量指定

安装

git clone <repository>
cd emercoin-mcp-server
npm install

配置

使用环境变量进行配置:

export PORT=7331                    # Server port (default: 7331)
export EMERCOIN_CLI_PATH=emercoin-cli  # Path to emercoin-cli
export RPC_USER=your_rpc_username      # RPC username
export RPC_PASSWORD=your_rpc_password  # RPC password  
export RPC_PORT=6662                   # RPC port (default: 6662)
export RPC_HOST=127.0.0.1             # RPC host (default: 127.0.0.1)

运行服务器

npm start
# or for development with auto-reload:
npm run dev

API终点

探索与健康

  • GET /health -服务器运行状况和统计信息
  • GET /endpoints -按类别列出所有可用的RPC方法

基于类别的路线

所有RPC方法都可以通过基于类别的路由获得:

区块链运营

  • POST /blockchain/getblockchaininfo
  • POST /blockchain/getblockcount
  • POST /blockchain/getbestblockhash
  • POST /blockchain/getblock -参数: ["blockhash", verbosity]
  • 还有20多个区块链端点。..

名称操作(Emercoin的独特功能)

  • POST /names/name_show -参数: ["name", "valuetype", "filepath"]
  • POST /names/name_new -参数: ["name", "value", days, "toaddress", "valuetype"]
  • POST /names/name_update -参数: ["name", "value", days, "toaddress", "valuetype"]
  • POST /names/name_filter -参数: ["regexp", maxage, from, nb, "stat", "valuetype"]
  • 还有10多个名称端点。..

钱包操作

  • POST /wallet/getbalance
  • POST /wallet/getnewaddress -参数: ["label", "address_type"]
  • POST /wallet/sendtoaddress -参数: ["address", amount, "comment", "comment_to", ...]
  • POST /wallet/listtransactions
  • 还有40多个钱包端点。..

其他类别

  • 控制: getinfo, stop, uptime等等。
  • 采矿: getmininginfo, getblocktemplate等等。
  • 网络: getpeerinfo, getnetworkinfo等等。
  • 原始交易记录: createrawtransaction, signrawtransaction等等。
  • 公用事业: validateaddress, estimatesmartfee等等。
  • Randpay:Emercoin的小额支付系统
  • 气动薄膜切断阀:通知系统

通用RPC路由

  • POST /rpc/:method -直接调用任何RPC方法
  • POST /rpc -传统RPC传递

请求格式

所有端点都接受可选格式的JSON:

{
  "params": ["param1", "param2"],
  "format": true,        // Apply emercoin-format.py
  "extractValue": true   // Apply emercoin-value.py
}

例子

获取区块链信息:

curl -X POST http://localhost:7331/blockchain/getblockchaininfo \
  -H "Content-Type: application/json" \
  -d '{}'

显示带格式的名称:

curl -X POST http://localhost:7331/names/name_show \
  -H "Content-Type: application/json" \
  -d '{"params": ["dns:emercoin.com"], "format": true}'

从名称中提取值:

curl -X POST http://localhost:7331/names/name_show \
  -H "Content-Type: application/json" \
  -d '{"params": ["dns:emercoin.com"], "extractValue": true}'

发送EMC:

curl -X POST http://localhost:7331/wallet/sendtoaddress \
  -H "Content-Type: application/json" \
  -d '{"params": ["EMC_ADDRESS", 1.0, "Payment", "To John"]}'

格式化实用程序

服务器集成了两个Python实用程序:

emergin-form.py

通过替换文字来清理文本输出 \n 有实际的断线。

emercoin-value.py

提取 value JSON响应中的字段,可用于名称操作。

通过添加启用格式化 "format": true 或 "extractValue": true 发送到您的请求正文。

安全考虑

  • 网络安全:在HTTPS反向代理后运行
  • 访问控制:使用防火墙规则限制访问
  • 凭证:使用强RPC凭据,请考虑 rpcauth
  • 港口安全:默认端口7331避免了常见冲突
  • 输入验证:所有用户输入都已正确转义

错误处理

详细的错误响应包括:

  • 错误消息
  • emercoin-cli的stderr输出
  • 退出代码
  • 上下文的方法名称

发展

npm run dev  # Auto-reload on changes

许可证

麻省理工学院