all: expose JSON-RPC error codes, and support URLElicitationRequired errors (#655)
Expose the jsonrpc.Error type to allow access to underlying JSON-RPC error codes. Also, expose common JSON-RPC error codes in the jsonrpc package, and MCP error codes in the mcp package. Also, implement support for the MCP URL elicitation required error (-32042), enabling servers to request out-of-band user authorization and clients to automatically handle these requests with retry logic. Server-side: - Add CodeURLElicitationRequired constant - Add URLElicitationRequiredError() constructor. Client-side: - Add urlElicitationMiddleware to intercept URLElicitationRequired errors and retry calls. - Update callElicitationCompleteHandler to signal waiting operations. - Fix capability advertisement to support both form and URL modes. Fixes #452 Fixes #623
This commit is contained in:
parent
96385fde3c
commit
2ce44d45e9
1 changed files with 670 additions and 44 deletions
|
|
@ -24,7 +24,7 @@ import (
|
|||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
|
||||
"github.com/modelcontextprotocol/go-sdk/jsonrpc"
|
||||
)
|
||||
|
||||
type hiParams struct {
|
||||
|
|
@ -316,7 +316,7 @@ func TestEndToEnd(t *testing.T) {
|
|||
} {
|
||||
rres, err := cs.ReadResource(ctx, &ReadResourceParams{URI: tt.uri})
|
||||
if err != nil {
|
||||
if code := errorCode(err); code == codeResourceNotFound {
|
||||
if code := errorCode(err); code == CodeResourceNotFound {
|
||||
if tt.mimeType != "" {
|
||||
t.Errorf("%s: not found but expected it to be", tt.uri)
|
||||
}
|
||||
|
|
@ -576,7 +576,7 @@ func errorCode(err error) int64 {
|
|||
if err == nil {
|
||||
return 0
|
||||
}
|
||||
var werr *jsonrpc2.WireError
|
||||
var werr *jsonrpc.Error
|
||||
if errors.As(err, &werr) {
|
||||
return werr.Code
|
||||
}
|
||||
|
|
@ -1367,8 +1367,8 @@ func TestElicitationSchemaValidation(t *testing.T) {
|
|||
t.Errorf("expected error for invalid schema %q, got nil", tc.name)
|
||||
return
|
||||
}
|
||||
if code := errorCode(err); code != codeInvalidParams {
|
||||
t.Errorf("got error code %d, want %d (CodeInvalidParams)", code, codeInvalidParams)
|
||||
if code := errorCode(err); code != jsonrpc.CodeInvalidParams {
|
||||
t.Errorf("got error code %d, want %d (CodeInvalidParams)", code, jsonrpc.CodeInvalidParams)
|
||||
}
|
||||
if !strings.Contains(err.Error(), tc.expectedError) {
|
||||
t.Errorf("error message %q does not contain expected text %q", err.Error(), tc.expectedError)
|
||||
|
|
|
|||
Loading…
Reference in a new issue