Skip to content

Conversation

@cdivilly
Copy link

@cdivilly cdivilly commented Dec 12, 2025

Fixes #560

  • Uses build-helper-maven-plugin to generate a Maven property named automatic.module.name generated from ${project.groupId}.${project.artifactId}, whilst ensuring the value is a syntactically valid Java Module name, by replacing any - characters with . characters
  • Remove legacy configuration of Automatic-Module-Name in ./mcp-core/pom.xml bnd-maven-plugin configuration which was generating a value with an invalid value (Java Module names cannot contain the - character)
  • Modifies ./pom.xml maven-jar-plugin configuration to add Automatic-Module-Name property to the JAR manifest. Doing this here, ensures each sub-project JAR has a valid automatic module name

Motivation and Context

In versions 0.12.1 and older, the SDK consisted of a single module, mcp. The Automatic-Module-Name manifest attribute was generated by the bnd-maven-plugin. Note that the single module name does not contain any dash (-) characters.

In 0.13.0 and later, the SDK was refactored into multiple modules, mcp-core, mcp-json etc. Note the addition of the - character in the artifactId. The existing logic for generating Automatic-Module-Name was not updated, resulting in syntactically invalid values being generated for the value, as Java module names are not allowed contain the - character:

Automatic-Module-Name: io.modelcontextprotocol.sdk.mcp-core
  • This invalid module name prevents use of 0.13.0 and later versions of the SDK in any Java application that uses Java Modules.

With the changes described above, this becomes:

Automatic-Module-Name: io.modelcontextprotocol.sdk.mcp.core
  • Java module based applications can once again use the MCP SDK

How Has This Been Tested?

  • Checked the contents of META/MANIFEST.MF in each jar is a valid Java module name
  • Rebuilt the downstream application that was regressed by this issue using the rebuilt jars. Compile time error previously reported no longer occurs

Breaking Changes

  • OSGi support is explicitly removed, but OSGi has been broken since 0.13.0 anyways, so effectively this PR does not change the status of OSGi support.
  • I have a branch that could restore OSGi support: main...cdivilly:mcp-java-sdk:fix/mcp-osgi-support. I am unhappy with the approach taken, I think a more comprehensive solution would build OSGi support into each module. I'm unconvinced this repo should take on that effort.

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

  • One new maven plugin: org.codehaus.mojo:build-helper-maven-plugin is added to the root pom.xml. This purpose of this plugin is to generate and rewrite the value of ${automatic.module.name} property into a syntactically valid Java module name
  • Configuring Automatic-Module-Name is moved from the bnd-maven-plugin configuration to the maven-jar-plugin configuration, so it can be uniformly applied to all sub-modules.

@cdivilly cdivilly changed the title Modify maven-jar-plugin config to generate syntactically correct auto… Invalid Automatic-Module-Name in mcp-core Dec 12, 2025
@cdivilly cdivilly marked this pull request as draft December 12, 2025 18:46
@cdivilly
Copy link
Author

More testing shows a split package issue. The package io.modelcontextprotocol.json is duplicated across the mcp-core and mcp-json jars. The package does not appear in the source code for mcp-core, it appears to be added in during the build process.

In Java modules, it is not permitted for the same package name to be used in more than one jar.

@cdivilly
Copy link
Author

The bnd-maven-plugin is pulling in the io.modelcontextprotocol.json package into mcp-core/target/classes

Due to the specific bnd-maven-plugin configuration in mcp-core, the class files from mcp-json are assembled into the mcp-core jar.

@cdivilly
Copy link
Author

cdivilly commented Dec 15, 2025

I've revised this PR to address the split package issue.

  1. Move automatic module name generation to maven-jar-plugin. Ensures all modules have a valid name
  2. Remove OSGi config from mcp-core. bnd-maven-plugin causes the classes in mcp-json to be duplicated into mcp-core, which then causes split-package issue.
  3. I've prepared a separate branch that would restore the OSGi support, but I am not in favour of merging it as it leads to a bifurcated dependency graph. The branch is here: main...cdivilly:mcp-java-sdk:fix/mcp-osgi-support

@cdivilly cdivilly marked this pull request as ready for review December 15, 2025 11:46
@cdivilly cdivilly force-pushed the fix/regressed-automatic-module-name branch 2 times, most recently from 6fb0ef4 to a4af515 Compare December 15, 2025 15:25
…nfiguration, as causes duplicate classes, causing split package problem across mcp-json and mcp-core.
@cdivilly cdivilly force-pushed the fix/regressed-automatic-module-name branch from a4af515 to 1a2fb85 Compare December 15, 2025 15:51
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.

Invalid Automatic-Module-Name in mcp-core

1 participant