Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UnrecognizedPropertyException in MCP WebFlux Transport #2484

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hariohmprasath
Copy link

Fix UnrecognizedPropertyException in MCP WebFlux Transport

Issue

When using the MCP server with WebFlux transport, the server fails with UnrecognizedPropertyException when receiving JSON payloads containing unknown fields. This occurs because the default ObjectMapper configuration is too strict and fails on unknown properties.

Fixes #2481

Changes

  • Modified McpWebFluxServerAutoConfiguration to use Spring Boot's auto-configured ObjectMapper instead of creating a new one
  • Added test coverage to verify that JSON deserialization works correctly with unknown fields
  • The auto-configured ObjectMapper comes with Spring Boot's default settings, including FAIL_ON_UNKNOWN_PROPERTIES=false

Testing

Added unit test that verifies:

  • The WebFlux transport is configured with the correct ObjectMapper
  • The ObjectMapper is configured to ignore unknown properties
  • JSON payloads with unknown fields can be deserialized without exceptions

Impact

This change ensures that the MCP server can handle JSON payloads that may contain additional fields not defined in the model classes, which is particularly important for forward compatibility and client-server version mismatches.

Related PRs

N/A

refactor: Clean up McpWebFluxServerAutoConfiguration and add tests

- Reorganize imports and improve code formatting for better readability.
- Update `webFluxTransport` method to accept a custom `ObjectMapper`.
- Introduce `McpWebFluxServerAutoConfigurationTests` to validate configuration and ensure proper handling of unknown JSON properties.

Signed-off-by: Hari Ohm Prasath <[email protected]>
Signed-off-by: Hari Ohm Prasth Rajagopal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "tools"
3 participants