diff --git a/mcp/generate.go b/mcp/generate.go index 6ac0a65..cfffef8 100644 --- a/mcp/generate.go +++ b/mcp/generate.go @@ -66,7 +66,7 @@ var declarations = config{ "CallToolResult": {}, "CancelledNotification": { Name: "-", - Fields: config{"Params": {Name: "CancelledParams"}}, + Fields: config{"Params": {Name: "cancelledParams"}}, }, "ClientCapabilities": {}, "GetPromptRequest": { diff --git a/mcp/protocol.go b/mcp/protocol.go index 2664ce3..5450f71 100644 --- a/mcp/protocol.go +++ b/mcp/protocol.go @@ -54,17 +54,6 @@ type CallToolResult struct { IsError bool `json:"isError,omitempty"` } -type CancelledParams struct { - // An optional string describing the reason for the cancellation. This MAY be - // logged or presented to the user. - Reason string `json:"reason,omitempty"` - // The ID of the request to cancel. - // - // This MUST correspond to the ID of a request previously issued in the same - // direction. - RequestID any `json:"requestId"` -} - // Capabilities a client may support. Known capabilities are defined here, in // this schema, but this is not a closed set: any client can define its own, // additional capabilities. @@ -315,6 +304,17 @@ type ToolAnnotations struct { Title string `json:"title,omitempty"` } +type cancelledParams struct { + // An optional string describing the reason for the cancellation. This MAY be + // logged or presented to the user. + Reason string `json:"reason,omitempty"` + // The ID of the request to cancel. + // + // This MUST correspond to the ID of a request previously issued in the same + // direction. + RequestID any `json:"requestId"` +} + // Describes the name and version of an MCP implementation. type implementation struct { Name string `json:"name"` diff --git a/mcp/transport.go b/mcp/transport.go index f69299d..f0fda45 100644 --- a/mcp/transport.go +++ b/mcp/transport.go @@ -126,7 +126,7 @@ type canceller struct { // Preempt implements jsonrpc2.Preempter. func (c *canceller) Preempt(ctx context.Context, req *jsonrpc2.Request) (result any, err error) { if req.Method == "notifications/cancelled" { - var params CancelledParams + var params cancelledParams if err := json.Unmarshal(req.Params, ¶ms); err != nil { return nil, err } @@ -151,7 +151,7 @@ func call(ctx context.Context, conn *jsonrpc2.Connection, method string, params, return fmt.Errorf("calling %q: %w", method, ErrConnectionClosed) case ctx.Err() != nil: // Notify the peer of cancellation. - err := conn.Notify(xcontext.Detach(ctx), "notifications/cancelled", &CancelledParams{ + err := conn.Notify(xcontext.Detach(ctx), "notifications/cancelled", &cancelledParams{ Reason: ctx.Err().Error(), RequestID: call.ID().Raw(), })