import type { Tool } from "@modelcontextprotocol/server"; import type { DispatchContext, Middleware, HandlerResult } from '../types.js'; import type { RequestedSchema } from './elicit.js'; /** * Execute a tool call through the middleware pipeline. * * 1. Run each mw.before(ctx) in order. First rejection stops the before-chain. * 2. If all before hooks pass, call executeTool(). If rejected, skip executeTool. * 3. Run ALL mw.after(ctx, result) hooks — even if before was rejected. * Each after hook can modify result. After hooks that throw are caught silently. */ export declare function executeMiddleware(middleware: Middleware[], ctx: DispatchContext, executeTool: () => Promise): Promise; /** * Create an elicitation middleware. * Checks required params vs provided args. If missing and client supports * elicitation, asks the client. Otherwise returns MISSING_PARAM error. * Only prompts for primitive types (string/number/boolean/enum). */ export declare function createElicitationMiddleware(getToolDef: (name: string) => Tool | null, elicitFn: ((requestedSchema: RequestedSchema, message: string) => Promise | null>) | null): Middleware; /** * 全局 rate limit 中间件。防 AI 失控循环调用(execute_gdscript/read_scene 等) * 耗尽 CPU/IO/子进程槽。固定窗口计数:windowMs 内最多 maxPerWindow 次,超限拒绝。 * 属软限(防失控循环,非硬 DoS 防护——后者需容器级隔离)。默认 60 次/秒,可按部署调整。 */ export declare function createRateLimitMiddleware(maxPerWindow?: number, windowMs?: number): Middleware;