@pairdraw/mcp 0.21.0 → 0.22.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/dist/server.d.mts CHANGED
@@ -151,7 +151,11 @@ type MCPResult = {
151
151
  declare const MAX_RESULT_BYTES = 900000;
152
152
  declare function resultTooLargeMessage(kind: string, bytes: number, hint: string): string;
153
153
  declare function ok(data: unknown, toolName?: string): MCPResult;
154
+ /** A picture a client can see, with the text a client that ignores images assigns to it. */
155
+ declare function imageResult(data: string, mimeType: string, summary: string): MCPResult;
154
156
  declare function fail(e: unknown): MCPResult;
157
+ /** The bytes a Base64 string decodes to, from its own length, without decoding it. */
158
+ declare function decodedBase64Bytes(base64: string): number;
155
159
  //#endregion
156
160
  //#region src/tool/registration.d.ts
157
161
  type RPCSender = (body: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown>;
package/dist/server.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { l as fail, n as startServer, o as MCP_AGENT_KINDS, s as registerTools, t as MCP_VERSION, u as ok } from "./server-i_dkLeLx.mjs";
1
+ import { l as fail, n as startServer, o as MCP_AGENT_KINDS, s as registerTools, t as MCP_VERSION, u as ok } from "./server-BHPENxBB.mjs";
2
2
  export { MCP_AGENT_KINDS, MCP_VERSION, fail, ok, registerTools, startServer };
package/dist/stdio.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import "./rolldown-runtime-ClRpJifh.mjs";
3
- import { c as registerSkill, r as createServerInstructions, s as registerTools, t as MCP_VERSION } from "./server-i_dkLeLx.mjs";
3
+ import { c as registerSkill, r as createServerInstructions, s as registerTools, t as MCP_VERSION } from "./server-BHPENxBB.mjs";
4
4
  import { a as getSocketPath, o as platformHasUnixSockets } from "./paths-BpcXnrbP.mjs";
5
5
  import { t as resolveMCPRoot } from "./root-BzmoiT2g.mjs";
6
6
  import { r as parseDisabledTools } from "./policy-CVfvvMB7.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pairdraw/mcp",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "@hono/node-server": "^1.19.17",
17
17
  "@modelcontextprotocol/server": "^2.0.0",
18
- "@pairdraw/core": "^0.21.0",
18
+ "@pairdraw/core": "^0.22.0",
19
19
  "@valibot/to-json-schema": "^1.8.0",
20
20
  "es-toolkit": "^1.52.0",
21
21
  "hono": "^4.13.13",
package/src/result.ts CHANGED
@@ -31,7 +31,25 @@ export function ok(data: unknown, toolName?: string): MCPResult {
31
31
  return { content: [{ type: 'text', text }] }
32
32
  }
33
33
 
34
+ /** A picture a client can see, with the text a client that ignores images assigns to it. */
35
+ export function imageResult(data: string, mimeType: string, summary: string): MCPResult {
36
+ return {
37
+ content: [
38
+ { type: 'text', text: summary },
39
+ { type: 'image', data, mimeType }
40
+ ]
41
+ }
42
+ }
43
+
34
44
  export function fail(e: unknown): MCPResult {
35
45
  const msg = e instanceof Error ? e.message : String(e)
36
46
  return { content: [{ type: 'text', text: JSON.stringify({ error: msg }) }], isError: true }
37
47
  }
48
+
49
+ /** The bytes a Base64 string decodes to, from its own length, without decoding it. */
50
+ export function decodedBase64Bytes(base64: string): number {
51
+ let padding = 0
52
+ if (base64.endsWith('==')) padding = 2
53
+ else if (base64.endsWith('=')) padding = 1
54
+ return Math.max(0, Math.floor((base64.length * 3) / 4) - padding)
55
+ }
@@ -2,7 +2,15 @@ import { Buffer } from 'node:buffer'
2
2
 
3
3
  import * as v from 'valibot'
4
4
 
5
- import { MAX_RESULT_BYTES, fail, ok, resultTooLargeMessage, type MCPResult } from '#mcp/result'
5
+ import {
6
+ MAX_RESULT_BYTES,
7
+ decodedBase64Bytes,
8
+ fail,
9
+ imageResult,
10
+ ok,
11
+ resultTooLargeMessage,
12
+ type MCPResult
13
+ } from '#mcp/result'
6
14
  import {
7
15
  automationTargetSchema,
8
16
  sendCommand,
@@ -54,7 +62,7 @@ export function registerBrowserTools(register: RegisterBrowserTool, sendRPC: RPC
54
62
  async (args: { kind: string }) => {
55
63
  try {
56
64
  const res = await sendCommand(sendRPC, 'browser_screenshot', { kind: args.kind })
57
- return pngResult(res.result)
65
+ return pngResult(res.result, args.kind)
58
66
  } catch (e) {
59
67
  return fail(e)
60
68
  }
@@ -159,7 +167,7 @@ function snapshotLayer(result: unknown): { id?: string } {
159
167
  }
160
168
 
161
169
  /** A browser screenshot is an image. Anything else is the same failure the window reports. */
162
- function pngResult(result: unknown): MCPResult {
170
+ function pngResult(result: unknown, kind: string): MCPResult {
163
171
  if (!isPNGResult(result)) return fail(new Error('The page returned no picture'))
164
172
  const bytes = Buffer.byteLength(result.base64, 'utf8')
165
173
  if (bytes > MAX_RESULT_BYTES) {
@@ -173,7 +181,11 @@ function pngResult(result: unknown): MCPResult {
173
181
  )
174
182
  )
175
183
  }
176
- return { content: [{ type: 'image', data: result.base64, mimeType: 'image/png' }] }
184
+ return imageResult(
185
+ result.base64,
186
+ 'image/png',
187
+ `Screenshot of the ${kind} page from "browser_screenshot" (${Math.ceil(decodedBase64Bytes(result.base64) / 1024)} KB, image/png).`
188
+ )
177
189
  }
178
190
 
179
191
  function isPNGResult(result: unknown): result is { base64: string; mimeType: 'image/png' } {
@@ -15,7 +15,7 @@ import * as v from 'valibot'
15
15
  import { CODEGEN_PROMPT, parseToolArgs } from '@pairdraw/core/tools'
16
16
 
17
17
  import type { RPCJSONObject } from '#mcp/json'
18
- import { MAX_RESULT_BYTES, fail, ok, resultTooLargeMessage } from '#mcp/result'
18
+ import { MAX_RESULT_BYTES, fail, imageResult, ok, resultTooLargeMessage } from '#mcp/result'
19
19
  import { SKILL_FILE_PATHS, SKILL_FILES, type SkillFilePath } from '#mcp/skill/content'
20
20
  import { registerBrowserTools } from '#mcp/tool/browser'
21
21
  import { createToolDescriptors, getMCPToolDefinitions } from '#mcp/tool/manifest'
@@ -221,15 +221,12 @@ export function registerTools(mcpServer: McpServer, options: RegisterToolsOption
221
221
  )
222
222
  )
223
223
  }
224
- return {
225
- content: [
226
- {
227
- type: 'image' as const,
228
- data: base64,
229
- mimeType: r.mimeType
230
- }
231
- ]
232
- }
224
+ const facts = Object.fromEntries(Object.entries(r).filter(([key]) => key !== 'base64'))
225
+ return imageResult(
226
+ base64,
227
+ r.mimeType,
228
+ `Image from "${def.name}": ${JSON.stringify(facts)}`
229
+ )
233
230
  }
234
231
  return ok(r, def.name)
235
232
  } catch (e) {
@@ -322,10 +319,19 @@ export function registerTools(mcpServer: McpServer, options: RegisterToolsOption
322
319
  command: 'open_file',
323
320
  args: { ...target, path: safe.realPath }
324
321
  })
325
- const res = result as { ok?: boolean; result?: unknown; target?: unknown; error?: string }
322
+ const res = result as {
323
+ ok?: boolean
324
+ result?: { diagnostics?: unknown }
325
+ target?: unknown
326
+ error?: string
327
+ }
326
328
  if (res.ok === false) return fail(new Error(res.error))
327
- const response: { opened: true; target?: unknown } = { opened: true }
329
+ const response: { opened: true; target?: unknown; diagnostics?: unknown } = {
330
+ opened: true
331
+ }
328
332
  if (res.target) response.target = res.target
333
+ // What the read had to skip, so an agent can tell the person before editing farther.
334
+ if (res.result?.diagnostics !== undefined) response.diagnostics = res.result.diagnostics
329
335
  return ok(response)
330
336
  } catch (e) {
331
337
  return fail(e)