import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import { z } from 'zod'; import { type AnyOperation } from './operation.js'; /** * Everything that makes a service a service, independent of how it is started: * its identity, its operations, and how to build an authenticated client for an * account. The stdio bin (`server()`) and the shared HTTP host (`src/host`) both * consume this shape, so one definition serves both transports. */ export type ServiceDefinition = { /** MCP server name (the service, e.g. 'gmail'). */ name: string; /** Server version; defaults to the package version. */ version?: string; /** * Human-readable server name for client UIs (MCP `Implementation.title`). * `description` and `websiteUrl` postdate the 2025-06-18 `Implementation` * (the shipped SDK carries them); clients that predate them ignore them. * @see https://modelcontextprotocol.io/specification/2025-06-18/schema (Implementation) */ title?: string; /** One-line server summary for client UIs (MCP `Implementation.description`). */ description?: string; /** Project URL for client UIs (MCP `Implementation.websiteUrl`); defaults to the package homepage. */ websiteUrl?: string; /** * Usage notes served in the MCP initialize result (`InitializeResult.instructions`); * clients typically inject this into the agent's context at connect time, * making it the primary server-authored channel for usage guidance (support * varies by client; it is a hint, like the tool annotations). * @see https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle */ instructions?: string; /** Every operation this server exposes, keyed by wire name (tools and methods merged). */ operations: Record>; /** Build the authenticated client for the account this instance is bound to. */ client: (account: string | undefined) => Promise; /** Optional consent flow, invoked by the `auth` subcommand. */ runAuth?: (account: string | undefined) => Promise; /** * Certify an error as stale stored credentials (e.g. OAuth `invalid_grant`). * A certified failure rebuilds the client from disk, so a re-auth heals a * running instance, and retries once only when the operation's annotations * make a second attempt safe (read-only or idempotent); otherwise the error * envelope tells the agent to retry. Typed like `runAuth`: the auth layer * supplies the predicate, this generic layer never inspects error shapes. */ staleCredentials?: (error: unknown) => boolean; }; export type ServerOptions = ServiceDefinition & { /** Transport to connect; defaults to stdio. Injectable for tests. */ transport?: Transport; }; /** * Build the MCP `tools/list` payload from the operations: each one's input and * output JSON Schema, the four-hint annotations quad declared on its * definition, and the source reference page under `_meta[SOURCE_META_KEY]`. * On the wire, every operation is a "tool" (MCP has no other word). Pure; * exported for tests. */ export declare function toolDefinitions(operations: Record>): { name: string; description: string; inputSchema: z.core.ZodStandardJSONSchemaPayload>; outputSchema: z.core.ZodStandardJSONSchemaPayload>; annotations: import("./operation.js").OperationAnnotations; _meta: { "com.simiancraft.google-mcp/source": `https://${string}`; }; }[]; /** * Run one operation by name: resolve it, validate input against its schema, run * the handler, validate the output, and return both a structured result and a text * rendering (for clients that do not yet read `structuredContent`). All failure * paths return an `isError` result rather than throwing, with one exception: * a handler error that `rethrows` certifies escapes untouched, so the * credential-healing layer in `createServer()` can see it typed rather than * flattened into envelope text. Exported for tests. */ export declare function callOperation(operations: Record>, client: Client, name: string, rawArgs: unknown, rethrows?: (error: unknown) => boolean): Promise; /** * Wire a service definition into an MCP `Server` bound to one account: the * `tools/list` payload, dispatch, validation, error wrapping, and * stale-credential healing. Transport-agnostic and not yet connected: the * stdio runner (`server()`) connects it to stdio, and the shared HTTP host * builds one per client session. The client is built up front, so a missing * or unreadable token surfaces here, before anything is served. */ export declare function createServer(definition: ServiceDefinition, account: string | undefined): Promise; /** * Turn a service definition into a running stdio MCP server bound to the * `GOOGLE_MCP_ACCOUNT` account. Identical for every service; only the bound * `Client` type and the operations differ. Owns the process-level concerns * (the `auth` subcommand and the account env var); `createServer()` owns the * protocol wiring. */ export declare function server(options: ServerOptions): Promise; //# sourceMappingURL=server.d.ts.map