cctether 0.3.3 → 0.5.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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/mcp.js +64 -0
  3. package/src/tools.js +55 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cctether",
3
- "version": "0.3.3",
3
+ "version": "0.5.0",
4
4
  "description": "Let Claude Code use your browser over your own connection — no third-party relay.",
5
5
  "keywords": [
6
6
  "claude-code",
package/src/mcp.js CHANGED
@@ -32,6 +32,30 @@ export function createMcpSession({ write, browser, version, log = () => {}, unav
32
32
  const reply = (id, result) => write(JSON.stringify({ jsonrpc: '2.0', id, result }));
33
33
  const replyError = (id, code, message) => write(JSON.stringify({ jsonrpc: '2.0', id: id ?? null, error: { code, message } }));
34
34
 
35
+ // The tool list is this server's, so an extension older than the server may not know a tool
36
+ // (e.g. while a new version waits for Chrome Web Store review). It says so itself; no version
37
+ // comparison here.
38
+ function outdatedExtension(name) {
39
+ const ext = browser?.status?.()?.info?.extension || 'unknown';
40
+ return `${name} is not supported by the connected cctether browser extension (version ${ext}; this server is ${version}). `
41
+ + 'The extension is older than the server: ask the user to update it (chrome://extensions → Developer mode → Update). '
42
+ + 'If the Chrome Web Store does not have the new version yet, this tool can\'t be used for now.';
43
+ }
44
+
45
+ /** The connected extension's version, if it is older than this server; else null. */
46
+ function olderExtension() {
47
+ const ext = browser?.status?.()?.info?.extension;
48
+ return typeof ext === 'string' && compareVersions(ext, version) < 0 ? ext : null;
49
+ }
50
+
51
+ // An older extension rejects an argument or value it doesn't know with bad_args: say why.
52
+ function withVersionNote(message) {
53
+ const ext = olderExtension();
54
+ if (!ext) return message;
55
+ return `${message}\n(The connected cctether browser extension is version ${ext}, older than this server, ${version}: this argument or value may be newer than the extension. `
56
+ + 'Ask the user to update the extension; until then, use the arguments the error says it accepts.)';
57
+ }
58
+
35
59
  async function callTool(params) {
36
60
  const name = params?.name;
37
61
  const tool = TOOLS.find((t) => t.name === name);
@@ -40,8 +64,17 @@ export function createMcpSession({ write, browser, version, log = () => {}, unav
40
64
  const invalid = validate(tool.inputSchema, args);
41
65
  if (invalid) return { result: errorResult(`Invalid arguments: ${invalid}.`) };
42
66
  if (unavailable) return { result: errorResult(unavailable) };
67
+ // Calls an older extension accepts but answers differently, without an error (SPEC §5.2).
68
+ const needs = minExtensionFor(name, args);
69
+ const ext = browser?.status?.()?.info?.extension;
70
+ if (needs && typeof ext === 'string' && compareVersions(ext, needs.version) < 0) {
71
+ return { result: errorResult(`${needs.what} needs the cctether browser extension ${needs.version} or newer; the connected one is ${ext} (this server is ${version}). `
72
+ + `Ask the user to update the extension. Until then: ${needs.instead}`) };
73
+ }
43
74
  try {
44
75
  const r = await browser.call(name, args, toolTimeoutMs(name, args));
76
+ if (!r.ok && isUnknownToolAnswer(r.error)) return { result: errorResult(outdatedExtension(name)) };
77
+ if (!r.ok && r.error?.code === 'bad_args') return { result: errorResult(withVersionNote(r.error.message)) };
45
78
  if (!r.ok) return { result: errorResult(r.error.message) };
46
79
  return { result: { content: sanitizeContent(r.data?.content) } };
47
80
  } catch (e) {
@@ -108,6 +141,37 @@ function errorResult(text) {
108
141
  return { content: [{ type: 'text', text }], isError: true };
109
142
  }
110
143
 
144
+ /** Compare dotted version numbers: < 0 if a is older than b. Non-numeric parts count as 0. */
145
+ export function compareVersions(a, b) {
146
+ const pa = String(a).split('.').map((x) => parseInt(x, 10) || 0);
147
+ const pb = String(b).split('.').map((x) => parseInt(x, 10) || 0);
148
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
149
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0);
150
+ if (d) return d;
151
+ }
152
+ return 0;
153
+ }
154
+
155
+ /**
156
+ * The extension version a call needs when an older extension would accept it but quietly do
157
+ * something else; else null. (Unknown arguments are no problem: older extensions reject them.)
158
+ */
159
+ export function minExtensionFor(name, args) {
160
+ if (name === 'screenshot' && args.full_page === true && (args.ref != null || args.selector != null)) {
161
+ return {
162
+ version: '0.5.0',
163
+ what: 'A screenshot of an element\'s whole scrollable content (full_page with ref or selector)',
164
+ instead: 'screenshot the element without full_page, and scroll it with scroll to see the rest.',
165
+ };
166
+ }
167
+ return null;
168
+ }
169
+
170
+ /** What an extension answers for a tool it doesn't have (extension/background/app.js onCall). */
171
+ function isUnknownToolAnswer(error) {
172
+ return error?.code === 'bad_args' && typeof error.message === 'string' && error.message.startsWith('Unknown tool "');
173
+ }
174
+
111
175
  const IMAGE_TYPES = new Set(['image/jpeg', 'image/png', 'image/webp']);
112
176
 
113
177
  /** Pass through only well-formed text and image items. */
package/src/tools.js CHANGED
@@ -6,8 +6,10 @@ const tab = { type: 'integer', description: 'Tab id from list_tabs. Default: the
6
6
  const ref = { type: 'integer', minimum: 1, description: 'Element number from read_page (interactive mode) or find. Invalid after navigation.' };
7
7
  const selector = { type: 'string', minLength: 1, maxLength: 2000, description: 'CSS selector (the first visible match, else the first match).' };
8
8
  const selectorFirst = { type: 'string', minLength: 1, maxLength: 2000, description: 'CSS selector (the first match, visible or not).' };
9
- const x = { type: 'number', description: 'Viewport x in CSS pixels (= screenshot pixels unless the screenshot was scaled).' };
10
- const y = { type: 'number', description: 'Viewport y in CSS pixels.' };
9
+ const x = { type: 'number', description: 'Viewport x in CSS pixels, or with screenshot: x on that image.' };
10
+ const y = { type: 'number', description: 'Viewport y in CSS pixels, or with screenshot: y on that image.' };
11
+ const text = { type: 'string', minLength: 1, maxLength: 1000, description: 'Visible text or aria-label of the element (within selector, if given). Acts only on one exact match, else lists candidates.' };
12
+ const shot = { type: 'integer', minimum: 1, description: 'A screenshot number: x, y are then a point on that image.' };
11
13
  const timeout = (def, max) => ({ type: 'integer', minimum: 100, maximum: max, description: `Milliseconds, default ${def}.` });
12
14
 
13
15
  const READ = { readOnlyHint: true, destructiveHint: false, openWorldHint: true };
@@ -48,7 +50,7 @@ export const TOOLS = [
48
50
  {
49
51
  name: 'navigate',
50
52
  title: 'Navigate',
51
- description: 'Load a URL in a tab, or go back / forward / reload. Waits for the page to load.',
53
+ description: 'Load a URL in a tab, or go back / forward / reload. Waits for the page to load, then for wait_for if given.',
52
54
  inputSchema: {
53
55
  type: 'object',
54
56
  properties: {
@@ -56,6 +58,12 @@ export const TOOLS = [
56
58
  action: { type: 'string', enum: ['back', 'forward', 'reload'], description: 'Instead of url.' },
57
59
  tab,
58
60
  timeout_ms: timeout(30000, 120000),
61
+ wait_for: {
62
+ type: 'object',
63
+ properties: { text: { type: 'string', minLength: 1, maxLength: 1000 }, selector },
64
+ additionalProperties: false,
65
+ description: 'Then wait (within timeout_ms) for this, as wait_for does, e.g. for content an app renders after loading.',
66
+ },
59
67
  },
60
68
  additionalProperties: false,
61
69
  },
@@ -82,15 +90,15 @@ export const TOOLS = [
82
90
  {
83
91
  name: 'find',
84
92
  title: 'Find elements',
85
- description: 'Find elements by CSS selector. Returns count, and for each: ref number, tag, text, key attributes, position, visibility.',
93
+ description: 'Find elements by CSS selector and/or visible text. Returns count, and for each: ref number, tag, text, key attributes, position, visibility.',
86
94
  inputSchema: {
87
95
  type: 'object',
88
96
  properties: {
89
97
  selector,
98
+ text: { ...text, description: 'Visible text or aria-label (within selector, if given): exact matches first, then ones containing it.' },
90
99
  limit: { type: 'integer', minimum: 1, maximum: 200, description: 'Default 20.' },
91
100
  tab,
92
101
  },
93
- required: ['selector'],
94
102
  additionalProperties: false,
95
103
  },
96
104
  annotations: READ,
@@ -98,11 +106,11 @@ export const TOOLS = [
98
106
  {
99
107
  name: 'screenshot',
100
108
  title: 'Screenshot',
101
- description: 'Screenshot the visible area (default), the full page, or one element (ref or selector).',
109
+ description: 'Screenshot the visible area (default), the full page, or one element (ref or selector). Each screenshot has a number for click/hover/scroll.',
102
110
  inputSchema: {
103
111
  type: 'object',
104
112
  properties: {
105
- full_page: { type: 'boolean' },
113
+ full_page: { type: 'boolean', description: 'With ref/selector: the whole scrollable content of that element (e.g. an app\'s content pane).' },
106
114
  ref,
107
115
  selector,
108
116
  format: { type: 'string', enum: ['jpeg', 'png'], description: 'Default jpeg.' },
@@ -112,15 +120,44 @@ export const TOOLS = [
112
120
  additionalProperties: false,
113
121
  },
114
122
  annotations: READ,
123
+ timeoutMs: (a) => (a.full_page && (a.ref != null || a.selector != null) ? 90000 : DEFAULT_TIMEOUT_MS),
124
+ },
125
+ {
126
+ name: 'resize_viewport',
127
+ title: 'Resize viewport',
128
+ description: 'Resize a tab\'s viewport (CSS px) without resizing the browser window, e.g. width 390 to check a narrow layout. A desktop viewport, not mobile-device emulation. An omitted dimension keeps its current size. reset: true clears the override; it also ends when cctether detaches from the tab (5 min without tool calls, pause).',
129
+ inputSchema: {
130
+ type: 'object',
131
+ properties: {
132
+ width: { type: 'integer', minimum: 200, maximum: 3840 },
133
+ height: { type: 'integer', minimum: 200, maximum: 3840 },
134
+ reset: { type: 'boolean', description: 'Back to the real size.' },
135
+ tab,
136
+ },
137
+ additionalProperties: false,
138
+ },
139
+ annotations: ACT,
140
+ },
141
+ {
142
+ name: 'set_color_scheme',
143
+ title: 'Set color scheme',
144
+ description: 'Make a tab see a dark or light color scheme (the prefers-color-scheme media feature), e.g. to check a page\'s dark mode, without changing the browser\'s own setting. It does not operate a site\'s own theme switch or change a theme the site saved. "system" removes the override; it also ends when cctether detaches from the tab (5 min without tool calls, pause).',
145
+ inputSchema: {
146
+ type: 'object',
147
+ properties: { scheme: { type: 'string', enum: ['dark', 'light', 'system'] }, tab },
148
+ required: ['scheme'],
149
+ additionalProperties: false,
150
+ },
151
+ annotations: ACT,
115
152
  },
116
153
  {
117
154
  name: 'click',
118
155
  title: 'Click',
119
- description: 'Click an element (ref or selector) or a point (x, y) with real mouse events. Scrolls the element into view first.',
156
+ description: 'Click an element (ref, selector and/or text) or a point (x, y; with screenshot, a point on that image) with real mouse events. Scrolls the element into view first.',
120
157
  inputSchema: {
121
158
  type: 'object',
122
159
  properties: {
123
- ref, selector, x, y,
160
+ ref, selector, text, x, y, screenshot: shot,
124
161
  button: { type: 'string', enum: ['left', 'right', 'middle'] },
125
162
  click_count: { type: 'integer', minimum: 1, maximum: 3, description: '2 = double click.' },
126
163
  modifiers: { type: 'array', items: { type: 'string', enum: ['Alt', 'Control', 'Meta', 'Shift'] }, maxItems: 4 },
@@ -167,14 +204,14 @@ export const TOOLS = [
167
204
  {
168
205
  name: 'scroll',
169
206
  title: 'Scroll',
170
- description: 'Scroll an element into view (ref or selector), or scroll the page — or the scrollable element under (x, y) — in a direction.',
207
+ description: 'Scroll an element into view (ref, selector and/or text), or scroll the page — or the scrollable element under (x, y) — in a direction.',
171
208
  inputSchema: {
172
209
  type: 'object',
173
210
  properties: {
174
- ref, selector,
211
+ ref, selector, text,
175
212
  direction: { type: 'string', enum: ['up', 'down', 'left', 'right'] },
176
213
  amount: { type: 'integer', minimum: 1, maximum: 100000, description: 'Pixels, default 80% of the viewport.' },
177
- x, y,
214
+ x, y, screenshot: shot,
178
215
  tab,
179
216
  },
180
217
  additionalProperties: false,
@@ -184,14 +221,14 @@ export const TOOLS = [
184
221
  {
185
222
  name: 'hover',
186
223
  title: 'Hover',
187
- description: 'Move the mouse over an element (ref or selector) or a point (x, y).',
188
- inputSchema: { type: 'object', properties: { ref, selector, x, y, tab }, additionalProperties: false },
224
+ description: 'Move the mouse over an element (ref, selector and/or text) or a point (x, y).',
225
+ inputSchema: { type: 'object', properties: { ref, selector, text, x, y, screenshot: shot, tab }, additionalProperties: false },
189
226
  annotations: ACT,
190
227
  },
191
228
  {
192
229
  name: 'select_option',
193
230
  title: 'Select option',
194
- description: 'Choose option(s) in a <select>, matching each value against option value, then visible label.',
231
+ description: 'Choose option(s) in a <select>, matching each value against option value, then label. Also a custom dropdown that declares itself (role combobox or listbox): opens it and clicks the matching option (one value).',
195
232
  inputSchema: {
196
233
  type: 'object',
197
234
  properties: {
@@ -207,14 +244,14 @@ export const TOOLS = [
207
244
  {
208
245
  name: 'wait_for',
209
246
  title: 'Wait for',
210
- description: 'Wait until text appears on the page, or an element matching selector appears (with gone: true, until it disappears).',
247
+ description: 'Wait until text appears on the page, or an element matching selector, or text inside such an element (selector + text). gone: true waits until it is not there. Says if it was there from the start.',
211
248
  inputSchema: {
212
249
  type: 'object',
213
250
  properties: {
214
251
  text: { type: 'string', minLength: 1, maxLength: 1000 },
215
252
  selector,
216
253
  gone: { type: 'boolean' },
217
- timeout_ms: timeout(10000, 120000),
254
+ timeout_ms: timeout(10000, 600000),
218
255
  tab,
219
256
  },
220
257
  additionalProperties: false,
@@ -225,7 +262,7 @@ export const TOOLS = [
225
262
  {
226
263
  name: 'evaluate',
227
264
  title: 'Run JavaScript',
228
- description: 'Run JavaScript in the page and return the result as JSON. Works like the DevTools console: the value of the last expression is returned, top-level await is allowed. world "page" (default) shares globals with the page; "isolated" sees only the DOM.',
265
+ description: 'Run JavaScript in the page and return the result as JSON. Works like the DevTools console: the value of the last expression is returned (a Promise is awaited), top-level await is allowed. world "page" (default) shares globals with the page; "isolated" sees only the DOM.',
229
266
  inputSchema: {
230
267
  type: 'object',
231
268
  properties: {