add
Perform addition of two numbers using the MCP Communication Server, enabling real-time data communication and calculations for client applications.
Instructions
Add two numbers
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"a": {
"type": "number"
},
"b": {
"type": "number"
}
},
"required": [
"a",
"b"
],
"type": "object"
}
Implementation Reference
- src/index.ts:54-56 (handler)The handler function for the 'add' tool. It receives two numbers 'a' and 'b' as input and returns their sum as a text content block.async ({ a, b }: { a: number; b: number }) => ({ content: [{ type: "text", text: String(a + b) }] })
- src/index.ts:52-52 (schema)The input schema for the 'add' tool, defining two required number parameters 'a' and 'b' using Zod validation.inputSchema: { a: z.number(), b: z.number() }
- src/index.ts:48-57 (registration)The registration of the 'add' tool using server.registerTool, including title, description, input schema, and inline handler function.server.registerTool("add", { title: "Addition Tool", description: "Add two numbers", inputSchema: { a: z.number(), b: z.number() } }, async ({ a, b }: { a: number; b: number }) => ({ content: [{ type: "text", text: String(a + b) }] }) );