DOCS/CLI/ADD TOOLS
Add Tools to Your MCP Server
After scaffolding your server with agenticmarket create, you can add new tools with a single command. For the full end-to-end tutorial, see How to Create an MCP Server.
Using the CLI generator
bashagenticmarket add tool get-weather
This command:
- Creates
src/tools/get-weather.tswith a Zod-validated tool skeleton - Adds the import to
src/tools/index.ts - Registers the tool in the tool registry automatically
You do not need to edit index.ts manually.
Generated tool structure
Every generated tool follows this pattern:
typescriptimport { z } from "zod"; import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; export function registerGetWeatherTool(server: McpServer): void { server.tool( "get_weather", "Describe what this tool does for the AI agent.", { location: z.string().describe("City name or coordinates"), }, async ({ location }) => { // Your logic here return { content: [ { type: "text" as const, text: JSON.stringify({ location, temp: "22°C" }), }, ], }; }, ); }
Key points:
- Tool names use
snake_case(get_weather, notgetWeather) - Descriptions help AI agents decide when to call your tool — be specific
- Zod schemas validate input before your handler runs
- Return
isError: truefor error responses so the AI knows something failed
For API wrapper projects
If you scaffolded with the API wrapper template, your generated tools use the built-in apiClient:
typescriptimport { apiClient } from "../lib/api-client.js"; const data = await apiClient.get("/users", { q: query });
The apiClient automatically:
- Injects your API key or bearer token from
.env - Enforces request timeouts (configurable via
API_TIMEOUT_MS) - Throws typed
ApiClientErrorwith status codes for clean error handling
Adding tools manually
You can also create tool files manually. Just follow the pattern above and register them in src/tools/index.ts:
typescriptimport { registerGetWeatherTool } from "./get-weather.js"; export function registerAllTools(server: McpServer): void { registerGetWeatherTool(server); // add more tools here }
Naming conventions
| Convention | Example |
|---|---|
| File name | get-weather.ts (kebab-case) |
| Tool name | get_weather (snake_case) |
| Function name | registerGetWeatherTool (PascalCase with prefix) |
| Description | Short, specific sentence for AI agents |
AgenticMarket