Skip to content

API: declarations prevent subclassing/extending public classes #793

Closed

Description

@scottslewis

I would like to extend the McpAsyncServer, McpSyncServer and the stateless versions to extend the behavior of these servers via a new MCP extension under development.

Currently, these classes, and a couple of classes that their constructors depend upon (McpServerFeatures.Sync and Async) are package protected meaning that only the code in the sdk can use these constructors, effectively preventing the creation of subclasses.

Environment

version 0.18.0.SNAPSHOT of sdk as of 2/14/2026
Please provide as many details as possible: Spring MCP version, Java version, which vector store you use if any, etc

Expected behavior

Ability to declare subclasses of McpSyncServer, McpAsyncServer, and stateless analogs. Subclass constructors must call the superclass constructor and so currently cannot be from outside of io.modelcontextprotocol package namespace.

Minimal Complete Reproducible example

The follow code will not compile, because the superclass (McpAsyncServer) constructor is package private.

	class AsyncToolGroupServer extends McpAsyncServer {

		public AsyncToolGroupServer(McpServerTransportProvider mcpTransportProvider, McpJsonMapper jsonMapper,
				Async features, Duration requestTimeout, McpUriTemplateManagerFactory uriTemplateManagerFactory,
				JsonSchemaValidator jsonSchemaValidator) {
			super(mcpTransportProvider, jsonMapper, features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator);
		}
}

fix pr forthcoming

Activity

  1. Kehrlann commented on Feb 20, 2026

    @Kehrlann
    Contributor

    As I mentioned in #794 :

    As a rule of thumb, we avoid making our core implementations extensible through subclassing. Instead, we prefer composition, and introducing specific APIs.

    Would you be so kind as to open an issue about your specific need, IIRC customizing params in notifications? I think you mentioned notifyToolsListChanged, but this could probably apply to all notifications.

  2. added theissue type on Feb 20, 2026
  3. scottslewis commented on Feb 22, 2026

    @scottslewis
    Author

    Would you be so kind as to open an issue about your specific need, IIRC customizing params in notifications? I think you mentioned notifyToolsListChanged, but this could probably apply to all notifications.

    See #831

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions