Package com.codename1.mcp
package com.codename1.mcp
Model Context Protocol (MCP) headless API for Codename One applications.
This package lets any Codename One application expose itself to an LLM agent (Claude Desktop/Code, Codex, opencode, and other MCP hosts) so the agent can read the current screen, drive the user interface, and invoke domain specific tools the application publishes. It is supported on desktop style targets that own a standard input/output stream: the JavaSE port and ParparVM native desktop builds.
The server is intentionally thin. It reuses the portable accessibility semantics
tree from com.codename1.ui.accessibility for automatic user interface
driving and the Tool contract for developer defined
tools, so no new tool abstraction is introduced.
Getting started
// From the application init/start, or via the desktop launcher --mcp-stdio flag:
MCP.startStdioServer();
// Publish an application specific tool:
MCP.addTool(new Tool("current_user", "Returns the signed in user",
"{\"type\":\"object\",\"properties\":{}}",
new ToolHandler() {
public String invoke(String argumentsJson) {
return "{\"name\":\"" + session.getUser().getName() + "\"}";
}
}));
-
ClassDescriptionPublic entry point for the Codename One MCP headless API.Supplies the platform loopback socket transport.Supplies the platform stdio transport.Describes the MCP server entry to register with a host: the stable server name it appears under and the command line that launches the application in stdio MCP mode.Detects installed MCP hosts and registers a Codename One application's stdio MCP server with them, so an end user can point Claude Desktop, Claude Code and similar tools at the application without editing config by hand.A detected MCP host and where its config lives.A Model Context Protocol server.A bidirectional line delimited transport for MCP JSON-RPC messages.How much of the MCP conversation the server echoes to the Codename One log, so a developer can watch and debug what an agent is doing.