example-tool
Processes input data to transform or analyze strings for integration within MCP server workflows. This tool handles text processing tasks within the TypeScript-based MCP Server Template framework.
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)Handler implementation for 'example-tool' that extracts input, validates with Zod, processes via helper function, and returns the tool result.'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)Tool schema definition for 'example-tool' including name, description, and input schema.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:21-22 (registration)Combines example tools and handlers into global collections used by the MCP server for tool listing and execution.const ALL_TOOLS = [...EXAMPLE_TOOLS] const ALL_HANDLERS = { ...EXAMPLE_HANDLERS }
- src/index.ts:31-34 (registration)Registers the request handler for listing available tools, which includes 'example-tool' via ALL_TOOLS.server.setRequestHandler(ListToolsRequestSchema, async () => { log('Received list tools request') return { tools: ALL_TOOLS } })
- src/tools/example.ts:28-31 (helper)Helper function called by the tool handler to process the input string.async function handleExampleProcess(input: string): Promise<string> { log('Processing input:', input) return `Processed: ${input}` }