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

- Class
  Description
  MCP
  Public entry point for the Codename One MCP headless API.
  MCP.SocketTransportFactory
  Supplies the platform loopback socket transport.
  MCP.StdioTransportFactory
  Supplies the platform stdio transport.
  MCPClientDescriptor
  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.
  MCPClientRegistrar
  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, Codex and similar tools at the application without editing config by hand.
  MCPClientRegistrar.MCPClient
  A detected MCP host and where its config lives.
  MCPLoopbackSocketTransport
  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.
  MCPLoopbackSocketTransport.Connection
  The per-connection callback the socket API instantiates.
  MCPServer
  A Model Context Protocol server.
  MCPTransport
  A bidirectional line delimited transport for MCP JSON-RPC messages.
  MCPVerbosity
  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.