@cursormesh/mcp-bridge 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -2
- package/dist/hub.js +203 -0
- package/dist/index.js +257 -0
- package/dist/token.js +23 -0
- package/package.json +48 -4
package/README.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cursormesh/mcp-bridge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Local **Model Context Protocol (MCP)** bridge for the [CursorMesh](https://cursormesh.app/) Chrome extension.
|
|
4
|
+
|
|
5
|
+
Connect **Antigravity, Claude Code, Claude Desktop, Cursor, Windsurf, or Codex** to your real Google Chrome browser with visible multiplayer AI cursors, automatic Chrome Tab Groups, non-intrusive background execution, domain allowlist/denylist rules, and an instant `Alt+Shift+X` STOP kill switch.
|
|
6
|
+
|
|
7
|
+
## Quick Setup
|
|
8
|
+
|
|
9
|
+
1. Install the **CursorMesh** Chrome extension from [cursormesh.app](https://cursormesh.app/).
|
|
10
|
+
2. Add CursorMesh to your MCP client configuration (`mcp_config.json`):
|
|
11
|
+
|
|
12
|
+
### macOS / Linux
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"cursormesh": {
|
|
17
|
+
"command": "npx",
|
|
18
|
+
"args": ["-y", "@cursormesh/mcp-bridge", "--agent-name", "Antigravity", "--agent-color", "#FF2E88"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Windows
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"mcpServers": {
|
|
28
|
+
"cursormesh": {
|
|
29
|
+
"command": "cmd",
|
|
30
|
+
"args": ["/c", "npx", "-y", "@cursormesh/mcp-bridge", "--agent-name", "Antigravity", "--agent-color", "#FF2E88"]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
3. Print your local pairing token and paste it in the CursorMesh Chrome extension (MCP tab):
|
|
37
|
+
```bash
|
|
38
|
+
npx -y @cursormesh/mcp-bridge --print-token
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Security
|
|
42
|
+
- Listens strictly on `127.0.0.1:47891` (never exposed to LAN/internet).
|
|
43
|
+
- Rejects any browser web `Origin` (anti-CSWSH protection).
|
|
44
|
+
- Requires a persistent 256-bit local pairing token stored in `~/.cursormesh/token`.
|
|
45
|
+
|
|
46
|
+
## Available MCP Tools
|
|
47
|
+
`list_tabs`, `open_tab`, `switch_tab`, `close_tab`, `navigate`, `snapshot`, `screenshot`, `hover`, `click`, `fill`, `scroll`, `release_cursor`.
|
package/dist/hub.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import { WebSocketServer, WebSocket } from 'ws';
|
|
3
|
+
import { AGENT_PALETTE, DEFAULT_BRIDGE_HOST, DEFAULT_BRIDGE_PORT, } from '@cursormesh/protocol';
|
|
4
|
+
export class CursorMeshHub {
|
|
5
|
+
token;
|
|
6
|
+
port;
|
|
7
|
+
host;
|
|
8
|
+
server = null;
|
|
9
|
+
wss = null;
|
|
10
|
+
extensionSocket = null;
|
|
11
|
+
agents = new Map();
|
|
12
|
+
pending = new Map();
|
|
13
|
+
colorCursor = 0;
|
|
14
|
+
constructor(token, port = DEFAULT_BRIDGE_PORT, host = DEFAULT_BRIDGE_HOST) {
|
|
15
|
+
this.token = token;
|
|
16
|
+
this.port = port;
|
|
17
|
+
this.host = host;
|
|
18
|
+
}
|
|
19
|
+
async start() {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const server = http.createServer((_req, res) => {
|
|
22
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
23
|
+
res.end(JSON.stringify({
|
|
24
|
+
service: 'cursormesh-hub',
|
|
25
|
+
extensionConnected: this.extensionSocket?.readyState === WebSocket.OPEN,
|
|
26
|
+
activeAgents: this.agents.size,
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
29
|
+
const wss = new WebSocketServer({
|
|
30
|
+
server,
|
|
31
|
+
verifyClient: (info, cb) => {
|
|
32
|
+
const origin = info.origin || '';
|
|
33
|
+
// Only allow local Node clients (no origin) or Chrome extensions.
|
|
34
|
+
if (!origin || origin.startsWith('chrome-extension://')) {
|
|
35
|
+
cb(true);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
cb(false, 403, 'Forbidden origin');
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
server.once('error', (err) => {
|
|
42
|
+
if (err.code === 'EADDRINUSE') {
|
|
43
|
+
resolve(false);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
reject(err);
|
|
47
|
+
});
|
|
48
|
+
server.listen(this.port, this.host, () => {
|
|
49
|
+
this.server = server;
|
|
50
|
+
this.wss = wss;
|
|
51
|
+
this.attachHandlers(wss);
|
|
52
|
+
console.error(`[CursorMesh Hub] Listening on ws://${this.host}:${this.port}`);
|
|
53
|
+
resolve(true);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
attachHandlers(wss) {
|
|
58
|
+
wss.on('connection', (ws) => {
|
|
59
|
+
let role = null;
|
|
60
|
+
const authTimeout = setTimeout(() => {
|
|
61
|
+
if (!role)
|
|
62
|
+
ws.close(4000, 'Auth timeout');
|
|
63
|
+
}, 5000);
|
|
64
|
+
ws.on('message', (raw) => {
|
|
65
|
+
let msg;
|
|
66
|
+
try {
|
|
67
|
+
msg = JSON.parse(raw.toString('utf8'));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (msg.type === 'event' && msg.event === 'ping') {
|
|
73
|
+
this.send(ws, { type: 'event', event: 'pong' });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (msg.type === 'hello') {
|
|
77
|
+
if (msg.token !== this.token) {
|
|
78
|
+
ws.close(4001, 'Invalid pairing token');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
clearTimeout(authTimeout);
|
|
82
|
+
role = msg.role;
|
|
83
|
+
if (role === 'extension') {
|
|
84
|
+
if (this.extensionSocket && this.extensionSocket !== ws) {
|
|
85
|
+
this.extensionSocket.close(4002, 'Replaced by newer extension connection');
|
|
86
|
+
}
|
|
87
|
+
this.extensionSocket = ws;
|
|
88
|
+
console.error('[CursorMesh Hub] Chrome extension connected');
|
|
89
|
+
this.broadcastAgents();
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const color = msg.agent?.color || AGENT_PALETTE[this.colorCursor++ % AGENT_PALETTE.length];
|
|
93
|
+
const identity = {
|
|
94
|
+
agentId: msg.agent?.agentId || `agent-${Date.now()}`,
|
|
95
|
+
name: msg.agent?.name || `Agent ${this.agents.size + 1}`,
|
|
96
|
+
color,
|
|
97
|
+
source: msg.agent?.source || 'mcp',
|
|
98
|
+
connectedAt: Date.now(),
|
|
99
|
+
};
|
|
100
|
+
this.agents.set(ws, identity);
|
|
101
|
+
console.error(`[CursorMesh Hub] Agent connected: ${identity.name} (${identity.color})`);
|
|
102
|
+
this.broadcastAgents();
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (!role)
|
|
107
|
+
return;
|
|
108
|
+
if (role === 'agent' && msg.type === 'command') {
|
|
109
|
+
this.forwardCommandToExtension(ws, msg);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (role === 'extension' && msg.type === 'response') {
|
|
113
|
+
this.forwardResponseToAgent(msg);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (role === 'extension' && msg.type === 'event' && msg.event === 'stop_all') {
|
|
117
|
+
this.abortAllPending('Detenido por el usuario (Kill Switch).');
|
|
118
|
+
for (const agentWs of this.agents.keys()) {
|
|
119
|
+
this.send(agentWs, { type: 'event', event: 'stop_all' });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
ws.on('close', () => {
|
|
124
|
+
clearTimeout(authTimeout);
|
|
125
|
+
if (ws === this.extensionSocket) {
|
|
126
|
+
this.extensionSocket = null;
|
|
127
|
+
this.abortAllPending('La extensión de Chrome se desconectó.');
|
|
128
|
+
console.error('[CursorMesh Hub] Chrome extension disconnected');
|
|
129
|
+
}
|
|
130
|
+
if (this.agents.has(ws)) {
|
|
131
|
+
const id = this.agents.get(ws);
|
|
132
|
+
this.agents.delete(ws);
|
|
133
|
+
console.error(`[CursorMesh Hub] Agent disconnected: ${id.name}`);
|
|
134
|
+
this.broadcastAgents();
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
forwardCommandToExtension(agentWs, msg) {
|
|
140
|
+
if (!this.extensionSocket || this.extensionSocket.readyState !== WebSocket.OPEN) {
|
|
141
|
+
this.send(agentWs, {
|
|
142
|
+
type: 'response',
|
|
143
|
+
requestId: msg.requestId,
|
|
144
|
+
ok: false,
|
|
145
|
+
error: 'La extensión CursorMesh en Chrome no está conectada. Ábrela en Chrome, pega tu token de emparejamiento y comprueba que esté activada.',
|
|
146
|
+
});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const identity = this.agents.get(agentWs) || msg.agent;
|
|
150
|
+
const enriched = { ...msg, agent: identity };
|
|
151
|
+
const timer = setTimeout(() => {
|
|
152
|
+
this.pending.delete(msg.requestId);
|
|
153
|
+
this.send(agentWs, {
|
|
154
|
+
type: 'response',
|
|
155
|
+
requestId: msg.requestId,
|
|
156
|
+
ok: false,
|
|
157
|
+
error: `Timeout esperando respuesta de Chrome para "${msg.command}".`,
|
|
158
|
+
});
|
|
159
|
+
}, 65_000);
|
|
160
|
+
this.pending.set(msg.requestId, { agentSocket: agentWs, timer });
|
|
161
|
+
this.send(this.extensionSocket, enriched);
|
|
162
|
+
}
|
|
163
|
+
forwardResponseToAgent(msg) {
|
|
164
|
+
const entry = this.pending.get(msg.requestId);
|
|
165
|
+
if (!entry)
|
|
166
|
+
return;
|
|
167
|
+
clearTimeout(entry.timer);
|
|
168
|
+
this.pending.delete(msg.requestId);
|
|
169
|
+
this.send(entry.agentSocket, msg);
|
|
170
|
+
}
|
|
171
|
+
abortAllPending(reason) {
|
|
172
|
+
for (const [requestId, entry] of this.pending.entries()) {
|
|
173
|
+
clearTimeout(entry.timer);
|
|
174
|
+
this.send(entry.agentSocket, {
|
|
175
|
+
type: 'response',
|
|
176
|
+
requestId,
|
|
177
|
+
ok: false,
|
|
178
|
+
error: reason,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
this.pending.clear();
|
|
182
|
+
}
|
|
183
|
+
broadcastAgents() {
|
|
184
|
+
if (!this.extensionSocket || this.extensionSocket.readyState !== WebSocket.OPEN)
|
|
185
|
+
return;
|
|
186
|
+
const list = Array.from(this.agents.values());
|
|
187
|
+
const ev = {
|
|
188
|
+
type: 'event',
|
|
189
|
+
event: 'agents_updated',
|
|
190
|
+
payload: list,
|
|
191
|
+
};
|
|
192
|
+
this.send(this.extensionSocket, ev);
|
|
193
|
+
}
|
|
194
|
+
send(ws, msg) {
|
|
195
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
196
|
+
ws.send(JSON.stringify(msg));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
close() {
|
|
200
|
+
this.wss?.close();
|
|
201
|
+
this.server?.close();
|
|
202
|
+
}
|
|
203
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
+
import { WebSocket } from 'ws';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { AGENT_PALETTE, DEFAULT_BRIDGE_HOST, DEFAULT_BRIDGE_PORT, } from '@cursormesh/protocol';
|
|
8
|
+
import { CursorMeshHub } from './hub.js';
|
|
9
|
+
import { getOrCreateToken, getTokenFilePath } from './token.js';
|
|
10
|
+
function getArg(flag) {
|
|
11
|
+
const idx = process.argv.indexOf(flag);
|
|
12
|
+
return idx >= 0 && process.argv[idx + 1] ? process.argv[idx + 1] : undefined;
|
|
13
|
+
}
|
|
14
|
+
const token = getOrCreateToken();
|
|
15
|
+
const port = Number(getArg('--port') || process.env.CURSORMESH_PORT || DEFAULT_BRIDGE_PORT);
|
|
16
|
+
const host = DEFAULT_BRIDGE_HOST;
|
|
17
|
+
if (process.argv.includes('--print-token')) {
|
|
18
|
+
console.log(token);
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
const agentName = getArg('--agent-name') || process.env.CURSORMESH_AGENT_NAME || 'Antigravity';
|
|
22
|
+
const agentColor = getArg('--agent-color') ||
|
|
23
|
+
process.env.CURSORMESH_AGENT_COLOR ||
|
|
24
|
+
AGENT_PALETTE[Math.abs(hashString(agentName)) % AGENT_PALETTE.length];
|
|
25
|
+
const agentIdentity = {
|
|
26
|
+
agentId: `mcp_${crypto.randomBytes(6).toString('hex')}`,
|
|
27
|
+
name: agentName,
|
|
28
|
+
color: agentColor,
|
|
29
|
+
source: 'mcp',
|
|
30
|
+
connectedAt: Date.now(),
|
|
31
|
+
};
|
|
32
|
+
function hashString(str) {
|
|
33
|
+
let h = 0;
|
|
34
|
+
for (let i = 0; i < str.length; i++)
|
|
35
|
+
h = (h * 31 + str.charCodeAt(i)) | 0;
|
|
36
|
+
return h;
|
|
37
|
+
}
|
|
38
|
+
class HubAgentClient {
|
|
39
|
+
url;
|
|
40
|
+
authToken;
|
|
41
|
+
identity;
|
|
42
|
+
ws = null;
|
|
43
|
+
pending = new Map();
|
|
44
|
+
connecting = null;
|
|
45
|
+
constructor(url, authToken, identity) {
|
|
46
|
+
this.url = url;
|
|
47
|
+
this.authToken = authToken;
|
|
48
|
+
this.identity = identity;
|
|
49
|
+
}
|
|
50
|
+
async ensureConnected() {
|
|
51
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN)
|
|
52
|
+
return;
|
|
53
|
+
if (this.connecting)
|
|
54
|
+
return this.connecting;
|
|
55
|
+
this.connecting = new Promise((resolve, reject) => {
|
|
56
|
+
const ws = new WebSocket(this.url);
|
|
57
|
+
ws.once('open', () => {
|
|
58
|
+
this.ws = ws;
|
|
59
|
+
this.connecting = null;
|
|
60
|
+
ws.send(JSON.stringify({
|
|
61
|
+
type: 'hello',
|
|
62
|
+
role: 'agent',
|
|
63
|
+
token: this.authToken,
|
|
64
|
+
agent: this.identity,
|
|
65
|
+
}));
|
|
66
|
+
resolve();
|
|
67
|
+
});
|
|
68
|
+
ws.on('message', (raw) => {
|
|
69
|
+
let msg;
|
|
70
|
+
try {
|
|
71
|
+
msg = JSON.parse(raw.toString('utf8'));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (msg.type === 'response') {
|
|
77
|
+
this.handleResponse(msg);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
ws.once('error', (err) => {
|
|
81
|
+
this.connecting = null;
|
|
82
|
+
reject(err);
|
|
83
|
+
});
|
|
84
|
+
ws.on('close', () => {
|
|
85
|
+
this.ws = null;
|
|
86
|
+
for (const [, p] of this.pending) {
|
|
87
|
+
p.reject(new Error('Conexión perdida con el hub CursorMesh.'));
|
|
88
|
+
}
|
|
89
|
+
this.pending.clear();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
return this.connecting;
|
|
93
|
+
}
|
|
94
|
+
handleResponse(msg) {
|
|
95
|
+
const entry = this.pending.get(msg.requestId);
|
|
96
|
+
if (!entry)
|
|
97
|
+
return;
|
|
98
|
+
this.pending.delete(msg.requestId);
|
|
99
|
+
if (msg.ok)
|
|
100
|
+
entry.resolve(msg.data);
|
|
101
|
+
else
|
|
102
|
+
entry.reject(new Error(msg.error || 'Error ejecutando acción en Chrome'));
|
|
103
|
+
}
|
|
104
|
+
async sendCommand(command, params) {
|
|
105
|
+
await this.ensureConnected();
|
|
106
|
+
const requestId = `req_${crypto.randomBytes(8).toString('hex')}`;
|
|
107
|
+
const payload = {
|
|
108
|
+
type: 'command',
|
|
109
|
+
requestId,
|
|
110
|
+
agent: this.identity,
|
|
111
|
+
command,
|
|
112
|
+
params,
|
|
113
|
+
};
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
this.pending.set(requestId, { resolve, reject });
|
|
116
|
+
this.ws.send(JSON.stringify(payload));
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function formatSnapshot(snap) {
|
|
121
|
+
const lines = [
|
|
122
|
+
`# ${snap.title}`,
|
|
123
|
+
`URL: ${snap.url} (tabId: ${snap.tabId})`,
|
|
124
|
+
`Viewport: ${snap.viewport.width}x${snap.viewport.height} · scrollY: ${snap.viewport.scrollY}/${snap.viewport.scrollHeight}`,
|
|
125
|
+
];
|
|
126
|
+
if (snap.headings.length) {
|
|
127
|
+
lines.push('', '## Encabezados', ...snap.headings.map((h) => `- ${h}`));
|
|
128
|
+
}
|
|
129
|
+
lines.push('', `## Elementos interactivos (${snap.elements.length})`);
|
|
130
|
+
for (const el of snap.elements) {
|
|
131
|
+
const meta = [el.tag, el.role ? `role=${el.role}` : '', el.type ? `type=${el.type}` : '']
|
|
132
|
+
.filter(Boolean)
|
|
133
|
+
.join(' ');
|
|
134
|
+
const label = el.text || el.placeholder || el.href || '(sin texto)';
|
|
135
|
+
const val = el.value ? ` value="${el.value}"` : '';
|
|
136
|
+
lines.push(`- [${el.uid}] <${meta}> "${label}"${val} @(${el.rect.x},${el.rect.y})`);
|
|
137
|
+
}
|
|
138
|
+
if (snap.textPreview) {
|
|
139
|
+
lines.push('', '## Texto visible', snap.textPreview);
|
|
140
|
+
}
|
|
141
|
+
return lines.join('\n');
|
|
142
|
+
}
|
|
143
|
+
async function main() {
|
|
144
|
+
const hub = new CursorMeshHub(token, port, host);
|
|
145
|
+
const becameLeader = await hub.start();
|
|
146
|
+
console.error(`[CursorMesh] Token file: ${getTokenFilePath()} | Mode: ${becameLeader ? 'Hub + MCP' : 'MCP Client -> existing Hub'} | Agent: ${agentIdentity.name} (${agentIdentity.color})`);
|
|
147
|
+
if (process.argv.includes('--hub-only')) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const client = new HubAgentClient(`ws://${host}:${port}`, token, agentIdentity);
|
|
151
|
+
await client.ensureConnected();
|
|
152
|
+
const server = new McpServer({
|
|
153
|
+
name: 'cursormesh',
|
|
154
|
+
version: '0.1.0',
|
|
155
|
+
});
|
|
156
|
+
const textResult = (text) => ({ content: [{ type: 'text', text }] });
|
|
157
|
+
server.tool('list_tabs', 'Lista todas las pestañas abiertas en Chrome con su tabId.', {}, async () => {
|
|
158
|
+
const tabs = await client.sendCommand('list_tabs', {});
|
|
159
|
+
return textResult(JSON.stringify(tabs, null, 2));
|
|
160
|
+
});
|
|
161
|
+
server.tool('open_tab', 'Abre una nueva pestaña en Chrome dentro del grupo de pestañas con color de este agente.', {
|
|
162
|
+
url: z.string().url().describe('URL completa a abrir'),
|
|
163
|
+
active: z.boolean().optional().describe('Traer la pestaña al frente (por defecto true)'),
|
|
164
|
+
group: z.boolean().optional().describe('Agrupar en el grupo de pestañas del agente (por defecto true)'),
|
|
165
|
+
}, async ({ url, active, group }) => {
|
|
166
|
+
const data = await client.sendCommand('open_tab', { url, active, group });
|
|
167
|
+
return textResult(JSON.stringify(data, null, 2));
|
|
168
|
+
});
|
|
169
|
+
server.tool('switch_tab', 'Activa una pestaña concreta por su tabId.', { tabId: z.number().int() }, async ({ tabId }) => {
|
|
170
|
+
const data = await client.sendCommand('switch_tab', { tabId });
|
|
171
|
+
return textResult(JSON.stringify(data, null, 2));
|
|
172
|
+
});
|
|
173
|
+
server.tool('close_tab', 'Cierra una pestaña por su tabId.', { tabId: z.number().int() }, async ({ tabId }) => {
|
|
174
|
+
const data = await client.sendCommand('close_tab', { tabId });
|
|
175
|
+
return textResult(JSON.stringify(data, null, 2));
|
|
176
|
+
});
|
|
177
|
+
server.tool('navigate', 'Navega a una URL en la pestaña indicada (o la pestaña activa).', {
|
|
178
|
+
url: z.string().url(),
|
|
179
|
+
tabId: z.number().int().optional(),
|
|
180
|
+
}, async ({ url, tabId }) => {
|
|
181
|
+
const data = await client.sendCommand('navigate', { url, tabId });
|
|
182
|
+
return textResult(JSON.stringify(data, null, 2));
|
|
183
|
+
});
|
|
184
|
+
server.tool('snapshot', 'Obtiene un mapa estructurado de la página con identificadores [uid] de botones, enlaces y campos.', {
|
|
185
|
+
tabId: z.number().int().optional(),
|
|
186
|
+
maxElements: z.number().int().min(10).max(250).optional(),
|
|
187
|
+
}, async ({ tabId, maxElements }) => {
|
|
188
|
+
const snap = (await client.sendCommand('snapshot', { tabId, maxElements }));
|
|
189
|
+
return textResult(formatSnapshot(snap));
|
|
190
|
+
});
|
|
191
|
+
server.tool('screenshot', 'Captura una imagen visual de la pestaña activa o indicada.', {
|
|
192
|
+
tabId: z.number().int().optional(),
|
|
193
|
+
format: z.enum(['png', 'jpeg']).optional(),
|
|
194
|
+
}, async ({ tabId, format }) => {
|
|
195
|
+
const res = (await client.sendCommand('screenshot', {
|
|
196
|
+
tabId,
|
|
197
|
+
format: format || 'jpeg',
|
|
198
|
+
quality: 82,
|
|
199
|
+
}));
|
|
200
|
+
const base64 = res.dataUrl.split(',')[1] || '';
|
|
201
|
+
return {
|
|
202
|
+
content: [
|
|
203
|
+
{ type: 'text', text: `Captura de tabId ${res.tabId} (${res.url})` },
|
|
204
|
+
{ type: 'image', data: base64, mimeType: res.mimeType },
|
|
205
|
+
],
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
server.tool('hover', 'Desliza el cursor virtual del agente sobre un elemento (por uid, selector CSS o coordenadas).', {
|
|
209
|
+
tabId: z.number().int().optional(),
|
|
210
|
+
uid: z.string().optional(),
|
|
211
|
+
selector: z.string().optional(),
|
|
212
|
+
x: z.number().optional(),
|
|
213
|
+
y: z.number().optional(),
|
|
214
|
+
}, async (params) => {
|
|
215
|
+
const data = await client.sendCommand('hover', params);
|
|
216
|
+
return textResult(JSON.stringify(data, null, 2));
|
|
217
|
+
});
|
|
218
|
+
server.tool('click', 'Mueve suavemente el cursor virtual hasta el objetivo, muestra la onda de clic y hace clic.', {
|
|
219
|
+
tabId: z.number().int().optional(),
|
|
220
|
+
uid: z.string().optional().describe('uid devuelto por snapshot (ej. e12)'),
|
|
221
|
+
selector: z.string().optional().describe('Selector CSS alternativo'),
|
|
222
|
+
x: z.number().optional(),
|
|
223
|
+
y: z.number().optional(),
|
|
224
|
+
doubleClick: z.boolean().optional(),
|
|
225
|
+
}, async (params) => {
|
|
226
|
+
const data = await client.sendCommand('click', params);
|
|
227
|
+
return textResult(JSON.stringify(data, null, 2));
|
|
228
|
+
});
|
|
229
|
+
server.tool('fill', 'Mueve el cursor virtual a un campo de texto y escribe el valor indicado.', {
|
|
230
|
+
tabId: z.number().int().optional(),
|
|
231
|
+
uid: z.string().optional(),
|
|
232
|
+
selector: z.string().optional(),
|
|
233
|
+
value: z.string(),
|
|
234
|
+
pressEnter: z.boolean().optional(),
|
|
235
|
+
}, async (params) => {
|
|
236
|
+
const data = await client.sendCommand('fill', params);
|
|
237
|
+
return textResult(JSON.stringify(data, null, 2));
|
|
238
|
+
});
|
|
239
|
+
server.tool('scroll', 'Hace scroll suave en la página.', {
|
|
240
|
+
tabId: z.number().int().optional(),
|
|
241
|
+
direction: z.enum(['up', 'down', 'top', 'bottom']).optional(),
|
|
242
|
+
amount: z.number().int().optional(),
|
|
243
|
+
}, async (params) => {
|
|
244
|
+
const data = await client.sendCommand('scroll', params);
|
|
245
|
+
return textResult(JSON.stringify(data, null, 2));
|
|
246
|
+
});
|
|
247
|
+
server.tool('release_cursor', 'Oculta el cursor virtual de este agente en la pestaña cuando termina su tarea.', { tabId: z.number().int().optional() }, async ({ tabId }) => {
|
|
248
|
+
const data = await client.sendCommand('release_cursor', { tabId });
|
|
249
|
+
return textResult(JSON.stringify(data, null, 2));
|
|
250
|
+
});
|
|
251
|
+
const transport = new StdioServerTransport();
|
|
252
|
+
await server.connect(transport);
|
|
253
|
+
}
|
|
254
|
+
main().catch((err) => {
|
|
255
|
+
console.error('[CursorMesh] Fatal error:', err);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
});
|
package/dist/token.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
const DIR = path.join(os.homedir(), '.cursormesh');
|
|
6
|
+
const TOKEN_FILE = path.join(DIR, 'token');
|
|
7
|
+
export function getTokenFilePath() {
|
|
8
|
+
return TOKEN_FILE;
|
|
9
|
+
}
|
|
10
|
+
export function getOrCreateToken() {
|
|
11
|
+
if (process.env.CURSORMESH_TOKEN?.trim()) {
|
|
12
|
+
return process.env.CURSORMESH_TOKEN.trim();
|
|
13
|
+
}
|
|
14
|
+
fs.mkdirSync(DIR, { recursive: true });
|
|
15
|
+
if (fs.existsSync(TOKEN_FILE)) {
|
|
16
|
+
const existing = fs.readFileSync(TOKEN_FILE, 'utf8').trim();
|
|
17
|
+
if (existing.length >= 16)
|
|
18
|
+
return existing;
|
|
19
|
+
}
|
|
20
|
+
const token = `cm_${crypto.randomBytes(20).toString('hex')}`;
|
|
21
|
+
fs.writeFileSync(TOKEN_FILE, token + '\n', { encoding: 'utf8', mode: 0o600 });
|
|
22
|
+
return token;
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cursormesh/mcp-bridge",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local MCP bridge (127.0.0.1) connecting Antigravity, Claude Code, Claude Desktop, Cursor, Windsurf, and Codex to the CursorMesh Chrome extension with visible multi-agent virtual cursors.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://cursormesh.app/",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"cursormesh",
|
|
9
|
+
"mcp",
|
|
10
|
+
"model-context-protocol",
|
|
11
|
+
"chrome",
|
|
12
|
+
"browser-automation",
|
|
13
|
+
"ai-agents",
|
|
14
|
+
"claude",
|
|
15
|
+
"cursor",
|
|
16
|
+
"antigravity"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"bin": {
|
|
20
|
+
"cursormesh-mcp": "dist/index.js",
|
|
21
|
+
"mcp-bridge": "dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -p tsconfig.json",
|
|
36
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
37
|
+
"start": "node dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@cursormesh/protocol": "^0.1.0",
|
|
41
|
+
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
42
|
+
"ws": "^8.18.1",
|
|
43
|
+
"zod": "^3.24.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^22.14.0",
|
|
47
|
+
"@types/ws": "^8.18.0",
|
|
48
|
+
"typescript": "^5.8.2"
|
|
49
|
+
}
|
|
50
|
+
}
|