add
Adds two numbers interactively using the MCP Elicitations Demo Server. Input two numeric values to calculate their sum dynamically.
Instructions
Adds two numbers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | First number | |
| b | Yes | Second number |
Implementation Reference
- src/tools/tool-add.ts:13-24 (handler)The async handler function for the 'add' tool. It validates the input arguments using AddSchema, computes the sum of 'a' and 'b', and returns a structured text response containing the result.handler: async (args: any) => { const validatedArgs = AddSchema.parse(args); const sum = validatedArgs.a + validatedArgs.b; return { content: [ { type: "text" as const, text: `The sum of ${validatedArgs.a} and ${validatedArgs.b} is ${sum}.`, }, ], }; },
- src/tools/tool-add.ts:4-7 (schema)Zod schema (AddSchema) defining the input structure for the 'add' tool: two number fields 'a' and 'b' with descriptions.const AddSchema = z.object({ a: z.number().describe("First number"), b: z.number().describe("Second number"), });
- src/tools/index.ts:22-37 (registration)Registration of the 'add' tool by including 'addTool' in the 'allTools' array, which is used by getTools() for listing tools and getToolHandler() for execution dispatching.const allTools = [ echoTool, addTool, longRunningOperationTool, printEnvTool, sampleLlmTool, sampleWithPreferencesTool, sampleMultimodalTool, sampleConversationTool, sampleAdvancedTool, getTinyImageTool, annotatedMessageTool, getResourceReferenceTool, elicitationTool, getResourceLinksTool, ];
- src/tools/index.ts:8-8 (registration)Import statement that brings the 'addTool' into the index module for registration.import { addTool } from "./tool-add.js";