/** * Type definitions for utility functions */ import type { ZodRawShape } from 'zod'; /** * The values an argument accepts beyond its primitive type. Compiled into the * tool's input schema (`src/tools/toolSchema.ts`), so it is enforced on * `tools/call`, advertised on `tools/list` (`enum` / `pattern` / `integer` + * `minimum`/`maximum`), and applied by the same schema to direct `execute()` * callers. A string argument without a domain is any text without control * characters. * - `choices` (string): one of a closed set of values (the CLI's own choices) * - `pattern` (string): an anchored (`^…$`), flag-free grammar, so the * advertised JSON Schema pattern means exactly what is enforced; `expected` * completes "Argument 'x' must be ." * - `multilineText` (string): text that may also contain newline, carriage * return and tab (source code); every other control character is rejected * - `integer` (number): a whole number with optional inclusive `min`/`max` * bounds, advertised as JSON Schema `type: "integer"` */ export type ArgumentDomain = { kind: 'choices'; values: readonly [string, ...string[]]; } | { kind: 'pattern'; regex: RegExp; expected: string; } | { kind: 'multilineText'; } | { kind: 'integer'; min?: number; max?: number; }; export interface CommandArgument { name: string; type: 'string' | 'number' | 'boolean'; required: boolean; description: string; /** Values accepted beyond the primitive type (string or number arguments). */ domain?: ArgumentDomain; } /** * Command execution result */ export interface CommandResult { /** Exit code of the command */ exitCode: number; success: boolean; output: string; /** Error that occurred during execution, if any */ error?: Error; /** * Optional structured payload for tools that declare an `outputSchema`. * Returned to MCP clients as `structuredContent` alongside the text content. * Only consumed on success; ignored on error results. */ structuredContent?: { [key: string]: unknown; }; /** True when the runner cut the middle out of `output` for exceeding its capture cap. */ outputTruncated?: boolean; /** Signal name (or `'unknown'`) when the child was killed by an external signal rather than exiting normally. */ terminatedBySignal?: string; } /** * Resource types supported by the loader */ export declare enum ResourceType { SPEC = "spec", SNIPPET = "snippet", INSTRUCT = "instruct" } /** * Resource loading result */ export interface ResourceResult { /** Content of the loaded resource */ content: string; /** Metadata type of the resource */ metadataType: string; /** Whether the resource was found */ found: boolean; } export interface ProcessResult { stdout: string; stderr: string; exitCode: number; /** True when stdout exceeded its capture cap and its middle was dropped. */ stdoutTruncated?: boolean; /** Signal name (or `'unknown'`) when the child was terminated by an external signal. */ terminatedBySignal?: string; } /** Per-call process options. */ export interface ProcessRunOptions { /** * Stdout capture cap for this call (characters), in place of the runner's * default. Raised by commands that must parse their whole JSON envelope. */ maxStdoutChars?: number; } /** * The longest delay a Node timer honors (2^31 - 1 ms, about 24.8 days). Node * turns a larger delay into 1 ms (with a TimeoutOverflowWarning), so a budget * above it would kill a command at once instead of never. */ export declare const MAX_TIMER_DELAY_MS = 2147483647; /** Exit code the process runner reports when it terminates a command for exceeding its timeout. */ export declare const EXIT_CODE_TIMEOUT = 124; /** Exit code the process runner reports when the MCP client cancels a command. */ export declare const EXIT_CODE_CANCELLED = 130; /** True when the runner stopped the child itself, so its output is partial. */ export declare function isRunnerStoppedExit(exitCode: number | undefined): boolean; export interface ProcessRunner { run(command: string, args: string[], cwd?: string, timeoutMs?: number, /** Abort signal from the MCP client; aborting kills the child process. */ signal?: AbortSignal, options?: ProcessRunOptions): Promise; } /** * Common interface for command processing (execution or text generation) */ export interface CommandProcessor { process(command: string, args: string[], /** * Absolute working directory, already resolved and validated by the command * layer: a project directory from `resolveProjectDirectory` or an init * destination from `checkInitDestination` (`src/utils/projectDirectory.ts`), * or the installed package directory as a neutral cwd for commands that need * no project. Processors do not check it again. */ customWorkingDir?: string, timeoutMs?: number, /** Abort signal from the MCP client; propagated to the process runner. */ signal?: AbortSignal, options?: ProcessRunOptions): Promise; } export interface CommandExecutor { /** * @param args Tool arguments. * @param signal Optional abort signal from the MCP client (`tools/call` * cancellation). Commands that spawn a child process propagate it so the * child is killed on cancellation; others ignore it. */ execute(args: Record, signal?: AbortSignal): Promise; } /** Ensures configured ServiceNow authentication has been resolved once. */ export type EnsureAuthValidated = () => Promise; /** * Metadata annotations for tools: https://modelcontextprotocol.io/docs/concepts/tools */ export interface CommandAnnotations { title?: string; readOnlyHint?: boolean; destructiveHint?: boolean; idempotentHint?: boolean; openWorldHint?: boolean; [key: string]: unknown; } export interface CommandMetadata { name: string; description: string; arguments: CommandArgument[]; annotations?: CommandAnnotations; /** Command-specific timeout in milliseconds. Overrides the default process timeout. */ timeoutMs?: number; /** * Optional MCP output schema (a Zod raw shape). When set, the tool advertises * an `outputSchema` and its successful results must include `structuredContent` * matching this shape (the MCP SDK validates this). */ outputSchema?: ZodRawShape; } /** A command registered as an MCP tool: its declaration plus how it runs. */ export type CLICommand = CommandExecutor & CommandMetadata; /** * Factory for creating consistent CommandResult objects */ export declare const CommandResultFactory: { /** * Normalize an unknown error to an Error instance */ normalizeError(error: unknown): Error; /** * Create a success result, optionally with structured content for tools that * declare an MCP output schema. */ success(output: string, exitCode?: number, structuredContent?: { [key: string]: unknown; }): CommandResult; /** * Create an error result from a message. * Output is the raw error message without prefix (e.g. no "Error: " wrapper). * Presentation formatting (prefixes, exit codes) is applied by ToolsManager.formatResult(). */ error(message: string, exitCode?: number): CommandResult; /** * Create an error result from an Error or unknown value. * Output is the raw error message without prefix (e.g. no "Error: " wrapper). * Presentation formatting (prefixes, exit codes) is applied by ToolsManager.formatResult(). */ fromError(error: unknown, exitCode?: number): CommandResult; /** * Create an error result with custom output text */ errorWithOutput(output: string, error: unknown, exitCode?: number): CommandResult; }; //# sourceMappingURL=types.d.ts.map