@rebilder/mcp-server 0.3.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ProbeOutcome } from '@rebilder/agent-readability/probe';
2
- import { ArsVantage, ArsResult } from '@rebilder/agent-readability';
2
+ import { ArsVantage, ArsEvidence, ArsResult } from '@rebilder/agent-readability';
3
3
 
4
4
  /**
5
5
  * json.ts — the JSON value type everything on the wire is expressed in, and the
@@ -95,35 +95,32 @@ declare function decodeFrame(value: JsonValue): DecodedFrame;
95
95
  declare function decodeLine(line: string): DecodedFrame;
96
96
 
97
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.
98
+ * index-client.ts — the Rebilder API client, and the only file in `src/` allowed
99
+ * to reference `fetch` (see `eslint.config.mjs`).
100
+ *
101
+ * By default (no `REBILDER_API_KEY` set), the only call this module makes to
102
+ * Rebilder is a READ of our public index: `GET /api/public/index/<domain>`.
103
+ * It sends no scan, no URL the user asked about, no page content, no hostname
104
+ * other than the domain the caller explicitly asked to look up, and no
105
+ * identifier of any kind — and it NEVER attaches `Authorization` even when an
106
+ * API key is configured.
107
+ *
108
+ * When `REBILDER_API_KEY` is explicitly configured, `listSiteFixes` and
109
+ * `verifyFix` send Bearer-authenticated requests to `/v1/site-fixes` and
110
+ * `/v1/site-fixes/verify` on `REBILDER_API_URL`. When `REBILDER_API_KEY` is
111
+ * unset, both methods return `{ kind: 'unauthenticated' }` without touching
112
+ * the network.
119
113
  */
120
114
 
121
115
  declare const DEFAULT_INDEX_BASE_URL = "https://rebilder.com";
122
116
  declare const INDEX_BASE_URL_ENV = "REBILDER_API_URL";
117
+ declare const API_KEY_ENV = "REBILDER_API_KEY";
118
+ declare const DEFAULT_VERIFY_TIMEOUT_MS = 15000;
123
119
  /** Structural: the subset of `fetch` used here, so tests need no globals. */
124
120
  type FetchLike = (url: string, init: {
125
- method: 'GET';
121
+ method: 'GET' | 'POST';
126
122
  headers: Record<string, string>;
123
+ body?: string;
127
124
  signal: AbortSignal;
128
125
  redirect: 'error';
129
126
  }) => Promise<{
@@ -142,9 +139,85 @@ type IndexLookup = {
142
139
  url: string;
143
140
  detail: string;
144
141
  };
142
+ interface ListSiteFixesParams {
143
+ readonly limit?: number;
144
+ readonly band?: string;
145
+ readonly platform?: string;
146
+ }
147
+ interface SiteFixItem {
148
+ readonly fixId: string;
149
+ readonly rank: number;
150
+ readonly band: string;
151
+ readonly title: string;
152
+ readonly summary: string;
153
+ readonly tierRequired: string;
154
+ readonly status: string;
155
+ readonly targetUrl: string | null;
156
+ readonly prompt: string | null;
157
+ readonly acceptanceCriteria: readonly string[];
158
+ readonly basis: string;
159
+ }
160
+ interface SiteFixesResponse {
161
+ readonly storeId: string;
162
+ readonly domain: string;
163
+ readonly plan: string;
164
+ readonly totalCount: number;
165
+ readonly fixes: readonly SiteFixItem[];
166
+ }
167
+ type ApiFailureCode = 'unauthorized' | 'forbidden' | 'not-found' | 'bad-request' | 'client-error' | 'server-error' | 'network-error' | 'invalid-response';
168
+ type SiteFixesResult = {
169
+ readonly kind: 'ok';
170
+ readonly url: string;
171
+ readonly data: SiteFixesResponse;
172
+ } | {
173
+ readonly kind: 'unauthenticated';
174
+ } | {
175
+ readonly kind: 'failed';
176
+ readonly url: string;
177
+ readonly status: number | null;
178
+ readonly code: ApiFailureCode;
179
+ readonly detail: string;
180
+ };
181
+ interface VerifyFixParams {
182
+ readonly fixId: string;
183
+ readonly url?: string;
184
+ }
185
+ interface VerifyFixCheck {
186
+ readonly name: string;
187
+ readonly passed: boolean;
188
+ readonly detail: string;
189
+ }
190
+ interface VerifyFixIndexNow {
191
+ readonly status: string;
192
+ readonly submittedCount: number;
193
+ }
194
+ interface VerifyFixResponse {
195
+ readonly fixId: string;
196
+ readonly url: string;
197
+ readonly verified: boolean;
198
+ readonly checkedAt: string;
199
+ readonly checks: readonly VerifyFixCheck[];
200
+ readonly indexNow?: VerifyFixIndexNow;
201
+ }
202
+ type VerifyFixResult = {
203
+ readonly kind: 'ok';
204
+ readonly url: string;
205
+ readonly data: VerifyFixResponse;
206
+ } | {
207
+ readonly kind: 'unauthenticated';
208
+ } | {
209
+ readonly kind: 'failed';
210
+ readonly url: string;
211
+ readonly status: number | null;
212
+ readonly code: ApiFailureCode;
213
+ readonly detail: string;
214
+ };
145
215
  interface IndexClient {
146
216
  readonly baseUrl: string;
217
+ readonly hasApiKey: boolean;
147
218
  lookup(domain: string): Promise<IndexLookup>;
219
+ listSiteFixes(params?: ListSiteFixesParams): Promise<SiteFixesResult>;
220
+ verifyFix(params: VerifyFixParams): Promise<VerifyFixResult>;
148
221
  }
149
222
  /**
150
223
  * A registrable domain and nothing else: labels of 1–63 chars from
@@ -162,10 +235,15 @@ declare function normalizeDomain(value: string): string;
162
235
  * back to production rather than being honoured quietly.
163
236
  */
164
237
  declare function resolveIndexBaseUrl(raw: string | undefined): string;
238
+ declare function resolveApiKey(raw: string | undefined): string | undefined;
165
239
  declare function indexEntryUrl(baseUrl: string, domain: string): string;
240
+ declare function siteFixesUrl(baseUrl: string, params?: ListSiteFixesParams): string;
241
+ declare function verifyFixUrl(baseUrl: string): string;
166
242
  interface IndexClientOptions {
167
243
  readonly baseUrl?: string;
244
+ readonly apiKey?: string;
168
245
  readonly timeoutMs?: number;
246
+ readonly verifyTimeoutMs?: number;
169
247
  /** Injected in tests. Defaults to the platform `fetch`. */
170
248
  readonly fetchImpl?: FetchLike;
171
249
  }
@@ -198,8 +276,10 @@ declare function createIndexClient(options?: IndexClientOptions): IndexClient;
198
276
  *
199
277
  * The budget is a SOFT cap: one MCP session is one "run", and a session that
200
278
  * 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.
279
+ * scans (§3.3 sends five requests per URL, six since ARS 0.3 when the page
280
+ * links a Markdown copy instead of sending one), so the default is low enough
281
+ * to bound an accident and the error message says exactly how to raise it. The
282
+ * floor is one cold scan of the larger kind.
203
283
  */
204
284
 
205
285
  interface Scanner {
@@ -281,12 +361,15 @@ declare function createServer(options: McpServerOptions): McpServer;
281
361
  * and a fake index client and no globals. This file is the seam, and `bin.ts`
282
362
  * is its only caller in production.
283
363
  *
284
- * TWO ENVIRONMENT VARIABLES, BOTH READ ONCE AT STARTUP:
364
+ * THREE ENVIRONMENT VARIABLES, ALL READ ONCE AT STARTUP:
285
365
  * - `REBILDER_MCP_PROBE_BUDGET` — the politeness soft cap. An env var and not a
286
366
  * tool argument on purpose: the person who launched the process gets to raise
287
367
  * it, a model reading a web page does not (design §5.2).
288
- * - `REBILDER_API_URL` — the public index base, for our own staging. Validated
289
- * to https with no credentials, and ignored otherwise.
368
+ * - `REBILDER_API_URL` — the Rebilder API base, for staging. Validated to
369
+ * https with no credentials, query, or fragment, and ignored otherwise.
370
+ * - `REBILDER_API_KEY` — optional store API key for authenticated fix-loop
371
+ * tools (`list_site_fixes`, `verify_fix`). When unset, local tools and
372
+ * `get_index_entry` remain credential-free.
290
373
  *
291
374
  * There is no environment variable that allows private hosts, plaintext http,
292
375
  * a bigger body cap, or skipping robots.txt. That is not an oversight.
@@ -468,7 +551,7 @@ declare function untrustedNonce(source: string, text: string, attempt?: number):
468
551
  declare function wrapUntrusted(block: UntrustedBlock): string;
469
552
 
470
553
  /**
471
- * schema.ts — the declared input and output schemas for the five tools.
554
+ * schema.ts — the declared input and output schemas for the eight tools.
472
555
  *
473
556
  * `outputSchema` is not decoration. A client that knows the shape of a result
474
557
  * can render it, diff it, and validate it; a model that gets `structuredContent`
@@ -491,6 +574,12 @@ declare function wrapUntrusted(block: UntrustedBlock): string;
491
574
 
492
575
  type JsonSchema = JsonObject;
493
576
  declare const ARS_RESULT_SCHEMA: JsonSchema;
577
+ declare const CHECK_DOCS_INPUT: JsonSchema;
578
+ declare const LIST_SITE_FIXES_INPUT: JsonSchema;
579
+ declare const VERIFY_FIX_INPUT: JsonSchema;
580
+ declare const CHECK_DOCS_OUTPUT: JsonSchema;
581
+ declare const LIST_SITE_FIXES_OUTPUT: JsonSchema;
582
+ declare const VERIFY_FIX_OUTPUT: JsonSchema;
494
583
 
495
584
  /**
496
585
  * tools/types.ts — what a tool is, and the argument helpers every tool shares.
@@ -536,10 +625,87 @@ interface Tool {
536
625
  }
537
626
 
538
627
  /**
539
- * tools/index.ts — the registry. Five tools, declaration order is `tools/list`
540
- * order, and the order is chosen for a reader: scan, compare, explain, look up,
541
- * install. That is the arc of a conversation with this server, ending at the
542
- * thing that fixes the problem.
628
+ * tools/check-docs.ts — "can a coding agent follow this docs page without getting stuck?"
629
+ *
630
+ * Uses `deps.scanner.scan(url, vantage)` — which routes exclusively through
631
+ * `probeStrict` with the mandatory politeness limiter and never imports
632
+ * `./probe/local`. Everything runs locally on the user's machine with zero
633
+ * telemetry: nothing is uploaded to Rebilder, no packages are installed, and
634
+ * no code is executed.
635
+ *
636
+ * Every byte derived from the fetched documentation page is returned with
637
+ * `origin: 'target'`, so `result.ts` automatically wraps the text summary in
638
+ * the content-nonce untrusted-content quarantine.
639
+ */
640
+
641
+ type DocsFindingSeverity = 'blocking' | 'should-fix' | 'passed';
642
+ type DocsFindingCheck = 'fetch' | 'install' | 'code' | 'auth' | 'freshness';
643
+ interface DocsFinding {
644
+ readonly id: string;
645
+ readonly check: DocsFindingCheck;
646
+ readonly severity: DocsFindingSeverity;
647
+ readonly title: string;
648
+ readonly detail: string;
649
+ readonly evidence: readonly string[];
650
+ readonly fix: string | null;
651
+ }
652
+ interface DocsRetrievalSummary {
653
+ readonly browserStatus: number | null;
654
+ readonly agentStatus: number | null;
655
+ readonly agentContentType: string | null;
656
+ readonly markdown: 'negotiated' | 'alternate' | 'none';
657
+ readonly markdownUrl: string | null;
658
+ readonly serverHtmlCodeBlocks: number;
659
+ readonly llmsTxt: 'links-page' | 'links-section' | 'no-link' | 'missing' | 'unavailable';
660
+ }
661
+ interface DocsCheckReport {
662
+ readonly url: string;
663
+ readonly finalUrl: string;
664
+ readonly checkedAt: string;
665
+ readonly verdict: 'can-follow' | 'likely-stuck';
666
+ readonly stuckAt: readonly string[];
667
+ readonly analyzedSource: 'markdown' | 'html';
668
+ readonly 'fetch': DocsRetrievalSummary;
669
+ readonly installManagers: readonly string[];
670
+ readonly blocking: readonly DocsFinding[];
671
+ readonly shouldFix: readonly DocsFinding[];
672
+ readonly passed: readonly DocsFinding[];
673
+ readonly findings: readonly DocsFinding[];
674
+ readonly scope: string;
675
+ readonly untrustedContentNotice: string;
676
+ }
677
+ declare function analyzeDocsEvidence(evidence: ArsEvidence, checkedAt: Date): DocsCheckReport;
678
+
679
+ /**
680
+ * tools/list-site-fixes.ts — fetch the merchant's ranked `/console/fix` queue.
681
+ *
682
+ * Opt-in and authenticated via `REBILDER_API_KEY`. When `REBILDER_API_KEY` is
683
+ * unset, this tool fails locally with actionable setup guidance without making
684
+ * any network call, preserving zero-credential local operation for all other
685
+ * tools.
686
+ *
687
+ * Results cross a network boundary and include fields derived from observed
688
+ * site crawls and prompts, so every response (and API failure) routes through
689
+ * `origin: 'target'` untrusted-content quarantine.
690
+ */
691
+
692
+ declare const listSiteFixesTool: Tool;
693
+
694
+ /**
695
+ * tools/verify-fix.ts — trigger independent live URL re-verification for a fix.
696
+ *
697
+ * Opt-in and authenticated via `REBILDER_API_KEY`. Validates `fixId` and any
698
+ * optional `url` syntactically before checking credentials or making a network
699
+ * request. Live-fetched check details come from the target origin and are
700
+ * quarantined with `origin: 'target'`.
701
+ */
702
+
703
+ declare const verifyFixTool: Tool;
704
+
705
+ /**
706
+ * tools/index.ts — the registry. Eight tools, declaration order is `tools/list`
707
+ * order: local scan, compare, docs, explain, public index lookup, install
708
+ * snippet, and opt-in authenticated fix queue + live verification.
543
709
  */
544
710
 
545
711
  declare const TOOLS: readonly Tool[];
@@ -549,7 +715,7 @@ declare function findTool(name: string): Tool | undefined;
549
715
  * render.ts — the prose a model reads. Plain text, no ANSI (this output goes
550
716
  * into a transcript, not a terminal), no box drawing.
551
717
  *
552
- * TWO RULES FROM CLAUDE.md HARD RULE 10 ARE ENFORCED HERE RATHER THAN REMEMBERED:
718
+ * TWO ARS REPORTING RULES ARE ENFORCED HERE RATHER THAN REMEMBERED:
553
719
  * - every ARS number declares measured vs. heuristic, and a heuristic value
554
720
  * never renders without its label;
555
721
  * - a score is never printed without the hashes that make it reproducible.
@@ -563,15 +729,9 @@ declare function findTool(name: string): Tool | undefined;
563
729
  /** The whole report. Callers put it through the untrusted-content funnel. */
564
730
  declare function formatScanSummary(result: ArsResult): string;
565
731
 
566
- /**
567
- * version.ts — identity constants. `SERVER_VERSION` is asserted equal to
568
- * `package.json`'s version by a test, because a server that misreports its own
569
- * version in the `initialize` handshake is worse than one that has no version
570
- * at all: clients log it and users quote it in bug reports.
571
- */
572
732
  declare const SERVER_NAME = "@rebilder/mcp-server";
573
733
  declare const SERVER_TITLE = "Rebilder \u2014 Agent Readability";
574
- declare const SERVER_VERSION = "0.3.0";
734
+ declare const SERVER_VERSION = "0.5.0";
575
735
  /**
576
736
  * The newest MCP revision this server implements. `2025-06-18` introduced tool
577
737
  * `outputSchema` and `structuredContent`, which the design requires (§5.6), and
@@ -595,4 +755,4 @@ declare const LATEST_PROTOCOL_VERSION = "2025-11-25";
595
755
  */
596
756
  declare const SUPPORTED_PROTOCOL_VERSIONS: readonly string[];
597
757
 
598
- 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 };
758
+ export { API_KEY_ENV, ARS_RESULT_SCHEMA, type ApiFailureCode, CHECK_DOCS_INPUT, CHECK_DOCS_OUTPUT, type CallToolResult, DEFAULT_INDEX_BASE_URL, DEFAULT_VERIFY_TIMEOUT_MS, type DocsCheckReport, type DocsFinding, type DocsFindingCheck, type DocsFindingSeverity, type DocsRetrievalSummary, ERROR_CODES, type Environment, type FetchLike, INDEX_BASE_URL_ENV, type IndexClient, type IndexClientOptions, type IndexLookup, type JsonRpcFailure, type JsonRpcResponse, type JsonRpcSuccess, type JsonSchema, LATEST_PROTOCOL_VERSION, LIST_SITE_FIXES_INPUT, LIST_SITE_FIXES_OUTPUT, type ListSiteFixesParams, type McpServer, type McpServerOptions, PROBE_BUDGET_ENV, SERVER_INSTRUCTIONS, SERVER_NAME, SERVER_TITLE, SERVER_VERSION, SUPPORTED_PROTOCOL_VERSIONS, type Scanner, type ServerDependencies, type SiteFixItem, type SiteFixesResponse, type SiteFixesResult, type StdioStreams, TOOLS, type Tool, type ToolDeps, type ToolReturn, UNTRUSTED_NOTICE, type UntrustedBlock, VERIFY_FIX_INPUT, VERIFY_FIX_OUTPUT, type VerifyFixCheck, type VerifyFixIndexNow, type VerifyFixParams, type VerifyFixResponse, type VerifyFixResult, analyzeDocsEvidence, createDefaultScanner, createDependencies, createIndexClient, createLineReader, createServer, decodeFrame, decodeLine, encodeFrame, failure, findTool, formatScanSummary, indexEntryUrl, isValidDomain, listSiteFixesTool, listToolsResult, localFailure, normalizeDomain, probeBudgetFromEnv, resolveApiKey, resolveIndexBaseUrl, sanitizeUntrustedText, serveStdio, siteFixesUrl, success, targetFailure, toCallToolResult, untrustedNonce, verifyFixTool, verifyFixUrl, wrapUntrusted };