// Public surface of @napster-corp/edge-mcp. // // Importing this module, in a browser, does two things as an intentional side // effect (see package.json `sideEffects`): // 1. Guarantees `document.modelContext` exists AND is our annotation-carrying // implementation, via the vendored WebMCP polyfill. Installed // unconditionally: a pre-existing native or foreign implementation is // replaced (current native surfaces drop tool annotations from getTools() // and reject foreign tool objects in executeTool()); only a re-import of // this same fork is a no-op. // 2. Installs the MCP-shaped live-state resource extension onto it. // // Outside a browser (SSR, workers, edge runtimes) it does nothing and touches no // globals. The website developer writes STANDARD WebMCP — `document.modelContext // .registerTool(...)` with standard `annotations` — and never a Napster-specific // method. Safety levels are expressed with the standard annotation hints // (readOnlyHint / destructiveHint / idempotentHint / untrustedContentHint), not a // proprietary tier API. Our remaining value-adds (live state, dev tooling) live // off the call site, below. import { initializeWebMCPPolyfill } from './webmcp-polyfill/index.js'; import { getModelContext, isBrowserEnvironment } from './model-context.js'; import { installResourceExtension } from './resources.js'; import { debugLog } from './debug.js'; if (isBrowserEnvironment()) { // Guarantee the standard surface. The polyfill is vendored in // ./webmcp-polyfill (forked from @mcp-b/webmcp-polyfill 3.0.0) so we control // the version and carry the annotations-in-getTools() fix. Installs // unconditionally — a native or foreign occupant at document.modelContext is // replaced (native drops annotations and rejects foreign tool objects); only // our own prior install is left in place, so double imports / HMR are safe. initializeWebMCPPolyfill(); const mc = getModelContext(); if (mc) { installResourceExtension(mc); debugLog('document.modelContext ready (polyfill) + resource extension installed'); } } // ---- Standard-surface adapter (the single swap point) ---- export { getModelContext, getModelContextWithResources, isBrowserEnvironment, registerTool, } from './model-context.js'; // ---- Opt-in flow logging (off by default) ---- export { setDebug } from './debug.js'; // ---- Value-add: live state (MCP-shaped resource extension) ---- export { installResourceExtension, registerResource } from './resources.js'; // ---- Types ---- export type { // standard WebMCP surface ModelContext, ModelContextWithResources, ToolAnnotations, ToolContent, ToolResult, ToolDescriptor, ToolInfo, // resources ResourceDescriptor, ResourceInfo, ResourceUpdate, ResourceExtension, } from './types.js';