UNPKG

mcp-framework

Version:

Framework for building Model Context Protocol (MCP) servers in Typescript

27 lines (26 loc) 913 B
import { z } from "zod"; export class MCPPrompt { get promptDefinition() { return { name: this.name, description: this.description, arguments: Object.entries(this.schema).map(([name, schema]) => ({ name, description: schema.description, required: schema.required ?? false, })), }; } async getMessages(args = {}) { const zodSchema = z.object(Object.fromEntries(Object.entries(this.schema).map(([key, schema]) => [key, schema.type]))); const validatedArgs = (await zodSchema.parse(args)); return this.generateMessages(validatedArgs); } async fetch(url, init) { const response = await fetch(url, init); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); } }