foxcode-channel 0.2.0 → 0.3.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/lib.mjs +20 -6
- package/package.json +1 -1
- package/server.mjs +10 -0
package/lib.mjs
CHANGED
|
@@ -70,6 +70,21 @@ export function buildToolResultMessage(tool, content) {
|
|
|
70
70
|
return { type: 'tool_result', id, tool, content, ts: Date.now() }
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Assert that the MCP client (Claude Code) advertises claude/channel support.
|
|
75
|
+
* Throws if the capability is missing — meaning Claude was launched without
|
|
76
|
+
* --dangerously-load-development-channels server:<name>.
|
|
77
|
+
* @param {object|undefined} clientCapabilities - from mcp.getClientCapabilities()
|
|
78
|
+
*/
|
|
79
|
+
export function assertChannelCapability(clientCapabilities, serverName = 'foxcode') {
|
|
80
|
+
if (!clientCapabilities?.experimental?.['claude/channel']) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
'Client does not support claude/channel. ' +
|
|
83
|
+
`Start Claude Code with: claude --dangerously-load-development-channels server:${serverName}`
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
73
88
|
/**
|
|
74
89
|
* MCP tool definitions exposed by the channel plugin.
|
|
75
90
|
*/
|
|
@@ -107,7 +122,7 @@ export const TOOL_DEFINITIONS = [
|
|
|
107
122
|
'Subsequent operations target this managed tab. closeTab() without args closes it;',
|
|
108
123
|
'next navigate() creates a fresh tab.',
|
|
109
124
|
'',
|
|
110
|
-
'Usage: write JS code using `api` object.
|
|
125
|
+
'Usage: write JS code using `api` object. All functions are methods of `api` — call as `api.method()` or destructure first: `const {method} = api`.',
|
|
111
126
|
'All selector-based helpers auto-wait for element (poll 100ms, default timeout 2000ms).',
|
|
112
127
|
'Override: pass {timeout: 5000} as last arg.',
|
|
113
128
|
'',
|
|
@@ -135,11 +150,10 @@ export const TOOL_DEFINITIONS = [
|
|
|
135
150
|
'opts = {timeout: ms} — override auto-wait timeout per call',
|
|
136
151
|
'',
|
|
137
152
|
'Example:',
|
|
138
|
-
'
|
|
139
|
-
'await
|
|
140
|
-
'await
|
|
141
|
-
'await
|
|
142
|
-
'return await snapshot();',
|
|
153
|
+
'await api.navigate("https://example.com/login");',
|
|
154
|
+
'await api.fill("#email", "user@test.com");',
|
|
155
|
+
'await api.click("button[type=submit]");',
|
|
156
|
+
'return await api.snapshot();',
|
|
143
157
|
].join('\n'),
|
|
144
158
|
inputSchema: {
|
|
145
159
|
type: 'object',
|
package/package.json
CHANGED
package/server.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import { WebSocketServer } from 'ws'
|
|
|
19
19
|
import {
|
|
20
20
|
nextId, buildChannelMeta, buildReplyMessage, buildEditMessage,
|
|
21
21
|
buildToolUseMessage, buildToolResultMessage, TOOL_DEFINITIONS,
|
|
22
|
+
assertChannelCapability,
|
|
22
23
|
} from './lib.mjs'
|
|
23
24
|
import { validateCode } from './validator.mjs'
|
|
24
25
|
|
|
@@ -166,5 +167,14 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
|
166
167
|
|
|
167
168
|
// --- Start ---
|
|
168
169
|
|
|
170
|
+
mcp.oninitialized = () => {
|
|
171
|
+
try {
|
|
172
|
+
assertChannelCapability(mcp.getClientCapabilities())
|
|
173
|
+
} catch (err) {
|
|
174
|
+
process.stderr.write(`foxcode: FATAL: ${err.message}\n`)
|
|
175
|
+
process.exit(1)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
169
179
|
await mcp.connect(new StdioServerTransport())
|
|
170
180
|
process.stderr.write(`foxcode: ws://localhost:${PORT}\n`)
|