Rebasely Beta: data may be purged

examples/MCP-tools Public

TypeScript · 25 lines · 932 B · at dae155a

import type { z } from "zod";// What a tool gets besides its input. `now` is passed in rather than read from the clock so// tests can pin it.export type ToolContext = { now: Date };// One tool: its MCP metadata, its schemas and a pure function from parsed input to output.// The server registers it (src/server.ts); nothing here knows about MCP or HTTP.export type Tool<I extends z.ZodObject, O extends z.ZodObject> = {  name: string;  title: string;  // Read by the model when it decides whether and how to call the tool.  description: string;  input: I;  output: O;  run(input: z.output<I>, ctx: ToolContext): z.input<O>;};// Any tool, for code that handles them all alike. `run` is a method, so a specific tool is// assignable here.export type AnyTool = Tool<z.ZodObject, z.ZodObject>;export function defineTool<I extends z.ZodObject, O extends z.ZodObject>(tool: Tool<I, O>): Tool<I, O> {  return tool;}