Skip to content

fix(mcp): preserve complete input schemas - #86

Merged
mudler merged 1 commit into
mudler:mainfrom
mudler-agent:fix/preserve-mcp-schemas
Oct 9, 2026
Merged

mudler merged 1 commit into
mudler:mainfrom
mudler-agent:fix/preserve-mcp-schemas

Conversation

@mudler-agent

Copy link
Copy Markdown
Contributor

Summary

Preserve the official MCP SDK's complete Tool.InputSchema as json.RawMessage when constructing model-facing tool parameters.

The previous conversion through LangChainGo's jsonschema.Definition loses keywords that the struct cannot represent. For example, a nullable enum expressed with anyOf becomes {"properties":{}}. Its enum and default disappear. Root references, definitions, and compositions can disappear too.

MCP discovery now forwards the schema without that conversion or nullable/boolean coercion. The exported CoerceNullableTypes helper remains available, deprecated and isolated from discovery, for existing callers.

Tests

  • Add discovery regressions for nullable enums, explicit defaults, references, compositions, boolean subschemas, constraints, and absent properties.
  • Add eight HTTP serialization cases for OpenAI and LocalAI, covering streaming, completion, metadata, and native-media paths.
  • Replace the obsolete expectation that discovery inserts empty properties.

Verification commands (all pass):

go test . -count=1 -args -ginkgo.label-filter='!e2e'
go test ./clients ./examples/... ./prompt ./structures ./tests/... -count=1
go test -race . ./clients -run 'Test(MCPDiscoveryPreservesInputSchema|ClientsPreserveRawToolSchema|Coerce|BooleanSchema|Normalization)' -count=1

The corrected regression tests fail before the implementation. Independent review and a separate non-e2e test run pass.

Scope

No dependency upgrade or broader LLM migration. The default MCP path preserves schemas; opt-in strict-tool mode retains its existing transformations. HTTP tests use local mock servers, not external model services.

The restricted schema conversion drops defaults, compositions, and root
keywords. Preserve the official MCP SDK schema as raw JSON instead of
rebuilding it through LangChainGo definitions.

Keep the deprecated normalization helper for existing callers, but remove
it from discovery. Replace the invented-properties test with lossless
discovery regressions. Check OpenAI and LocalAI HTTP serialization for
completion and streaming requests.
@mudler
mudler merged commit 2cc5667 into mudler:main Oct 9, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants