Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mcp/server/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
sdkmcp "github.com/modelcontextprotocol/go-sdk/mcp"
llm "github.com/mutablelogic/go-llm"
schema "github.com/mutablelogic/go-llm/kernel/schema"
jsonschema "github.com/mutablelogic/go-server/pkg/jsonschema"
types "github.com/mutablelogic/go-server/pkg/types"
trace "go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -44,6 +45,9 @@ func (s *Server) RemoveTools(names ...string) {
func sdkToolFromTool(t llm.Tool, tracer trace.Tracer) (*sdkmcp.Tool, sdkmcp.ToolHandler, error) {
// Build input schema — SDK accepts any JSON-marshalable value.
inputSchema := t.InputSchema()
if inputSchema == nil {
inputSchema = jsonschema.MustFor[struct{}]()
}
Comment thread
djthorpe marked this conversation as resolved.
var err error
inputSchemaRaw, err := json.Marshal(inputSchema)
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions mcp/server/tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

// Packages
sdkmcp "github.com/modelcontextprotocol/go-sdk/mcp"
llm "github.com/mutablelogic/go-llm"
homeassistant "github.com/mutablelogic/go-llm/homeassistant/connector"
schema "github.com/mutablelogic/go-llm/kernel/schema"
mock "github.com/mutablelogic/go-llm/mcp/mock"
Expand Down Expand Up @@ -285,6 +286,29 @@ func TestAddToolsBadInputSchema(t *testing.T) {
}
}

type nilInputSchemaTool struct{}

func (nilInputSchemaTool) Name() string { return "nil_input_schema" }
func (nilInputSchemaTool) Description() string { return "tool with nil input schema" }
func (nilInputSchemaTool) InputSchema() *jsonschema.Schema { return nil }
func (nilInputSchemaTool) OutputSchema() *jsonschema.Schema {
return nil
}
func (nilInputSchemaTool) Meta() llm.ToolMeta { return llm.ToolMeta{} }
func (nilInputSchemaTool) Run(context.Context, json.RawMessage) (any, error) {
return map[string]any{"ok": true}, nil
}

func TestAddToolsNilInputSchemaDefaultsToEmptyObject(t *testing.T) {
srv, err := server.New("test-server", "1.0.0")
if err != nil {
t.Fatal(err)
}
if err := srv.AddTools(nilInputSchemaTool{}); err != nil {
t.Fatalf("expected nil input schema to be accepted, got error: %v", err)
}
}
Comment thread
djthorpe marked this conversation as resolved.

///////////////////////////////////////////////////////////////////////////////
// TESTS — Session context injection (T6)

Expand Down