surfcad-mcp 0.2.2 → 0.2.4

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/src/server.mjs CHANGED
@@ -19,10 +19,31 @@ import {
19
19
  } from './bridge/relayServer.mjs';
20
20
  import { RelaySession } from './relay.mjs';
21
21
  import { augmentScreenshotTool, callPairedBridgeTool } from './screenshotFile.mjs';
22
- import { callPromptTool, isPromptTool, promptToolDefinitions } from './prompt/promptTools.mjs';
22
+ import {
23
+ callPromptTool,
24
+ isPromptTool,
25
+ PROMPT_ONBOARDING_NOTE,
26
+ PROMPT_SERVER_INSTRUCTIONS,
27
+ PROMPT_WEBHOOK_ACTIVE,
28
+ promptToolDefinitions,
29
+ } from './prompt/promptTools.mjs';
23
30
 
24
31
  const PAIR_TOOL_NAME = 'pair';
25
32
 
33
+ const STATUS_PROMPT_NOTE = ' This process also adds webhookRegistered (true when a prompt webhook is registered; the URL and any bearer are not included), queued (prompt messages waiting for read_messages; cancelled prompts are not counted), counts ({ queued, delivered, replied, cancelled }), and last ({ id, state } of the latest prompt, or null).';
34
+
35
+ /**
36
+ * MCP-only fields on the bridge status tool. The host command and commands.json stay unchanged.
37
+ * @param {{ name: string, description?: string }} tool
38
+ */
39
+ function augmentStatusTool(tool) {
40
+ if (!tool || tool.name !== 'status') return tool;
41
+ return {
42
+ ...tool,
43
+ description: `${tool.description || ''}${STATUS_PROMPT_NOTE}`,
44
+ };
45
+ }
46
+
26
47
  /** A bridge call that has to pair first waits this long for Allow, then fails. */
27
48
  const AUTO_PAIR_WAIT_MS = 1000;
28
49
  /** The pair tool returns pair_pending before typical MCP client timeouts (60 s). */
@@ -54,6 +75,29 @@ function textResult(value, isError = false) {
54
75
  };
55
76
  }
56
77
 
78
+ /**
79
+ * Pair success is ordinary text content so every MCP client, including Claude Code,
80
+ * shows the note. No structuredContent and no _meta.
81
+ * @param {Record<string, unknown>} result
82
+ * @param {{ webhookRegistered: () => boolean }} prompts
83
+ */
84
+ function pairToolResult(result, prompts) {
85
+ const webhookRegistered = prompts.webhookRegistered() === true;
86
+ const note = webhookRegistered ? PROMPT_WEBHOOK_ACTIVE : PROMPT_ONBOARDING_NOTE;
87
+ const payload = {
88
+ ...(result && typeof result === 'object' ? result : {}),
89
+ webhookRegistered,
90
+ note,
91
+ };
92
+ return {
93
+ content: [
94
+ { type: 'text', text: JSON.stringify(payload, null, 2) },
95
+ { type: 'text', text: note },
96
+ ],
97
+ isError: false,
98
+ };
99
+ }
100
+
57
101
  function toolErrorPayload(err) {
58
102
  if (err && typeof err === 'object' && err.code) {
59
103
  return formatBridgeError({
@@ -73,18 +117,21 @@ function toolErrorPayload(err) {
73
117
  export async function createSurfcadMcpServer(options = {}) {
74
118
  const catalog = options.catalog || loadCommandsCatalog();
75
119
  const session = options.session || new RelaySession();
76
- const bridgeTools = bridgeToolDefinitions(catalog).map((tool) => augmentScreenshotTool(tool));
120
+ const bridgeTools = bridgeToolDefinitions(catalog).map((tool) => augmentStatusTool(augmentScreenshotTool(tool)));
77
121
 
78
122
  const server = new Server(
79
123
  { name: 'surfcad-mcp', version: loadPackageVersion() },
80
- { capabilities: { tools: {} } },
124
+ {
125
+ capabilities: { tools: {} },
126
+ instructions: PROMPT_SERVER_INSTRUCTIONS,
127
+ },
81
128
  );
82
129
 
83
130
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
84
131
  tools: [
85
132
  {
86
133
  name: PAIR_TOOL_NAME,
87
- description: `Pair this MCP server to an open SurfCAD tab via the local WebSocket relay. ${pairingEnvHint()}`,
134
+ description: `Pair this MCP server to an open SurfCAD tab via the local WebSocket relay. ${pairingEnvHint()} ${PROMPT_SERVER_INSTRUCTIONS}`,
88
135
  inputSchema: {
89
136
  type: 'object',
90
137
  additionalProperties: false,
@@ -130,7 +177,7 @@ export async function createSurfcadMcpServer(options = {}) {
130
177
  }
131
178
  try {
132
179
  const result = await waitForPairing(session.pair(code), PAIR_TOOL_WAIT_MS);
133
- return textResult(result);
180
+ return pairToolResult(result, session.prompts);
134
181
  } catch (err) {
135
182
  return textResult(toolErrorPayload(err), true);
136
183
  }
@@ -159,6 +206,9 @@ export async function createSurfcadMcpServer(options = {}) {
159
206
  try {
160
207
  session.noteAgentToolCall();
161
208
  const out = await callPairedBridgeTool(session, name, args);
209
+ if (name === 'status' && out.isError !== true && out.value && typeof out.value === 'object' && !Array.isArray(out.value)) {
210
+ return textResult({ ...out.value, ...session.prompts.deliveryStatus() });
211
+ }
162
212
  return textResult(out.value, out.isError === true);
163
213
  } catch (err) {
164
214
  const code = err?.code;