all: remove ServerRequest[T] for concrete T (#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.
This commit is contained in:
Jonathan Amsterdam 2025-08-21 12:10:53 -04:00 • committed by GitHub
commit 6378df6f24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 107 additions and 89 deletions

View file

@ -16,7 +16,7 @@ import (
// a CompletionHandler to an MCP Server's options.
func main() {
// Define your custom CompletionHandler logic.
myCompletionHandler := func(_ context.Context, req *mcp.ServerRequest[*mcp.CompleteParams]) (*mcp.CompleteResult, error) {
myCompletionHandler := func(_ context.Context, req *mcp.CompleteRequest) (*mcp.CompleteResult, error) {
// In a real application, you'd implement actual completion logic here.
// For this example, we return a fixed set of suggestions.
var suggestions []string

View file

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

View file

@ -22,7 +22,7 @@ type HiArgs struct {
Name string `json:"name" jsonschema:"the name to say hi to"`
}
func SayHi(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args HiArgs) (*mcp.CallToolResult, any, error) {
func SayHi(ctx context.Context, req *mcp.CallToolRequest, args HiArgs) (*mcp.CallToolResult, any, error) {
return &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{Text: "Hi " + args.Name},
@ -69,7 +69,7 @@ var embeddedResources = map[string]string{
"info": "This is the hello example server.",
}
func handleEmbeddedResource(_ context.Context, req *mcp.ServerRequest[*mcp.ReadResourceParams]) (*mcp.ReadResourceResult, error) {
func handleEmbeddedResource(_ context.Context, req *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error) {
u, err := url.Parse(req.Params.URI)
if err != nil {
return nil, err

View file

@ -431,7 +431,7 @@ func (k knowledgeBase) openNodes(names []string) (KnowledgeGraph, error) {
}, nil
}
func (k knowledgeBase) CreateEntities(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args CreateEntitiesArgs) (*mcp.CallToolResult, CreateEntitiesResult, error) {
func (k knowledgeBase) CreateEntities(ctx context.Context, req *mcp.CallToolRequest, args CreateEntitiesArgs) (*mcp.CallToolResult, CreateEntitiesResult, error) {
var res mcp.CallToolResult
entities, err := k.createEntities(args.Entities)
@ -450,7 +450,7 @@ func (k knowledgeBase) CreateEntities(ctx context.Context, req *mcp.ServerReques
return &res, CreateEntitiesResult{Entities: entities}, nil
}
func (k knowledgeBase) CreateRelations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args CreateRelationsArgs) (*mcp.CallToolResult, CreateRelationsResult, error) {
func (k knowledgeBase) CreateRelations(ctx context.Context, req *mcp.CallToolRequest, args CreateRelationsArgs) (*mcp.CallToolResult, CreateRelationsResult, error) {
var res mcp.CallToolResult
relations, err := k.createRelations(args.Relations)
@ -465,7 +465,7 @@ func (k knowledgeBase) CreateRelations(ctx context.Context, req *mcp.ServerReque
return &res, CreateRelationsResult{Relations: relations}, nil
}
func (k knowledgeBase) AddObservations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args AddObservationsArgs) (*mcp.CallToolResult, AddObservationsResult, error) {
func (k knowledgeBase) AddObservations(ctx context.Context, req *mcp.CallToolRequest, args AddObservationsArgs) (*mcp.CallToolResult, AddObservationsResult, error) {
var res mcp.CallToolResult
observations, err := k.addObservations(args.Observations)
@ -482,7 +482,7 @@ func (k knowledgeBase) AddObservations(ctx context.Context, req *mcp.ServerReque
}, nil
}
func (k knowledgeBase) DeleteEntities(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args DeleteEntitiesArgs) (*mcp.CallToolResult, any, error) {
func (k knowledgeBase) DeleteEntities(ctx context.Context, req *mcp.CallToolRequest, args DeleteEntitiesArgs) (*mcp.CallToolResult, any, error) {
var res mcp.CallToolResult
err := k.deleteEntities(args.EntityNames)
@ -497,7 +497,7 @@ func (k knowledgeBase) DeleteEntities(ctx context.Context, req *mcp.ServerReques
return &res, nil, nil
}
func (k knowledgeBase) DeleteObservations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args DeleteObservationsArgs) (*mcp.CallToolResult, any, error) {
func (k knowledgeBase) DeleteObservations(ctx context.Context, req *mcp.CallToolRequest, args DeleteObservationsArgs) (*mcp.CallToolResult, any, error) {
var res mcp.CallToolResult
err := k.deleteObservations(args.Deletions)
@ -512,7 +512,7 @@ func (k knowledgeBase) DeleteObservations(ctx context.Context, req *mcp.ServerRe
return &res, nil, nil
}
func (k knowledgeBase) DeleteRelations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args DeleteRelationsArgs) (*mcp.CallToolResult, struct{}, error) {
func (k knowledgeBase) DeleteRelations(ctx context.Context, req *mcp.CallToolRequest, args DeleteRelationsArgs) (*mcp.CallToolResult, struct{}, error) {
var res mcp.CallToolResult
err := k.deleteRelations(args.Relations)
@ -527,7 +527,7 @@ func (k knowledgeBase) DeleteRelations(ctx context.Context, req *mcp.ServerReque
return &res, struct{}{}, nil
}
func (k knowledgeBase) ReadGraph(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args any) (*mcp.CallToolResult, KnowledgeGraph, error) {
func (k knowledgeBase) ReadGraph(ctx context.Context, req *mcp.CallToolRequest, args any) (*mcp.CallToolResult, KnowledgeGraph, error) {
var res mcp.CallToolResult
graph, err := k.loadGraph()
@ -542,7 +542,7 @@ func (k knowledgeBase) ReadGraph(ctx context.Context, req *mcp.ServerRequest[*mc
return &res, graph, nil
}
func (k knowledgeBase) SearchNodes(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args SearchNodesArgs) (*mcp.CallToolResult, KnowledgeGraph, error) {
func (k knowledgeBase) SearchNodes(ctx context.Context, req *mcp.CallToolRequest, args SearchNodesArgs) (*mcp.CallToolResult, KnowledgeGraph, error) {
var res mcp.CallToolResult
graph, err := k.searchNodes(args.Query)
@ -557,7 +557,7 @@ func (k knowledgeBase) SearchNodes(ctx context.Context, req *mcp.ServerRequest[*
return &res, graph, nil
}
func (k knowledgeBase) OpenNodes(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args OpenNodesArgs) (*mcp.CallToolResult, KnowledgeGraph, error) {
func (k knowledgeBase) OpenNodes(ctx context.Context, req *mcp.CallToolRequest, args OpenNodesArgs) (*mcp.CallToolResult, KnowledgeGraph, error) {
var res mcp.CallToolResult
graph, err := k.openNodes(args.Names)

View file

@ -231,7 +231,7 @@ func deepCopyThoughts(thoughts []*Thought) []*Thought {
}
// StartThinking begins a new sequential thinking session for a complex problem.
func StartThinking(ctx context.Context, _ *mcp.ServerRequest[*mcp.CallToolParams], args StartThinkingArgs) (*mcp.CallToolResult, any, error) {
func StartThinking(ctx context.Context, _ *mcp.CallToolRequest, args StartThinkingArgs) (*mcp.CallToolResult, any, error) {
sessionID := args.SessionID
if sessionID == "" {
sessionID = randText()
@ -264,7 +264,7 @@ func StartThinking(ctx context.Context, _ *mcp.ServerRequest[*mcp.CallToolParams
}
// ContinueThinking adds the next thought step, revises a previous step, or creates a branch in the thinking process.
func ContinueThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args ContinueThinkingArgs) (*mcp.CallToolResult, any, error) {
func ContinueThinking(ctx context.Context, req *mcp.CallToolRequest, args ContinueThinkingArgs) (*mcp.CallToolResult, any, error) {
// Handle revision of existing thought
if args.ReviseStep != nil {
err := store.CompareAndSwap(args.SessionID, func(session *ThinkingSession) (*ThinkingSession, error) {
@ -391,7 +391,7 @@ func ContinueThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolP
}
// ReviewThinking provides a complete review of the thinking process for a session.
func ReviewThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args ReviewThinkingArgs) (*mcp.CallToolResult, any, error) {
func ReviewThinking(ctx context.Context, req *mcp.CallToolRequest, args ReviewThinkingArgs) (*mcp.CallToolResult, any, error) {
// Get a snapshot of the session to avoid race conditions
sessionSnapshot, exists := store.SessionSnapshot(args.SessionID)
if !exists {
@ -428,7 +428,7 @@ func ReviewThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolPar
}
// ThinkingHistory handles resource requests for thinking session data and history.
func ThinkingHistory(ctx context.Context, req *mcp.ServerRequest[*mcp.ReadResourceParams]) (*mcp.ReadResourceResult, error) {
func ThinkingHistory(ctx context.Context, req *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error) {
// Extract session ID from URI (e.g., "thinking://session_123")
u, err := url.Parse(req.Params.URI)
if err != nil {

View file

@ -387,11 +387,11 @@ func TestThinkingHistory(t *testing.T) {
ctx := context.Background()
// Test listing all sessions
listParams := &mcp.ReadResourceParams{
URI: "thinking://sessions",
}
result, err := ThinkingHistory(ctx, requestFor(listParams))
result, err := ThinkingHistory(ctx, &mcp.ReadResourceRequest{
Params: &mcp.ReadResourceParams{
URI: "thinking://sessions",
},
})
if err != nil {
t.Fatalf("ThinkingHistory() error = %v", err)
}
@ -417,11 +417,9 @@ func TestThinkingHistory(t *testing.T) {
}
// Test getting specific session
sessionParams := &mcp.ReadResourceParams{
URI: "thinking://session1",
}
result, err = ThinkingHistory(ctx, requestFor(sessionParams))
result, err = ThinkingHistory(ctx, &mcp.ReadResourceRequest{
Params: &mcp.ReadResourceParams{URI: "thinking://session1"},
})
if err != nil {
t.Fatalf("ThinkingHistory() error = %v", err)
}
@ -491,7 +489,3 @@ func TestInvalidOperations(t *testing.T) {
t.Error("Expected error for invalid revision step")
}
}
func requestFor[P mcp.Params](p P) *mcp.ServerRequest[P] {
return &mcp.ServerRequest[P]{Params: p}
}

View file

@ -24,7 +24,7 @@ type SayHiParams struct {
Name string `json:"name"`
}
func SayHi(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParams], args SayHiParams) (*mcp.CallToolResult, any, error) {
func SayHi(ctx context.Context, req *mcp.CallToolRequest, args SayHiParams) (*mcp.CallToolResult, any, error) {
return &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{Text: "Hi " + args.Name},