example-tool
Process input data strings using a TypeScript-based tool designed for integration into the MCP Server Template, enabling efficient data handling and service-based architecture.
Instructions
An example tool that processes input data
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | Input string to process |
Implementation Reference
- src/tools/example.ts:35-53 (handler)The handler function for 'example-tool' that extracts input, validates with Zod, calls the helper, and returns the processed result or error.'example-tool': async (request) => { try { const { input } = request.params.arguments as { input: string } const inputSchema = z.object({ input: z.string().min(1, 'Input must not be empty') }) inputSchema.parse({ input }) const result = await handleExampleProcess(input) return { toolResult: { content: [{ type: 'text', text: result }], }, } } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error) throw new Error(`Failed to process input: ${errorMessage}`) } }
- src/tools/example.ts:8-22 (schema)The complete tool definition for 'example-tool', including name, description, and input schema for validation.const EXAMPLE_TOOL: Tool = { name: 'example-tool', description: 'An example tool that processes input data', inputSchema: { type: 'object', properties: { input: { type: 'string', description: 'Input string to process', minLength: 1 } }, required: ['input'] } }
- src/index.ts:20-23 (registration)Merges the example tools and handlers into global collections used for listing tools and dispatching calls in the MCP server.// Combine all tools const ALL_TOOLS = [...EXAMPLE_TOOLS] const ALL_HANDLERS = { ...EXAMPLE_HANDLERS }
- src/tools/example.ts:28-31 (helper)Supporting helper function that performs the core processing logic for the tool input.async function handleExampleProcess(input: string): Promise<string> { log('Processing input:', input) return `Processed: ${input}` }