Skip to main content
Glama
tool-factory.ts•662 B
import { z } from 'zod'; import type { ToolHandler } from '../tool-types.js'; /** * Factory function to create type-safe tool handlers */ export function createToolHandler<TSchema extends z.ZodTypeAny>(config: { name: string; description: string; inputSchema: TSchema; handler: (input: z.infer<TSchema>) => AsyncGenerator<{ content: Array<{ type: string; text: string }> }>; }): ToolHandler<TSchema> { return { name: config.name, description: config.description, inputSchema: config.inputSchema, async *handler({ input }) { const validated = config.inputSchema.parse(input); yield* config.handler(validated); } }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/GustyCube/discord-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server