Class HttpMcpServer

java.lang.Object
com.tnsai.mcp.server.HttpMcpServer

public class HttpMcpServer extends Object
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();
 
  • 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 ID
      method - the notification method
      params - optional params (may be null)
    • broadcastNotification

      public void broadcastNotification(String method, com.fasterxml.jackson.databind.JsonNode params)
      Broadcasts a notification to all active sessions.
      Parameters:
      method - the notification method
      params - optional params (may be null)
    • getSessionManager

      public McpSessionManager getSessionManager()
      Returns the session manager.
      Returns:
      the session manager
    • builder

      public static HttpMcpServer.Builder builder()
      Creates a new builder for HttpMcpServer.
      Returns:
      a new Builder instance