Class McpHttpServer

java.lang.Object
eu.mrapik.minecraftservermcp.mcp.McpHttpServer

public final class McpHttpServer extends Object
Embeds Jetty and the MCP SDK's streamable HTTP servlet so clients connect to http://host:port plus the configured servlet path (see PluginSettings.mcpPath()).

Authentication uses two layers that must agree:

  • ServerTransportSecurityValidator — runs on the HTTP upgrade/handshake path; rejects requests without a valid token before MCP sessions attach (401/403).
  • McpTransportContextExtractor — copies the same token into McpTransportContext so ToolInvocationGate and ResourceInvocationGate can resolve the profile on each tool or resource read.
Built-in tools and resources are registered after the server is built: BuiltinToolCatalog for tools and BuiltinMcpResources for filesystem/player MCP resources (same token policy keys as in config.yml).

Security notes: Use HTTPS (SslSettings) when tokens cross an untrusted network so bearer tokens are not sent in cleartext. Tokens and keystore passwords in config.yml are still secrets at rest—restrict file permissions. This stack does not implement rate limiting or mTLS; expose the MCP port only where appropriate. Changing ssl.* requires a server restart (reload does not rebind TLS).

  • Constructor Details

  • Method Details

    • start

      public void start() throws Exception
      Starts Jetty; call from the plugin's onEnable after construction.
      Throws:
      Exception - if Jetty fails to bind or start
    • stop

      public void stop()
      Stops the MCP server and Jetty; idempotent aside from logged warnings.
    • api

      public MinecraftServerMcp api()
      Public API for registering tools (same instance plugins receive from the service manager).
      Returns:
      the MinecraftServerMcp implementation
    • mcpServer

      @Nullable public @Nullable io.modelcontextprotocol.server.McpAsyncServer mcpServer()
      Exposes the underlying MCP async server (same instance passed to MinecraftServerMcpImpl).
      Returns:
      the async MCP server created in the constructor