Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class MCPServer
- Object
- MCPServer
A Model Context Protocol server. Speaks JSON-RPC 2.0 over a pluggable
MCPTransport, dispatching the MCP methods initialize, tools/list,
tools/call, resources/list, resources/read, ping and the
notifications/* family.
Tools are Tool instances. The built in tools from
McpUiTools expose the accessibility semantics tree so any application is
drivable without code; applications add domain tools with addTool(Tool).
The message dispatch is thread free and reentrant: handleMessage(String)
takes one request line and returns one response line (or null for a notification),
which makes it directly unit testable. start(MCPTransport) wraps that in a
reader thread over the transport.
Fields
public static final int PARSE_ERROR = -32700 | Standard JSON-RPC and MCP error codes. |
public static final int INVALID_REQUEST = -32600 | |
public static final int METHOD_NOT_FOUND = -32601 | |
public static final int INVALID_PARAMS = -32602 | |
public static final int INTERNAL_ERROR = -32603 | |
public static final int RESOURCE_NOT_FOUND = -32002 | |
public static final String DEFAULT_PROTOCOL_VERSION = "2024-11-05" | MCP protocol revision advertised when the client does not request one, or requests one this server does not implement. |
Constructors
public MCPServer() |
Methods
Inherited methods
Field details
PARSE_ERROR
public static final int PARSE_ERROR = -32700INVALID_REQUEST
public static final int INVALID_REQUEST = -32600METHOD_NOT_FOUND
public static final int METHOD_NOT_FOUND = -32601INVALID_PARAMS
public static final int INVALID_PARAMS = -32602INTERNAL_ERROR
public static final int INTERNAL_ERROR = -32603RESOURCE_NOT_FOUND
public static final int RESOURCE_NOT_FOUND = -32002DEFAULT_PROTOCOL_VERSION
public static final String DEFAULT_PROTOCOL_VERSION = "2024-11-05"Constructor details
MCPServer
public MCPServer()Method details
setVerbosity
public void setVerbosity(MCPVerbosity verbosity)MCPVerbosity.OFF.getVerbosity
public MCPVerbosity getVerbosity()addTool
public synchronized void addTool(Tool tool)removeTool
public synchronized void removeTool(String name)setServerInfo
public void setServerInfo(String name, String version)initialize.setScreenshotEnabled
public void setScreenshotEnabled(boolean screenshotEnabled)isRunning
public synchronized boolean isRunning()start
public synchronized void start(MCPTransport transport)stop
public synchronized void stop()handleMessage
public String handleMessage(String line)