Package eu.mrapik.minecraftservermcp.mcp
Class McpHttpServer
java.lang.Object
eu.mrapik.minecraftservermcp.mcp.McpHttpServer
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 intoMcpTransportContextsoToolInvocationGateandResourceInvocationGatecan resolve the profile on each tool or resource read.
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 Summary
ConstructorsConstructorDescriptionMcpHttpServer(JavaPlugin plugin, AtomicReference<PluginSettings> settingsRef, ServerFilePaths paths) Wires Jetty, MCP transport,MinecraftServerMcpImpl, and registersbuilt-in tools. -
Method Summary
Modifier and TypeMethodDescriptionapi()Public API for registering tools (same instance plugins receive from the service manager).@Nullable io.modelcontextprotocol.server.McpAsyncServerExposes the underlying MCP async server (same instance passed toMinecraftServerMcpImpl).voidstart()Starts Jetty; call from the plugin'sonEnableafter construction.voidstop()Stops the MCP server and Jetty; idempotent aside from logged warnings.
-
Constructor Details
-
McpHttpServer
public McpHttpServer(JavaPlugin plugin, AtomicReference<PluginSettings> settingsRef, ServerFilePaths paths) Wires Jetty, MCP transport,MinecraftServerMcpImpl, and registersbuilt-in tools.- Parameters:
plugin- MCP plugin instancesettingsRef- holds currentPluginSettings; updated on reloadpaths- server root for file tools
-
-
Method Details
-
start
Starts Jetty; call from the plugin'sonEnableafter 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 API for registering tools (same instance plugins receive from the service manager).- Returns:
- the
MinecraftServerMcpimplementation
-
mcpServer
@Nullable public @Nullable io.modelcontextprotocol.server.McpAsyncServer mcpServer()Exposes the underlying MCP async server (same instance passed toMinecraftServerMcpImpl).- Returns:
- the async MCP server created in the constructor
-