### Install Dependencies and Build Project Source: https://github.com/domdomegg/computer-use-mcp/blob/master/README.md Steps to set up the development environment for the computer-use-mcp project, including installing dependencies and building the project. ```bash npm install npm run build ``` -------------------------------- ### Equivalent Manual Server Setup Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-all.md Provides the equivalent manual setup for creating a server and registering all tools, demonstrating what createServer() does internally. This involves instantiating McpServer and then calling registerAll(). ```typescript const server = new McpServer({ name: 'computer-use-mcp', version: '1.0.0', }); registerAll(server); ``` -------------------------------- ### Custom MCP Server Configuration with Computer Tool Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-computer.md Set up a custom MCP server that includes only the computer control tool and custom initialization logic. This example also includes transport setup and signal handling for graceful shutdown. ```typescript import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'; import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; import {registerComputer} from 'computer-use-mcp/tools'; async function setupCustomServer() { const server = new McpServer({ name: 'custom-computer-use', version: '2.0.0', }); // Register the computer tool registerComputer(server); // Set up transport const transport = new StdioServerTransport(); // Handle cleanup process.on('SIGINT', async () => { await server.close(); process.exit(0); }); // Connect await server.connect(transport); console.error('Custom server running'); } setupCustomServer().catch(console.error); ``` -------------------------------- ### Install MCP Server via Command Line Source: https://github.com/domdomegg/computer-use-mcp/blob/master/README.md Installs the computer-use-mcp server at the user scope, making it available in all projects. Omit `--scope user` for local installation only. ```bash claude mcp add --scope user --transport stdio computer-use -- npx -y computer-use-mcp ``` -------------------------------- ### Minimal Server Setup with STDIO Transport Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/INDEX.md Sets up a basic MCP server using the STDIO transport. Ensure the server and transport are connected. ```typescript import {createServer} from 'computer-use-mcp'; import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; const server = createServer(); const transport = new StdioServerTransport(); await server.connect(transport); ``` -------------------------------- ### Quick Navigation Example Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/00_START_HERE.md This table demonstrates how to navigate to different documentation sections based on user needs. It maps common tasks to their corresponding files. ```markdown What I need → Go to ───────────────────────────────────────────── Setup/installation → configuration.md API reference → INDEX.md → api-reference/ Function signature → api-reference/* Parameter documentation → api-reference/computer-tool.md Type definitions → types.md Error handling → errors.md Code examples → QUICK_REFERENCE.md All tools/actions → INDEX.md#registered-tools Keyboard keys → types.md#keyboard-key-mapping Environment variables → configuration.md#environment-variables Error reference → errors.md ``` -------------------------------- ### Example GetScreenshotResponse Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/types.md An example of the JSON response received from the get_screenshot action, showing content type, image dimensions, and base64 data. ```json { "content": [ { "type": "text", "text": "{\"image_width\": 1920, \"image_height\": 1080}" }, { "type": "image", "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAY...", "mimeType": "image/png" } ] } ``` -------------------------------- ### Configure MCP Server in Claude Desktop Source: https://github.com/domdomegg/computer-use-mcp/blob/master/README.md Adds the computer-use-mcp server configuration to Claude Desktop's JSON settings. Requires Node.js installation. ```json { "mcpServers": { "computer-use": { "command": "npx", "args": [ "-y", "computer-use-mcp" ] } } } ``` -------------------------------- ### Basic Computer Tool Registration Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-computer.md Register the computer tool with a new MCP server instance. Ensure the MCP server and the computer-use-mcp tools are installed. ```typescript import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'; import {registerComputer} from 'computer-use-mcp/tools'; const server = new McpServer({ name: 'my-mcp-server', version: '1.0.0', }); // Register the computer tool registerComputer(server); // Now the server has the 'computer' tool available ``` -------------------------------- ### HTTP Transport Setup for MCP Server Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/create-server.md Illustrates setting up an MCP server with HTTP transport using Express. It's recommended to create a fresh server instance per request for stateless communication. ```typescript import express from 'express'; import {StreamableHTTPServerTransport} from '@modelcontextprotocol/sdk/server/streamableHttp.js'; import {createServer} from 'computer-use-mcp'; const app = express(); app.use(express.json()); app.post('/mcp', async (req, res) => { const server = createServer(); const httpTransport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true, }); res.on('close', () => { void server.close(); }); await server.connect(httpTransport); await httpTransport.handleRequest(req, res, req.body); }); const port = process.env.PORT || 3000; app.listen(port, () => { console.log(`MCP server running on http://localhost:${port}/mcp`); }); ``` -------------------------------- ### Take a Screenshot Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/QUICK_REFERENCE.md Action to capture the current screen. Use this to get visual information from the user's computer. ```typescript {action: 'get_screenshot'} ``` -------------------------------- ### Configure MCP Server in Claude Desktop Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/QUICK_REFERENCE.md Example JSON configuration for adding the computer-use-mcp server to Claude Desktop's configuration file. This allows Claude Desktop to manage the server. ```json # Claude Desktop JSON # Add to claude_desktop_config.json: # { # "mcpServers": { # "computer-use": {"command": "npx", "args": ["-y", "computer-use-mcp"]} # } # } ``` -------------------------------- ### Registering Computer Tool with Multiple Tools Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-computer.md Register the computer tool alongside other tools in an MCP server. This example shows registering the computer tool and then another custom tool. ```typescript import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'; import {registerComputer} from 'computer-use-mcp/tools'; const server = new McpServer({ name: 'multi-tool-server', version: '1.0.0', }); // Register computer control registerComputer(server); // Register other tools server.registerTool('other-tool', {...}); // Connect and run const transport = new StdioServerTransport(); await server.connect(transport); ``` -------------------------------- ### HTTP Server Setup with StreamableHTTPServerTransport Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/INDEX.md Configures an Express.js server to handle MCP requests over HTTP using the StreamableHTTPServerTransport. This setup enables JSON responses. ```typescript import express from 'express'; import {createServer} from 'computer-use-mcp'; import {StreamableHTTPServerTransport} from '@modelcontextprotocol/sdk/server/streamableHttp.js'; const app = express(); app.use(express.json()); app.post('/mcp', async (req, res) => { const server = createServer(); const httpTransport = new StreamableHTTPServerTransport({ enableJsonResponse: true, }); await server.connect(httpTransport); await httpTransport.handleRequest(req, res, req.body); }); app.listen(3000); ``` -------------------------------- ### Claude CLI Add Project Scope Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Install the computer-use-mcp for the project scope using the Claude CLI. This makes the MCP available only within the current project. ```bash claude mcp add --transport stdio computer-use -- npx -y computer-use-mcp ``` -------------------------------- ### Programmatic Server Creation Error Handling Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/errors.md Use a try-catch block to handle potential errors during server setup and connection. This ensures graceful failure and provides informative error messages. ```typescript import {createServer} from 'computer-use-mcp'; import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; async function setup() { try { const server = createServer(); const transport = new StdioServerTransport(); await server.connect(transport); } catch (error) { if (error instanceof Error) { console.error(`Setup failed: ${error.message}`); } process.exit(1); } } ``` -------------------------------- ### Perform Common Tool Actions Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/00_START_HERE.md Examples of performing various tool actions, including clicking at coordinates, typing text, and capturing a screenshot. These actions are part of the computer-use-mcp toolset. ```typescript // Click at coordinates {action: 'left_click', coordinate: [640, 360]} ``` ```typescript // Type text {action: 'type', text: 'Hello World'} ``` ```typescript // Take screenshot {action: 'get_screenshot'} ``` -------------------------------- ### HTTP Server Pattern with Express and MCP Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/QUICK_REFERENCE.md Sets up an Express.js HTTP server to handle MCP requests using the StreamableHTTPServerTransport. Ensure express and the SDK are installed. ```typescript import express from 'express'; import {createServer} from 'computer-use-mcp'; import {StreamableHTTPServerTransport} from '@modelcontextprotocol/sdk/server/streamableHttp.js'; const app = express(); app.use(express.json()); app.post('/mcp', async (req, res) => { const server = createServer(); const transport = new StreamableHTTPServerTransport({enableJsonResponse: true}); await server.connect(transport); await transport.handleRequest(req, res, req.body); }); app.listen(3000); ``` -------------------------------- ### Computer Tool Actions Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/INDEX.md Examples of various actions that can be performed using the computer tool, including mouse clicks, typing, keyboard shortcuts, and taking screenshots. ```typescript // Click a button { action: 'left_click', coordinate: [640, 360] } // Type text { action: 'type', text: 'Hello, World!' } // Press keyboard shortcut { action: 'key', text: 'Control_L+s' } // Take screenshot { action: 'get_screenshot' } ``` -------------------------------- ### Dockerfile for Computer Use MCP Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md A Dockerfile to build an image for the computer-use-mcp. It installs the package globally and sets environment variables for HTTP transport and port exposure. ```dockerfile FROM node:20-alpine WORKDIR /app RUN npm install -g computer-use-mcp # For X11 display forwarding on Linux ENV DISPLAY=:1 # Use HTTP transport for container deployment ENV MCP_TRANSPORT=http ENV PORT=3000 EXPOSE 3000 CMD ["computer-use-mcp"] ``` -------------------------------- ### Common Keyboard Key Combinations Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/QUICK_REFERENCE.md Examples of common keyboard shortcuts and their corresponding key names used in the 'key' action. Note the use of '_L' for Left modifier keys and platform-specific keys like 'Command' for macOS. ```bash Control_L+a # Ctrl+A Alt_L+Tab # Alt+Tab Shift_L+F5 # Shift+F5 Command+s # Cmd+S (macOS) ``` -------------------------------- ### Send JSON-RPC Request via HTTP Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Example of sending a JSON-RPC request to the computer-use-mcp service using cURL over HTTP. Each request creates a new server instance. ```bash curl -X POST http://localhost:3000/mcp \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}' ``` -------------------------------- ### Check for xdotool Availability on Linux Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Verify if the xdotool utility is installed on Linux, which is preferred for text input as it respects keyboard layouts. The server uses it automatically if available, falling back to nut-js otherwise. ```bash # Check if xdotool is available which xdotool ``` -------------------------------- ### Extra Fields Provided Error Example Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/errors.md Shows an error resulting from extra fields being provided in the input. The schema is strict and does not allow unrecognized keys. ```typescript { action: 'left_click', coordinate: [100, 100], extra_field: 'value' } // Zod error: Unrecognized key(s) in object: 'extra_field' ``` -------------------------------- ### Get Screenshot Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md Capture the entire screen and return the image with a cursor overlay. The image is downsampled to fit API limits and includes actual dimensions for coordinate mapping. A 1-second delay is included before capture. ```typescript // Capture current screen state { action: 'get_screenshot' } // Response structure { "content": [ { "type": "text", "text": "{\"image_width\": 1920, \"image_height\": 1080}" }, { "type": "image", "data": "iVBORw0KGgoAAAANSUhEUgAAAAEA...", "mimeType": "image/png" } ] } ``` -------------------------------- ### Handle Case Insensitivity and Whitespace in Key Conversion Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/to-keys.md Illustrates the toKeys() function's ability to handle case-insensitive input and trim whitespace from key strings when converting xdotool format to nut-js Key enum arrays. All provided examples are equivalent. ```typescript // All equivalent toKeys('return'); // [Key.Return] toKeys('Return'); // [Key.Return] toKeys('RETURN'); // [Key.Return] // Whitespace handling toKeys('Control_L + a'); // [Key.LeftControl, Key.A] toKeys(' Return '); // [Key.Return] toKeys('Shift_L + Page_Down '); // [Key.LeftShift, Key.PageDown] ``` -------------------------------- ### Recommended Server Creation using createServer() Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-all.md Illustrates the recommended method for creating a server with all tools registered by calling createServer() from 'computer-use-mcp'. This function internally calls registerAll(). ```typescript import {createServer} from 'computer-use-mcp'; // This calls registerAll() internally const server = createServer(); const transport = new StdioServerTransport(); await server.connect(transport); ``` -------------------------------- ### Basic Server Creation with Stdio Transport Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/create-server.md Demonstrates how to create a server instance and connect it using the Stdio transport. This is suitable for CLI applications. ```typescript import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; import {createServer} from 'computer-use-mcp'; const server = createServer(); const stdioTransport = new StdioServerTransport(); await server.connect(stdioTransport); console.log('Server running on stdio'); ``` -------------------------------- ### Basic Registration of All Tools Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-all.md Demonstrates how to import and use registerAll() to add all available tools to an McpServer instance. Ensure McpServer is imported from '@modelcontextprotocol/sdk/server/mcp.js' and registerAll from 'computer-use-mcp/tools'. ```typescript import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'; import {registerAll} from 'computer-use-mcp/tools'; const server = new McpServer({ name: 'my-server', version: '1.0.0', }); // Register all tools registerAll(server); // Server now has all available tools ``` -------------------------------- ### Create and Connect a Server Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/00_START_HERE.md Initializes and connects a server instance using the createServer function and a StdioServerTransport. Ensure the necessary imports are included. ```typescript import {createServer} from 'computer-use-mcp'; import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; const server = createServer(); await server.connect(new StdioServerTransport()); ``` -------------------------------- ### Get Cursor Position Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/QUICK_REFERENCE.md Action to retrieve the current X and Y coordinates of the mouse cursor. ```typescript {action: 'get_cursor_position'} ``` -------------------------------- ### Register All Tools with Transport Connection Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-all.md Shows how to register all tools and then connect the McpServer to a transport, such as StdioServerTransport. This is useful for setting up a server that can communicate over standard input/output. ```typescript import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'; import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; import {registerAll} from 'computer-use-mcp/tools'; async function main() { const server = new McpServer({ name: 'tool-server', version: '1.0.0', }); registerAll(server); const transport = new StdioServerTransport(); await server.connect(transport); console.error('Tools registered and connected'); } main().catch(console.error); ``` -------------------------------- ### createServer() Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/create-server.md Initializes and returns a new MCP server instance. This server comes with the 'computer' tool pre-registered, enabling computer control functionalities. The server is transport-agnostic and can be connected to stdio or HTTP transports. ```APIDOC ## createServer() ### Description Creates and configures a new MCP server instance with computer control capabilities. This is the primary export from the computer-use-mcp library, registering the 'computer' tool for full action support. The returned server can be connected to stdio or HTTP transports. ### Signature ```typescript function createServer(): McpServer ``` ### Returns - **Type**: `McpServer` - **Properties**: `name: 'computer-use-mcp'`, `version: '1.0.0'` - **Pre-configured Tools**: `computer` tool automatically registered ### Server Configuration - **Name**: `computer-use-mcp` - **Version**: `1.0.0` - **Registered Tools**: `computer` ### Tool Registration Automatically registers the `computer` tool with the following action types: - `get_screenshot` - `key` - `type` - `mouse_move` - `left_click` - `left_click_drag` - `right_click` - `middle_click` - `double_click` - `scroll` - `get_cursor_position` ### Transport Considerations Supports **Stdio** (default) and **HTTP** transports. For HTTP, a fresh server instance should be created per request. ``` -------------------------------- ### Coordinate Not Array of 2 Numbers Error Example Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/errors.md Illustrates an error where the coordinate is not an array of two numbers. The coordinate must be a tuple of two numbers. ```typescript { action: 'left_click', coordinate: 100 // Should be [number, number] } // Zod error: Expected array of length 2 ``` -------------------------------- ### Get Cursor Position Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md Retrieve the current cursor position in API image coordinates. The coordinates are scaled for the vision model, with (0,0) at the top-left corner. ```typescript // Query cursor location { action: 'get_cursor_position' } // Response { "x": 640, "y": 360 } ``` -------------------------------- ### registerAll() Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-all.md Registers all available tools with the MCP server. This function is called automatically by createServer(), so most users do not need to call it directly. ```APIDOC ## registerAll(server: McpServer) ### Description Registers all available tools provided by the computer-use-mcp library with the given MCP server. This function is called automatically by `createServer()`, so most users do not need to call it directly. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method N/A (SDK Function) ### Endpoint N/A (SDK Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **server** (`McpServer`) - Required - MCP server instance to register tools with (from @modelcontextprotocol/sdk/server/mcp.js) ### Return Value `void` - The function registers tools as a side effect and returns nothing. ### Tools Registered Currently registers: - `computer` (11 action types) - Mouse, keyboard, and screenshot control ### Usage Examples #### Basic Registration ```typescript import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'; import {registerAll} from 'computer-use-mcp/tools'; const server = new McpServer({ name: 'my-server', version: '1.0.0', }); // Register all tools registerAll(server); // Server now has all available tools ``` #### With Transport Connection ```typescript import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'; import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; import {registerAll} from 'computer-use-mcp/tools'; async function main() { const server = new McpServer({ name: 'tool-server', version: '1.0.0', }); registerAll(server); const transport = new StdioServerTransport(); await server.connect(transport); console.error('Tools registered and connected'); } main().catch(console.error); ``` ``` -------------------------------- ### Create MCP Server Instance Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-computer.md This function initializes and configures an MCP server instance. It automatically registers all computer-related functionalities. ```typescript export function createServer(): McpServer { const server = new McpServer({ name: 'computer-use-mcp', version: '1.0.0', }); registerAll(server); // Calls registerComputer internally return server; } ``` -------------------------------- ### Configure MCP Server in Cursor Source: https://github.com/domdomegg/computer-use-mcp/blob/master/README.md Sets up the computer-use-mcp server configuration for Cursor, either globally or per project. This can be done via a JSON configuration file. ```json { "mcpServers": { "computer-use": { "command": "npx", "args": ["-y", "computer-use-mcp"] } } } ``` -------------------------------- ### Invalid Action Value Error Example Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/errors.md Demonstrates an invalid action value error during Zod schema validation. Ensure the action value is one of the allowed enum values. ```typescript { action: 'unknown_action', coordinate: [100, 100] } // Zod error: Invalid enum value ``` -------------------------------- ### Graceful Server Shutdown Handling Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/create-server.md Shows how to implement graceful shutdown for the MCP server by listening for termination signals (SIGINT, SIGTERM) and closing the server before exiting. ```typescript import {createServer} from 'computer-use-mcp'; const server = createServer(); const stdioTransport = new StdioServerTransport(); await server.connect(stdioTransport); // Handle termination signals process.on('SIGINT', async () => { await server.close(); process.exit(0); }); process.on('SIGTERM', async () => { await server.close(); process.exit(0); }); ``` -------------------------------- ### Registering the Computer Tool Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md This snippet shows how to register the 'computer' tool with the MCP server, defining its capabilities and input schema. ```typescript server.registerTool( 'computer', { title: 'Computer Control', description: string, inputSchema: { action: 'key' | 'type' | 'mouse_move' | 'left_click' | 'left_click_drag' | 'right_click' | 'middle_click' | 'double_click' | 'scroll' | 'get_screenshot' | 'get_cursor_position', coordinate?: [number, number], text?: string }, annotations: { readOnlyHint: false } }, async (args) => CallToolResult ) ``` -------------------------------- ### Internal registerAll() Implementation Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-all.md Shows the internal structure of the registerAll() function, highlighting that it calls registerComputer() and is designed for future extensibility by allowing additional tools to be registered. ```typescript function registerAll(server: McpServer): void { registerComputer(server); } // Future addition // function registerAll(server: McpServer): void { // registerComputer(server); // registerNewTool(server); // registerAnotherTool(server); // } ``` -------------------------------- ### Run Docker Container with X11 Forwarding Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Execute a Docker container for computer-use-mcp with X11 display forwarding enabled on Linux. This mounts the X11 socket and forwards the display. ```bash docker run -it \ -e DISPLAY=:1 \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -p 3000:3000 \ computer-use-mcp ``` -------------------------------- ### MCP Environment Variables Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/QUICK_REFERENCE.md Configure the MCP transport mechanism and display settings using environment variables. ```bash MCP_TRANSPORT=stdio # Default transport ``` ```bash MCP_TRANSPORT=http # HTTP transport ``` ```bash PORT=3000 # HTTP port (default) ``` ```bash DISPLAY=:1 # X11 display (Linux) ``` -------------------------------- ### Parsing Key Names with Error Handling Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/INDEX.md Demonstrates how to parse key combinations into their respective enum values using `toKeys`. Includes error handling for invalid key names. ```typescript import {toKeys, InvalidKeyError} from 'computer-use-mcp'; try { const keys = toKeys('Control_L+Alt_L+Delete'); // keys = [Key.LeftControl, Key.LeftAlt, Key.Delete] } catch (e) { if (e instanceof InvalidKeyError) { console.error(`Bad key: ${e.message}`); } } ``` -------------------------------- ### Run MCP with HTTP Transport and Custom Port Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Launches the computer-use-mcp application using the HTTP transport on a specified port. This is suitable for web service deployment. ```bash export MCP_TRANSPORT=http export PORT=8080 npx computer-use-mcp ``` -------------------------------- ### Deploy MCP Server with Claude CLI Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/QUICK_REFERENCE.md Deploys the computer-use-mcp server using the Claude CLI with stdio transport. This command allows for quick deployment and integration with Claude. ```bash # Claude Code claude mcp add --scope user --transport stdio computer-use -- npx -y computer-use-mcp ``` -------------------------------- ### Correcting MCP Action and Text Input Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/QUICK_REFERENCE.md Demonstrates the correct format for sending key actions with text, ensuring required fields are present. ```typescript // ❌ Wrong: missing required text {action: 'key'} // ✅ Right {action: 'key', text: 'Control_L+a'} ``` -------------------------------- ### type Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md Type text into the active input field. This action uses xdotool on Linux to respect keyboard layout, and nut-js on other platforms. ```APIDOC ## type ### Description Type text into the active input field. ### Parameters #### Path Parameters - `text` (string) - Required - String to type, e.g., `"Hello World"`, `"user@example.com"` ### Response #### Success Response (200) - `ok` (boolean) - Indicates success. ### Response Example ```json { "ok": true } ``` ``` -------------------------------- ### Set Linux DISPLAY Variable Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Configure the DISPLAY environment variable for Linux to specify the X11 display server for GUI automation. Common values include default (:0) or network displays. ```bash # Default (first display) export DISPLAY=:0 ``` ```bash # Second display export DISPLAY=:1 ``` ```bash # Network display export DISPLAY=192.168.1.100:0 ``` -------------------------------- ### Configure MCP Transport Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Set the MCP_TRANSPORT environment variable to choose the communication mechanism. Use 'stdio' for default or 'http' for HTTP transport. ```bash # Use stdio (default, omit if not needed) export MCP_TRANSPORT=stdio ``` ```bash # Use HTTP export MCP_TRANSPORT=http ``` ```bash # Invalid value produces error export MCP_TRANSPORT=websocket # Error: Unknown transport: websocket. Use MCP_TRANSPORT=stdio or MCP_TRANSPORT=http ``` -------------------------------- ### get_screenshot Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md Captures the entire screen and returns the image with an overlay of the cursor's position. The image is downsampled to fit API limits and includes actual image dimensions for coordinate mapping. ```APIDOC ## get_screenshot ### Description Captures the entire screen and returns the image with cursor overlay. ### Parameters None ### Response #### Success Response (200) - `content` (array) - An array containing text and image data. - `type` (string) - Type of content, e.g., "text" or "image". - `text` (string) - JSON string with image dimensions (`image_width`, `image_height`). - `data` (string) - Base64-encoded PNG image data. - `mimeType` (string) - MIME type of the image, e.g., "image/png". ### Request Example ```json { "action": "get_screenshot" } ``` ``` -------------------------------- ### Set Server Port via Environment Variable Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Configure the TCP port for the HTTP server to listen on by setting the PORT environment variable. This is applicable only to the HTTP transport. ```bash # Listen on port 8080 PORT=8080 MCP_TRANSPORT=http npx computer-use-mcp ``` -------------------------------- ### Run MCP with Stdio Transport Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Launches the computer-use-mcp application using the stdio transport. This is ideal for CLI applications and development. ```bash MCP_TRANSPORT=stdio npx computer-use-mcp ``` -------------------------------- ### Correcting MCP Action and Coordinate Input Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/QUICK_REFERENCE.md Illustrates the correct way to specify click actions with coordinates, avoiding invalid actions and out-of-bounds values. ```typescript // ❌ Wrong: invalid action {action: 'click_button'} // ✅ Right {action: 'left_click', coordinate: [100, 100]} // ❌ Wrong: out of bounds coordinates {action: 'left_click', coordinate: [9999, 9999]} // ✅ Right: coordinates within screen bounds {action: 'left_click', coordinate: [960, 540]} ``` -------------------------------- ### Set HTTP Transport Environment Variables Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Configures the MCP transport to use HTTP and optionally sets the port. The default port is 3000. ```bash export MCP_TRANSPORT=http export PORT=3000 # Optional, defaults to 3000 ``` -------------------------------- ### registerComputer() Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-computer.md Registers the computer tool with an MCP server instance. This function is typically called automatically but can be used for advanced scenarios to add the tool to a pre-existing MCP server. ```APIDOC ## registerComputer() ### Description Registers the `computer` tool with the provided MCP server. This function is called automatically by `createServer()`, so most users do not need to call it directly. However, it is exported for advanced use cases where you want to add the computer control tool to a pre-existing MCP server instance. ### Signature ```typescript export function registerComputer(server: McpServer): void ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **server** (`McpServer`) - Required - MCP server instance to register the tool with (from @modelcontextprotocol/sdk/server/mcp.js) ### Return Value `void` — The function registers the tool as a side effect and returns nothing. ### Tool Registration Details - **Name**: `computer` - **Title**: `Computer Control` - **Input Schema**: Zod-validated schema with `action`, `coordinate`, `text` fields - **Output Schema**: None (varies by action type) - **Read-Only Hint**: `false` ### Input Schema ```json { "action": "key" | "type" | "mouse_move" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "scroll" | "get_screenshot" | "get_cursor_position", "coordinate"?: [number, number], "text"?: string } ``` **Validation Rules:** - `action` is required and must be one of the 11 supported action types - `coordinate` is optional, [number, number] array (validated as exactly 2 elements) - `text` is optional string - Strict validation enabled (no extra fields allowed) ``` -------------------------------- ### Convert Key Combinations to nut-js Key Enum Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/to-keys.md Shows how to convert key combinations, including modifiers like Control, Shift, and Alt, along with other keys, from xdotool format to nut-js Key enum arrays. Supports multi-key combinations. ```typescript // Ctrl+A toKeys('Control_L+a'); // [Key.LeftControl, Key.A] // Shift+Return toKeys('Shift_L+Return'); // [Key.LeftShift, Key.Return] // Alt+Tab toKeys('Alt_L+Tab'); // [Key.LeftAlt, Key.Tab] // Multi-key combinations toKeys('Control_L+Alt_L+Delete'); // [Key.LeftControl, Key.LeftAlt, Key.Delete] toKeys('Shift_L+F5'); // [Key.LeftShift, Key.F5] ``` -------------------------------- ### Convert Key String to Key Objects Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/to-keys.md This snippet demonstrates how the `toKeys` function is used internally by the computer tool. It takes a string like 'Control_L+a' and converts it into an array of Key objects, which are then used to simulate key presses and releases. ```typescript // Example: User requests "Press Ctrl+A" { action: 'key', text: 'Control_L+a' } // Internally: const keys = toKeys('Control_L+a'); // [Key.LeftControl, Key.A] await keyboard.pressKey(...keys); await keyboard.releaseKey(...keys); ``` -------------------------------- ### Press Keyboard Key Combination Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/QUICK_REFERENCE.md Action to simulate pressing a keyboard key or combination. Use key names like 'Control_L', 'Alt_L', 'Shift_L', 'Command', and standard characters. ```typescript {action: 'key', text: 'Control_L+s'} ``` -------------------------------- ### Convert Single Keys to nut-js Key Enum Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/to-keys.md Demonstrates converting various single keys like function keys, navigation keys, letters, numbers, and special keys from xdotool format to nut-js Key enum values. Input is case-insensitive. ```typescript import {toKeys} from 'computer-use-mcp'; // Function keys toKeys('F1'); // [Key.F1] toKeys('F12'); // [Key.F12] // Navigation toKeys('Home'); // [Key.Home] toKeys('End'); // [Key.End] toKeys('Page_Down'); // [Key.PageDown] // Letters (case insensitive) toKeys('a'); // [Key.A] toKeys('A'); // [Key.A] toKeys('RETURN'); // [Key.Return] toKeys('Return'); // [Key.Return] // Numbers toKeys('0'); // [Key.Num0] toKeys('9'); // [Key.Num9] // Special keys toKeys('Space'); // [Key.Space] toKeys('Tab'); // [Key.Tab] toKeys('Delete'); // [Key.Delete] ``` -------------------------------- ### toKeys() Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/to-keys.md Converts an xdotool key string into an array of nut-js Key enum values. This function is useful for translating key inputs from external tools or configurations into a format compatible with the nut-js library. ```APIDOC ## toKeys() ### Description Converts xdotool key string format to nut-js Key enum array. Handles key combinations separated by `+` and supports case-insensitive input with whitespace trimming. ### Signature ```typescript export const toKeys = (xdotoolString: string): Key[] ``` ### Parameters #### Path Parameters - **xdotoolString** (string) - Required - Key specification in xdotool format, e.g., `"Control_L+a"`, `"Return"`, `"Shift_L+Page_Down"` ### Returns #### Success Response - **Type**: `Key[]` - **Content**: Array of nut-js Key enum values corresponding to parsed keys. - **Order**: Keys appear in same order as input string. - **Length**: 1 (single key) to N (key combination with modifiers). ### Usage Examples #### Single Keys ```typescript import {toKeys} from 'computer-use-mcp'; // Function keys toKeys('F1'); // [Key.F1] toKeys('F12'); // [Key.F12] // Navigation toKeys('Home'); // [Key.Home] toKeys('End'); // [Key.End] toKeys('Page_Down'); // [Key.PageDown] // Letters (case insensitive) toKeys('a'); // [Key.A] toKeys('A'); // [Key.A] toKeys('RETURN'); // [Key.Return] toKeys('Return'); // [Key.Return] // Numbers toKeys('0'); // [Key.Num0] toKeys('9'); // [Key.Num9] // Special keys toKeys('Space'); // [Key.Space] toKeys('Tab'); // [Key.Tab] toKeys('Delete'); // [Key.Delete] ``` #### Key Combinations ```typescript // Ctrl+A toKeys('Control_L+a'); // [Key.LeftControl, Key.A] // Shift+Return toKeys('Shift_L+Return'); // [Key.LeftShift, Key.Return] // Alt+Tab toKeys('Alt_L+Tab'); // [Key.LeftAlt, Key.Tab] // Multi-key combinations toKeys('Control_L+Alt_L+Delete'); // [Key.LeftControl, Key.LeftAlt, Key.Delete] toKeys('Shift_L+F5'); // [Key.LeftShift, Key.F5] ``` #### Case Insensitivity and Whitespace ```typescript // All equivalent toKeys('return'); // [Key.Return] toKeys('Return'); // [Key.Return] toKeys('RETURN'); // [Key.Return] // Whitespace handling toKeys('Control_L + a'); // [Key.LeftControl, Key.A] toKeys(' Return '); // [Key.Return] toKeys('Shift_L + Page_Down '); // [Key.LeftShift, Key.PageDown] ``` ``` -------------------------------- ### key Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md Press and release a keyboard key or key combination. Supports a wide range of keys including function keys, navigation keys, modifiers, and media keys. ```APIDOC ## key ### Description Press and release a keyboard key or key combination. ### Parameters #### Path Parameters - `text` (string) - Required - Key name or combination, e.g., `"Return"`, `"Control_L+a"`, `"shift_l+f5"` ### Response #### Success Response (200) - `ok` (boolean) - Indicates success. ### Response Example ```json { "ok": true } ``` ``` -------------------------------- ### Register Computer Tool Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/register-computer.md Registers the 'computer' tool with an MCP server instance. This function is usually called automatically by createServer() but can be used for advanced use cases. ```typescript export function registerComputer(server: McpServer): void ``` -------------------------------- ### Configure Keyboard Auto-Delay Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Set the auto-delay for keyboard actions to 10ms. A lower delay than the mouse is suitable for rapid typing and form filling. ```typescript keyboard.config.autoDelayMs = 10; ``` -------------------------------- ### Configure Mouse Auto-Delay and Speed Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Set the auto-delay for mouse actions to 100ms and mouse movement speed to 1000 pixels per second. This ensures UI responsiveness and allows for smoother cursor movement. ```typescript mouse.config.autoDelayMs = 100; mouse.config.mouseSpeed = 1000; ``` -------------------------------- ### McpServer Class Definition Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/types.md Represents an MCP server instance. Use to register tools and manage server connections. Requires name and version during instantiation. ```typescript class McpServer { constructor(options: {name: string; version: string}) registerTool(name: string, definition: ToolDefinition, handler: ToolHandler): void connect(transport: ServerTransport): Promise close(): Promise } ``` -------------------------------- ### right_click Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md Click the right mouse button. Optionally moves the cursor to specified coordinates before clicking, typically to trigger a context menu. ```APIDOC ## right_click ### Description Click the right mouse button, optionally at specified coordinates. ### Parameters #### Path Parameters - `coordinate` (array) - Optional - [x, y] in API image space ### Response #### Success Response (200) - `ok` (boolean) - Indicates success. ### Response Example ```json { "ok": true } ``` ``` -------------------------------- ### Computer Tool Operations Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md The computer tool provides a unified interface for various computer input and output actions, including keyboard input, mouse control, and screen capture. ```APIDOC ## Computer Tool Operations ### Description This tool allows for direct control over computer input and output actions. It supports keyboard simulation, mouse movements and clicks, scrolling, and capturing screenshots. ### Method `server.registerTool` (internal registration, exposed as a tool) ### Parameters #### Input Schema - **action** (string) - Required - The action to perform on the system. Possible values: `'key' | 'type' | 'mouse_move' | 'left_click' | 'left_click_drag' | 'right_click' | 'middle_click' | 'double_click' | 'scroll' | 'get_screenshot' | 'get_cursor_position'` - **coordinate** (array of numbers) - Conditional - X and Y pixel coordinates. Required for: `mouse_move`, `left_click_drag`, `scroll`. Optional for: `left_click`, `right_click`, `middle_click`, `double_click`. In API image space (pre-scaled). - **text** (string) - Conditional - Text to type or key command to execute. Required for: `key`, `type`, `scroll`. Format: comma-separated for multiple keys (e.g., `"Control_L+a"` for Ctrl+A). For scroll, format as `"direction[:amount]"` (e.g., `"down:500"`). ### Request Example ```json { "action": "type", "text": "Hello, world!" } ``` ```json { "action": "mouse_move", "coordinate": [100, 200] } ``` ```json { "action": "scroll", "text": "down:500" } ``` ### Response #### Success Response - **CallToolResult** (object) - The result of the tool call. Specifics depend on the action performed. #### Response Example (for get_screenshot) ```json { "screenshot": "base64_encoded_image_string" } ``` ``` -------------------------------- ### Press Keyboard Key Combination Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md Use this action to simulate pressing and releasing a keyboard key or a combination of keys. Supported keys include function keys, navigation keys, editing keys, modifiers, keypad keys, punctuation, and media keys. ```typescript // Open a file dialog { action: 'key', text: 'Control_L+o' } ``` ```typescript // Navigate with arrow keys { action: 'key', text: 'Right' } ``` -------------------------------- ### left_click Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md Click the left mouse button. Optionally moves the cursor to specified coordinates before clicking. ```APIDOC ## left_click ### Description Click the left mouse button, optionally at specified coordinates. ### Parameters #### Path Parameters - `coordinate` (array) - Optional - [x, y] in API image space. If provided, moves to position first. ### Response #### Success Response (200) - `ok` (boolean) - Indicates success. ### Response Example ```json { "ok": true } ``` ``` -------------------------------- ### Set Stdio Transport Environment Variable Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/configuration.md Configures the MCP transport to use stdio. This is the default behavior and can be omitted. ```bash export MCP_TRANSPORT=stdio ``` -------------------------------- ### Type Text into Input Field Source: https://github.com/domdomegg/computer-use-mcp/blob/master/_autodocs/api-reference/computer-tool.md Use this action to type a string into the currently active input field. On Linux, it respects the system's keyboard layout using xdotool. On other platforms, it uses nut-js. Special characters are sent as literal keystrokes. ```typescript // Type a password { action: 'type', text: 'MySecurePassword123' } ``` ```typescript // Type an email address { action: 'type', text: 'user@example.com' } ```