Skip to content

Conversation

@nknize
Copy link

@nknize nknize commented Jan 16, 2026

Motivation and Context

Applications using the MCP Java SDK with JPMS (Java Platform Module System) currently require --add-opens JVM flags because the Jackson ObjectMapper uses setAccessible() to access record constructors. This breaks module encapsulation and prevents full JPMS adoption.

This change configures the ObjectMapper to:

  1. Disable CAN_OVERRIDE_ACCESS_MODIFIERS to prevent setAccessible() calls
  2. Use ParameterNamesModule to discover constructor parameter names from bytecode

The SDK already compiles with -parameters, so no additional build configuration is needed.

How Has This Been Tested?

  • Added JpmsCompatibilityTests that verify record deserialization works without reflection
  • Tested with simple records, records with maps/lists, and nested records
  • Verified CAN_OVERRIDE_ACCESS_MODIFIERS is disabled via configuration test
  • All existing tests pass

Breaking Changes

None. This is a transparent configuration change. Applications that previously worked will continue to work, and applications that required --add-opens flags can now remove them.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Resolves #753

The ParameterNamesModule dependency is already transitively available via Jackson, but is now explicitly declared in pom.xml for clarity.

  Configure ObjectMapper with JPMS-compatible settings:
  - Disable CAN_OVERRIDE_ACCESS_MODIFIERS to prevent setAccessible() calls
  - Add ParameterNamesModule to discover constructor parameter names from
    bytecode instead of reflection

  This allows applications using the MCP SDK to operate without
  `--add-opens` JVM flags, enabling full JPMS module encapsulation.

  The SDK already compiles with `-parameters` flag, which is required
  for ParameterNamesModule to function.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
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.

Add JPMS compatibility to Jackson JSON mapper

1 participant