import { Server } from 'node:http'; import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; /** * Publish ONE agentproto app as a standalone MCP App server: the app's own * bundled tools (`.agentproto/tools//TOOL.md` run through its * `.agentproto/drivers/*\/DRIVER.md` via AIP-30 `runTool`) plus its UI as a * `ui://` resource. No daemon behind it and no other tool: unlike the daemon * gateway (local-trust by design), this is the surface that may face the * public internet, so it serves exactly the app's declared `ui.tools`, and * refuses any of them that is not one of the app's own bundled tools. * * Multi-tenant: `startAppMcpHttp({ tenants })` serves `/mcp/`, each * tenant with its own resolved secrets (e.g. one shop's API key per tenant). * * NO BUILT-IN AUTHENTICATION. Anyone who can reach the port can call the * served tools with the (tenant's) secrets. The tenant slug in the URL only * SELECTS which secrets apply; it is not a credential and must not be treated * as one. For anything beyond loopback, put a front proxy in front that * terminates TLS and authenticates the caller (and maps caller -> tenant slug). * * Built-in hardening: Host/Origin are checked against an allowlist when bound * to loopback (DNS-rebinding guard) or when `allowedHosts` is set, request * bodies are capped (`maxBodyBytes`), and only POST is served. */ interface PublishedApp { readonly appId: string; readonly version: string; /** The `ui://…/view` uri the rendering tools point at. */ readonly resourceUri: string; /** The tool ids served (the app's `ui.tools`). */ readonly toolIds: readonly string[]; /** Secret names the app declares (`requirements.secrets`). */ readonly secretNames: readonly string[]; /** Build a fresh McpServer (the stateless HTTP transport is single-use, * so every request gets its own server). */ build(secrets?: Record): McpServer; } declare function loadPublishedApp(dir: string): Promise; interface StartAppMcpHttpOptions { app: PublishedApp; /** 0 or omitted = auto-assign. */ port?: number; /** Default 127.0.0.1. Put a TLS reverse proxy in front for public use. */ host?: string; /** Single-tenant secrets, served at `/mcp`. Ignored when `tenants` is set. */ secrets?: Record; /** Multi-tenant: tenant slug → its secrets, served at `/mcp/`. */ tenants?: Record>; /** * Hostnames (no port) accepted in the `Host` header and, when present, the * `Origin` header. Defaults to the loopback names when bound to a loopback * address; when bound elsewhere and unset, no Host/Origin check is applied * (the front proxy owns that). DNS-rebinding guard. */ allowedHosts?: readonly string[]; /** Max request body in bytes (default 1 MiB). Larger → 413. */ maxBodyBytes?: number; } interface AppMcpHttpHandle { readonly url: string; readonly server: Server; close(): Promise; } declare function isValidTenantSlug(slug: string): boolean; declare function startAppMcpHttp(opts: StartAppMcpHttpOptions): Promise; export { type AppMcpHttpHandle, type PublishedApp, type StartAppMcpHttpOptions, isValidTenantSlug, loadPublishedApp, startAppMcpHttp };