import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import { z } from 'zod'; import type { Provenance } from '../services/provenance.js'; import { type EntityName } from '../services/schema.js'; /** * Shared `msisdn` argument. Catalogue responses are personalised per number, so * nearly every tool takes one and falls back to the session default. */ export declare const msisdnField: z.ZodOptional; /** Shared output-format switch. */ export declare const responseFormatField: z.ZodDefault>; /** Wrap a text payload as a tool result, enforcing the shared size cap. */ export declare function textResult(text: string, limit?: number): CallToolResult; /** Wrap a JSON payload as a pretty-printed tool result. */ export declare function jsonResult(data: unknown, limit?: number): CallToolResult; /** Return a failure that the calling agent can act on. */ export declare function errorResult(message: string): CallToolResult; /** * Convert any thrown value into an actionable tool error. Prefixes keep the * agent oriented: an invalid phone number and an upstream outage need * different next steps. */ export declare function handleToolError(error: unknown, context: string): CallToolResult; export interface Page { items: T[]; total: number; offset: number; limit: number; returned: number; hasMore: boolean; nextOffset: number | null; } /** Slice a list into a page and report enough context to fetch the next one. */ export declare function paginate(items: T[], offset: number, limit: number): Page; /** A one-line pagination footer for markdown output. */ export declare function paginationNote(page: Page, unit?: string): string; /** * Caller-driven field projection. * * A fixed projection is the wrong shape for a router. Returning everything * wastes tokens on fields nobody reads; returning a hand-picked subset silently * withholds fields, which is worse, because the router cannot ask for what it * does not know exists. SchemaRouter (arXiv:2608.21375) measures both: * over-fetching inflates payload and latency, under-fetching removes fields * needed to answer, and — counter to intuition — minimising the field count * dropped answer accuracy from 0.71 to 0.56 for negligible token savings. * * So the default here is recall-preserving: every declared field except the * multi-kilobyte HTML blobs, each of which is announced as a `has*` flag so its * existence is never hidden. A caller that wants a narrower payload names the * fields it wants, and the server does not second-guess it. */ export interface FieldSelection { /** Top-level field names to emit, in declaration order. */ fields: string[]; /** Sub-fields to keep inside `bonus`, or null when bonus was not selected. */ bonusFields: string[] | null; /** True when the caller named fields rather than accepting the default. */ explicit: boolean; /** Group shorthands the caller used, echoed back for transparency. */ groups: string[]; } export type FieldResolution = { ok: true; selection: FieldSelection; } | { ok: false; message: string; }; /** * Build the `fields` argument for one entity. * * The description is generated from the registry so it cannot drift from what * the projection actually accepts. */ export declare function fieldsField(entity: EntityName): z.ZodOptional>; /** * Turn the requested field list into a concrete selection. * * Groups expand to their non-heavy fields; heavy fields must be named one by * one, so a shorthand can never silently pull several kilobytes of HTML into a * response. `all` is the explicit way to ask for everything. */ export declare function resolveFieldSelection(entity: EntityName, requested?: string[]): FieldResolution; /** * Apply a selection to one record. * * Heavy fields that exist but were not selected are reported as `has` * booleans. That is the difference between withholding a field and hiding it: * a router can see that terms and conditions are available and ask for them by * name on the next call, instead of assuming they do not exist. */ export declare function projectRecord(record: Record, entity: EntityName, selection: FieldSelection): Record; /** * Character budget for one projected listing. * * Sits well under CHARACTER_LIMIT so the envelope, the selection block and the * provenance block still fit after the items do. */ export declare const LISTING_BUDGET = 24000; /** * Keep as many records as fit inside a character budget. * * A fixed item count cannot hold a listing under a size cap, because the cost * per record depends on the projection the caller asked for: the same 40 * packages are a few kilobytes when projected narrowly and past the transport * limit when projected widely. That is exactly how a wider default projection * broke the offer-group expansion once already, cutting the JSON mid-string. * Measuring the serialised size instead makes the limit hold for any selection. * * One record is always kept, so a single oversized entry surfaces with an * actionable truncation note rather than an empty result. */ export declare function fitToBudget(items: T[], budget?: number): { items: T[]; used: number; dropped: number; }; /** * Fit records into a payload whose *serialised* form provably fits the cap. * * fitToBudget above estimates: it measures compact JSON while the result is * sent pretty-printed, and pretty-printing inflates a nested record (a `bonus` * array) far more than a flat one. The estimate held for the default projection * and broke for a caller asking for `bonus`: the payload passed * CHARACTER_LIMIT, capText cut it mid-string, and the JSON stopped parsing — * with isError false, so the caller saw a successful call holding invalid JSON. * An indexer pulling the catalogue for retrieval loses that page silently. * * This measures the payload that will actually be sent, so the guarantee is * exact rather than calibrated. The binary search costs a handful of * serialisations, which is nothing next to the upstream request that produced * the records. */ export declare function fitPayload(records: T[], build: (kept: T[]) => Record, wrap?: (payload: Record) => Record, limit?: number): { kept: T[]; dropped: number; payload: Record; size: number; }; /** Apply a selection to a list of records. */ export declare function projectList(records: Record[], entity: EntityName, selection: FieldSelection): Record[]; /** Report the selection back to the caller so a plan can be reproduced exactly. */ export declare function selectionMeta(selection: FieldSelection, entity: EntityName): Record; /** Standard JSON envelope: data, the fields actually returned, and provenance. */ export declare function routedResult(data: Record, selection: FieldSelection, entity: EntityName, provenance: Provenance): CallToolResult;