public final class MCPLoopbackSocketTransport
- Object
- MCPLoopbackSocketTransport
ImplementsMCPTransport
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.
Nested types
class MCPLoopbackSocketTransport.Connection | The per-connection callback the socket API instantiates. |
Methods
public int getPort() | |
public void open()
throws IOException | Opens the transport, blocking until it is ready to exchange messages. |
public String readMessage()
throws IOException | Reads the next complete JSON-RPC message. |
public void writeMessage(String message)
throws IOException | Writes a complete JSON-RPC message and flushes it. |
public void close() | Closes the transport and releases any underlying resources. |
Inherited methods
Method details
getPort
public int getPort()open
public void open()
throws IOExceptionOpens the transport, blocking until it is ready to exchange messages. For a
socket transport this waits for the first client connection.
Throws
readMessage
public String readMessage()
throws IOExceptionReads the next complete JSON-RPC message. Returns null at end of stream.
Throws
writeMessage
public void writeMessage(String message)
throws IOExceptionWrites a complete JSON-RPC message and flushes it. The value must not contain
embedded newlines.
Throws
close
public void close()Closes the transport and releases any underlying resources.