surfcad-mcp 0.3.3 → 0.3.5
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 +14 -12
- package/bin/surfcad-mcp.js +25 -1
- package/data/commands.json +453 -57
- package/data/helpers.json +41 -9
- package/package.json +1 -1
- package/src/bridge/relayHub.mjs +5 -2
- package/src/cli.mjs +3 -2
- package/src/errors.mjs +45 -2
- package/src/helpers.mjs +1 -1
- package/src/prompt/buildGuidance.mjs +3 -2
- package/src/prompt/errorHints.mjs +10 -7
- package/src/prompt/guide.mjs +94 -7
- package/src/prompt/promptSession.mjs +187 -34
- package/src/prompt/promptTools.mjs +48 -8
- package/src/relayMessages.mjs +12 -0
- package/src/remote/config.mjs +1 -0
- package/src/remote/httpFallback.mjs +11 -5
- package/src/remote/login.mjs +77 -11
- package/src/remote/processExit.mjs +137 -0
- package/src/remote/session.mjs +250 -43
- package/src/server.mjs +14 -4
- package/src/unlistedTools.mjs +32 -0
package/src/server.mjs
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from './bridge/relayServer.mjs';
|
|
23
23
|
import { RelaySession } from './relay.mjs';
|
|
24
24
|
import { resolveAgentName, resolveServerUrl } from './remote/config.mjs';
|
|
25
|
+
import { handleRemoteStdinEnd, installRemoteProcessExitLogs } from './remote/processExit.mjs';
|
|
25
26
|
import { RemoteSession } from './remote/session.mjs';
|
|
26
27
|
import { readSavedLogin } from './remote/tokenStore.mjs';
|
|
27
28
|
import { waitForPairing } from './pairWait.mjs';
|
|
@@ -45,6 +46,7 @@ import {
|
|
|
45
46
|
import { withErrorHint, withRowHints } from './prompt/errorHints.mjs';
|
|
46
47
|
import { callListHelpersTool, LIST_HELPERS_TOOL_NAME, listHelpersToolDefinition } from './helpers.mjs';
|
|
47
48
|
import { mergeRegisteredIntoListCommands } from './listCommandsMerge.mjs';
|
|
49
|
+
import { tabAdvertisesTool } from './unlistedTools.mjs';
|
|
48
50
|
|
|
49
51
|
const PAIR_TOOL_NAME = 'pair';
|
|
50
52
|
|
|
@@ -203,6 +205,8 @@ export async function createSurfcadMcpServer(options = {}) {
|
|
|
203
205
|
const session = options.session || new RelaySession();
|
|
204
206
|
const bridgeNames = new Set(catalog.commands.map((command) => command.name));
|
|
205
207
|
const bridgeTools = bridgeToolDefinitions(catalog).map((tool) => augmentStatusTool(augmentScreenshotTool(tool)));
|
|
208
|
+
/** Names outside the shipped catalog the paired tab was asked about (tabAdvertisesTool). */
|
|
209
|
+
const unlistedToolCache = new Map();
|
|
206
210
|
const mcpOnlyNames = registeredToolDefinitions(bridgeTools)
|
|
207
211
|
.map((tool) => tool.name)
|
|
208
212
|
.filter((name) => !bridgeNames.has(name));
|
|
@@ -253,7 +257,7 @@ export async function createSurfcadMcpServer(options = {}) {
|
|
|
253
257
|
}
|
|
254
258
|
|
|
255
259
|
if (isPromptTool(name)) {
|
|
256
|
-
if (name !== 'set_status') session.noteAgentToolCall();
|
|
260
|
+
if (name !== 'set_status' && name !== 'post_progress' && name !== 'close_session') session.noteAgentToolCall();
|
|
257
261
|
try {
|
|
258
262
|
const out = await callPromptTool(session.prompts, name, args);
|
|
259
263
|
if (out.isError) return errorResult(out.error, name);
|
|
@@ -282,7 +286,10 @@ export async function createSurfcadMcpServer(options = {}) {
|
|
|
282
286
|
}
|
|
283
287
|
|
|
284
288
|
const known = bridgeTools.some((t) => t.name === name);
|
|
285
|
-
|
|
289
|
+
// A name this package's catalog lacks is refused outright when nothing
|
|
290
|
+
// is paired; a paired tab is asked whether it advertises it (a tool the
|
|
291
|
+
// app shipped after this npm release) and the call is forwarded if so.
|
|
292
|
+
if (!known && !session.isPaired()) {
|
|
286
293
|
return errorResult({ code: 'unknown_tool', message: `Unknown tool: ${name}` });
|
|
287
294
|
}
|
|
288
295
|
|
|
@@ -300,6 +307,9 @@ export async function createSurfcadMcpServer(options = {}) {
|
|
|
300
307
|
return errorResult(notPairedError(), name);
|
|
301
308
|
}
|
|
302
309
|
}
|
|
310
|
+
if (!known && !(await tabAdvertisesTool(session, name, unlistedToolCache))) {
|
|
311
|
+
return errorResult({ code: 'unknown_tool', message: `Unknown tool: ${name}` });
|
|
312
|
+
}
|
|
303
313
|
|
|
304
314
|
try {
|
|
305
315
|
// A model-changing tool enters building if set_status has not already.
|
|
@@ -444,9 +454,9 @@ async function runRemoteMcpServer(options) {
|
|
|
444
454
|
});
|
|
445
455
|
}
|
|
446
456
|
|
|
457
|
+
installRemoteProcessExitLogs();
|
|
447
458
|
const onStdinClosed = () => {
|
|
448
|
-
remote
|
|
449
|
-
setTimeout(() => process.exit(0), 0).unref();
|
|
459
|
+
handleRemoteStdinEnd(remote);
|
|
450
460
|
};
|
|
451
461
|
process.stdin.once('end', onStdinClosed);
|
|
452
462
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tool the paired tab advertises but this package's catalog does not.
|
|
3
|
+
*
|
|
4
|
+
* `data/commands.json` ships with the npm release, so a tool the app added
|
|
5
|
+
* after that release (`insert_boss` at 0.3.4) is "Unknown tool" from an
|
|
6
|
+
* older `surfcad-mcp` even though the tab's `list_commands` lists it. When a
|
|
7
|
+
* paired session gets a name the catalog lacks, ask the tab once whether it
|
|
8
|
+
* has that command; forward the call when it does. Answers are cached per
|
|
9
|
+
* process. Not paired, or a tab that does not know the name either, stays
|
|
10
|
+
* `unknown_tool`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {{ call: (name: string, args: object) => Promise<unknown> }} session
|
|
15
|
+
* @param {string} name
|
|
16
|
+
* @param {Map<string, boolean>} cache
|
|
17
|
+
* @returns {Promise<boolean>}
|
|
18
|
+
*/
|
|
19
|
+
export async function tabAdvertisesTool(session, name, cache) {
|
|
20
|
+
if (typeof name !== 'string' || !name) return false;
|
|
21
|
+
if (cache.has(name)) return cache.get(name) === true;
|
|
22
|
+
let known = false;
|
|
23
|
+
try {
|
|
24
|
+
const listed = await session.call('list_commands', { names: [name] });
|
|
25
|
+
const rows = listed && typeof listed === 'object' && Array.isArray(listed.commands) ? listed.commands : [];
|
|
26
|
+
known = rows.some((row) => row && row.name === name);
|
|
27
|
+
} catch {
|
|
28
|
+
known = false;
|
|
29
|
+
}
|
|
30
|
+
cache.set(name, known);
|
|
31
|
+
return known;
|
|
32
|
+
}
|