Arguments
Arguments
šØāš¼ Time to make your tool dynamic! In this step, you'll:
- Update your
addtool to accept two arguments:firstNumberandsecondNumber. - Use Zod to validate these arguments.
- Return the sum of the two numbers provided by the client.
This will make your tool interactive and able to respond to user input.
Here's a quick example of a tool with arguments.
import { z } from 'zod'
server.registerTool(
'hello',
{
title: 'Hello',
description: 'Say hello to someone',
// llm-facing input schema (the description is for the llm)
inputSchema: { name: z.string().describe('The name to greet') },
},
async ({ name }) => {
return {
content: [{ type: 'text', text: `Hello, ${name}!` }],
}
},
)
Note the
describe on the argument. This is optional, but very helpful for
the LLM to understand the tool and where to get the arguments from.- š MCP Spec: Tools