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() + "\"}";
            }
        }));

Types

class MCPPublic entry point for the Codename One MCP headless API.
class MCPClientDescriptorDescribes 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.
class MCPClientRegistrarDetects 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, Codex and similar tools at the application without editing config by hand.
class MCPLoopbackSocketTransportLoopback 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.
class MCPServerA Model Context Protocol server.
interface MCPTransportA bidirectional line delimited transport for MCP JSON-RPC messages.
enum MCPVerbosityHow 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.