Skip to content

Commit 58fc9cf

Browse files
committed
all: remove ServerRequest[T] for concrete T
Replace all occurrences of ServerRequest[*CallToolParams] and other concrete instantiations with CallToolRequest and the like. Make the XXXRequest types aliases, to preserve the convenience of generics for the internal machinery (see shared.go, for example.) TODO: either expand the aliases or unexport ServerRequest. (The latter will be problematic for docs.)
1 parent 5b1f328 commit 58fc9cf

File tree

20 files changed

+106
-88
lines changed

20 files changed

+106
-88
lines changed

examples/server/completion/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
// a CompletionHandler to an MCP Server's options.
1717
func main() {
1818
// Define your custom CompletionHandler logic.
19-
myCompletionHandler := func(_ context.Context, req *mcp.ServerRequest[*mcp.CompleteParams]) (*mcp.CompleteResult, error) {
19+
myCompletionHandler := func(_ context.Context, req *mcp.CompleteRequest) (*mcp.CompleteResult, error) {
2020
// In a real application, you'd implement actual completion logic here.
2121
// For this example, we return a fixed set of suggestions.
2222
var suggestions []string

examples/server/custom-transport/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type HiArgs struct {
8585
}
8686

8787
// SayHi is a tool handler that responds with a greeting.
88-
func SayHi(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args HiArgs) (*mcp.CallToolResult, struct{}, error) {
88+
func SayHi(ctx context.Context, req *mcp.CallToolRequest, args HiArgs) (*mcp.CallToolResult, struct{}, error) {
8989
return &mcp.CallToolResult{
9090
Content: []mcp.Content{
9191
&mcp.TextContent{Text: "Hi " + args.Name},

examples/server/hello/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type HiArgs struct {
2222
Name string `json:"name" jsonschema:"the name to say hi to"`
2323
}
2424

25-
func SayHi(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args HiArgs) (*mcp.CallToolResult, any, error) {
25+
func SayHi(ctx context.Context, req *mcp.CallToolRequest, args HiArgs) (*mcp.CallToolResult, any, error) {
2626
return &mcp.CallToolResult{
2727
Content: []mcp.Content{
2828
&mcp.TextContent{Text: "Hi " + args.Name},
@@ -69,7 +69,7 @@ var embeddedResources = map[string]string{
6969
"info": "This is the hello example server.",
7070
}
7171

72-
func handleEmbeddedResource(_ context.Context, req *mcp.ServerRequest[*mcp.ReadResourceParams]) (*mcp.ReadResourceResult, error) {
72+
func handleEmbeddedResource(_ context.Context, req *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error) {
7373
u, err := url.Parse(req.Params.URI)
7474
if err != nil {
7575
return nil, err

examples/server/memory/kb.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ func (k knowledgeBase) openNodes(names []string) (KnowledgeGraph, error) {
431431
}, nil
432432
}
433433

434-
func (k knowledgeBase) CreateEntities(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args CreateEntitiesArgs) (*mcp.CallToolResult, CreateEntitiesResult, error) {
434+
func (k knowledgeBase) CreateEntities(ctx context.Context, req *mcp.CallToolRequest, args CreateEntitiesArgs) (*mcp.CallToolResult, CreateEntitiesResult, error) {
435435
var res mcp.CallToolResult
436436

437437
entities, err := k.createEntities(args.Entities)
@@ -450,7 +450,7 @@ func (k knowledgeBase) CreateEntities(ctx context.Context, req *mcp.ServerReques
450450
return &res, CreateEntitiesResult{Entities: entities}, nil
451451
}
452452

453-
func (k knowledgeBase) CreateRelations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args CreateRelationsArgs) (*mcp.CallToolResult, CreateRelationsResult, error) {
453+
func (k knowledgeBase) CreateRelations(ctx context.Context, req *mcp.CallToolRequest, args CreateRelationsArgs) (*mcp.CallToolResult, CreateRelationsResult, error) {
454454
var res mcp.CallToolResult
455455

456456
relations, err := k.createRelations(args.Relations)
@@ -465,7 +465,7 @@ func (k knowledgeBase) CreateRelations(ctx context.Context, req *mcp.ServerReque
465465
return &res, CreateRelationsResult{Relations: relations}, nil
466466
}
467467

468-
func (k knowledgeBase) AddObservations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args AddObservationsArgs) (*mcp.CallToolResult, AddObservationsResult, error) {
468+
func (k knowledgeBase) AddObservations(ctx context.Context, req *mcp.CallToolRequest, args AddObservationsArgs) (*mcp.CallToolResult, AddObservationsResult, error) {
469469
var res mcp.CallToolResult
470470

471471
observations, err := k.addObservations(args.Observations)
@@ -482,7 +482,7 @@ func (k knowledgeBase) AddObservations(ctx context.Context, req *mcp.ServerReque
482482
}, nil
483483
}
484484

485-
func (k knowledgeBase) DeleteEntities(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args DeleteEntitiesArgs) (*mcp.CallToolResult, any, error) {
485+
func (k knowledgeBase) DeleteEntities(ctx context.Context, req *mcp.CallToolRequest, args DeleteEntitiesArgs) (*mcp.CallToolResult, any, error) {
486486
var res mcp.CallToolResult
487487

488488
err := k.deleteEntities(args.EntityNames)
@@ -497,7 +497,7 @@ func (k knowledgeBase) DeleteEntities(ctx context.Context, req *mcp.ServerReques
497497
return &res, nil, nil
498498
}
499499

500-
func (k knowledgeBase) DeleteObservations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args DeleteObservationsArgs) (*mcp.CallToolResult, any, error) {
500+
func (k knowledgeBase) DeleteObservations(ctx context.Context, req *mcp.CallToolRequest, args DeleteObservationsArgs) (*mcp.CallToolResult, any, error) {
501501
var res mcp.CallToolResult
502502

503503
err := k.deleteObservations(args.Deletions)
@@ -512,7 +512,7 @@ func (k knowledgeBase) DeleteObservations(ctx context.Context, req *mcp.ServerRe
512512
return &res, nil, nil
513513
}
514514

515-
func (k knowledgeBase) DeleteRelations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args DeleteRelationsArgs) (*mcp.CallToolResult, struct{}, error) {
515+
func (k knowledgeBase) DeleteRelations(ctx context.Context, req *mcp.CallToolRequest, args DeleteRelationsArgs) (*mcp.CallToolResult, struct{}, error) {
516516
var res mcp.CallToolResult
517517

518518
err := k.deleteRelations(args.Relations)
@@ -527,7 +527,7 @@ func (k knowledgeBase) DeleteRelations(ctx context.Context, req *mcp.ServerReque
527527
return &res, struct{}{}, nil
528528
}
529529

530-
func (k knowledgeBase) ReadGraph(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args any) (*mcp.CallToolResult, KnowledgeGraph, error) {
530+
func (k knowledgeBase) ReadGraph(ctx context.Context, req *mcp.CallToolRequest, args any) (*mcp.CallToolResult, KnowledgeGraph, error) {
531531
var res mcp.CallToolResult
532532

533533
graph, err := k.loadGraph()
@@ -542,7 +542,7 @@ func (k knowledgeBase) ReadGraph(ctx context.Context, req *mcp.ServerRequest[*mc
542542
return &res, graph, nil
543543
}
544544

545-
func (k knowledgeBase) SearchNodes(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args SearchNodesArgs) (*mcp.CallToolResult, KnowledgeGraph, error) {
545+
func (k knowledgeBase) SearchNodes(ctx context.Context, req *mcp.CallToolRequest, args SearchNodesArgs) (*mcp.CallToolResult, KnowledgeGraph, error) {
546546
var res mcp.CallToolResult
547547

548548
graph, err := k.searchNodes(args.Query)
@@ -557,7 +557,7 @@ func (k knowledgeBase) SearchNodes(ctx context.Context, req *mcp.ServerRequest[*
557557
return &res, graph, nil
558558
}
559559

560-
func (k knowledgeBase) OpenNodes(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args OpenNodesArgs) (*mcp.CallToolResult, KnowledgeGraph, error) {
560+
func (k knowledgeBase) OpenNodes(ctx context.Context, req *mcp.CallToolRequest, args OpenNodesArgs) (*mcp.CallToolResult, KnowledgeGraph, error) {
561561
var res mcp.CallToolResult
562562

563563
graph, err := k.openNodes(args.Names)

examples/server/sequentialthinking/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func deepCopyThoughts(thoughts []*Thought) []*Thought {
231231
}
232232

233233
// StartThinking begins a new sequential thinking session for a complex problem.
234-
func StartThinking(ctx context.Context, _ *mcp.ServerRequest[*mcp.CallToolParams], args StartThinkingArgs) (*mcp.CallToolResult, any, error) {
234+
func StartThinking(ctx context.Context, _ *mcp.CallToolRequest, args StartThinkingArgs) (*mcp.CallToolResult, any, error) {
235235
sessionID := args.SessionID
236236
if sessionID == "" {
237237
sessionID = randText()
@@ -264,7 +264,7 @@ func StartThinking(ctx context.Context, _ *mcp.ServerRequest[*mcp.CallToolParams
264264
}
265265

266266
// ContinueThinking adds the next thought step, revises a previous step, or creates a branch in the thinking process.
267-
func ContinueThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args ContinueThinkingArgs) (*mcp.CallToolResult, any, error) {
267+
func ContinueThinking(ctx context.Context, req *mcp.CallToolRequest, args ContinueThinkingArgs) (*mcp.CallToolResult, any, error) {
268268
// Handle revision of existing thought
269269
if args.ReviseStep != nil {
270270
err := store.CompareAndSwap(args.SessionID, func(session *ThinkingSession) (*ThinkingSession, error) {
@@ -391,7 +391,7 @@ func ContinueThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolP
391391
}
392392

393393
// ReviewThinking provides a complete review of the thinking process for a session.
394-
func ReviewThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args ReviewThinkingArgs) (*mcp.CallToolResult, any, error) {
394+
func ReviewThinking(ctx context.Context, req *mcp.CallToolRequest, args ReviewThinkingArgs) (*mcp.CallToolResult, any, error) {
395395
// Get a snapshot of the session to avoid race conditions
396396
sessionSnapshot, exists := store.SessionSnapshot(args.SessionID)
397397
if !exists {
@@ -428,7 +428,7 @@ func ReviewThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolPar
428428
}
429429

430430
// ThinkingHistory handles resource requests for thinking session data and history.
431-
func ThinkingHistory(ctx context.Context, req *mcp.ServerRequest[*mcp.ReadResourceParams]) (*mcp.ReadResourceResult, error) {
431+
func ThinkingHistory(ctx context.Context, req *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error) {
432432
// Extract session ID from URI (e.g., "thinking://session_123")
433433
u, err := url.Parse(req.Params.URI)
434434
if err != nil {

examples/server/sequentialthinking/main_test.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,11 @@ func TestThinkingHistory(t *testing.T) {
387387
ctx := context.Background()
388388

389389
// Test listing all sessions
390-
listParams := &mcp.ReadResourceParams{
391-
URI: "thinking://sessions",
392-
}
393-
394-
result, err := ThinkingHistory(ctx, requestFor(listParams))
390+
result, err := ThinkingHistory(ctx, &mcp.ReadResourceRequest{
391+
Params: &mcp.ReadResourceParams{
392+
URI: "thinking://sessions",
393+
},
394+
})
395395
if err != nil {
396396
t.Fatalf("ThinkingHistory() error = %v", err)
397397
}
@@ -417,11 +417,9 @@ func TestThinkingHistory(t *testing.T) {
417417
}
418418

419419
// Test getting specific session
420-
sessionParams := &mcp.ReadResourceParams{
421-
URI: "thinking://session1",
422-
}
423-
424-
result, err = ThinkingHistory(ctx, requestFor(sessionParams))
420+
result, err = ThinkingHistory(ctx, &mcp.ReadResourceRequest{
421+
Params: &mcp.ReadResourceParams{URI: "thinking://session1"},
422+
})
425423
if err != nil {
426424
t.Fatalf("ThinkingHistory() error = %v", err)
427425
}
@@ -491,7 +489,3 @@ func TestInvalidOperations(t *testing.T) {
491489
t.Error("Expected error for invalid revision step")
492490
}
493491
}
494-
495-
func requestFor[P mcp.Params](p P) *mcp.ServerRequest[P] {
496-
return &mcp.ServerRequest[P]{Params: p}
497-
}

examples/server/sse/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type SayHiParams struct {
2424
Name string `json:"name"`
2525
}
2626

27-
func SayHi(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args SayHiParams) (*mcp.CallToolResult, any, error) {
27+
func SayHi(ctx context.Context, req *mcp.CallToolRequest, args SayHiParams) (*mcp.CallToolResult, any, error) {
2828
return &mcp.CallToolResult{
2929
Content: []mcp.Content{
3030
&mcp.TextContent{Text: "Hi " + args.Name},

internal/readme/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type HiParams struct {
1616
Name string `json:"name" jsonschema:"the name of the person to greet"`
1717
}
1818

19-
func SayHi(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args HiParams) (*mcp.CallToolResult, any, error) {
19+
func SayHi(ctx context.Context, req *mcp.CallToolRequest, args HiParams) (*mcp.CallToolResult, any, error) {
2020
return &mcp.CallToolResult{
2121
Content: []mcp.Content{&mcp.TextContent{Text: "Hi " + args.Name}},
2222
}, nil, nil

mcp/example_middleware_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func Example_loggingMiddleware() {
8989
},
9090
func(
9191
ctx context.Context,
92-
req *mcp.ServerRequest[*mcp.CallToolParams], args map[string]any,
92+
req *mcp.CallToolRequest, args map[string]any,
9393
) (*mcp.CallToolResult, any, error) {
9494
name, ok := args["name"].(string)
9595
if !ok {

mcp/mcp_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type hiParams struct {
3333
// TODO(jba): after schemas are stateless (WIP), this can be a variable.
3434
func greetTool() *Tool { return &Tool{Name: "greet", Description: "say hi"} }
3535

36-
func sayHi(ctx context.Context, req *ServerRequest[*CallToolParams], args hiParams) (*CallToolResult, any, error) {
36+
func sayHi(ctx context.Context, req *CallToolRequest, args hiParams) (*CallToolResult, any, error) {
3737
if err := req.Session.Ping(ctx, nil); err != nil {
3838
return nil, nil, fmt.Errorf("ping failed: %v", err)
3939
}
@@ -74,20 +74,20 @@ func TestEndToEnd(t *testing.T) {
7474
}
7575

7676
sopts := &ServerOptions{
77-
InitializedHandler: func(context.Context, *ServerRequest[*InitializedParams]) {
77+
InitializedHandler: func(context.Context, *InitializedRequest) {
7878
notificationChans["initialized"] <- 0
7979
},
80-
RootsListChangedHandler: func(context.Context, *ServerRequest[*RootsListChangedParams]) {
80+
RootsListChangedHandler: func(context.Context, *RootsListChangedRequest) {
8181
notificationChans["roots"] <- 0
8282
},
83-
ProgressNotificationHandler: func(context.Context, *ServerRequest[*ProgressNotificationParams]) {
83+
ProgressNotificationHandler: func(context.Context, *ProgressNotificationRequest) {
8484
notificationChans["progress_server"] <- 0
8585
},
86-
SubscribeHandler: func(context.Context, *ServerRequest[*SubscribeParams]) error {
86+
SubscribeHandler: func(context.Context, *SubscribeRequest) error {
8787
notificationChans["subscribe"] <- 0
8888
return nil
8989
},
90-
UnsubscribeHandler: func(context.Context, *ServerRequest[*UnsubscribeParams]) error {
90+
UnsubscribeHandler: func(context.Context, *UnsubscribeRequest) error {
9191
notificationChans["unsubscribe"] <- 0
9292
return nil
9393
},
@@ -98,7 +98,7 @@ func TestEndToEnd(t *testing.T) {
9898
Description: "say hi",
9999
}, sayHi)
100100
AddTool(s, &Tool{Name: "fail", InputSchema: &jsonschema.Schema{}},
101-
func(context.Context, *ServerRequest[*CallToolParams], map[string]any) (*CallToolResult, any, error) {
101+
func(context.Context, *CallToolRequest, map[string]any) (*CallToolResult, any, error) {
102102
return nil, nil, errTestFailure
103103
})
104104
s.AddPrompt(codeReviewPrompt, codReviewPromptHandler)
@@ -511,7 +511,7 @@ var embeddedResources = map[string]string{
511511
"info": "This is the MCP test server.",
512512
}
513513

514-
func handleEmbeddedResource(_ context.Context, req *ServerRequest[*ReadResourceParams]) (*ReadResourceResult, error) {
514+
func handleEmbeddedResource(_ context.Context, req *ReadResourceRequest) (*ReadResourceResult, error) {
515515
u, err := url.Parse(req.Params.URI)
516516
if err != nil {
517517
return nil, err
@@ -663,7 +663,7 @@ func TestCancellation(t *testing.T) {
663663
start = make(chan struct{})
664664
cancelled = make(chan struct{}, 1) // don't block the request
665665
)
666-
slowRequest := func(ctx context.Context, req *ServerRequest[*CallToolParams], args any) (*CallToolResult, any, error) {
666+
slowRequest := func(ctx context.Context, req *CallToolRequest, args any) (*CallToolResult, any, error) {
667667
start <- struct{}{}
668668
select {
669669
case <-ctx.Done():
@@ -852,7 +852,7 @@ func traceCalls[S Session](w io.Writer, prefix string) Middleware {
852852
}
853853
}
854854

855-
func nopHandler(context.Context, *ServerRequest[*CallToolParams]) (*CallToolResult, error) {
855+
func nopHandler(context.Context, *CallToolRequest) (*CallToolResult, error) {
856856
return nil, nil
857857
}
858858

@@ -1009,13 +1009,13 @@ func TestSynchronousNotifications(t *testing.T) {
10091009

10101010
var rootsChanged atomic.Bool
10111011
serverOpts := &ServerOptions{
1012-
RootsListChangedHandler: func(_ context.Context, req *ServerRequest[*RootsListChangedParams]) {
1012+
RootsListChangedHandler: func(_ context.Context, req *RootsListChangedRequest) {
10131013
rootsChanged.Store(true)
10141014
},
10151015
}
10161016
server := NewServer(testImpl, serverOpts)
10171017
cs, ss := basicClientServerConnection(t, client, server, func(s *Server) {
1018-
AddTool(s, &Tool{Name: "tool"}, func(ctx context.Context, req *ServerRequest[*CallToolParams], args any) (*CallToolResult, any, error) {
1018+
AddTool(s, &Tool{Name: "tool"}, func(ctx context.Context, req *CallToolRequest, args any) (*CallToolResult, any, error) {
10191019
if !rootsChanged.Load() {
10201020
return nil, nil, fmt.Errorf("didn't get root change notification")
10211021
}
@@ -1064,11 +1064,11 @@ func TestNoDistributedDeadlock(t *testing.T) {
10641064
}
10651065
client := NewClient(testImpl, clientOpts)
10661066
cs, _ := basicClientServerConnection(t, client, nil, func(s *Server) {
1067-
AddTool(s, &Tool{Name: "tool1"}, func(ctx context.Context, req *ServerRequest[*CallToolParams], args any) (*CallToolResult, any, error) {
1067+
AddTool(s, &Tool{Name: "tool1"}, func(ctx context.Context, req *CallToolRequest, args any) (*CallToolResult, any, error) {
10681068
req.Session.CreateMessage(ctx, new(CreateMessageParams))
10691069
return new(CallToolResult), nil, nil
10701070
})
1071-
AddTool(s, &Tool{Name: "tool2"}, func(ctx context.Context, req *ServerRequest[*CallToolParams], args any) (*CallToolResult, any, error) {
1071+
AddTool(s, &Tool{Name: "tool2"}, func(ctx context.Context, req *CallToolRequest, args any) (*CallToolResult, any, error) {
10721072
req.Session.Ping(ctx, nil)
10731073
return new(CallToolResult), nil, nil
10741074
})

0 commit comments

Comments
 (0)