The Cortex IDE MCP (Model Context Protocol) server allows external AI agents to interact with the running IDE. Any MCP-compatible client (Cursor, Claude Code, Windsurf, custom agents, etc.) can use it to take screenshots, inspect the DOM, execute JavaScript, control windows, and more.
flowchart LR
A[AI Agent] -->|stdio JSON-RPC| B[MCP Server]
B -->|TCP :4000| C[Cortex Desktop]
- Transport: stdio — the server reads JSON-RPC from stdin and writes responses to stdout
- Backend connection: TCP socket to
127.0.0.1:4000where Cortex Desktop listens - Protocol: Model Context Protocol via
@modelcontextprotocol/sdk - Validation: All tool parameters are validated at runtime with Zod schemas
| Tool | Version |
|---|---|
| Node.js | >= 24.x |
| npm | >= 10.x |
| Cortex Desktop | Running (the MCP server connects to it via TCP) |
cd mcp-server
npm installnpm run devnpm run build # Compile TypeScript → dist/
npm run start # Run compiled servernode dist/index.jsThe socket client can be configured via environment variables:
| Variable | Default | Description |
|---|---|---|
CORTEX_MCP_HOST |
127.0.0.1 |
Host where Cortex Desktop's MCP socket is listening |
CORTEX_MCP_PORT |
4000 |
Port for the socket connection |
Example:
CORTEX_MCP_HOST=127.0.0.1 CORTEX_MCP_PORT=4000 npm run startAdd to your Cursor MCP config (.cursor/mcp.json or global settings):
{
"mcpServers": {
"cortex-desktop": {
"command": "node",
"args": ["/path/to/cortex-ide/mcp-server/dist/index.js"]
}
}
}claude mcp add cortex-desktop node /path/to/cortex-ide/mcp-server/dist/index.jsAny MCP client that supports stdio transport can launch the server:
node /path/to/cortex-ide/mcp-server/dist/index.jsThe server communicates via stdin/stdout using JSON-RPC 2.0.
Test connectivity to Cortex Desktop.
Parameters: none
Capture a screenshot of the Cortex Desktop window.
| Parameter | Type | Default | Description |
|---|---|---|---|
windowLabel |
string | "main" |
Window to capture |
quality |
number (1-100) | 75 | JPEG quality (lower = smaller file) |
maxWidth |
number | - | Max width in pixels, resized proportionally |
Returns an image (base64 JPEG) and dimensions.
Get the HTML DOM content from Cortex Desktop.
| Parameter | Type | Default | Description |
|---|---|---|---|
windowLabel |
string | "main" |
Window to query |
selector |
string | - | CSS selector for a specific element |
Execute JavaScript code in the Cortex Desktop webview.
| Parameter | Type | Default | Description |
|---|---|---|---|
script |
string | required | JavaScript code to execute |
windowLabel |
string | "main" |
Target window |
Control Cortex Desktop windows.
| Parameter | Type | Default | Description |
|---|---|---|---|
operation |
string | required | minimize, maximize, unmaximize, close, show, hide, focus, center, setPosition, setSize, toggleFullscreen |
windowLabel |
string | "main" |
Target window |
x |
number | - | X position (for setPosition) |
y |
number | - | Y position (for setPosition) |
width |
number | - | Width (for setSize) |
height |
number | - | Height (for setSize) |
Simulate keyboard text input.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
string | required | Text to type |
delayMs |
number | 20 | Delay between keystrokes (ms) |
Simulate mouse actions.
| Parameter | Type | Default | Description |
|---|---|---|---|
action |
string | required | move, click, doubleClick, rightClick, scroll |
x |
number | - | X coordinate |
y |
number | - | Y coordinate |
scrollX |
number | - | Horizontal scroll amount |
scrollY |
number | - | Vertical scroll amount |
Manage localStorage in Cortex Desktop.
| Parameter | Type | Default | Description |
|---|---|---|---|
operation |
string | required | get, set, remove, clear, keys |
key |
string | - | Storage key |
value |
string | - | Value (for set) |
windowLabel |
string | "main" |
Target window |
Get the screen position and bounding rect of a DOM element.
| Parameter | Type | Default | Description |
|---|---|---|---|
selector |
string | required | CSS selector |
windowLabel |
string | "main" |
Target window |
Focus a DOM element and send text to it.
| Parameter | Type | Default | Description |
|---|---|---|---|
selector |
string | required | CSS selector |
text |
string | required | Text to send |
windowLabel |
string | "main" |
Target window |
List all open windows in Cortex Desktop.
Parameters: none
All tool outputs support truncation to stay within AI agent context limits. The default configuration:
| Setting | Default | Description |
|---|---|---|
enabled |
true |
Enable truncation |
maxLength |
2000 |
Maximum character length |
maxLines |
100 |
Maximum number of lines |
truncateMessage |
"... [truncated]" |
Appended when output is truncated |
Command-specific timeouts for the socket connection:
| Command | Timeout |
|---|---|
takeScreenshot |
60s |
getDom |
60s |
executeJs |
60s |
| Default | 30s |
The socket client will automatically attempt up to 3 reconnections if the connection drops.
mcp-server/
├── src/
│ ├── index.ts # MCP server setup, tool definitions, stdio transport
│ └── client.ts # CortexSocketClient — TCP socket connection to Cortex Desktop
├── dist/ # Compiled output (after npm run build)
├── package.json
└── tsconfig.json
- Never use
console.log— stdout is the MCP JSON-RPC transport. Useconsole.errorfor debug logging. - Server is stateless — all state lives in Cortex Desktop. The MCP server is a pass-through.
- All tool parameters must use Zod schemas for runtime validation.
- Respect truncation to prevent context overflow in AI agents.
- TypeScript strict mode is enforced.
- Define the tool in
registerTools()insrc/index.ts:
server.tool(
"my_tool_name",
"Description of what the tool does",
{
param1: z.string().describe("Parameter description"),
param2: z.number().optional().describe("Optional parameter"),
},
async (args) => {
const response = await socketClient.sendCommand("myCommand", {
param1: args.param1,
param2: args.param2,
});
if (!response.success) {
return {
content: [{ type: "text", text: `Error: ${response.error}` }],
isError: true,
};
}
return {
content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }],
};
}
);-
Ensure the corresponding command handler exists in Cortex Desktop's socket server (Rust backend).
-
Build and test:
npm run build
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | node dist/index.jsCortex Desktop is not running or the socket server is not listening on port 4000. Start Cortex Desktop first, then launch the MCP server.
The command-specific timeout was exceeded. For slow operations (screenshots, large DOM), the timeout is 60s. If Cortex Desktop is under heavy load, the response may take longer than expected.
The socket client is single-request — it processes one command at a time. If a previous command hasn't finished, the next one will be rejected. Wait for the pending request to complete.
Make sure the path in your agent config points to the compiled dist/index.js, not src/index.ts. Run npm run build first.