internal/mcp: apply JSON schema defaults
Before validating a tool input, apply the defaults from the input schema. Change-Id: I23fae4087f898d51b3d1f0578d3203b954cb5f2d Reviewed-on: https://go-review.googlesource.com/c/tools/+/680395 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
82be9ce756
commit
6a6c44171c
1 changed files with 59 additions and 16 deletions
|
|
@ -19,6 +19,7 @@ import (
|
|||
|
||||
"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
|
||||
"github.com/modelcontextprotocol/go-sdk/internal/util"
|
||||
"github.com/modelcontextprotocol/go-sdk/jsonschema"
|
||||
)
|
||||
|
||||
const DefaultPageSize = 1000
|
||||
|
|
@ -137,7 +138,7 @@ func (s *Server) addToolsErr(tools ...*ServerTool) error {
|
|||
// Resolve the schemas, with no base URI. We don't expect tool schemas to
|
||||
// refer outside of themselves.
|
||||
if st.Tool.InputSchema != nil {
|
||||
r, err := st.Tool.InputSchema.Resolve(nil)
|
||||
r, err := st.Tool.InputSchema.Resolve(&jsonschema.ResolveOptions{ValidateDefaults: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -146,7 +147,7 @@ func (s *Server) addToolsErr(tools ...*ServerTool) error {
|
|||
|
||||
// TODO: uncomment when output schemas drop.
|
||||
// if st.Tool.OutputSchema != nil {
|
||||
// st.outputResolved, err := st.Tool.OutputSchema.Resolve(nil)
|
||||
// st.outputResolved, err := st.Tool.OutputSchema.Resolve(&jsonschema.ResolveOptions{ValidateDefaults: true})
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
|
|
|||
Loading…
Reference in a new issue