Package com.tnsai.mcp.server
Class HttpMcpServer
java.lang.Object
com.tnsai.mcp.server.HttpMcpServer
HTTP-based MCP server using JDK built-in
HttpServer.
Implements the MCP Streamable HTTP transport (spec 2025-03-26) server side:
- POST - JSON-RPC request/notification endpoint
- GET - Server-initiated notification SSE stream
- DELETE - Session termination
Example usage:
HttpMcpServer server = HttpMcpServer.builder()
.port(8080)
.path("/mcp")
.serverName("MyServer")
.addToolProvider(myToolProvider)
.build();
server.start();
// ... server is running ...
server.stop();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidbroadcastNotification(String method, com.fasterxml.jackson.databind.JsonNode params) Broadcasts a notification to all active sessions.static HttpMcpServer.Builderbuilder()Creates a new builder for HttpMcpServer.intgetPort()Returns the port the server is listening on.Returns the session manager.voidsendNotification(String sessionId, String method, com.fasterxml.jackson.databind.JsonNode params) Sends a notification to a specific session.voidstart()Starts the HTTP server.voidstop()Stops the HTTP server.
-
Method Details
-
start
public void start()Starts the HTTP server. -
stop
public void stop()Stops the HTTP server. -
getPort
public int getPort()Returns the port the server is listening on.- Returns:
- the port number
-
sendNotification
public void sendNotification(String sessionId, String method, com.fasterxml.jackson.databind.JsonNode params) Sends a notification to a specific session.- Parameters:
sessionId- the session IDmethod- the notification methodparams- optional params (may be null)
-
broadcastNotification
Broadcasts a notification to all active sessions.- Parameters:
method- the notification methodparams- optional params (may be null)
-
getSessionManager
Returns the session manager.- Returns:
- the session manager
-
builder
Creates a new builder for HttpMcpServer.- Returns:
- a new Builder instance
-