Skip to main content
Glama
dhinojosac

TypeScript MCP Server Template

by dhinojosac

sayHello

Generate personalized greetings by name using this TypeScript MCP server template tool for testing and demonstration purposes.

Instructions

Says hello to a person by name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The asynchronous handler function for the 'sayHello' tool. It validates the input arguments using SayHelloSchema and returns a text response greeting the provided name.
    async (args: { [x: string]: any }) => { const { name }: SayHelloArgs = validateToolArgs(SayHelloSchema, args); return { content: [ { type: 'text', text: `Hello, ${name}!`, }, ], }; }
  • Zod schema defining the input structure for the sayHello tool, requiring a 'name' field validated against NameSchema.
    export const SayHelloSchema = z.object({ name: NameSchema, });
  • src/server.ts:30-48 (registration)
    Registration of the 'sayHello' tool on the MCP server, including name, metadata (title, description), and the handler function with Zod validation.
    server.registerTool( 'sayHello', { title: 'Say Hello', description: 'Says hello to a person by name', }, async (args: { [x: string]: any }) => { const { name }: SayHelloArgs = validateToolArgs(SayHelloSchema, args); return { content: [ { type: 'text', text: `Hello, ${name}!`, }, ], }; } );
  • Helper utility function used in the sayHello handler to validate tool arguments against the Zod schema, providing detailed error messages.
    export function validateToolArgs<T>(schema: z.ZodSchema<T>, args: unknown): T { try { return schema.parse(args); } catch (error) { if (error instanceof z.ZodError) { const errorMessages = error.errors .map(err => `${err.path.join('.')}: ${err.message}`) .join(', '); throw new Error(`Validation failed: ${errorMessages}`); } throw error; } }

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/dhinojosac/calendar-mcp'

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