/** * Console-script CLI builder shared by every TypeScript MCP server. * * TS counterpart of `mcp_core.build_cli` (core-py). `buildCli` wraps a * server's existing `serve(argv) -> number | void` entry point with * subcommand dispatch, without changing that entry point's behaviour for the * two invocation shapes it already handles: * * - Bare invocation (`argv` empty) still means "start the server". * - Any flag-prefixed argv (`--http` etc.) is passed through to `serve` * byte-for-byte, so existing `--http` semantics are untouched -- except * `-h`/`--help` (always) and `--version`/`-V` (only when `version` is set), * which are intercepted here and never reach `serve`. Starting the server on * those would hang in stdio mode instead of printing the requested output. * * A leading *positional* argv[0] is treated as a subcommand name -- either one * of the reserved built-ins (`config`/`relay`/`doctor`) or a server-specific * one supplied via `extra` -- and is routed to its handler instead of `serve`. * STDOUT is the MCP protocol channel in stdio mode, so only this subcommand * path prints to stdout; the `serve` path never touches stdout here. * * Built-in output convention: informational results (configured/not * configured, session details, doctor's `[ok]`/`[warn]`/`[fail]` lines) go to * stdout (`console.log`); failures and prompts (no active session, refused * delete, corrupt config) go to stderr (`console.error`) alongside a non-zero * return code. Credential *values* are never printed by any built-in -- only * names/keys/status. */ /** A server's start entry point. Returns an exit code, or nothing for 0. */ export type ServeFn = (argv: string[]) => number | void | Promise; /** * A subcommand handler. Receives the argv that follows the subcommand name * (e.g. for `config status --yes` the handler gets `['status', '--yes']`) and * returns the process exit code. */ export type CliHandler = (argv: string[]) => number | Promise; export interface BuildCliOptions { /** The server's start entry point (bare/flag argv routes here). */ serve: ServeFn; /** * Server-specific subcommands. A name here overrides the reserved built-in * of the same name (`config`/`relay`/`doctor`), so a server can supply its * own handler. */ extra?: Record; /** Powers `--version`/`-V`. When unset, those flags fall through to serve. */ version?: string; /** * Credential storage plugin slug (e.g. `"wet"`): decides where `config` and * `doctor` read/write via `PerPluginStore`. Servers save credentials under * this slug, not the console name, so the two must not be conflated. When * omitted it defaults to `serverName` with a trailing `"-mcp"` stripped, * which matches the wet/mnemo/crg convention; pass it explicitly when the * slug differs (telegram saves under `"telegram"` though its console name * is `"better-telegram-mcp"`). */ pluginName?: string; } /** * Build the console-script entry point for one MCP server. * * `serverName` is the console/display name (e.g. `"wet-mcp"`): it names the * program in help/usage and status lines, and keys relay session state and * run mode (which servers store under their `SERVER_NAME`). * * `options.pluginName` is the credential storage slug that `PerPluginStore` * keys on (e.g. `"wet"`): it decides where `config` and `doctor` read/write * credentials. Servers save creds under this slug, not under the console * name, so the two must not be conflated. When omitted it defaults to * `serverName` with a trailing `"-mcp"` stripped, which matches the wet/ * mnemo/crg convention; pass it explicitly when the slug differs (telegram * saves under `"telegram"` though its console name is `"better-telegram-mcp"`). * * `extra` subcommand names take precedence over the reserved built-ins, so a * server (or a test) can supply its own `doctor`/`config`/`relay` handler. * `version`, when set, powers `--version`/`-V` (handled before `serve` or any * subcommand runs); when unset, `--version`/`-V` falls through to `serve` like * any other flag. * * The returned `run(argv)` resolves to the process exit code. A server's entry * point calls it and exits: `buildCli(name, opts)(process.argv.slice(2)).then((c) => process.exit(c))`. */ export declare function buildCli(serverName: string, options: BuildCliOptions): (argv?: string[] | null) => Promise; //# sourceMappingURL=build-cli.d.ts.map