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 original MCP request waits up to 10 seconds by default (maximum 30 seconds), outside room locks. Timeouts release pending entries but cannot cancel browser execution. At most 64 calls wait concurrently; request and callback bodies are limited to 256 KiB.

Uses jose4j's JSON support already supplied by the server's ACME dependency. No app scripts, shared runtime changes or additional dependencies are required.

  • 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