Class MCPLoopbackSocketTransport

java.lang.Object
com.codename1.mcp.MCPLoopbackSocketTransport
All Implemented Interfaces:
MCPTransport

public final class MCPLoopbackSocketTransport extends Object implements MCPTransport

Loopback socket MCP transport built on the portable Socket API, so an agent can attach to a running app on ANY port that can bind the loopback interface - a device or simulator, not only the desktop.

The channel is bound to loopback only. That is the security boundary: an attaching agent can read the screen and drive the UI, so it must already be on the device (or on a host forwarding into it), never merely on the same network. There is no wildcard fallback; if the port cannot bind loopback this transport refuses to open.

The listening socket stays bound across client sessions, so an agent may disconnect and reconnect - each drive call is typically its own short-lived connection - without the server thread exiting.

  • Method Details

    • getPort

      public int getPort()
    • open

      public void open() throws IOException
      Description copied from interface: MCPTransport
      Opens the transport, blocking until it is ready to exchange messages. For a socket transport this waits for the first client connection.
      Specified by:
      open in interface MCPTransport
      Throws:
      IOException
    • readMessage

      public String readMessage() throws IOException
      Description copied from interface: MCPTransport
      Reads the next complete JSON-RPC message. Returns null at end of stream.
      Specified by:
      readMessage in interface MCPTransport
      Throws:
      IOException
    • writeMessage

      public void writeMessage(String message) throws IOException
      Description copied from interface: MCPTransport
      Writes a complete JSON-RPC message and flushes it. The value must not contain embedded newlines.
      Specified by:
      writeMessage in interface MCPTransport
      Throws:
      IOException
    • close

      public void close()
      Description copied from interface: MCPTransport
      Closes the transport and releases any underlying resources.
      Specified by:
      close in interface MCPTransport