cctether 0.4.0 → 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 +48 -0
  3. package/src/tools.js +27 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cctether",
3
- "version": "0.4.0",
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
@@ -42,6 +42,20 @@ export function createMcpSession({ write, browser, version, log = () => {}, unav
42
42
  + 'If the Chrome Web Store does not have the new version yet, this tool can\'t be used for now.';
43
43
  }
44
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
+
45
59
  async function callTool(params) {
46
60
  const name = params?.name;
47
61
  const tool = TOOLS.find((t) => t.name === name);
@@ -50,9 +64,17 @@ export function createMcpSession({ write, browser, version, log = () => {}, unav
50
64
  const invalid = validate(tool.inputSchema, args);
51
65
  if (invalid) return { result: errorResult(`Invalid arguments: ${invalid}.`) };
52
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
+ }
53
74
  try {
54
75
  const r = await browser.call(name, args, toolTimeoutMs(name, args));
55
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)) };
56
78
  if (!r.ok) return { result: errorResult(r.error.message) };
57
79
  return { result: { content: sanitizeContent(r.data?.content) } };
58
80
  } catch (e) {
@@ -119,6 +141,32 @@ function errorResult(text) {
119
141
  return { content: [{ type: 'text', text }], isError: true };
120
142
  }
121
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
+
122
170
  /** What an extension answers for a tool it doesn't have (extension/background/app.js onCall). */
123
171
  function isUnknownToolAnswer(error) {
124
172
  return error?.code === 'bad_args' && typeof error.message === 'string' && error.message.startsWith('Unknown tool "');
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,6 +120,7 @@ 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),
115
124
  },
116
125
  {
117
126
  name: 'resize_viewport',
@@ -144,11 +153,11 @@ export const TOOLS = [
144
153
  {
145
154
  name: 'click',
146
155
  title: 'Click',
147
- 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.',
148
157
  inputSchema: {
149
158
  type: 'object',
150
159
  properties: {
151
- ref, selector, x, y,
160
+ ref, selector, text, x, y, screenshot: shot,
152
161
  button: { type: 'string', enum: ['left', 'right', 'middle'] },
153
162
  click_count: { type: 'integer', minimum: 1, maximum: 3, description: '2 = double click.' },
154
163
  modifiers: { type: 'array', items: { type: 'string', enum: ['Alt', 'Control', 'Meta', 'Shift'] }, maxItems: 4 },
@@ -195,14 +204,14 @@ export const TOOLS = [
195
204
  {
196
205
  name: 'scroll',
197
206
  title: 'Scroll',
198
- 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.',
199
208
  inputSchema: {
200
209
  type: 'object',
201
210
  properties: {
202
- ref, selector,
211
+ ref, selector, text,
203
212
  direction: { type: 'string', enum: ['up', 'down', 'left', 'right'] },
204
213
  amount: { type: 'integer', minimum: 1, maximum: 100000, description: 'Pixels, default 80% of the viewport.' },
205
- x, y,
214
+ x, y, screenshot: shot,
206
215
  tab,
207
216
  },
208
217
  additionalProperties: false,
@@ -212,14 +221,14 @@ export const TOOLS = [
212
221
  {
213
222
  name: 'hover',
214
223
  title: 'Hover',
215
- description: 'Move the mouse over an element (ref or selector) or a point (x, y).',
216
- 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 },
217
226
  annotations: ACT,
218
227
  },
219
228
  {
220
229
  name: 'select_option',
221
230
  title: 'Select option',
222
- 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).',
223
232
  inputSchema: {
224
233
  type: 'object',
225
234
  properties: {
@@ -235,14 +244,14 @@ export const TOOLS = [
235
244
  {
236
245
  name: 'wait_for',
237
246
  title: 'Wait for',
238
- 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.',
239
248
  inputSchema: {
240
249
  type: 'object',
241
250
  properties: {
242
251
  text: { type: 'string', minLength: 1, maxLength: 1000 },
243
252
  selector,
244
253
  gone: { type: 'boolean' },
245
- timeout_ms: timeout(10000, 120000),
254
+ timeout_ms: timeout(10000, 600000),
246
255
  tab,
247
256
  },
248
257
  additionalProperties: false,
@@ -253,7 +262,7 @@ export const TOOLS = [
253
262
  {
254
263
  name: 'evaluate',
255
264
  title: 'Run JavaScript',
256
- 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.',
257
266
  inputSchema: {
258
267
  type: 'object',
259
268
  properties: {