import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import type { ZodRawShapeCompat } from '@modelcontextprotocol/sdk/server/zod-compat.js'; import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import { z } from 'zod'; import { type DiffSlot } from './diff.js'; import { type DiffStats, type ParsedFile } from './diff.js'; import { type FileSlot } from './file-store.js'; import { type ProgressExtra } from './progress.js'; import { createErrorToolResponse } from './tool-response.js'; export * from './tool-response.js'; export * from './tool-contracts.js'; export interface PromptParts { systemInstruction: string; prompt: string; } /** * Immutable snapshot of server-side state captured once at the start of a * tool execution, before `validateInput` runs. Threading it through both * `validateInput` and `buildPrompt` eliminates the TOCTOU gap that would * otherwise allow a concurrent `generate_diff` call to replace the cached * diff between the budget check and prompt assembly. */ export interface ToolExecutionContext { readonly diffSlot: DiffSlot | undefined; readonly fileSlot: FileSlot | undefined; /** Snapshotted Gemini context cache name for diff-dependent tools. */ readonly diffCacheSlotName: string | undefined; } /** Read the configured task TTL. Used by server-config for display. */ export declare function getTaskTtlMs(): number; /** Read the configured max task TTL cap. Used by server-config for display. */ export declare function getMaxTaskTtlMs(): number; /** Read the configured task poll interval. Used by server-config for display. */ export declare function getTaskPollIntervalMs(): number; export interface ToolAnnotations { readOnlyHint?: boolean; idempotentHint?: boolean; openWorldHint?: boolean; destructiveHint?: boolean; } export interface StructuredToolTaskConfig, TResult extends object = Record, TFinal extends TResult = TResult> { /** Tool name registered with the MCP server (e.g. 'analyze_pr_impact'). */ name: string; /** Human-readable title shown to clients. */ title: string; /** Short description of the tool's purpose. */ description: string; /** Zod schema or raw shape for MCP request validation at the transport boundary. */ inputSchema: z.ZodType | ZodRawShapeCompat; /** Zod schema for validating the complete tool input inside the handler. */ fullInputSchema: z.ZodType; /** * Zod schema for the final structured result after any transformResult. * When geminiSchema is also provided, this is only used for outputSchema * derivation — the actual Gemini response is parsed against geminiSchema. */ resultSchema: z.ZodType; /** * Optional Zod schema for parsing and validating the raw Gemini response. * When set, Gemini is instructed to produce this shape and the response is * parsed against it (instead of resultSchema). The transformResult hook * then extends the parsed result into the final TFinal shape. */ geminiSchema?: z.ZodType; /** Stable error code returned on failure (e.g. 'E_INSPECT_QUALITY'). */ errorCode: string; /** Optional post-processing hook called after resultSchema.parse(). The return value replaces the parsed result. */ transformResult?: (input: TInput, result: TResult, ctx: ToolExecutionContext) => TFinal; /** Optional validation hook for input parameters. */ validateInput?: (input: TInput, ctx: ToolExecutionContext) => Promise | undefined>; /** Optional flag to enforce diff presence and budget check before tool execution. */ requiresDiff?: boolean; /** Optional flag to enforce file presence and budget check before tool execution. */ requiresFile?: boolean; /** Optional override for schema validation retries. Defaults to GEMINI_SCHEMA_RETRIES env var. */ schemaRetries?: number; /** Optional thinking level. */ thinkingLevel?: 'minimal' | 'low' | 'medium' | 'high'; /** Optional timeout in ms for the Gemini call. Defaults to 90,000 ms. Use DEFAULT_TIMEOUT_PRO_MS for Pro model calls. */ timeoutMs?: number; /** Optional max output tokens for Gemini. */ maxOutputTokens?: number; /** * Optional sampling temperature for this tool's Gemini call. * Gemini 3 recommends 1.0 for all tasks. */ temperature?: number; /** Optional opt-in to Gemini thought output. Defaults to false. */ includeThoughts?: boolean; /** Optional deterministic JSON mode for stricter key ordering and repair prompting. */ deterministicJson?: boolean; /** Optional batch execution mode. Defaults to runtime setting. */ batchMode?: 'off' | 'inline'; /** Optional formatter for human-readable text output. */ formatOutput?: (result: TFinal) => string; /** MCP per-tool task negotiation mode for task-backed execution. */ taskSupport?: 'optional' | 'required'; /** Optional context text used in progress messages. */ progressContext?: (input: TInput) => string; /** Optional short outcome suffix for the completion progress message (e.g., "3 findings"). */ formatOutcome?: (result: TFinal) => string; /** Optional MCP annotation overrides for this tool. */ annotations?: ToolAnnotations; /** Builds the system instruction and user prompt from parsed tool input. */ buildPrompt: (input: TInput, ctx: ToolExecutionContext) => PromptParts; /** * Optional custom generation function. When provided, replaces the standard * generateStructuredJson + resultSchema.parse pipeline. Must return a parsed TResult. */ customGenerate?: (promptParts: PromptParts, ctx: ToolExecutionContext, opts: { onLog: (level: string, data: unknown) => Promise; signal?: AbortSignal; }) => Promise; } export declare function summarizeSchemaValidationErrorForRetry(errorMessage: string): string; export declare function wrapToolHandler(options: { toolName: string; progressContext?: (input: TInput) => string; }, handler: (input: TInput, extra: ProgressExtra) => Promise | TResult): (input: TInput, extra: ProgressExtra) => Promise; export declare function canSendLoggingMessages(server: McpServer): boolean; export declare function createGeminiLogger(server: McpServer): (level: string, data: unknown) => Promise; export declare function registerStructuredToolTask, TFinal extends TResult = TResult>(server: McpServer, config: StructuredToolTaskConfig): void; export interface TaskBackedToolConfig, TOutputSchema extends z.ZodType = z.ZodType> { name: string; title: string; description: string; inputSchema: ZodRawShapeCompat | z.ZodType; outputSchema?: TOutputSchema; annotations?: ToolAnnotations; taskSupport?: 'optional' | 'required'; errorCode: string; handler: (input: TInput, extra: ProgressExtra) => Promise | CallToolResult; } export declare function registerTaskBackedTool, TOutputSchema extends z.ZodType = z.ZodType>(server: McpServer, config: TaskBackedToolConfig): void; export interface DiffContextSnapshot { diff: string; parsedFiles: readonly ParsedFile[]; stats: Readonly; repository: string; } export declare function getDiffContextSnapshot(ctx: ToolExecutionContext): DiffContextSnapshot; export interface FileContextSnapshot { filePath: string; content: string; language: string; lineCount: number; sizeChars: number; } export declare function getFileContextSnapshot(ctx: ToolExecutionContext): FileContextSnapshot;