Class McpStreamableServer
- All Implemented Interfaces:
McpServer
This class extends McpServerBase and provides functionality for creating and managing
MCP servers that use HTTP streaming for communication. The streamable mode is designed for web
applications that require real-time, bidirectional communication with the MCP server.
The server uses Jetty as the underlying HTTP server and supports various configuration options including:
- Custom port binding
- Configurable MCP endpoint path
- Keep-alive interval management
- Delete operation control
This server mode is particularly suitable for:
- Web applications requiring real-time communication
- Browser-based MCP client integrations
- Scenarios needing HTTP-based streaming communication
- Author:
- codeboyzhou
- See Also:
-
McpServerBaseMcpServerConfigurationMcpServerStreamableHttpServletStreamableServerTransportProviderJettyHttpServer
-
Field Summary
Fields inherited from class com.github.thought2code.mcp.annotated.server.McpServerBase
configuration -
Constructor Summary
ConstructorsConstructorDescriptionMcpStreamableServer(McpServerConfiguration configuration) Constructs a newMcpStreamableServerwith the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionio.modelcontextprotocol.server.McpServer.SyncSpecification<?>Creates and returns a synchronization specification for Streamable HTTP mode.voidStarts the Jetty HTTP server with the configured transport provider.Methods inherited from class com.github.thought2code.mcp.annotated.server.McpServerBase
createSyncServer, defineCapabilities, registerComponents
-
Constructor Details
-
McpStreamableServer
Constructs a newMcpStreamableServerwith the specified configuration.The constructor initializes the server with the provided configuration, which contains all necessary settings for the streamable HTTP server including port number, endpoint path, keep-alive interval, and other transport options.
- Parameters:
configuration- the server configuration containing streamable settings- Throws:
NullPointerException- if the configuration is null- See Also:
-
-
Method Details
-
createSyncSpecification
public io.modelcontextprotocol.server.McpServer.SyncSpecification<?> createSyncSpecification()Creates and returns a synchronization specification for Streamable HTTP mode.This method creates an
McpServer.SyncSpecificationthat uses HTTP streaming transport provider for communication. The transport provider is configured with the following settings from the configuration:- Port number for binding the HTTP server
- MCP endpoint path for the streaming API
- Whether to disallow delete operations
- Keep-alive interval for maintaining connections
The method also stores the port number and transport provider instance for later use when starting the HTTP server.
- Returns:
- a synchronization specification configured for HTTP streaming transport
- See Also:
-
HttpServletStreamableServerTransportProviderMcpServerStreamableMcpJsonMapper
-
startHttpServer
public void startHttpServer()Starts the Jetty HTTP server with the configured transport provider.This method creates a new
JettyHttpServerinstance, configures it with the transport provider created bycreateSyncSpecification(), binds it to the configured port, and starts the server. The server will begin accepting incoming HTTP connections for MCP streaming communication.This method should be called after
createSyncSpecification()has been invoked to ensure the transport provider is properly initialized.- See Also:
-
JettyHttpServerHttpServletStreamableServerTransportProvidercreateSyncSpecification()
-