mcp: introduce Requests (#267)
Handlers and client/server methods take a single request argument combining the session and params. This slightly simplifies the signature for handlers, since there is no longer an often-ignored session argument. But more importantly, it opens the door to adding more information in requests, such as auth info and HTTP request headers. For #243.
This commit is contained in:
parent
e097918484
commit
6e03217c83
8 changed files with 517 additions and 380 deletions
|
|
@ -16,17 +16,17 @@ import (
|
|||
// a CompletionHandler to an MCP Server's options.
|
||||
func main() {
|
||||
// Define your custom CompletionHandler logic.
|
||||
myCompletionHandler := func(_ context.Context, _ *mcp.ServerSession, params *mcp.CompleteParams) (*mcp.CompleteResult, error) {
|
||||
myCompletionHandler := func(_ context.Context, req *mcp.ServerRequest[*mcp.CompleteParams]) (*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
|
||||
switch params.Ref.Type {
|
||||
switch req.Params.Ref.Type {
|
||||
case "ref/prompt":
|
||||
suggestions = []string{"suggestion1", "suggestion2", "suggestion3"}
|
||||
case "ref/resource":
|
||||
suggestions = []string{"suggestion4", "suggestion5", "suggestion6"}
|
||||
default:
|
||||
return nil, fmt.Errorf("unrecognized content type %s", params.Ref.Type)
|
||||
return nil, fmt.Errorf("unrecognized content type %s", req.Params.Ref.Type)
|
||||
}
|
||||
|
||||
return &mcp.CompleteResult{
|
||||
|
|
|
|||
|
|
@ -85,10 +85,10 @@ type HiArgs struct {
|
|||
}
|
||||
|
||||
// SayHi is a tool handler that responds with a greeting.
|
||||
func SayHi(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[HiArgs]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
func SayHi(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[HiArgs]]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
return &mcp.CallToolResultFor[struct{}]{
|
||||
Content: []mcp.Content{
|
||||
&mcp.TextContent{Text: "Hi " + params.Arguments.Name},
|
||||
&mcp.TextContent{Text: "Hi " + req.Params.Arguments.Name},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ type HiArgs struct {
|
|||
Name string `json:"name" jsonschema:"the name to say hi to"`
|
||||
}
|
||||
|
||||
func SayHi(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[HiArgs]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
func SayHi(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[HiArgs]]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
return &mcp.CallToolResultFor[struct{}]{
|
||||
Content: []mcp.Content{
|
||||
&mcp.TextContent{Text: "Hi " + params.Arguments.Name},
|
||||
&mcp.TextContent{Text: "Hi " + req.Params.Arguments.Name},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -69,8 +69,8 @@ var embeddedResources = map[string]string{
|
|||
"info": "This is the hello example server.",
|
||||
}
|
||||
|
||||
func handleEmbeddedResource(_ context.Context, _ *mcp.ServerSession, params *mcp.ReadResourceParams) (*mcp.ReadResourceResult, error) {
|
||||
u, err := url.Parse(params.URI)
|
||||
func handleEmbeddedResource(_ context.Context, req *mcp.ServerRequest[*mcp.ReadResourceParams]) (*mcp.ReadResourceResult, error) {
|
||||
u, err := url.Parse(req.Params.URI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ func handleEmbeddedResource(_ context.Context, _ *mcp.ServerSession, params *mcp
|
|||
}
|
||||
return &mcp.ReadResourceResult{
|
||||
Contents: []*mcp.ResourceContents{
|
||||
{URI: params.URI, MIMEType: "text/plain", Text: text},
|
||||
{URI: req.Params.URI, MIMEType: "text/plain", Text: text},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ func (fs *fileStore) Read() ([]byte, error) {
|
|||
|
||||
// Write saves data to file with 0600 permissions.
|
||||
func (fs *fileStore) Write(data []byte) error {
|
||||
if err := os.WriteFile(fs.path, data, 0600); err != nil {
|
||||
if err := os.WriteFile(fs.path, data, 0o600); err != nil {
|
||||
return fmt.Errorf("failed to write file %s: %w", fs.path, err)
|
||||
}
|
||||
return nil
|
||||
|
|
@ -431,10 +431,10 @@ func (k knowledgeBase) openNodes(names []string) (KnowledgeGraph, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (k knowledgeBase) CreateEntities(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[CreateEntitiesArgs]) (*mcp.CallToolResultFor[CreateEntitiesResult], error) {
|
||||
func (k knowledgeBase) CreateEntities(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[CreateEntitiesArgs]]) (*mcp.CallToolResultFor[CreateEntitiesResult], error) {
|
||||
var res mcp.CallToolResultFor[CreateEntitiesResult]
|
||||
|
||||
entities, err := k.createEntities(params.Arguments.Entities)
|
||||
entities, err := k.createEntities(req.Params.Arguments.Entities)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -450,10 +450,10 @@ func (k knowledgeBase) CreateEntities(ctx context.Context, ss *mcp.ServerSession
|
|||
return &res, nil
|
||||
}
|
||||
|
||||
func (k knowledgeBase) CreateRelations(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[CreateRelationsArgs]) (*mcp.CallToolResultFor[CreateRelationsResult], error) {
|
||||
func (k knowledgeBase) CreateRelations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[CreateRelationsArgs]]) (*mcp.CallToolResultFor[CreateRelationsResult], error) {
|
||||
var res mcp.CallToolResultFor[CreateRelationsResult]
|
||||
|
||||
relations, err := k.createRelations(params.Arguments.Relations)
|
||||
relations, err := k.createRelations(req.Params.Arguments.Relations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -469,10 +469,10 @@ func (k knowledgeBase) CreateRelations(ctx context.Context, ss *mcp.ServerSessio
|
|||
return &res, nil
|
||||
}
|
||||
|
||||
func (k knowledgeBase) AddObservations(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[AddObservationsArgs]) (*mcp.CallToolResultFor[AddObservationsResult], error) {
|
||||
func (k knowledgeBase) AddObservations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[AddObservationsArgs]]) (*mcp.CallToolResultFor[AddObservationsResult], error) {
|
||||
var res mcp.CallToolResultFor[AddObservationsResult]
|
||||
|
||||
observations, err := k.addObservations(params.Arguments.Observations)
|
||||
observations, err := k.addObservations(req.Params.Arguments.Observations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -488,10 +488,10 @@ func (k knowledgeBase) AddObservations(ctx context.Context, ss *mcp.ServerSessio
|
|||
return &res, nil
|
||||
}
|
||||
|
||||
func (k knowledgeBase) DeleteEntities(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[DeleteEntitiesArgs]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
func (k knowledgeBase) DeleteEntities(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[DeleteEntitiesArgs]]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
var res mcp.CallToolResultFor[struct{}]
|
||||
|
||||
err := k.deleteEntities(params.Arguments.EntityNames)
|
||||
err := k.deleteEntities(req.Params.Arguments.EntityNames)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -503,10 +503,10 @@ func (k knowledgeBase) DeleteEntities(ctx context.Context, ss *mcp.ServerSession
|
|||
return &res, nil
|
||||
}
|
||||
|
||||
func (k knowledgeBase) DeleteObservations(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[DeleteObservationsArgs]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
func (k knowledgeBase) DeleteObservations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[DeleteObservationsArgs]]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
var res mcp.CallToolResultFor[struct{}]
|
||||
|
||||
err := k.deleteObservations(params.Arguments.Deletions)
|
||||
err := k.deleteObservations(req.Params.Arguments.Deletions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -518,10 +518,10 @@ func (k knowledgeBase) DeleteObservations(ctx context.Context, ss *mcp.ServerSes
|
|||
return &res, nil
|
||||
}
|
||||
|
||||
func (k knowledgeBase) DeleteRelations(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[DeleteRelationsArgs]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
func (k knowledgeBase) DeleteRelations(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[DeleteRelationsArgs]]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
var res mcp.CallToolResultFor[struct{}]
|
||||
|
||||
err := k.deleteRelations(params.Arguments.Relations)
|
||||
err := k.deleteRelations(req.Params.Arguments.Relations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -533,7 +533,7 @@ func (k knowledgeBase) DeleteRelations(ctx context.Context, ss *mcp.ServerSessio
|
|||
return &res, nil
|
||||
}
|
||||
|
||||
func (k knowledgeBase) ReadGraph(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[struct{}]) (*mcp.CallToolResultFor[KnowledgeGraph], error) {
|
||||
func (k knowledgeBase) ReadGraph(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[struct{}]]) (*mcp.CallToolResultFor[KnowledgeGraph], error) {
|
||||
var res mcp.CallToolResultFor[KnowledgeGraph]
|
||||
|
||||
graph, err := k.loadGraph()
|
||||
|
|
@ -549,10 +549,10 @@ func (k knowledgeBase) ReadGraph(ctx context.Context, ss *mcp.ServerSession, par
|
|||
return &res, nil
|
||||
}
|
||||
|
||||
func (k knowledgeBase) SearchNodes(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[SearchNodesArgs]) (*mcp.CallToolResultFor[KnowledgeGraph], error) {
|
||||
func (k knowledgeBase) SearchNodes(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[SearchNodesArgs]]) (*mcp.CallToolResultFor[KnowledgeGraph], error) {
|
||||
var res mcp.CallToolResultFor[KnowledgeGraph]
|
||||
|
||||
graph, err := k.searchNodes(params.Arguments.Query)
|
||||
graph, err := k.searchNodes(req.Params.Arguments.Query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -565,10 +565,10 @@ func (k knowledgeBase) SearchNodes(ctx context.Context, ss *mcp.ServerSession, p
|
|||
return &res, nil
|
||||
}
|
||||
|
||||
func (k knowledgeBase) OpenNodes(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[OpenNodesArgs]) (*mcp.CallToolResultFor[KnowledgeGraph], error) {
|
||||
func (k knowledgeBase) OpenNodes(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[OpenNodesArgs]]) (*mcp.CallToolResultFor[KnowledgeGraph], error) {
|
||||
var res mcp.CallToolResultFor[KnowledgeGraph]
|
||||
|
||||
graph, err := k.openNodes(params.Arguments.Names)
|
||||
graph, err := k.openNodes(req.Params.Arguments.Names)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ func TestSaveAndLoadGraph(t *testing.T) {
|
|||
|
||||
// Test malformed data handling
|
||||
if fs, ok := s.(*fileStore); ok {
|
||||
err := os.WriteFile(fs.path, []byte("invalid json"), 0600)
|
||||
err := os.WriteFile(fs.path, []byte("invalid json"), 0o600)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to write invalid json: %v", err)
|
||||
}
|
||||
|
|
@ -450,7 +450,7 @@ func TestMCPServerIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
createResult, err := kb.CreateEntities(ctx, serverSession, createEntitiesParams)
|
||||
createResult, err := kb.CreateEntities(ctx, requestFor(serverSession, createEntitiesParams))
|
||||
if err != nil {
|
||||
t.Fatalf("MCP CreateEntities failed: %v", err)
|
||||
}
|
||||
|
|
@ -463,7 +463,7 @@ func TestMCPServerIntegration(t *testing.T) {
|
|||
|
||||
// Test ReadGraph through MCP
|
||||
readParams := &mcp.CallToolParamsFor[struct{}]{}
|
||||
readResult, err := kb.ReadGraph(ctx, serverSession, readParams)
|
||||
readResult, err := kb.ReadGraph(ctx, requestFor(serverSession, readParams))
|
||||
if err != nil {
|
||||
t.Fatalf("MCP ReadGraph failed: %v", err)
|
||||
}
|
||||
|
|
@ -487,7 +487,7 @@ func TestMCPServerIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
relationsResult, err := kb.CreateRelations(ctx, serverSession, createRelationsParams)
|
||||
relationsResult, err := kb.CreateRelations(ctx, requestFor(serverSession, createRelationsParams))
|
||||
if err != nil {
|
||||
t.Fatalf("MCP CreateRelations failed: %v", err)
|
||||
}
|
||||
|
|
@ -510,7 +510,7 @@ func TestMCPServerIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
obsResult, err := kb.AddObservations(ctx, serverSession, addObsParams)
|
||||
obsResult, err := kb.AddObservations(ctx, requestFor(serverSession, addObsParams))
|
||||
if err != nil {
|
||||
t.Fatalf("MCP AddObservations failed: %v", err)
|
||||
}
|
||||
|
|
@ -528,7 +528,7 @@ func TestMCPServerIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
searchResult, err := kb.SearchNodes(ctx, serverSession, searchParams)
|
||||
searchResult, err := kb.SearchNodes(ctx, requestFor(serverSession, searchParams))
|
||||
if err != nil {
|
||||
t.Fatalf("MCP SearchNodes failed: %v", err)
|
||||
}
|
||||
|
|
@ -546,7 +546,7 @@ func TestMCPServerIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
openResult, err := kb.OpenNodes(ctx, serverSession, openParams)
|
||||
openResult, err := kb.OpenNodes(ctx, requestFor(serverSession, openParams))
|
||||
if err != nil {
|
||||
t.Fatalf("MCP OpenNodes failed: %v", err)
|
||||
}
|
||||
|
|
@ -569,7 +569,7 @@ func TestMCPServerIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
deleteObsResult, err := kb.DeleteObservations(ctx, serverSession, deleteObsParams)
|
||||
deleteObsResult, err := kb.DeleteObservations(ctx, requestFor(serverSession, deleteObsParams))
|
||||
if err != nil {
|
||||
t.Fatalf("MCP DeleteObservations failed: %v", err)
|
||||
}
|
||||
|
|
@ -590,7 +590,7 @@ func TestMCPServerIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
deleteRelResult, err := kb.DeleteRelations(ctx, serverSession, deleteRelParams)
|
||||
deleteRelResult, err := kb.DeleteRelations(ctx, requestFor(serverSession, deleteRelParams))
|
||||
if err != nil {
|
||||
t.Fatalf("MCP DeleteRelations failed: %v", err)
|
||||
}
|
||||
|
|
@ -605,7 +605,7 @@ func TestMCPServerIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
deleteEntResult, err := kb.DeleteEntities(ctx, serverSession, deleteEntParams)
|
||||
deleteEntResult, err := kb.DeleteEntities(ctx, requestFor(serverSession, deleteEntParams))
|
||||
if err != nil {
|
||||
t.Fatalf("MCP DeleteEntities failed: %v", err)
|
||||
}
|
||||
|
|
@ -614,7 +614,7 @@ func TestMCPServerIntegration(t *testing.T) {
|
|||
}
|
||||
|
||||
// Verify final state
|
||||
finalRead, err := kb.ReadGraph(ctx, serverSession, readParams)
|
||||
finalRead, err := kb.ReadGraph(ctx, requestFor(serverSession, readParams))
|
||||
if err != nil {
|
||||
t.Fatalf("Final MCP ReadGraph failed: %v", err)
|
||||
}
|
||||
|
|
@ -647,7 +647,7 @@ func TestMCPErrorHandling(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err := kb.AddObservations(ctx, serverSession, addObsParams)
|
||||
_, err := kb.AddObservations(ctx, requestFor(serverSession, addObsParams))
|
||||
if err == nil {
|
||||
t.Errorf("expected MCP AddObservations to return error for non-existent entity")
|
||||
} else {
|
||||
|
|
@ -678,7 +678,7 @@ func TestMCPResponseFormat(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
result, err := kb.CreateEntities(ctx, serverSession, createParams)
|
||||
result, err := kb.CreateEntities(ctx, requestFor(serverSession, createParams))
|
||||
if err != nil {
|
||||
t.Fatalf("CreateEntities failed: %v", err)
|
||||
}
|
||||
|
|
@ -701,3 +701,7 @@ func TestMCPResponseFormat(t *testing.T) {
|
|||
t.Errorf("expected Content[0] to be TextContent")
|
||||
}
|
||||
}
|
||||
|
||||
func requestFor[P mcp.Params](ss *mcp.ServerSession, p P) *mcp.ServerRequest[P] {
|
||||
return &mcp.ServerRequest[P]{Session: ss, Params: p}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,8 +231,8 @@ func deepCopyThoughts(thoughts []*Thought) []*Thought {
|
|||
}
|
||||
|
||||
// StartThinking begins a new sequential thinking session for a complex problem.
|
||||
func StartThinking(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[StartThinkingArgs]) (*mcp.CallToolResultFor[any], error) {
|
||||
args := params.Arguments
|
||||
func StartThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[StartThinkingArgs]]) (*mcp.CallToolResultFor[any], error) {
|
||||
args := req.Params.Arguments
|
||||
|
||||
sessionID := args.SessionID
|
||||
if sessionID == "" {
|
||||
|
|
@ -266,8 +266,8 @@ func StartThinking(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallT
|
|||
}
|
||||
|
||||
// ContinueThinking adds the next thought step, revises a previous step, or creates a branch in the thinking process.
|
||||
func ContinueThinking(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[ContinueThinkingArgs]) (*mcp.CallToolResultFor[any], error) {
|
||||
args := params.Arguments
|
||||
func ContinueThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[ContinueThinkingArgs]]) (*mcp.CallToolResultFor[any], error) {
|
||||
args := req.Params.Arguments
|
||||
|
||||
// Handle revision of existing thought
|
||||
if args.ReviseStep != nil {
|
||||
|
|
@ -395,8 +395,8 @@ func ContinueThinking(ctx context.Context, ss *mcp.ServerSession, params *mcp.Ca
|
|||
}
|
||||
|
||||
// ReviewThinking provides a complete review of the thinking process for a session.
|
||||
func ReviewThinking(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[ReviewThinkingArgs]) (*mcp.CallToolResultFor[any], error) {
|
||||
args := params.Arguments
|
||||
func ReviewThinking(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[ReviewThinkingArgs]]) (*mcp.CallToolResultFor[any], error) {
|
||||
args := req.Params.Arguments
|
||||
|
||||
// Get a snapshot of the session to avoid race conditions
|
||||
sessionSnapshot, exists := store.SessionSnapshot(args.SessionID)
|
||||
|
|
@ -434,11 +434,11 @@ func ReviewThinking(ctx context.Context, ss *mcp.ServerSession, params *mcp.Call
|
|||
}
|
||||
|
||||
// ThinkingHistory handles resource requests for thinking session data and history.
|
||||
func ThinkingHistory(ctx context.Context, ss *mcp.ServerSession, params *mcp.ReadResourceParams) (*mcp.ReadResourceResult, error) {
|
||||
func ThinkingHistory(ctx context.Context, req *mcp.ServerRequest[*mcp.ReadResourceParams]) (*mcp.ReadResourceResult, error) {
|
||||
// Extract session ID from URI (e.g., "thinking://session_123")
|
||||
u, err := url.Parse(params.URI)
|
||||
u, err := url.Parse(req.Params.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid thinking resource URI: %s", params.URI)
|
||||
return nil, fmt.Errorf("invalid thinking resource URI: %s", req.Params.URI)
|
||||
}
|
||||
if u.Scheme != "thinking" {
|
||||
return nil, fmt.Errorf("invalid thinking resource URI scheme: %s", u.Scheme)
|
||||
|
|
@ -456,7 +456,7 @@ func ThinkingHistory(ctx context.Context, ss *mcp.ServerSession, params *mcp.Rea
|
|||
return &mcp.ReadResourceResult{
|
||||
Contents: []*mcp.ResourceContents{
|
||||
{
|
||||
URI: params.URI,
|
||||
URI: req.Params.URI,
|
||||
MIMEType: "application/json",
|
||||
Text: string(data),
|
||||
},
|
||||
|
|
@ -478,7 +478,7 @@ func ThinkingHistory(ctx context.Context, ss *mcp.ServerSession, params *mcp.Rea
|
|||
return &mcp.ReadResourceResult{
|
||||
Contents: []*mcp.ResourceContents{
|
||||
{
|
||||
URI: params.URI,
|
||||
URI: req.Params.URI,
|
||||
MIMEType: "application/json",
|
||||
Text: string(data),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func TestStartThinking(t *testing.T) {
|
|||
Arguments: args,
|
||||
}
|
||||
|
||||
result, err := StartThinking(ctx, nil, params)
|
||||
result, err := StartThinking(ctx, requestFor(params))
|
||||
if err != nil {
|
||||
t.Fatalf("StartThinking() error = %v", err)
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ func TestContinueThinking(t *testing.T) {
|
|||
Arguments: startArgs,
|
||||
}
|
||||
|
||||
_, err := StartThinking(ctx, nil, startParams)
|
||||
_, err := StartThinking(ctx, requestFor(startParams))
|
||||
if err != nil {
|
||||
t.Fatalf("StartThinking() error = %v", err)
|
||||
}
|
||||
|
|
@ -105,7 +105,7 @@ func TestContinueThinking(t *testing.T) {
|
|||
Arguments: continueArgs,
|
||||
}
|
||||
|
||||
result, err := ContinueThinking(ctx, nil, continueParams)
|
||||
result, err := ContinueThinking(ctx, requestFor(continueParams))
|
||||
if err != nil {
|
||||
t.Fatalf("ContinueThinking() error = %v", err)
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ func TestContinueThinkingWithCompletion(t *testing.T) {
|
|||
Arguments: startArgs,
|
||||
}
|
||||
|
||||
_, err := StartThinking(ctx, nil, startParams)
|
||||
_, err := StartThinking(ctx, requestFor(startParams))
|
||||
if err != nil {
|
||||
t.Fatalf("StartThinking() error = %v", err)
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ func TestContinueThinkingWithCompletion(t *testing.T) {
|
|||
Arguments: continueArgs,
|
||||
}
|
||||
|
||||
result, err := ContinueThinking(ctx, nil, continueParams)
|
||||
result, err := ContinueThinking(ctx, requestFor(continueParams))
|
||||
if err != nil {
|
||||
t.Fatalf("ContinueThinking() error = %v", err)
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ func TestContinueThinkingRevision(t *testing.T) {
|
|||
Arguments: continueArgs,
|
||||
}
|
||||
|
||||
result, err := ContinueThinking(ctx, nil, continueParams)
|
||||
result, err := ContinueThinking(ctx, requestFor(continueParams))
|
||||
if err != nil {
|
||||
t.Fatalf("ContinueThinking() error = %v", err)
|
||||
}
|
||||
|
|
@ -289,7 +289,7 @@ func TestContinueThinkingBranching(t *testing.T) {
|
|||
Arguments: continueArgs,
|
||||
}
|
||||
|
||||
result, err := ContinueThinking(ctx, nil, continueParams)
|
||||
result, err := ContinueThinking(ctx, requestFor(continueParams))
|
||||
if err != nil {
|
||||
t.Fatalf("ContinueThinking() error = %v", err)
|
||||
}
|
||||
|
|
@ -356,7 +356,7 @@ func TestReviewThinking(t *testing.T) {
|
|||
Arguments: reviewArgs,
|
||||
}
|
||||
|
||||
result, err := ReviewThinking(ctx, nil, reviewParams)
|
||||
result, err := ReviewThinking(ctx, requestFor(reviewParams))
|
||||
if err != nil {
|
||||
t.Fatalf("ReviewThinking() error = %v", err)
|
||||
}
|
||||
|
|
@ -431,7 +431,7 @@ func TestThinkingHistory(t *testing.T) {
|
|||
URI: "thinking://sessions",
|
||||
}
|
||||
|
||||
result, err := ThinkingHistory(ctx, nil, listParams)
|
||||
result, err := ThinkingHistory(ctx, requestFor(listParams))
|
||||
if err != nil {
|
||||
t.Fatalf("ThinkingHistory() error = %v", err)
|
||||
}
|
||||
|
|
@ -461,7 +461,7 @@ func TestThinkingHistory(t *testing.T) {
|
|||
URI: "thinking://session1",
|
||||
}
|
||||
|
||||
result, err = ThinkingHistory(ctx, nil, sessionParams)
|
||||
result, err = ThinkingHistory(ctx, requestFor(sessionParams))
|
||||
if err != nil {
|
||||
t.Fatalf("ThinkingHistory() error = %v", err)
|
||||
}
|
||||
|
|
@ -496,7 +496,7 @@ func TestInvalidOperations(t *testing.T) {
|
|||
Arguments: continueArgs,
|
||||
}
|
||||
|
||||
_, err := ContinueThinking(ctx, nil, continueParams)
|
||||
_, err := ContinueThinking(ctx, requestFor(continueParams))
|
||||
if err == nil {
|
||||
t.Error("Expected error for non-existent session")
|
||||
}
|
||||
|
|
@ -511,7 +511,7 @@ func TestInvalidOperations(t *testing.T) {
|
|||
Arguments: reviewArgs,
|
||||
}
|
||||
|
||||
_, err = ReviewThinking(ctx, nil, reviewParams)
|
||||
_, err = ReviewThinking(ctx, requestFor(reviewParams))
|
||||
if err == nil {
|
||||
t.Error("Expected error for non-existent session in review")
|
||||
}
|
||||
|
|
@ -541,8 +541,12 @@ func TestInvalidOperations(t *testing.T) {
|
|||
Arguments: invalidReviseArgs,
|
||||
}
|
||||
|
||||
_, err = ContinueThinking(ctx, nil, invalidReviseParams)
|
||||
_, err = ContinueThinking(ctx, requestFor(invalidReviseParams))
|
||||
if err == nil {
|
||||
t.Error("Expected error for invalid revision step")
|
||||
}
|
||||
}
|
||||
|
||||
func requestFor[P mcp.Params](p P) *mcp.ServerRequest[P] {
|
||||
return &mcp.ServerRequest[P]{Params: p}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ type SayHiParams struct {
|
|||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func SayHi(ctx context.Context, cc *mcp.ServerSession, params *mcp.CallToolParamsFor[SayHiParams]) (*mcp.CallToolResultFor[any], error) {
|
||||
func SayHi(ctx context.Context, req *mcp.ServerRequest[*mcp.CallToolParamsFor[SayHiParams]]) (*mcp.CallToolResultFor[any], error) {
|
||||
return &mcp.CallToolResultFor[any]{
|
||||
Content: []mcp.Content{
|
||||
&mcp.TextContent{Text: "Hi " + params.Arguments.Name},
|
||||
&mcp.TextContent{Text: "Hi " + req.Params.Arguments.Name},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue