import { c as SectionCatalog } from "../../sections-WxUvdqm-.js"; import { g as CollectionConfig, v as ContentConfig } from "../../rule-DYNYH_ha.js"; import { O as ResolveEditor, n as WorkerRoute } from "../../index-FUN1hqS9.js"; import { i as EditorSession, n as AgentScope, r as EditorAgent, t as AgentAccess } from "../../types-B8yzm4Q0.js"; import { t as D1Client } from "../../session-BVt9M6O0.js"; import { D as EditorRouteEnv, n as DraftSoftLocks, r as PublishDeps } from "../../versions-DF-daHUH.js"; import { SQLiteTable } from "drizzle-orm/sqlite-core"; //#region src/core/mcp/route.d.ts /** One collection the endpoint exposes: its main table and its config. */ interface McpCollection { table: SQLiteTable; config: CollectionConfig; /** * Where a collection with drafts saves them: the deps `versionsRoute` takes, * minus the table and config above. Pass the same `bufferKv`, `validate`, * `softLocks`, and `redirects` the editor uses, so an agent's edit meets the * same checks. Leave it out and the collection is read-only over MCP. * * The versions table must record provenance (`versions.provenance`, and the * migration that adds its columns), so every agent edit names its token. * `mcpRoute` throws when it doesn't. */ drafts?: Omit, "table" | "config"> & { softLocks?: DraftSoftLocks; }; } /** How the server names itself to a client. The name is the site's, so it's * yours to choose—for example, `site-example`. */ interface McpServerInfo { name: string; version: string; /** A display name, for a client that shows one. */ title?: string; } interface McpRouteConfig { /** The collections an agent may reach. A collection marked `admin.hidden` * gets no tools, as in {@link collectionTools}. */ collections: McpCollection[]; /** Resolve the editor session from the browser's cookie. A call with no * bearer token runs as this editor. */ resolveEditor: ResolveEditor; /** * Resolve an agent token to the editor it acts for, with `agent` set— * normally {@link resolveMcpSession}. Omit it and the route takes no bearer * tokens, so only a signed-in editor on the site's own origin can call it. */ resolveAgent?: ResolveEditor; /** The server's identity, sent in the handshake and on every modern result. */ server: McpServerInfo; /** * Guidance a client can put in front of the model: what the site is and how * its content is organized. Tool descriptions already say when to use each * tool, so don't repeat them here. */ instructions?: string; /** The site's section catalog, passed through to {@link collectionTools}. */ sections?: SectionCatalog; /** Mount path. Default `/api/louise/mcp`. */ path?: string; } /** * The MCP endpoint for a site's content. Mount it like any editor route; it * returns `undefined` for every path but its own, so `composeWorker` falls * through. * * ```ts * mcpRoute({ * collections: [{ table: pages, config: pagesConfig }], * resolveEditor, * server: { name: "site-example", version: "1.0.0" }, * }); * ``` */ declare function mcpRoute(config: McpRouteConfig): WorkerRoute; //#endregion //#region src/core/mcp/tokens.d.ts /** Every agent token starts with this, so a secret scanner can recognize one * that leaked into a repository or a log. */ declare const AGENT_TOKEN_PREFIX = "louise_at_"; /** How long a token lasts when its issuer doesn't say. */ declare const AGENT_TOKEN_DEFAULT_DAYS = 30; /** The longest a token may last. A token outlives its purpose more often than * it's revoked, so expiry is the control that always runs. */ declare const AGENT_TOKEN_MAX_DAYS = 90; /** The `agent_tokens` columns, to compose into your own schema. */ declare const agentTokensColumns: { /** The public ID, such as `tok_4f9c2a1b7e3d5a60`. Safe to show and log. */ id: import("drizzle-orm").IsPrimaryKey>>; /** SHA-256 of the whole token, in hex. The token itself is never stored. */ tokenHash: import("drizzle-orm").NotNull>; /** The token's last four characters, so a person can tell tokens apart. */ hint: import("drizzle-orm").NotNull>; /** What the issuer called it, such as "Claude Code on Kai's laptop". */ name: import("drizzle-orm").NotNull>; /** The editor the token acts for. */ userId: import("drizzle-orm").NotNull>; /** Collection slug to access, as JSON. */ scope: import("drizzle-orm").NotNull, Readonly>>>; createdAt: import("drizzle-orm").NotNull>; expiresAt: import("drizzle-orm").NotNull>; lastUsedAt: import("drizzle-orm/sqlite-core").SQLiteTimestampBuilderInitial<"last_used_at">; revokedAt: import("drizzle-orm/sqlite-core").SQLiteTimestampBuilderInitial<"revoked_at">; }; /** The ready-made `agent_tokens` table. Add it to the schema drizzle-kit reads, * so the migration creates it. */ declare const agentTokens: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{ name: "agent_tokens"; schema: undefined; columns: { id: import("drizzle-orm/sqlite-core").SQLiteColumn<{ name: "id"; tableName: "agent_tokens"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: true; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, { length: number | undefined; }>; tokenHash: import("drizzle-orm/sqlite-core").SQLiteColumn<{ name: "token_hash"; tableName: "agent_tokens"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, { length: number | undefined; }>; hint: import("drizzle-orm/sqlite-core").SQLiteColumn<{ name: "hint"; tableName: "agent_tokens"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, { length: number | undefined; }>; name: import("drizzle-orm/sqlite-core").SQLiteColumn<{ name: "name"; tableName: "agent_tokens"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, { length: number | undefined; }>; userId: import("drizzle-orm/sqlite-core").SQLiteColumn<{ name: "user_id"; tableName: "agent_tokens"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, { length: number | undefined; }>; scope: import("drizzle-orm/sqlite-core").SQLiteColumn<{ name: "scope"; tableName: "agent_tokens"; dataType: "json"; columnType: "SQLiteTextJson"; data: Readonly>; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; identity: undefined; generated: undefined; }, {}, { $type: Readonly>; }>; createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{ name: "created_at"; tableName: "agent_tokens"; dataType: "date"; columnType: "SQLiteTimestamp"; data: Date; driverParam: number; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; expiresAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{ name: "expires_at"; tableName: "agent_tokens"; dataType: "date"; columnType: "SQLiteTimestamp"; data: Date; driverParam: number; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; lastUsedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{ name: "last_used_at"; tableName: "agent_tokens"; dataType: "date"; columnType: "SQLiteTimestamp"; data: Date; driverParam: number; notNull: false; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; revokedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{ name: "revoked_at"; tableName: "agent_tokens"; dataType: "date"; columnType: "SQLiteTimestamp"; data: Date; driverParam: number; notNull: false; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; }; dialect: "sqlite"; }>; type AgentTokenTable = typeof agentTokens; /** A token as its owner sees it: everything but the secret and its hash. */ interface AgentTokenInfo { id: string; name: string; hint: string; scope: AgentScope; createdAt: Date; expiresAt: Date; lastUsedAt: Date | null; revokedAt: Date | null; } interface IssueAgentTokenInput { /** The editor issuing it. The token acts as them, never as anyone else. */ owner: EditorSession; /** A name the editor recognizes later, in a list or a version's history. */ name: string; /** What it may reach. Required and non-empty: there's no default scope. */ scope: AgentScope; /** Days until it expires, from 1 to {@link AGENT_TOKEN_MAX_DAYS}. Default * {@link AGENT_TOKEN_DEFAULT_DAYS}. */ expiresInDays?: number; } /** * Issue a token. Returns the token itself, which is the only time anyone sees * it, and what's stored about it. * * An agent can't issue a token: `owner` must be a person's session, so a * leaked token can't mint a longer-lived one. */ declare function issueAgentToken(d1: D1Client, input: IssueAgentTokenInput, table?: AgentTokenTable): Promise<{ token: string; info: AgentTokenInfo; }>; /** An editor's tokens, newest first, including revoked and expired ones so the * list shows what happened to each. */ declare function listAgentTokens(d1: D1Client, userId: string, table?: AgentTokenTable): Promise; /** * Revoke one of an editor's tokens. Returns false when they have no live token * with that ID, including one that belongs to someone else, so the answer * doesn't say whether another editor's token exists. */ declare function revokeAgentToken(d1: D1Client, target: { id: string; userId: string; }, table?: AgentTokenTable): Promise; /** A live token's owner and scope, as {@link verifyAgentToken} finds them. */ interface VerifiedAgentToken { id: string; name: string; userId: string; scope: AgentScope; } /** * Look a token up. Returns null when it's malformed, unknown, revoked, or * expired, without saying which: the caller answers every one of those the same * way. * * The lookup is by the token's hash, so the comparison that could leak timing * runs on a digest, never on the secret. */ declare function verifyAgentToken(d1: D1Client, token: string, table?: AgentTokenTable): Promise; /** * Whether `scope` grants `need` on the collection `slug`. A collection the * scope doesn't list is out of reach. */ declare function agentMay(scope: AgentScope, slug: string, need: AgentAccess): boolean; /** * Check a scope an issuer supplied, or one read back from D1. Returns the * scope, or a sentence saying what's wrong with it. */ declare function parseAgentScope(raw: unknown): AgentScope | string; /** * The token in a request's `Authorization: Bearer` header, or null when there's * no bearer credential. The scheme is matched without regard to case, as HTTP * requires. */ declare function bearerToken(request: Request): string | null; /** Hex SHA-256 of a token. A token carries 256 random bits, so a fast hash is * enough: there's nothing to guess that a slow one would protect. */ declare function hashAgentToken(token: string): Promise; //#endregion //#region src/core/mcp/session.d.ts interface ResolveMcpSessionConfig { /** * Re-derive the editor who owns a token, on every request, the way the * cookie path re-derives the editor from their session. Return null when * they're no longer an editor, and all their tokens stop working. * * With Louise's auth, that's `editorForUser` from `louise-toolkit/auth`, * given the same `tablePrefix` and `resolveAdmins` as `getLouiseAuth`: * * ```ts * resolveUser: (userId, env) => editorForUser(env, userId), * ``` */ resolveUser: (userId: string, env: Env) => EditorSession | null | Promise; /** The token table, if you composed your own from `agentTokensColumns`. */ table?: AgentTokenTable; } /** * A resolver for `mcpRoute`'s `resolveAgent`: the request's bearer token, as * the editor who issued it, with `agent` set to the token's name and scope. * Returns null for a request with no bearer token, and for a token that's * unknown, revoked, or expired, or whose editor has lost access. */ declare function resolveMcpSession(config: ResolveMcpSessionConfig): ResolveEditor; //#endregion //#region src/core/mcp/tokens-route.d.ts interface AgentTokensRouteConfig { /** The same cookie-session resolver the other editor routes take. */ resolveEditor: ResolveEditor; /** The collections a token's scope may name. Pass the list `mcpRoute` takes. */ collections: readonly { config: CollectionConfig; }[]; /** The token table, if you composed your own from `agentTokensColumns`. */ table?: AgentTokenTable; /** Mount path. Default `/api/louise/mcp/tokens`. */ path?: string; } /** * The editor's own tokens: * * - `GET` lists them, newest first, without their secrets. * - `POST` with `{ name, scope, expiresInDays? }` issues one, and answers `201` * with `{ token, info }`. It's the only response that ever holds the token. * - `DELETE ?id=tok_…` revokes one, and answers `204`, or `404` when the editor * has no live token with that ID. * * An editor sees and revokes only the tokens they issued. */ declare function agentTokensRoute(config: AgentTokensRouteConfig): WorkerRoute; //#endregion //#region src/core/mcp/protocol.d.ts /** The stateless revision: every request carries its version in `_meta`. */ declare const MCP_MODERN_VERSIONS: readonly ["2026-07-28"]; /** * The revisions that open with an `initialize` handshake. Served too, because * most clients in use still speak them, and a legacy client has no way to * move forward on its own. Newest first: the answer to an `initialize` asking * for a version this route doesn't know. `2024-11-05` isn't here because it * used the older HTTP+SSE transport, which this route doesn't implement. */ declare const MCP_LEGACY_VERSIONS: readonly ["2025-11-25", "2025-06-18", "2025-03-26"]; //#endregion //#region src/core/mcp/tools.d.ts /** A JSON Schema fragment. Deliberately loose: MCP passes these through to the * client verbatim, and pinning a full JSON Schema type here would buy nothing. */ type JsonSchema = Record; /** Which primitive a tool maps to, for the slices that execute them. Callers * switch on this rather than parsing {@link McpTool.name}. */ type McpToolOperation = "list" | "get" | "count" | "search" | "create" | "update_field" | "add_section" | "publish"; /** The operations that only read, which `mcpRoute` executes. */ declare const MCP_READ_OPERATIONS: readonly McpToolOperation[]; /** MCP's behavior hints for a tool. Clients treat them as hints, never as a * guarantee, so they describe the tool rather than enforce anything. */ interface McpToolAnnotations { readOnlyHint?: boolean; destructiveHint?: boolean; idempotentHint?: boolean; openWorldHint?: boolean; } /** One generated tool, in the shape `tools/list` reports it. */ interface McpTool { /** Wire name, for example, `get_pages`. Unique across a config. */ name: string; /** What the tool does and when to use it, which is what an agent reads to * choose between tools that overlap. */ description: string; /** JSON Schema for the tool's arguments. */ inputSchema: JsonSchema; annotations: McpToolAnnotations; /** The collection this acts on—not part of the MCP wire shape, but what * the route's dispatcher routes on. */ collection: string; operation: McpToolOperation; } /** Most documents a list or search call returns, and the default. */ declare const MCP_LIMIT_MAX = 100; declare const MCP_LIMIT_DEFAULT = 20; interface CollectionToolsOptions { /** * The site's section catalog. Supplying it adds `add__section` for * writable versioned collections, with `section` constrained to the catalog's * names—so an agent cannot insert a section the site does not render. * Omit it, or leave the collection without a `sections` field, and no * section tool is generated. */ sections?: SectionCatalog; } /** JSON Schema object for a field map, with `required` derived from the fields. */ /** * Fields an agent never writes. The database assigns `id`. On a collection * with drafts, `status` and `publishedVersionId` are visibility and the live * pointer, which only publish and unpublish move (ADR 0021). */ declare function reservedAgentFields(collection: CollectionConfig): ReadonlySet; /** * The MCP tools one collection exposes. * * Two `admin` hints decide the shape, reusing what the Structure Builder already * reads rather than inventing an MCP-specific visibility flag: * * - `admin.hidden` → **no tools at all**. These are system/log tables a human * never browses, so an agent has no business browsing them either. * - `admin.readOnly` → read tools only. The editor suppresses create/edit for * machine-written tables; an agent gets the same treatment. * * Write tools require `versions.drafts`, because ADR 0009 puts every agent edit * through the draft path—a collection with no version history has nowhere safe * to land one. `publish_` is generated separately from the write tools so a * token can be scoped to draft-only. * * Every description says when to use the tool as well as what it does, and * names the better tool where two overlap: an agent picks from descriptions * alone, so that sentence is the whole of its guidance. */ declare function collectionTools(collection: CollectionConfig, options?: CollectionToolsOptions): McpTool[]; /** Every tool across a content config, in collection order. */ declare function contentTools(config: ContentConfig, options?: CollectionToolsOptions): McpTool[]; //#endregion export { AGENT_TOKEN_DEFAULT_DAYS, AGENT_TOKEN_MAX_DAYS, AGENT_TOKEN_PREFIX, type AgentAccess, type AgentScope, type AgentTokenInfo, type AgentTokenTable, type AgentTokensRouteConfig, type CollectionToolsOptions, type EditorAgent, type IssueAgentTokenInput, type JsonSchema, MCP_LEGACY_VERSIONS, MCP_LIMIT_DEFAULT, MCP_LIMIT_MAX, MCP_MODERN_VERSIONS, MCP_READ_OPERATIONS, type McpCollection, type McpRouteConfig, type McpServerInfo, type McpTool, type McpToolAnnotations, type McpToolOperation, type ResolveMcpSessionConfig, type VerifiedAgentToken, agentMay, agentTokens, agentTokensColumns, agentTokensRoute, bearerToken, collectionTools, contentTools, hashAgentToken, issueAgentToken, listAgentTokens, mcpRoute, parseAgentScope, reservedAgentFields, resolveMcpSession, revokeAgentToken, verifyAgentToken };