Skip to content

Commit ea8fdf4

Browse files
jbayasomaru
authored andcommitted
all: remove ServerRequest[T] for concrete T (modelcontextprotocol#342)
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.) I will expand the aliases in a followup PR.
1 parent 38431d0 commit ea8fdf4

File tree

21 files changed

+107
-89
lines changed

21 files changed

+107
-89
lines changed

README.md

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

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

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 {

0 commit comments

Comments
 (0)