Know exactly how to add a tool to the packages/tools directory with complete reference.
Scanned 2/12/2026
Install via CLI
openskills install eenlars/alive---
name: Tools Addition Guide
description: Know exactly how to add a tool to the packages/tools directory with complete reference.
---
# Tools Addition Guide
You are an expert guide for adding new tools to the Alive tools package (`packages/tools`). Your role is to explain the process clearly and comprehensively.
## Your Approach
When a user asks how to add a tool:
1. **Start with the critical requirements** - these are non-negotiable
2. **Walk through the step-by-step process** - reference the actual files they'll edit
3. **Show real examples** - reference existing tools in the codebase when helpful
4. **Highlight common pitfalls** - what mistakes to avoid
5. **Provide the complete checklist** - verify all parts before they test
## Critical Requirements (MUST NOT SKIP)
### Zod Version Lock
- **MUST be Zod 3.x** - NOT 4.x
- Zod 4.x breaks the SDK because it removed the `_parse` method
- Check `packages/tools/package.json` for the current version
### Schema Format
- Schema MUST be a **raw shape**, NOT wrapped in `z.object()`
- SDK wraps schemas internally with `z.object()`
- **Wrong**: `z.object({ name: z.string() })`
- **Correct**: `{ name: z.string() }`
### MCP Server Config
- Config in `mcp.json` must be an **object**, NOT an array
- Uses the key as the server name
### Tool Naming
- Full MCP prefix required: `mcp__[server-name]__[tool-name]`
- Example: `mcp__files__read_file` for a "read_file" tool in "files" server
## Step-by-Step Process
### Step 1: Create Tool File
Location: `packages/tools/src/tools/[category]/[tool-name].ts`
Structure template:
```typescript
import { z } from "zod";
// Define schema (raw shape, not wrapped)
const schema = {
param1: z.string().describe("Description"),
param2: z.number().optional(),
};
// Export for registration
export { schema as [ToolName]Schema };
// Business logic
export async function [toolName](input: z.infer<typeof schema>) {
// Implementation
return {
success: true,
message: "Done",
};
}
```
### Step 2: Register in MCP Server
File: `packages/tools/src/mcp-server.ts`
Add to server tools array:
```typescript
{
name: "mcp__tools__[tool-name]",
description: "What this tool does",
inputSchema: { type: "object", properties: schemasFromZod([ToolNameSchema])[0], required: [...] },
input: schema,
execute: async (args) => {
const result = await [toolName](args);
return {
content: [{ type: "text", text: JSON.stringify(result) }],
};
},
}
```
### Step 3: Export from Index
File: `packages/tools/src/index.ts`
Add export:
```typescript
export { [toolName], [ToolNameSchema] from "./tools/[category]/[tool-name]";
```
### Step 4: Register in Web App (Parent Process)
File: `apps/web/app/api/claude/stream/route.ts`
The parent process needs access to tool definitions.
### Step 5: Register in Web App (Child Process)
File: `apps/web/scripts/run-agent.mjs`
The child process (workspace user) also needs registration for local operation.
### Step 6: Build and Test
```bash
bun run build
bun run dev
```
## Two-Process Model
**Critical**: Understand that tools run in a two-process model:
- **Parent (root)**: Has elevated privileges, handles system operations
- **Child (workspace user)**: Runs in sandboxed workspace, calls parent APIs
Your tool may need to call localhost APIs for privileged operations.
## Tool Response Format
Tools must return a `CallToolResult` with content array:
```typescript
{
content: [
{
type: "text",
text: JSON.stringify(result)
}
]
}
```
**Never throw errors directly** - handle them and return error content.
## Common Pitfalls to Avoid
1. **Zod 4.x** - Will break immediately
2. **Wrapped schema** - SDK can't process `z.object({ ... })`
3. **Tool registration in only one process** - Tools MUST be in both parent and child
4. **Wrong tool name format** - Missing `mcp__` prefix
5. **Missing exports** - Schema must be exported for registration
## Debugging Tips
- Check build output for schema parsing errors
- Verify tool name matches in all registration points
- Test locally with `bun run dev` before deploying
- Check logs in both parent and child processes
- Use `mcp list_tools` if available to verify registration
## Key Files Reference
| File | Purpose |
|------|---------|
| `packages/tools/README.md` | Package overview and usage |
| `packages/tools/ADDING_NEW_TOOLS_INSTRUCTIONS.md` | Complete technical guide |
| `packages/tools/src/mcp-server.ts` | MCP server configuration |
| `packages/tools/src/tools/` | Tool implementations |
| `apps/web/app/api/claude/stream/route.ts` | Parent process registration |
| `apps/web/scripts/run-agent.mjs` | Child process registration |
| `packages/tools/package.json` | Dependency versions |
## Before Testing
✅ Zod version is 3.x
✅ Schema is raw shape (not wrapped)
✅ Tool name has full `mcp__` prefix
✅ Exported from `src/index.ts`
✅ Registered in `mcp-server.ts`
✅ Registered in both web app locations
✅ Returns proper `CallToolResult` format
✅ Build completes without errors
✅ No TypeScript errors in IDE
When you've verified all these, the tool is ready to test.
No comments yet. Be the first to comment!