English | 🇨🇳中文
jsonrpc4go
A high-performance JSON-RPC 2.0 implementation in Go. Supports HTTP/TCP, service registration & discovery (Consul / Nacos / etcd), client-side load-balancing, rate limiting, hooks, batch calls and notifications.
接入你的智能体
從發布者安裝。不是 PlugMCP 端點。
遠端 URL 還是本機指令? 兩種安裝方式的差異
來自發布者
English | 🇨🇳中文
A high-performance JSON-RPC 2.0 implementation in Go. Supports HTTP/TCP, service registration & discovery (Consul / Nacos / etcd), client-side load-balancing, rate limiting, hooks, batch calls and notifications.
A pure Go JSON‑RPC 2.0 client‑server implementation. Optimized for the MCP (Model Context Protocol), yet fully general‑purpose for arbitrary JSON‑RPC 2.0 scenarios. Supports HTTP and TCP transports, with built‑in Consul and Nacos for service registry & discovery.
JSON-RPC 2.0 is the wire protocol that powers MCP (Model Context Protocol) — the standard interface between LLMs and external tools / data sources. Because jsonrpc4go speaks this protocol natively over both HTTP and TCP, it is an ideal foundation for building MCP servers and clients in Go, letting AI agents call your services as first-class tools.
Model Context Protocol (MCP) standardizes how AI assistants discover and invoke external tools, resources and prompts. Its transport layer is exactly JSON-RPC 2.0 — the same protocol jsonrpc4go is built on. This makes jsonrpc4go a ready-to-use foundation for AI-native services:
method = ServiceName/Method.Server / Client APIs.// Any registered method is already an AI-callable tool over JSON-RPC 2.0.
s, _ := jsonrpc4go.NewServer("http", 3232)
s.Register(new(IntRpc)) // IntRpc.Add is now callable by any MCP client
s.Start()
go get -u github.com/sunquakes/jsonrpc4go
package main
import (
"github.com/sunquakes/jsonrpc4go"
)
type IntRpc struct{}
type Params struct {
A int `json:"a"`
B int `json:"b"`
}
func (i *IntRpc) Add(params *Params, result *int) error {
*result = params.A + params.B
return nil
}
func main() {
s, _ := jsonrpc4go.NewServer("http", 3232) // the protocol is http
s.Register(new(IntRpc))
s.Start()
}
package main
import (
"fmt"
"github.com/sunquakes/jsonrpc4go"
)
type Params struct {
A int `json:"a"`
B int `json:"b"`
}
type Result2 struct {
C int `json:"c"`
}
func main() {
result := new(int)
c, _ := jsonrpc4go.NewClient("IntRpc", "http", "127.0.0.1:3232")
err := c.Call("Add", Params{1, 6}, result, false)
// data sent: {"id":"1604283212", "jsonrpc":"2.0", "method":"IntRpc/Add", "params":{"a":1,"b":6}}
// data received: {"id":"1604283212", "jsonrpc":"2.0", "result":7}
fmt.Println(err) // nil
fmt.Println(*result) // 7
}
go test -v ./test/...
s, _ := jsonrpc4go.NewServer("tcp", 3232) // the protocol is tcp
c, _ := jsonrpc4go.NewClient("IntRpc", "tcp", "127.0.0.1:3232") // the protocol is tcp
// Set the hook function of before method execution
s.SetBeforeFunc(func(id interface{}, method string, params interface{}) error {
// If the function returns an error, the program stops execution and returns an error message to the client
// return errors.New("Custom Error")
return nil
})
// Set the hook function of after method execution
s.SetAfterFunc(func(id interface{}, method string, result interface{}) error {
// If the function returns an error, the program stops execution and returns an error message to the client
// return errors.New("Custom Error")
return nil
})
s.SetRateLimit(20, 10) //The maximum concurrent number is 10, The maximum request speed is 20 times per second
// Add the following code before 's.Start()'
s.SetOptions(server.TcpOptions{"aaaaaa", nil}) // Custom package EOF when the protocol is tcp
// Add the following code before 'c.Call()' or 'c.BatchCall()'
c.SetOptions(client.TcpOptions{"aaaaaa", nil}) // Custom package EOF when the protocol is tcp
// notify
result2 := new(Result2)
err2 := c.Call("Add2", Params{1, 6}, result2, true)
// data sent: {"jsonrpc":"2.0","method":"IntRpc/Add2","params":{"a":1,"b":6}}
// data received: {"jsonrpc":"2.0","result":{"c":7}}
fmt.Println(err2) // nil
fmt.Println(*result2) // {7}
// batch call
result3 := new(int)
err3 := c.BatchAppend("Add1", Params{1, 6}, result3, false)
result4 := new(int)
err4 := c.BatchAppend("Add", Params{2, 3}, result4, false)
c.BatchCall()
// data sent: [{"id":"1604283212","jsonrpc":"2.0","method":"IntRpc/Add1","params":{"a":1,"b":6}},{"id":"1604283212","jsonrpc":"2.0","method":"IntRpc/Add","params":{"a":2,"b":3}}]
// data received: [{"id":"1604283212","jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found","data":null}},{"id":"1604283212","jsonrpc":"2.0","result":5}]
fmt.Println((*err3).Error()) // Method not found
fmt.Println(*result3) // 0
fmt.Println(*err4) // nil
fmt.Println(*result4) // 5
c, _ := jsonrpc4go.NewClient("IntRpc", "tcp", "127.0.0.1:3232,127.0.0.1:3233,127.0.0.1:3234")
/**
* check: true or false. The switch of the health check.
* interval: The interval of the health check. For example: 10s.
* timeout: Timeout. For example: 10s.
* instanceId: Instance ID. Distinguish the same service in different nodes. For example: 1.
*/
dc, _ := consul.NewConsul("http://localhost:8500?check=true&instanceId=1&interval=10s&timeout=10s")
// Set in the server.
s, _ := jsonrpc4go.NewServer("tcp", 3614)
// If the default node ip is used, the second parameter can be set ""
s.SetDiscovery(dc, "127.0.0.1")
s.Register(new(IntRpc))
s.Start()
// Set in the client
c, _ := jsonrpc4go.NewClient("IntRpc", "tcp", dc)
dc, _ := nacos.NewNacos("http://127.0.0.1:8849")
// Set in the server.
s, _ := jsonrpc4go.NewServer("tcp", 3616)
// If the default node ip is used, the second parameter can be set ""
s.SetDiscovery(dc, "127.0.0.1")
s.Register(new(IntRpc))
s.Start()
// Set in the client
c, _ := jsonrpc4go.NewClient("IntRpc", "tcp", dc)
Source code in jsonrpc4go is available under the Apache-2.0 license.
A pure Go JSON‑RPC 2.0 client‑server implementation. Optimized for the MCP (Model Context Protocol), yet fully general‑purpose for arbitrary JSON‑RPC 2.0 scenarios. Supports HTTP and TCP transports, w
總覽
A pure Go JSON‑RPC 2.0 client‑server implementation. Optimized for the MCP (Model Context Protocol), yet fully general‑purpose for arbitrary JSON‑RPC 2.0 scenarios. Supports HTTP and TCP transports, with built‑in Consul and Nacos for service registry & discovery.
工具
尚無工具清單。遠端伺服器會在首次健康檢查後取得工具清單。
常見問題
在本頁複製適用於 Cursor、Claude Desktop、Claude Code 或 VS Code 的 stdio 設定。它使用發布者的安裝方式,而不是 PlugMCP 代理伺服器。
這筆記錄未列出必要的環境變數。
Jsonrpc4go 透過 stdio 在本機執行。
上次檢查時間:2026-10-28。 A pure Go JSON‑RPC 2.0 client‑server implementation. Optimized for the MCP (Model Context Protocol), yet fully general‑purpose for arbitrary JSON‑RPC 2.0 scenarios. Supports HTTP and TCP transports, with built‑in Consul and Nacos for service registry & discovery.