jsonrpc: package with JSON-RPC symbols (#117)

Move the aliases to the internal/jsonrpc2 package into their own
package.

Fixes #115.
This commit is contained in:
Jonathan Amsterdam 2025-07-10 14:33:23 -04:00 • committed by GitHub
commit bfa5e30cd1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@ import (
"testing"
"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
"github.com/modelcontextprotocol/go-sdk/jsonrpc"
)
func TestBatchFraming(t *testing.T) {
@ -22,10 +23,10 @@ func TestBatchFraming(t *testing.T) {
r, w := io.Pipe()
tport := newIOConn(rwc{r, w})
tport.outgoingBatch = make([]JSONRPCMessage, 0, 2)
tport.outgoingBatch = make([]jsonrpc.Message, 0, 2)
// Read the two messages into a channel, for easy testing later.
read := make(chan JSONRPCMessage)
read := make(chan jsonrpc.Message)
go func() {
for range 2 {
msg, _ := tport.Read(ctx)
@ -34,7 +35,7 @@ func TestBatchFraming(t *testing.T) {
}()
// The first write should not yet be observed by the reader.
tport.Write(ctx, &JSONRPCRequest{ID: jsonrpc2.Int64ID(1), Method: "test"})
tport.Write(ctx, &jsonrpc.Request{ID: jsonrpc2.Int64ID(1), Method: "test"})
select {
case got := <-read:
t.Fatalf("after one write, got message %v", got)
@ -42,10 +43,10 @@ func TestBatchFraming(t *testing.T) {
}
// ...but the second write causes both messages to be observed.
tport.Write(ctx, &JSONRPCRequest{ID: jsonrpc2.Int64ID(2), Method: "test"})
tport.Write(ctx, &jsonrpc.Request{ID: jsonrpc2.Int64ID(2), Method: "test"})
for _, want := range []int64{1, 2} {
got := <-read
if got := got.(*JSONRPCRequest).ID.Raw(); got != want {
if got := got.(*jsonrpc.Request).ID.Raw(); got != want {
t.Errorf("got message #%d, want #%d", got, want)
}
}