Skip to main content
Glama
dhinojosac

TypeScript MCP Server Template

by dhinojosac

sayHello

Greets a user by name within the TypeScript MCP Server Template, using Fastify and Docker, to simplify personalized interactions in server applications.

Instructions

Says hello to a person by name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that executes the sayHello tool logic: validates the input using SayHelloSchema and returns an MCP-formatted text response with a personalized greeting.
    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 by NameSchema.
    export const SayHelloSchema = z.object({ name: NameSchema, });
  • src/server.ts:30-48 (registration)
    Registration of the sayHello tool on the MCP server instance, including metadata (title, description) and the inline handler function.
    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}!`, }, ], }; } );
  • Reusable Zod schema for person names, used within SayHelloSchema for input validation.
    export const NameSchema = z .string() .min(1, 'Name is required') .max(100, 'Name cannot exceed 100 characters') .describe("Person's name");
  • Utility function to parse and validate tool arguments against a Zod schema, throwing descriptive errors on failure; used in the sayHello handler.
    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; } }

Other Tools

Related Tools

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