mcp: fix cancellation for HTTP transport
In #202, I added the checkRequest helper to validate incoming requests, and invoked it in the stremable transports to preemptively reject invalid HTTP requests, so that a jsonrpc error could be translated to an HTTP error. However, this introduced a bug: since cancellation was handled in the jsonrpc2 layer, we never had to validate it in the mcp layer, and therefore never added methodInfo. As a result, it was reported as an invalid request in the http layer. Add a test, and a fix. The simplest fix was to create stubs that are placeholders for cancellation. This was discovered in the course of investigating #285.
This commit is contained in:
parent
a834f3cf9a
commit
bb6dadecca
1 changed files with 72 additions and 26 deletions
|
|
@ -646,8 +646,7 @@ func TestCancellation(t *testing.T) {
|
|||
start = make(chan struct{})
|
||||
cancelled = make(chan struct{}, 1) // don't block the request
|
||||
)
|
||||
|
||||
slowRequest := func(ctx context.Context, req *ServerRequest[*CallToolParamsFor[map[string]any]]) (*CallToolResult, error) {
|
||||
slowRequest := func(ctx context.Context, req *ServerRequest[*CallToolParams]) (*CallToolResult, error) {
|
||||
start <- struct{}{}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
|
@ -658,7 +657,7 @@ func TestCancellation(t *testing.T) {
|
|||
return nil, nil
|
||||
}
|
||||
_, cs := basicConnection(t, func(s *Server) {
|
||||
s.AddTool(&Tool{Name: "slow", InputSchema: &jsonschema.Schema{}}, slowRequest)
|
||||
AddTool(s, &Tool{Name: "slow"}, slowRequest)
|
||||
})
|
||||
defer cs.Close()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue