mcp: allow any value for schemas (#517)
As discussed at length in https://github.com/modelcontextprotocol/go-sdk/issues/518, coupling our schema fields to jsonschema.Schema limits our user's ability to use a different schema package, and makes it impossible for our client to talk to some backends. This CL relaxes the type of `*jsonschema.Schema` fields to be of type `any`, which is a breaking change but is unlikely to affect most server code. (It *is* a nontrivial change for clients). Fixes https://github.com/modelcontextprotocol/go-sdk/issues/518
This commit is contained in:
parent
5f05f8a43a
commit
964574b818
1 changed files with 201 additions and 47 deletions
|
|
@ -13,8 +13,6 @@ package mcp
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
)
|
||||
|
||||
// Optional annotations for the client. The client can use annotations to inform
|
||||
|
|
@ -913,14 +911,38 @@ type Tool struct {
|
|||
// This can be used by clients to improve the LLM's understanding of available
|
||||
// tools. It can be thought of like a "hint" to the model.
|
||||
Description string `json:"description,omitempty"`
|
||||
// A JSON Schema object defining the expected parameters for the tool.
|
||||
InputSchema *jsonschema.Schema `json:"inputSchema"`
|
||||
// InputSchema holds a JSON Schema object defining the expected parameters
|
||||
// for the tool.
|
||||
//
|
||||
// From the server, this field may be set to any value that JSON-marshals to
|
||||
// valid JSON schema (including json.RawMessage). However, for tools added
|
||||
// using [AddTool], which automatically validates inputs and outputs, the
|
||||
// schema must be in a draft the SDK understands. Currently, the SDK uses
|
||||
// github.com/google/jsonschema-go for inference and validation, which only
|
||||
// supports the 2020-12 draft of JSON schema. To do your own validation, use
|
||||
// [Server.AddTool].
|
||||
//
|
||||
// From the client, this field will hold the default JSON marshaling of the
|
||||
// server's input schema (a map[string]any).
|
||||
InputSchema any `json:"inputSchema"`
|
||||
// Intended for programmatic or logical use, but used as a display name in past
|
||||
// specs or fallback (if title isn't present).
|
||||
Name string `json:"name"`
|
||||
// An optional JSON Schema object defining the structure of the tool's output
|
||||
// returned in the structuredContent field of a CallToolResult.
|
||||
OutputSchema *jsonschema.Schema `json:"outputSchema,omitempty"`
|
||||
// OutputSchema holds an optional JSON Schema object defining the structure
|
||||
// of the tool's output returned in the StructuredContent field of a
|
||||
// CallToolResult.
|
||||
//
|
||||
// From the server, this field may be set to any value that JSON-marshals to
|
||||
// valid JSON schema (including json.RawMessage). However, for tools added
|
||||
// using [AddTool], which automatically validates inputs and outputs, the
|
||||
// schema must be in a draft the SDK understands. Currently, the SDK uses
|
||||
// github.com/google/jsonschema-go for inference and validation, which only
|
||||
// supports the 2020-12 draft of JSON schema. To do your own validation, use
|
||||
// [Server.AddTool].
|
||||
//
|
||||
// From the client, this field will hold the default JSON marshaling of the
|
||||
// server's output schema (a map[string]any).
|
||||
OutputSchema any `json:"outputSchema,omitempty"`
|
||||
// Intended for UI and end-user contexts — optimized to be human-readable and
|
||||
// easily understood, even by those unfamiliar with domain-specific terminology.
|
||||
// If not provided, Annotations.Title should be used for display if present,
|
||||
|
|
@ -1022,9 +1044,18 @@ type ElicitParams struct {
|
|||
Meta `json:"_meta,omitempty"`
|
||||
// The message to present to the user.
|
||||
Message string `json:"message"`
|
||||
// A restricted subset of JSON Schema.
|
||||
// A JSON schema object defining the requested elicitation schema.
|
||||
//
|
||||
// From the server, this field may be set to any value that can JSON-marshal
|
||||
// to valid JSON schema (including json.RawMessage for raw schema values).
|
||||
// Internally, the SDK uses github.com/google/jsonschema-go for validation,
|
||||
// which only supports the 2020-12 draft of the JSON schema spec.
|
||||
//
|
||||
// From the client, this field will use the default JSON marshaling (a
|
||||
// map[string]any).
|
||||
//
|
||||
// Only top-level properties are allowed, without nesting.
|
||||
RequestedSchema *jsonschema.Schema `json:"requestedSchema"`
|
||||
RequestedSchema any `json:"requestedSchema"`
|
||||
}
|
||||
|
||||
func (x *ElicitParams) isParams() {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue