Nimiq JSON-RPC协议转换工具

将Nimiq JSON-RPC API转换为MCP工具的服务,适用于开发者和客户端工具集成。

  • by maestroi
  • Go
  • 本地部署
  • 更新于
在 GitHub 查看 maestroi/nimiq-mcp

使用说明

尼米克mcp

A. 模型上下文协议 服务器,该服务器将NimiqJSON-RPC API公开为MCP工具。每个OpenRPC定义的方法都变成了一个工具;调用将被转发到您配置的Nimiq RPC端点。

存储库: github/maestroi/nimiq-mcp

需求

  • 去 1.24或更新版本(参见 go.mod)
  • 访问Nimiq JSON-RPC节点(以下为默认值)

构建

git clone https://github.com/maestroi/nimiq-mcp.git
cd nimiq-mcp
go build -o nimiq-mcp .

跑

stdio(默认)

适用于桌面MCP客户端(Cursor、Claude Code等):

./nimiq-mcp

SSE(HTTP,传统)

对于仍使用SSE传输的远程或集装箱设置:

export MCP_TRANSPORT=sse
export MCP_SSE_PORT=8081   # optional, default 8081
./nimiq-mcp

流式HTTP(推荐)

当前的MCP远程传输:单端点 /mcp 在监听端口上。

export MCP_TRANSPORT=streamable-http
# alias: MCP_TRANSPORT=http
export MCP_SSE_PORT=8081   # optional, default 8081
./nimiq-mcp

环境变量

变量 默认值 描述
NIMIQ_RPC_URL https://rpc.nimiqwatch.com Nimiq JSON-RPC基本URL
MCP_TRANSPORT stdio stdio, sse,或 streamable-http (别名: http)
MCP_SSE_PORT 8081 监听端口时 MCP_TRANSPORT 是 sse 或 streamable-http
ENABLE_WALLET_TOOLS false 设置 true 注册标记的工具 wallet
ENABLE_VALIDATOR_TOOLS false 设置 true 注册标记的工具 validator

默认情况下,钱包和验证器工具处于关闭状态;仅在需要时启用它们。

码头工人

docker build -t nimiq-mcp .
docker run --rm -e MCP_TRANSPORT=streamable-http -p 8081:8081 nimiq-mcp

或者使用捆绑的Compose文件(端口8081上的HTTP;set MCP_TRANSPORT 到 sse 或 streamable-http):

docker compose up --build

本地测试

单元测试和构建

go test ./...
go vet ./...
go build -o nimiq-mcp .

标准烟雾测试(MCP initialize)

不需要游标;检查进程是否在stdin/stdout上讲MCP:

echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' \
  | go run .

你应该看到一个JSON行 protocolVersion 和 serverInfo (日志会转到stderr,因此不会破坏stdout上的协议)。

SSE烟雾测试(可选)

在一个终端中:

export MCP_TRANSPORT=sse
./nimiq-mcp

在另一个:

curl -sS -m 3 http://localhost:8081/sse | head

你应该看看SSE event: 线。使用 Ctrl+C 停止服务器。

流式HTTP烟雾测试(可选)

在一个终端中:

export MCP_TRANSPORT=streamable-http
./nimiq-mcp

在另一个:

curl -sS -X POST http://localhost:8081/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'

你应该看到一个JSON正文 result 包含 protocolVersion 和 serverInfo.


MCP客户端配置(光标、克劳德桌面等)

光标

此回购包括 .cursor/mcp.json 所以 将此文件夹作为工作区打开 足够了:Cursor合并项目级MCP配置并解析 ${workspaceFolder} 到存储库根目录。

  1. 要求: 使用1.24+ PATH (与发展相同)。
  2. 重新加载MCP: 编辑后 mcp.json,完全退出并重新启动Cursor,或从重新加载MCP 设置→ 特性→ 模型上下文协议.
  3. 验证: 在聊天中,检查 可用工具 Nimiq RPC工具(例如。 getBlockNumber).如果失败了,打开 输出→ MCP日志.

可选全局配置(~/.cursor/mcp.json 在Linux/macOS上, %USERPROFILE%\.cursor\mcp.json 在Windows上)以相同的方式工作;使用a 绝对路径 如果你不想使用二进制文件 go run:

{
  "mcpServers": {
    "nimiq": {
      "command": "/absolute/path/to/nimiq-mcp",
      "env": {
        "NIMIQ_RPC_URL": "https://rpc.nimiqwatch.com"
      }
    }
  }
}

启动速度更快 go build -o nimiq-mcp . 在回购中:

{
  "mcpServers": {
    "nimiq": {
      "command": "${workspaceFolder}/nimiq-mcp",
      "env": {
        "NIMIQ_RPC_URL": "https://rpc.nimiqwatch.com"
      }
    }
  }
}

克劳德桌面

编辑应用程序配置文件(如果缺少,请创建):

操作系统 路径
macOS ~/Library/Application Support/Claude/claude_desktop_config.json
窗户 %APPDATA%\Claude\claude_desktop_config.json
Linux ~/.config/Claude/claude_desktop_config.json

使用 完整路径 到您构建的二进制文件(Claude不支持Cursor的 ${workspaceFolder}):

{
  "mcpServers": {
    "nimiq": {
      "command": "/absolute/path/to/nimiq-mcp",
      "env": {
        "NIMIQ_RPC_URL": "https://rpc.nimiqwatch.com"
      }
    }
  }
}

保存后重新启动Claude Desktop。

Docker(stdio,可选)

如果使用名为的本地映像 nimiq-mcp:

{
  "mcpServers": {
    "nimiq": {
      "command": "docker",
      "args": ["run", "--rm", "-i", "nimiq-mcp"],
      "env": {
        "NIMIQ_RPC_URL": "https://rpc.nimiqwatch.com"
      }
    }
  }
}

SSE/HTTP客户端

对于通过HTTP/SSE连接的客户端,请使用以下命令运行服务器 MCP_TRANSPORT=sse 并将客户端指向您的URL(例如 http://localhost:8081/sse 如果您的客户端需要原始SSE端点,请查看客户端的文档)。

发展

go test ./...
go vet ./...

CI和发布

持续集成 (.github/workflows/ci.yml)运行推送和拉取请求 main / master: go test, go vet, go build和a 本地 docker build 以验证Dockerfile。确实如此 不 发表任何东西。

发布 (.github/workflows/release.yml)当您推送匹配的版本标记时运行 v*例如 v1.0.0:

git tag v1.0.0
git push origin v1.0.0

该工作流程:

  1. GoRelease --为Linux、macOS和Windows(适用时为amd64/arm64)构建存档、校验和,并将其附加到 GitHub发布 对于这个标签。
  2. 码头工人 --构建多拱形图像(linux/amd64, linux/arm64)并推动它 GitHub容器注册表 作为 ghcr.io/<owner>/nimiq-mcp:<tag> 和 :latest.

拉取映像(如果包是私有的,则在登录GHCR后):

docker pull ghcr.io/maestroi/nimiq-mcp:latest

新的GHCR包可能默认为私有;更改包下的可见性 软件包设置 如果你想公开的话。