@rebilder/mcp-server 0.2.1 → 0.4.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/index.d.cts DELETED
@@ -1,585 +0,0 @@
1
- import { ProbeOutcome } from '@rebilder/agent-readability/probe';
2
- import { ArsVantage, ArsResult } from '@rebilder/agent-readability';
3
-
4
- /**
5
- * json.ts — the JSON value type everything on the wire is expressed in, and the
6
- * one conversion into it.
7
- *
8
- * Why a nominal `JsonValue` rather than `unknown` plus casts: every value this
9
- * package produces crosses a JSON-RPC boundary, and a value that cannot be
10
- * serialised (a `Date`, an `undefined` in an array, a cycle) becomes a broken
11
- * frame on stdout rather than a type error. `toJsonObject` does the round-trip
12
- * once, at the boundary, so the failure is a caught exception in one place
13
- * instead of a malformed line the client cannot parse.
14
- */
15
- type JsonValue = string | number | boolean | null | JsonValue[] | {
16
- [key: string]: JsonValue;
17
- };
18
- type JsonObject = {
19
- [key: string]: JsonValue;
20
- };
21
-
22
- /**
23
- * jsonrpc.ts — JSON-RPC 2.0, by hand.
24
- *
25
- * WHY BY HAND. Every package in this repo carries zero external runtime
26
- * dependencies, and this one is distributed by `npx` onto strangers' machines:
27
- * an SDK here is a supply-chain surface on the one artifact whose whole pitch is
28
- * "run it locally, nothing leaves your machine". The protocol we need is three
29
- * methods and an envelope. It fits in this file.
30
- *
31
- * The envelope rules that matter and that a hand-rolled implementation gets
32
- * wrong if it is not explicit about them:
33
- * - A request without an `id` is a NOTIFICATION and gets no response, ever.
34
- * Answering a notification is the classic way a hand-rolled server
35
- * deadlocks a well-behaved client.
36
- * - `id: null` is not a notification, it is an invalid request. `null` is
37
- * reserved for the id of an error response to an unparseable frame.
38
- * - Parse errors respond with `id: null` — there is no id to echo.
39
- * - Batches (a top-level array) were REMOVED in MCP 2025-06-18. We reject them
40
- * explicitly rather than silently answering the first element.
41
- */
42
-
43
- declare const JSONRPC_VERSION = "2.0";
44
- type JsonRpcId = string | number;
45
- interface JsonRpcRequest {
46
- /** Absent for notifications. */
47
- readonly id?: JsonRpcId;
48
- readonly method: string;
49
- readonly params?: JsonValue;
50
- }
51
- interface JsonRpcSuccess {
52
- readonly jsonrpc: typeof JSONRPC_VERSION;
53
- readonly id: JsonRpcId;
54
- readonly result: JsonObject;
55
- }
56
- interface JsonRpcErrorBody {
57
- readonly code: number;
58
- readonly message: string;
59
- readonly data?: JsonValue;
60
- }
61
- interface JsonRpcFailure {
62
- readonly jsonrpc: typeof JSONRPC_VERSION;
63
- readonly id: JsonRpcId | null;
64
- readonly error: JsonRpcErrorBody;
65
- }
66
- type JsonRpcResponse = JsonRpcSuccess | JsonRpcFailure;
67
- /**
68
- * The standard codes, plus `-32002`. That one is not in the JSON-RPC spec; it is
69
- * the code the MCP ecosystem uses for "server not initialized", and matching the
70
- * ecosystem is worth more here than inventing a private number.
71
- */
72
- declare const ERROR_CODES: {
73
- readonly parseError: -32700;
74
- readonly invalidRequest: -32600;
75
- readonly methodNotFound: -32601;
76
- readonly invalidParams: -32602;
77
- readonly internalError: -32603;
78
- readonly notInitialized: -32002;
79
- };
80
- declare function success(id: JsonRpcId, result: JsonObject): JsonRpcSuccess;
81
- declare function failure(id: JsonRpcId | null, code: number, message: string, data?: JsonValue): JsonRpcFailure;
82
- type DecodedFrame = {
83
- kind: 'request';
84
- request: JsonRpcRequest;
85
- } | {
86
- kind: 'notification';
87
- request: JsonRpcRequest;
88
- } | {
89
- kind: 'invalid';
90
- response: JsonRpcFailure;
91
- };
92
- /** Validates a parsed frame into a request, a notification, or a ready-made error. */
93
- declare function decodeFrame(value: JsonValue): DecodedFrame;
94
- /** One line of stdin → a frame, or the `-32700` response that answers it. */
95
- declare function decodeLine(line: string): DecodedFrame;
96
-
97
- /**
98
- * index-client.ts — the one network call this binary makes by default, and the
99
- * only file in `src/` allowed to reference `fetch` (see `eslint.config.mjs`).
100
- *
101
- * It is a READ of our public index: `GET /api/public/index/<domain>`. It sends
102
- * no scan, no URL the user asked about, no page content, no hostname other than
103
- * the domain the caller explicitly asked to look up, and no identifier of any
104
- * kind. That is the zero-telemetry contract stated as code rather than as a
105
- * paragraph in a README (design §5.6).
106
- *
107
- * The index is OPT-IN. A domain that is not listed is not a domain that scored
108
- * badly — it is a domain whose owner has not verified and opted in (§5.4), and
109
- * the "not listed" answer says so, because a model that reads "not found" and
110
- * infers "bad" would be inventing a judgement about a third party out of our
111
- * silence.
112
- *
113
- * WHY THE DOMAIN IS VALIDATED BEFORE THE URL IS BUILT. The path segment comes
114
- * from a tool argument, which in a prompt-injection scenario comes from a web
115
- * page. Encoding is not enough on its own: a strict syntactic gate keeps
116
- * "../../something", a URL, an IP literal or a 4 KB blob from ever becoming a
117
- * request, and it is exactly the same check the badge endpoint runs before its
118
- * DB read.
119
- */
120
-
121
- declare const DEFAULT_INDEX_BASE_URL = "https://rebilder.com";
122
- declare const INDEX_BASE_URL_ENV = "REBILDER_API_URL";
123
- /** Structural: the subset of `fetch` used here, so tests need no globals. */
124
- type FetchLike = (url: string, init: {
125
- method: 'GET';
126
- headers: Record<string, string>;
127
- signal: AbortSignal;
128
- redirect: 'error';
129
- }) => Promise<{
130
- status: number;
131
- text(): Promise<string>;
132
- }>;
133
- type IndexLookup = {
134
- kind: 'found';
135
- url: string;
136
- entry: JsonObject;
137
- } | {
138
- kind: 'not-listed';
139
- url: string;
140
- } | {
141
- kind: 'failed';
142
- url: string;
143
- detail: string;
144
- };
145
- interface IndexClient {
146
- readonly baseUrl: string;
147
- lookup(domain: string): Promise<IndexLookup>;
148
- }
149
- /**
150
- * A registrable domain and nothing else: labels of 1–63 chars from
151
- * `[a-z0-9-]` (punycode included, which is how internationalised domains
152
- * arrive), at least two labels, 253 chars total, no leading/trailing hyphen, and
153
- * a TLD that is not all digits — the last clause is what rejects an IPv4 literal
154
- * without a second parser.
155
- */
156
- declare function isValidDomain(value: string): boolean;
157
- declare function normalizeDomain(value: string): string;
158
- /**
159
- * Resolves the API base. `REBILDER_API_URL` exists for our own staging and is
160
- * held to the same rules as anything else that decides where bytes go: https
161
- * only, no credentials in the URL, no query, no fragment. Anything else falls
162
- * back to production rather than being honoured quietly.
163
- */
164
- declare function resolveIndexBaseUrl(raw: string | undefined): string;
165
- declare function indexEntryUrl(baseUrl: string, domain: string): string;
166
- interface IndexClientOptions {
167
- readonly baseUrl?: string;
168
- readonly timeoutMs?: number;
169
- /** Injected in tests. Defaults to the platform `fetch`. */
170
- readonly fetchImpl?: FetchLike;
171
- }
172
- declare function createIndexClient(options?: IndexClientOptions): IndexClient;
173
-
174
- /**
175
- * scanner.ts — the probe, wired for a process that lives on somebody's laptop.
176
- *
177
- * WHAT IS DIFFERENT ABOUT THIS CONSUMER. The hosted scanner fetches strangers'
178
- * origins from our IP space, so its risk is SSRF and amplification. This one
179
- * fetches from the user's own machine, which deletes both of those for this
180
- * component (design §5.6) — and leaves one that people forget: our User-Agent is
181
- * on every one of those requests. A thousand developers running an assistant
182
- * that hammers an origin is our reputation being spent, from addresses we do not
183
- * control and cannot rate-limit. Hence:
184
- *
185
- * - THE POLITENESS LIMITER IS NOT OPTIONAL AND NOT REACHABLE FROM A TOOL CALL.
186
- * `createDefaultScanner` builds it; no tool input schema has a field that
187
- * touches it. The only override is `REBILDER_MCP_PROBE_BUDGET`, an
188
- * environment variable — which is to say, a decision made by the human who
189
- * launched the process, not by a model reading a web page mid-conversation.
190
- * That distinction is the whole point (§5.2).
191
- *
192
- * - `probeStrict` ONLY. `probeLocal` — private hosts, plaintext http — is not
193
- * imported here and must never be. §5.2 names this exact scenario: "an MCP
194
- * server on a developer's machine with private hosts allowed, driven by a
195
- * model whose context contains untrusted web text, will fetch
196
- * http://169.254.169.254/ on request." The CLI has `--allow-private` because
197
- * a human types it. A conversation has no equivalent, so there is no flag.
198
- *
199
- * The budget is a SOFT cap: one MCP session is one "run", and a session that
200
- * scans five cold URLs is doing normal work. 20 requests is roughly four cold
201
- * scans (§3.3 sends five requests per URL), so the default is low enough to
202
- * bound an accident and the error message says exactly how to raise it.
203
- */
204
-
205
- interface Scanner {
206
- scan(target: string, vantage: ArsVantage): Promise<ProbeOutcome>;
207
- }
208
- declare const PROBE_BUDGET_ENV = "REBILDER_MCP_PROBE_BUDGET";
209
- /**
210
- * Parses the one override. Anything unparseable falls back to the default
211
- * rather than throwing: refusing to start because of a typo in an env var is a
212
- * worse failure than scanning politely.
213
- */
214
- declare function probeBudgetFromEnv(raw: string | undefined): number;
215
- interface DefaultScannerOptions {
216
- /** Requests per session. Clamped. Comes from the environment, never from a tool call. */
217
- readonly maxProbesPerRun?: number;
218
- }
219
- /**
220
- * One limiter per server, because one MCP session is one run. Deliberately NOT
221
- * module-global: two servers in one process (tests, or a future supervisor) must
222
- * not share a budget, and a module-level counter in a long-lived process starts
223
- * refusing unrelated work on its twenty-first scan with no signal (§5.2).
224
- */
225
- declare function createDefaultScanner(options?: DefaultScannerOptions): Scanner;
226
-
227
- /**
228
- * server.ts — the MCP method layer: `initialize`, `tools/list`, `tools/call`,
229
- * `ping`, and the notifications that carry no reply.
230
- *
231
- * TRANSPORT-FREE ON PURPOSE. This file never touches stdin, stdout, or
232
- * `process`. `./stdio` feeds it lines and writes what comes back, which is what
233
- * makes the whole protocol surface testable without spawning anything — and
234
- * what would make a second transport a new file rather than a rewrite. HTTP is
235
- * NOT that second transport: an HTTP-reachable scanner inherits the entire abuse
236
- * surface of the hosted one (SSRF via somebody else's argument, amplification,
237
- * rate limiting, a budget somebody else spends), which is exactly what running
238
- * on the user's own machine deletes. Deferred, deliberately (design §5.6).
239
- *
240
- * WHAT IS AN ERROR RESULT AND WHAT IS A PROTOCOL ERROR — the split the MCP spec
241
- * draws and this file follows:
242
- * - malformed frame, unknown method, unknown tool, arguments that do not fit
243
- * the declared schema → JSON-RPC error. The client is at fault.
244
- * - the tool ran and the answer is bad news (unreachable host, refused by
245
- * policy, budget spent, no such check id) → a RESULT with `isError: true`,
246
- * which is a thing the model can read and act on.
247
- * A tool handler that throws is caught here and converted to the second form:
248
- * no exception from this package ever reaches a transport.
249
- */
250
-
251
- /**
252
- * Shown to the user's assistant once, at connect time. It is the only place we
253
- * get to set expectations before a model starts calling things, so it says the
254
- * two things that change behaviour: scans are local and never uploaded, and
255
- * everything a scan returns is untrusted third-party text.
256
- */
257
- declare const SERVER_INSTRUCTIONS: string;
258
- interface McpServerOptions {
259
- readonly scanner: Scanner;
260
- readonly indexClient: IndexClient;
261
- readonly instructions?: string;
262
- }
263
- interface McpServer {
264
- /** True once `initialize` has been answered. */
265
- readonly initialized: boolean;
266
- /** `null` for notifications — a notification never gets a reply. */
267
- handleFrame(frame: DecodedFrame): Promise<JsonRpcResponse | null>;
268
- handleLine(line: string): Promise<JsonRpcResponse | null>;
269
- }
270
- declare function listToolsResult(): JsonObject;
271
- declare function createServer(options: McpServerOptions): McpServer;
272
-
273
- /**
274
- * deps.ts — the wiring, in one place, reading the environment exactly once.
275
- *
276
- * The rest of `src/` never touches `process`: dependencies arrive as arguments,
277
- * which is what lets the whole protocol surface be tested with a fake scanner
278
- * and a fake index client and no globals. This file is the seam, and `bin.ts`
279
- * is its only caller in production.
280
- *
281
- * TWO ENVIRONMENT VARIABLES, BOTH READ ONCE AT STARTUP:
282
- * - `REBILDER_MCP_PROBE_BUDGET` — the politeness soft cap. An env var and not a
283
- * tool argument on purpose: the person who launched the process gets to raise
284
- * it, a model reading a web page does not (design §5.2).
285
- * - `REBILDER_API_URL` — the public index base, for our own staging. Validated
286
- * to https with no credentials, and ignored otherwise.
287
- *
288
- * There is no environment variable that allows private hosts, plaintext http,
289
- * a bigger body cap, or skipping robots.txt. That is not an oversight.
290
- */
291
-
292
- interface Environment {
293
- readonly [key: string]: string | undefined;
294
- }
295
- interface ServerDependencies {
296
- readonly scanner: Scanner;
297
- readonly indexClient: IndexClient;
298
- }
299
- declare function createDependencies(env?: Environment): ServerDependencies;
300
-
301
- /**
302
- * stdio.ts — the transport. Newline-delimited JSON-RPC over stdin/stdout, which
303
- * is what `npx -y @rebilder/mcp-server` speaks when a client launches it.
304
- *
305
- * THE ONE RULE THAT BREAKS EVERYTHING WHEN BROKEN: stdout carries protocol
306
- * frames and nothing else. A stray `console.log`, a banner, a progress dot — any
307
- * of them lands mid-stream and the client's parser dies on a frame it did not
308
- * ask for. All human-facing output goes to stderr, which the client shows in its
309
- * logs. `createLineReader` is separated out so a test can prove the framing
310
- * (split lines, blank lines, a message arriving in three chunks, a UTF-8
311
- * character split across a chunk boundary) without any process at all.
312
- *
313
- * ORDERING. Frames are handled one at a time, in arrival order, by chaining onto
314
- * a promise: two `tools/call`s in flight at once would race the politeness
315
- * limiter against itself and interleave two scans' worth of requests at one
316
- * origin. Sequential is also what makes the limiter's per-host spacing mean what
317
- * it says.
318
- */
319
-
320
- interface StdioStreams {
321
- /** Async iterable of chunks — `process.stdin` satisfies this. */
322
- readonly input: AsyncIterable<Uint8Array | string>;
323
- readonly write: (text: string) => void;
324
- readonly writeError: (text: string) => void;
325
- }
326
- /**
327
- * Splits a chunk stream into complete lines. A chunk boundary can fall anywhere,
328
- * including inside a multi-byte character, which is why decoding is streaming
329
- * rather than per-chunk.
330
- */
331
- declare function createLineReader(): {
332
- push(chunk: Uint8Array | string): string[];
333
- flush(): string[];
334
- };
335
- /** One frame out, one line, no trailing prose. */
336
- declare function encodeFrame(response: JsonRpcResponse): string;
337
- /**
338
- * Runs until stdin closes. Resolves when the stream ends, so `bin.ts` can exit
339
- * cleanly rather than being killed — a client that closes the pipe is asking the
340
- * server to stop, not crashing it.
341
- */
342
- declare function serveStdio(server: McpServer, streams: StdioStreams): Promise<void>;
343
-
344
- /**
345
- * result.ts — the funnel. Every tool result in this package is built here and
346
- * nowhere else.
347
- *
348
- * THE POINT OF THE FUNNEL IS THAT FRAMING CANNOT BE FORGOTTEN. Tool handlers do
349
- * not build MCP content arrays; they return a `ToolReturn`, and `ToolReturn` is
350
- * a DISCRIMINATED UNION on `origin`. There is no default. A handler that omits
351
- * `origin` does not compile, and a handler that says `origin: 'target'` gets the
352
- * untrusted-content quarantine whether or not its author thought about it. That
353
- * is the structural version of design §5.6's requirement, as opposed to the
354
- * version where somebody remembers.
355
- *
356
- * WHERE THE LINE IS DRAWN, and it is drawn wide on purpose: `'target'` means
357
- * "any string in this result crossed a network boundary into our process". That
358
- * covers the obvious case (a scanned page's text and the check evidence derived
359
- * from it) and the less obvious one (`get_index_entry`, whose payload is served
360
- * by our own API but describes a third party). Only results assembled entirely
361
- * from this package's own constants and the caller's own arguments —
362
- * `explain_check`, `install_snippet` — are `'local'`.
363
- *
364
- * ONE TEXT BLOCK. Design §5.6: "one text block plus structuredContent". The
365
- * quarantine lives inside that single block, under a one-line trusted header
366
- * that names the tool and the source, so a client rendering only `content[0]`
367
- * still shows the notice.
368
- */
369
-
370
- interface TextContent {
371
- readonly type: 'text';
372
- readonly text: string;
373
- }
374
- /** The MCP `CallToolResult` shape, narrowed to what this server emits. */
375
- interface CallToolResult {
376
- readonly content: TextContent[];
377
- readonly structuredContent?: JsonObject;
378
- readonly isError?: boolean;
379
- }
380
- interface ToolReturnBase {
381
- /** The prose the model reads. For `'target'` returns it is quarantined. */
382
- readonly summary: string;
383
- /** Validated against the tool's declared `outputSchema`. */
384
- readonly structured: JsonObject;
385
- /** Tool-level failure: a bad target, an unreachable host, a refused policy. */
386
- readonly isError?: boolean;
387
- }
388
- interface LocalToolReturn extends ToolReturnBase {
389
- /** Assembled from this package's constants and the caller's arguments only. */
390
- readonly origin: 'local';
391
- }
392
- interface TargetToolReturn extends ToolReturnBase {
393
- /** Contains bytes that came off somebody else's socket. */
394
- readonly origin: 'target';
395
- /** URL the bytes came from. Printed on the quarantine marker. */
396
- readonly source: string;
397
- }
398
- type ToolReturn = LocalToolReturn | TargetToolReturn;
399
- declare function toCallToolResult(value: ToolReturn): CallToolResult;
400
- /** A tool-level failure with no third-party bytes in it. */
401
- declare function localFailure(summary: string, structured: JsonObject): LocalToolReturn;
402
- /**
403
- * A tool-level failure produced while talking to `source`. Used for every branch
404
- * of every scan — including the ones that failed before a byte arrived, because
405
- * "we could not reach it" and "it told us to go away" are both statements about
406
- * the target, and routing them through the same door is what keeps the door from
407
- * having exceptions.
408
- */
409
- declare function targetFailure(source: string, summary: string, structured: JsonObject): TargetToolReturn;
410
-
411
- /**
412
- * untrusted.ts — the delimiter, the notice, and the sanitiser. One helper, used
413
- * by one funnel (`./result`), so that framing cannot be forgotten by the person
414
- * adding the sixth tool.
415
- *
416
- * WHY THIS FILE IS NOT OPTIONAL. This server exists to put what a third-party
417
- * page says in front of a model. That is a prompt-injection pipe by
418
- * construction: the page author chooses the text, and the text lands in the
419
- * context of an assistant that has tools. A company whose entire product is
420
- * "what agents read" does not get to ship that unframed (design §5.6).
421
- *
422
- * WHAT FRAMING CAN AND CANNOT DO. It cannot make injected instructions safe —
423
- * no delimiter does. What it does is remove every excuse: the model is told, in
424
- * the same message, exactly which bytes are third-party and what their status
425
- * is, and the page cannot forge the end of its own quarantine.
426
- *
427
- * THE NONCE IS DERIVED FROM THE CONTENT. A fixed delimiter is escapable: the
428
- * page includes our closing marker and everything after it reads as trusted
429
- * text. Here the marker contains `sha256(source + text)`, so escaping requires
430
- * writing a page that contains the hash of itself — a preimage the author would
431
- * have to find before writing the page. `derivePreimageSafeNonce` re-derives
432
- * with a counter in the (impossible-by-construction, cheap-to-check) case that
433
- * the marker still appears, and the last resort neutralises the collision in the
434
- * text rather than emitting an escapable frame.
435
- *
436
- * SANITISATION IS PART OF FRAMING, NOT A SEPARATE NICETY. Terminal escapes can
437
- * rewrite what a human sees in their client's transcript; bidi controls can
438
- * reverse the visual order of a sentence without changing its bytes; Unicode
439
- * TAG characters (U+E0000–U+E007F) are invisible in every renderer and carry a
440
- * full ASCII alphabet, which is the standard way to hide an instruction inside
441
- * innocuous-looking prose. All three are stripped before the text is quoted,
442
- * and the notice says the text was sanitised so nobody reads a stripped page as
443
- * a faithful byte-for-byte quote.
444
- */
445
- /** The human-readable warning printed immediately above every quoted block. */
446
- declare const UNTRUSTED_NOTICE: string;
447
- interface UntrustedBlock {
448
- /** Where the bytes came from. Rendered on the BEGIN marker. */
449
- readonly source: string;
450
- readonly text: string;
451
- }
452
- /**
453
- * Strips what a renderer would not show and an attacker would use. Newlines and
454
- * tabs survive — the shape of a page is evidence, and mangling it would make the
455
- * quoted excerpt useless for the thing the user asked about.
456
- */
457
- declare function sanitizeUntrustedText(text: string): string;
458
- /** `sha256(attempt:source:text)`, truncated. Deterministic, so tests are exact. */
459
- declare function untrustedNonce(source: string, text: string, attempt?: number): string;
460
- /**
461
- * The whole quarantine: notice, BEGIN marker with the source, sanitised text,
462
- * END marker. `./result` is the only caller; nothing else in this package builds
463
- * a content string that contains third-party bytes.
464
- */
465
- declare function wrapUntrusted(block: UntrustedBlock): string;
466
-
467
- /**
468
- * schema.ts — the declared input and output schemas for the five tools.
469
- *
470
- * `outputSchema` is not decoration. A client that knows the shape of a result
471
- * can render it, diff it, and validate it; a model that gets `structuredContent`
472
- * alongside a declared schema stops re-parsing prose. Design §5.6 requires it,
473
- * and `tests/schema.test.ts` asserts that a REAL `ArsResult` — produced by
474
- * running the real probe over an injected transport and scoring the result —
475
- * validates against `ARS_RESULT_SCHEMA` key for key. That test is the point: the
476
- * schema is checked against the package, not against our memory of it, so a
477
- * MINOR bump in `@rebilder/agent-readability` that adds a field fails here
478
- * instead of silently shipping a lying schema.
479
- *
480
- * INPUT SCHEMAS ARE CLOSED (`additionalProperties: false`) AND SMALL. There is
481
- * deliberately no argument anywhere in this file that touches the politeness
482
- * limiter, the robots gate, the redirect cap, the byte cap, or private-host
483
- * access. Those are not knobs a model in a conversation gets to turn: the whole
484
- * reason `probeLocal` lives behind a separate entry point is that a config flag
485
- * eventually gets set to `true` by something reading attacker-controlled text
486
- * (design §5.2). A test asserts this file contains no such property name.
487
- */
488
-
489
- type JsonSchema = JsonObject;
490
- declare const ARS_RESULT_SCHEMA: JsonSchema;
491
-
492
- /**
493
- * tools/types.ts — what a tool is, and the argument helpers every tool shares.
494
- *
495
- * `defineTool` exists so that the registry can hold five tools with five
496
- * different argument types without an `any` anywhere: the generic is erased at
497
- * the boundary by the closure, not by a cast. `parse` returns either the typed
498
- * arguments or an `InvalidParams`, and the server turns the latter into a
499
- * JSON-RPC `-32602` — the spec's answer for a malformed call, as distinct from a
500
- * tool that ran and failed, which is an `isError` RESULT (design §5.6: "probe
501
- * failures return isError: true, never a throw").
502
- */
503
-
504
- interface ToolDeps {
505
- readonly scanner: Scanner;
506
- readonly indexClient: IndexClient;
507
- }
508
- /**
509
- * MCP tool behaviour hints. All five tools are read-only; only the three that
510
- * touch a socket are open-world. `install_snippet` and `explain_check` are
511
- * closed-world, which is the machine-readable form of "generated locally with no
512
- * network".
513
- */
514
- interface ToolAnnotations extends JsonObject {
515
- readonly title: string;
516
- readonly readOnlyHint: boolean;
517
- readonly destructiveHint: boolean;
518
- readonly idempotentHint: boolean;
519
- readonly openWorldHint: boolean;
520
- }
521
- interface InvalidParams {
522
- readonly kind: 'invalid-params';
523
- readonly message: string;
524
- }
525
- interface Tool {
526
- readonly name: string;
527
- readonly title: string;
528
- readonly description: string;
529
- readonly inputSchema: JsonSchema;
530
- readonly outputSchema: JsonSchema;
531
- readonly annotations: ToolAnnotations;
532
- invoke(args: JsonObject, deps: ToolDeps): Promise<ToolReturn | InvalidParams>;
533
- }
534
-
535
- /**
536
- * tools/index.ts — the registry. Five tools, declaration order is `tools/list`
537
- * order, and the order is chosen for a reader: scan, compare, explain, look up,
538
- * install. That is the arc of a conversation with this server, ending at the
539
- * thing that fixes the problem.
540
- */
541
-
542
- declare const TOOLS: readonly Tool[];
543
- declare function findTool(name: string): Tool | undefined;
544
-
545
- /**
546
- * render.ts — the prose a model reads. Plain text, no ANSI (this output goes
547
- * into a transcript, not a terminal), no box drawing.
548
- *
549
- * TWO RULES FROM CLAUDE.md HARD RULE 10 ARE ENFORCED HERE RATHER THAN REMEMBERED:
550
- * - every ARS number declares measured vs. heuristic, and a heuristic value
551
- * never renders without its label;
552
- * - a score is never printed without the hashes that make it reproducible.
553
- *
554
- * A third comes from §3.3: when a capture was truncated, byte figures are floors
555
- * and print as ">= N", because rendering a truncated body's size as a total
556
- * makes the heaviest pages look the cheapest on the one number this product is
557
- * built on.
558
- */
559
-
560
- /** The whole report. Callers put it through the untrusted-content funnel. */
561
- declare function formatScanSummary(result: ArsResult): string;
562
-
563
- /**
564
- * version.ts — identity constants. `SERVER_VERSION` is asserted equal to
565
- * `package.json`'s version by a test, because a server that misreports its own
566
- * version in the `initialize` handshake is worse than one that has no version
567
- * at all: clients log it and users quote it in bug reports.
568
- */
569
- declare const SERVER_NAME = "@rebilder/mcp-server";
570
- declare const SERVER_TITLE = "Rebilder \u2014 Agent Readability";
571
- declare const SERVER_VERSION = "0.2.1";
572
- /**
573
- * The MCP revision this server implements. `2025-06-18` is the revision that
574
- * introduced tool `outputSchema` and `structuredContent`, which the design
575
- * requires (§5.6), and that removed JSON-RPC batching — see `server.ts`.
576
- */
577
- declare const LATEST_PROTOCOL_VERSION = "2025-06-18";
578
- /**
579
- * Revisions we will speak if the client asks for one of them. Ordered newest
580
- * first. A client asking for anything else gets `LATEST_PROTOCOL_VERSION` back
581
- * and decides for itself whether to continue, which is what the spec prescribes.
582
- */
583
- declare const SUPPORTED_PROTOCOL_VERSIONS: readonly string[];
584
-
585
- export { ARS_RESULT_SCHEMA, type CallToolResult, DEFAULT_INDEX_BASE_URL, ERROR_CODES, type Environment, type FetchLike, INDEX_BASE_URL_ENV, type IndexClient, type IndexLookup, type JsonRpcFailure, type JsonRpcResponse, type JsonRpcSuccess, type JsonSchema, LATEST_PROTOCOL_VERSION, type McpServer, type McpServerOptions, PROBE_BUDGET_ENV, SERVER_INSTRUCTIONS, SERVER_NAME, SERVER_TITLE, SERVER_VERSION, SUPPORTED_PROTOCOL_VERSIONS, type Scanner, type ServerDependencies, type StdioStreams, TOOLS, type Tool, type ToolDeps, type ToolReturn, UNTRUSTED_NOTICE, type UntrustedBlock, createDefaultScanner, createDependencies, createIndexClient, createLineReader, createServer, decodeFrame, decodeLine, encodeFrame, failure, findTool, formatScanSummary, indexEntryUrl, isValidDomain, listToolsResult, localFailure, normalizeDomain, probeBudgetFromEnv, resolveIndexBaseUrl, sanitizeUntrustedText, serveStdio, success, targetFailure, toCallToolResult, untrustedNonce, wrapUntrusted };