example_operation
Process user data by validating and structuring inputs such as name, email, and date for integration with AI models in the MCP Server TypeScript Template.
Instructions
A simple example operation
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"name": "<name>",
"email": "<email>",
"date": "<date>"
},
"name": "example_operation"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | ||
| Yes | |||
| name | Yes |
Implementation Reference
- operations/example-operation.ts:9-11 (handler)Core execution logic for the example_operation tool: builds a URL and sends an API request.
export async function exampleApiCall(params: z.infer<typeof ExampleSchema>) { return sendRequest(buildUrl("https://example.com/search", params)); } - index.ts:55-61 (handler)MCP CallToolRequest handler dispatching for example_operation: validates input with schema and invokes the core handler.
case "example_operation": { const args = ExampleSchema.parse(request.params.arguments); const result = await operation.exampleApiCall(args); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; } - common/types.ts:10-14 (schema)Zod schema defining the input parameters for the example_operation tool (name, email, date).
export const ExampleSchema = z.object({ name: z.string(), email: z.string(), date: z.string(), }); - index.ts:34-38 (registration)Tool metadata registration in ListToolsResponse: name, description, and derived JSON input schema.
{ name: "example_operation", description: "A simple example operation", inputSchema: zodToJsonSchema(ExampleSchema), }, - index.ts:11-11 (registration)Import of the operation module containing the tool handler.
import * as operation from './operations/example-operation';