Class McpServerBase
- All Implemented Interfaces:
McpServer
- Direct Known Subclasses:
McpSseServer,McpStdioServer,McpStreamableServer
This class implements the core functionality shared across different MCP server implementations, including capability definition, component registration, and server creation. It serves as a foundation for concrete server implementations that handle different transport mechanisms (STDIO, SSE, STREAMABLE).
The class manages server configuration and provides default implementations for:
- Defining server capabilities based on configuration
- Registering MCP components (resources, prompts, tools)
- Creating a configured synchronous server instance
Concrete implementations need only provide the specific synchronization specification for
their transport mechanism by implementing the McpServer.createSyncSpecification() method.
- Author:
- codeboyzhou
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final McpServerConfigurationThe server configuration used by this MCP server. -
Constructor Summary
ConstructorsConstructorDescriptionMcpServerBase(@NotNull McpServerConfiguration configuration) Constructs a newMcpServerBasewith the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionio.modelcontextprotocol.server.McpSyncServerCreates and returns a fully configured MCP synchronous server instance.io.modelcontextprotocol.spec.McpSchema.ServerCapabilitiesDefines and returns the server capabilities based on the configuration.voidregisterComponents(io.modelcontextprotocol.server.McpSyncServer mcpSyncServer) Registers all MCP server components with the specified synchronous server.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.github.thought2code.mcp.annotated.server.McpServer
createSyncSpecification
-
Field Details
-
configuration
The server configuration used by this MCP server.
-
-
Constructor Details
-
McpServerBase
Constructs a newMcpServerBasewith the specified configuration.- Parameters:
configuration- the server configuration containing all settings for the MCP server, including capabilities, timeouts, and transport settings
-
-
Method Details
-
defineCapabilities
public io.modelcontextprotocol.spec.McpSchema.ServerCapabilities defineCapabilities()Defines and returns the server capabilities based on the configuration.This method reads the capability settings from the server configuration and constructs a
McpSchema.ServerCapabilitiesobject that specifies which features are enabled (resources, prompts, tools, completions) and their respective change notification settings.- Specified by:
defineCapabilitiesin interfaceMcpServer- Returns:
- a configured ServerCapabilities object reflecting the server's supported features
- See Also:
-
registerComponents
public void registerComponents(io.modelcontextprotocol.server.McpSyncServer mcpSyncServer) Registers all MCP server components with the specified synchronous server.This method creates and registers the three main types of MCP components: resources, prompts, and tools. Each component type is handled by its respective registration class which scans for annotated methods and registers them with the server.
- Specified by:
registerComponentsin interfaceMcpServer- Parameters:
mcpSyncServer- the synchronous server instance to register components with- See Also:
-
createSyncServer
public io.modelcontextprotocol.server.McpSyncServer createSyncServer()Creates and returns a fully configured MCP synchronous server instance.This method builds a synchronous server by combining:
- The server capabilities defined by
defineCapabilities() - All available completion specifications from
McpServerCompletion.all() - Server information (name, version) from the configuration
- Instructions and request timeout from the configuration
The method uses the synchronization specification provided by the concrete implementation through
McpServer.createSyncSpecification().- Specified by:
createSyncServerin interfaceMcpServer- Returns:
- a fully configured MCP synchronous server ready to start
- See Also:
-
McpSyncServerMcpServerCompletion
- The server capabilities defined by
-