types.ts
Language TypeScript1.2 KB37 lines
import type { ZodRawShape } from "zod";import type { PlinthConfig } from "../lib/config.js";import type { RateLimiter } from "../lib/rateLimit.js";/** MCP tool call result (text content only). */export type ToolResult = {content: Array<{ type: "text"; text: string }>;isError?: boolean;/** SDK result type carries an open index signature. */[key: string]: unknown;};/*** Per-invocation context. Config is injected rather than read from a global so* handlers are portable across Node (stdio) and the Workers isolate, where each* request/instance carries its own env-derived config.*/export interface ToolContext {config: PlinthConfig;/** Shared rate limiter enforcing the 10/10s cap. Optional in tests. */limiter?: RateLimiter;}/*** A self-contained tool module. Every handler goes through plinthRequest(),* which refuses to run until live requests are deliberately enabled, so a tool* is always discoverable (ListTools) but cannot reach production by accident.*/export interface ToolModule {name: string;config: {title: string;description: string;inputSchema: ZodRawShape;};handler: (args: Record<string, unknown>, ctx: ToolContext) => Promise<ToolResult> | ToolResult;}