Skip to content

Input validation doesn't catch missing fields #449

@iwyrkore

Description

@iwyrkore

Describe the bug
The input validation for a tool call doesn't seem to catch missing required fields. It does catch invalid fields that are not in the schema.

To Reproduce
Steps to reproduce the behavior:

  1. I added a second field the the basic example (and also output the tool info):

Run this file:

// Copyright 2025 The Go MCP SDK Authors. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/modelcontextprotocol/go-sdk/mcp"
)

type SayHiParams struct {
	Name  string `json:"name"`
	Title string `json:"title"`
}

func SayHi(ctx context.Context, req *mcp.CallToolRequest, args SayHiParams) (*mcp.CallToolResult, any, error) {
	return &mcp.CallToolResult{
		Content: []mcp.Content{
			&mcp.TextContent{Text: "Hi " + args.Title + " " + args.Name},
		},
	}, nil, nil
}

func main() {
	ctx := context.Background()
	clientTransport, serverTransport := mcp.NewInMemoryTransports()

	server := mcp.NewServer(&mcp.Implementation{Name: "greeter", Version: "v0.0.1"}, nil)
	mcp.AddTool(server, &mcp.Tool{Name: "greet", Description: "say hi"}, SayHi)

	serverSession, err := server.Connect(ctx, serverTransport, nil)
	if err != nil {
		log.Fatal(err)
	}

	client := mcp.NewClient(&mcp.Implementation{Name: "client"}, nil)
	clientSession, err := client.Connect(ctx, clientTransport, nil)
	if err != nil {
		log.Fatal(err)
	}

	res, err := clientSession.CallTool(ctx, &mcp.CallToolParams{
		Name:      "greet",
		Arguments: map[string]any{"name": "user"},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(res.Content[0].(*mcp.TextContent).Text)

	clientSession.Close()
	serverSession.Wait()

	// Output: 
        // {"tools":[{"description":"say hi","inputSchema":{"type":"object","required":["name","title"],"properties":{"name":{"type":"string"},"title":{"type":"string"}},"additionalProperties":false},"name":"greet"}]}
Hi  user
        // Hi  user
}

Expected behavior
I would have expected that it would generate a validation error for the missing field "title" in the tool call.

Additional context
The schema looks correct:

"inputSchema":{"type":"object","required":["name","title"],"properties":{"name":{"type":"string"},"title":{"type":"string"}},"additionalProperties":false}

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingneeds investigationstatus unclear, requires more work and discussion

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions