Skip to main content
Glama
add-new-tool.md1.98 kB
--- name: How to Add a New Tool description: A step-by-step guide for extending Code-MCP with new capabilities. category: workflows --- # Extending Code-MCP: Adding a New Tool Follow this pattern to add new tools to the Code-MCP server. ## 1. Define Schema & Handler Create a new file in `src/tools/` (or add to an existing related file). - Use `zod` to define the input schema. - Export `toolNameSchema` and `toolNameHandler`. ```typescript import { z } from "zod"; export const myNewToolSchema = { name: "my_new_tool", description: "Description of what it does", inputSchema: z.object({ arg1: z.string(), }), }; export const myNewToolHandler = (args: { arg1: string }) => { return { content: [{ type: "text", text: \`Result: \${args.arg1}\` }], }; }; ``` ## 2. Export Helper Ensure your new tool functions are exported from the module. ## 3. Register in `src/index.ts` (Stdio Server) - Import the schema and handler. - Add to the `toolRegistry` map. ## 4. Register in `src/server.ts` (HTTP Server) - Import the schema and handler. - Add to the `toolRegistry` map. ## 5. Update Coordination (Optional but Recommended) Update `suggest_tool_chain` in `src/tools/coordination.ts` to recommend your tool in relevant contexts. ## 6. Add Tests (CRITICAL) Create a `*.test.ts` file in `src/tools/` and add unit tests using `vitest`. > [!IMPORTANT] > **Check your imports!** > Ensure you have exported your handler from the source file and imported it correctly in the test file. > Example: `import { myNewToolHandler } from "./myNewSource.js";` ## 7. Verify & Refine 1. Run `npm run build` to check for compilation errors (missing exports/imports). 2. Run `npm test` to verify logic. 3. **Logic Check**: Ensure your tool does not just return a static template. - Does it process the input? - Does it have conditional logic? - Does it provide specific, context-aware value? - _If no, go back to Step 1 and add heuristics or logic._

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/millsydotdev/Code-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server