Skip to content

Improved Tool Schema Validation for Broader MCP Server Compatibility#2342

Merged
kevalmahajan merged 1 commit intomainfrom
2322_json_validation_failures_gateways
Jan 23, 2026
Merged

Improved Tool Schema Validation for Broader MCP Server Compatibility#2342
kevalmahajan merged 1 commit intomainfrom
2322_json_validation_failures_gateways

Conversation

@kevalmahajan
Copy link
Copy Markdown
Member

@kevalmahajan kevalmahajan commented Jan 23, 2026

🐛 Bug-fix PR

📌 Summary

Closes #2322

This PR fixes an issue with the validation of JSON Schemas attached to tools during insert/update operations causing failure of registration of some MCP servers in Context Forge Gateway.

Previously, only Draft 7 schemas were checked, and invalid schemas would raise a ValueError. The new implementation:

  • Detects the correct schema draft automatically.
  • Supports multiple drafts (Draft 4, 6, 7, 2019-09, 2020-12).
  • Logs warnings for unsupported drafts or invalid schemas instead of raising exceptions.

This improves stability and provides better visibility into schema issues.


🔁 Reproduction Steps

  1. Create or update a tool with an Draft4 (or any other than draft7) JSON Schema.
  2. Trigger an insert or update operation.
  3. Observe a runtime jsonschema.SchemaError or unclear failure behavior.

🐞 Root Cause

  • Always used Draft 7 validator, ignoring other schema drafts.
  • Raised a ValueError for invalid schemas, potentially crashing the operation.

💡 Fix Description

  1. Use jsonschema.validators.validator_for to detect the appropriate validator.
  2. Validate schemas explicitly via check_schema.
  3. Supported draft check: Verifies the detected validator is one of the explicitly supported drafts:
    1. Draft 4
    2. Draft 6
    3. Draft 7
    4. Draft 2019-09
    5. Draft 2020-12
  4. Logs a warning if the schema uses an unsupported or unknown draft.

🧪 Verification

Check Command Status
Lint suite make lint
Unit tests make test
Coverage ≥ 90 % make coverage
Manual regression no longer fails steps / screenshots

📐 MCP Compliance (if relevant)

  • Matches current MCP spec
  • No breaking change to MCP clients

✅ Checklist

  • Code formatted (make black isort pre-commit)
  • No secrets/credentials committed

@kevalmahajan kevalmahajan added wxo wxo integration bug Something isn't working labels Jan 23, 2026
Copy link
Copy Markdown
Collaborator

@madhav165 madhav165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look fine

…patibility

- Use jsonschema.validators.validator_for to detect schema draft automatically
- Support multiple JSON Schema drafts (Draft 4, 6, 7, 2019-09, 2020-12)
- Log warnings for unsupported drafts or invalid schemas instead of raising errors
- Handle None schemas gracefully
- Apply consistent validation behavior to both tool and prompt schemas
- Add comprehensive tests for different schema drafts
- Add fallback validator logic in tool_service.py for runtime validation
- Disable MCP SDK's built-in input validation which uses strict Draft 2020-12

Closes #2322

Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
@crivetimihai crivetimihai force-pushed the 2322_json_validation_failures_gateways branch from ef295a3 to 579597a Compare January 23, 2026 13:45
@crivetimihai
Copy link
Copy Markdown
Member

Additional Fixes Added

During integration testing against real MCP servers, discovered and fixed additional issues:

Changes

  1. mcpgateway/services/tool_service.py - Added fallback validator logic

    • When auto-detected validator fails check_schema(), tries older drafts (Draft7 → Draft6 → Draft4)
    • Handles schemas using legacy features like Draft 4 style exclusiveMinimum: true
  2. mcpgateway/transports/streamablehttp_transport.py - Disabled MCP SDK's built-in input validation

    • Added validate_input=False to @mcp_app.call_tool() decorator
    • The SDK internally uses jsonschema.validate() which calls check_schema() with strict Draft 2020-12
    • Gateway handles schema validation separately in tool_service.py with multi-draft support

Testing

Verified against:

  • https://custom-registration-enum-val.onrender.com/mcp/
  • https://complex-tools-openapi-1.onrender.com/mcp/

Both servers now register and invoke tools successfully.

Related

Created issue #2348 to track feedback about behavioral changes (invalid schemas now persist with warnings rather than errors).

@crivetimihai crivetimihai self-assigned this Jan 23, 2026
@kevalmahajan kevalmahajan merged commit 579d677 into main Jan 23, 2026
51 checks passed
@kevalmahajan kevalmahajan deleted the 2322_json_validation_failures_gateways branch January 23, 2026 14:22
kcostell06 pushed a commit to kcostell06/mcp-context-forge that referenced this pull request Feb 24, 2026
…patibility (IBM#2342)

- Use jsonschema.validators.validator_for to detect schema draft automatically
- Support multiple JSON Schema drafts (Draft 4, 6, 7, 2019-09, 2020-12)
- Log warnings for unsupported drafts or invalid schemas instead of raising errors
- Handle None schemas gracefully
- Apply consistent validation behavior to both tool and prompt schemas
- Add comprehensive tests for different schema drafts
- Add fallback validator logic in tool_service.py for runtime validation
- Disable MCP SDK's built-in input validation which uses strict Draft 2020-12

Closes IBM#2322

Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working wxo wxo integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Few MCP servers are not supported - Error when adding gateway

3 participants