@apideck/docs-mcp
Version:
MCP server that lets agents search and retrieve your documentation at query time instead of relying on stale training data.
61 lines • 2.42 kB
TypeScript
/**
* WebMCP bridge: registers the docs server's tools with the browser
* (`document.modelContext`) so an agent on a docs page can search and read
* the docs through structured tool calls instead of scraping the page.
*
* Runs in the browser and has no Node dependencies. Tool names, schemas and
* annotations come from the server's `tools/list` at page load, so
* `extraTools` a host registers on the server show up here too. Every call is
* forwarded to the server's Streamable HTTP endpoint with `X-MCP-Client:
* webmcp`, which `onToolCall` reports as the caller.
*
* WebMCP is experimental (Chrome 149+, behind a flag or origin trial). Where
* `document.modelContext` is missing, registration is a no-op.
*/
/** The subset of the WebMCP tool definition this bridge uses. */
export interface WebMcpTool {
name: string;
description: string;
inputSchema: Record<string, unknown>;
execute: (inputs: Record<string, unknown>, ctx?: {
signal?: AbortSignal;
}) => Promise<string>;
annotations?: {
readOnlyHint?: boolean;
untrustedContentHint?: boolean;
consequentialHint?: boolean;
};
}
export interface ModelContext {
registerTool: (tool: WebMcpTool, opts?: {
signal?: AbortSignal;
}) => Promise<void> | void;
}
export interface RegisterDocsToolsOptions {
/** URL of the docs MCP endpoint, e.g. "/mcp" on the same origin. */
endpoint: string;
/** Extra request headers, e.g. a token for a gated endpoint. */
headers?: Record<string, string>;
/**
* Also register `read_current_page`, which returns the page the agent is
* on via get_doc with `location.href`. Needs pages to have public URLs
* (`--base-url` or the `metadata` hook). Default true.
*/
currentPageTool?: boolean;
/** Only register these server tools (by name). Default: all of them. */
tools?: string[];
/** Overrides for tests or non-standard hosts. */
modelContext?: ModelContext;
fetch?: typeof fetch;
location?: {
href: string;
};
}
export interface RegisteredDocsTools {
/** Names of the tools registered with the browser; empty when WebMCP is unavailable. */
tools: string[];
/** Unregisters every tool. */
unregister: () => void;
}
export declare const registerDocsTools: (opts: RegisterDocsToolsOptions) => Promise<RegisteredDocsTools>;
//# sourceMappingURL=webmcp.d.ts.map