Class McpHandler

java.lang.Object
net.targetr.rc.mcp.McpHandler
All Implemented Interfaces:
ResponseGenerator

public final class McpHandler extends Object implements ResponseGenerator
Minimal, stateless MCP 2025-11-25 Streamable HTTP endpoint at /api/mcp. Room codes provide access to room operations; no bearer token or account setup is required. Both tools require a room code and do not enumerate rooms. POST supports initialize, ping, tools/list and tools/call; GET returns 405 (no SSE).

execute_javascript writes once to the selected live WebSocket, without offline queuing or retries. Its injected ES5 reply/fail functions POST JSON to /api/mcp-result using a random, one-use token. The reply deadline defaults to 10 seconds (maximum 30 seconds), including send time; a blocked socket write can exceed it. Waiting occurs outside room locks. Timeouts release pending entries but cannot cancel browser execution. At most 64 calls per handler wait concurrently; request and callback bodies are limited to 256 KiB.

Uses jose4j's JSON support already supplied by the server's ACME dependency. JavaScript and generated reply JSON are each limited to 65,536 characters.

  • Constructor Details

    • McpHandler

      public McpHandler()
      Creates a handler using the shared rooms.
  • Method Details

    • generate

      public HttpResponse generate(HttpRequest request) throws IOException
      Handles an MCP request or a token-correlated browser reply.
      Specified by:
      generate in interface ResponseGenerator
      Parameters:
      request - incoming HTTP request
      Returns:
      JSON response, callback acknowledgement, or HTTP error
      Throws:
      IOException - if reading the request body fails