Skip to content

Commit 61040b7

Browse files
committed
update test
1 parent b95458b commit 61040b7

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

server/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,11 @@ func (s *MCPServer) handleListTools(
762762

763763
// Sort the tool names for consistent ordering
764764
sort.Strings(toolNames)
765+
766+
// Add tools in sorted order
767+
for _, name := range toolNames {
768+
tools = append(tools, s.tools[name].Tool)
769+
}
765770
toolsToReturn, nextCursor, err := listByPagination[mcp.Tool](ctx, s, request.Params.Cursor, tools)
766771
if err != nil {
767772
return nil, &requestError{

server/server_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package server
22

33
import (
44
"context"
5+
"encoding/base64"
56
"encoding/json"
67
"errors"
78
"fmt"
@@ -335,6 +336,7 @@ func TestMCPServer_Tools(t *testing.T) {
335336
toolsList := server.HandleMessage(ctx, []byte(`{
336337
"jsonrpc": "2.0",
337338
"id": 1,
339+
"method": "tools/list"
338340
}`))
339341
tt.validate(t, notifications, toolsList.(mcp.JSONRPCMessage))
340342
})
@@ -429,22 +431,22 @@ func TestMCPServer_HandleValidMessages(t *testing.T) {
429431

430432
func TestMCPServer_HandlePagination(t *testing.T) {
431433
server := createTestServer()
432-
434+
cursor := base64.StdEncoding.EncodeToString([]byte("My Resource"))
433435
tests := []struct {
434436
name string
435437
message string
436438
validate func(t *testing.T, response mcp.JSONRPCMessage)
437439
}{
438440
{
439441
name: "List resources with cursor",
440-
message: `{
442+
message: fmt.Sprintf(`{
441443
"jsonrpc": "2.0",
442444
"id": 1,
443445
"method": "resources/list",
444446
"params": {
445-
"cursor": "test-cursor"
447+
"cursor": "%s"
446448
}
447-
}`,
449+
}`, cursor),
448450
validate: func(t *testing.T, response mcp.JSONRPCMessage) {
449451
resp, ok := response.(mcp.JSONRPCResponse)
450452
assert.True(t, ok)

0 commit comments

Comments
 (0)