# Tools Directory Context
## Structure
Each subdirectory contains tools for a specific category:
```
tools/
├── index.ts # registerAllTools() - imports all categories
├── core/index.ts # introspect, help, status
├── content/index.ts # posts, pages, media, comments
├── taxonomy/index.ts # categories, tags, taxonomies
├── users/index.ts # user CRUD
├── plugins/index.ts # plugin CRUD
├── themes/index.ts # theme CRUD
├── gutenberg/ # Block editor operations
│ ├── index.ts # Gutenberg tool registration
│ └── helpers.ts # Block manipulation utilities
└── testing/index.ts # Test utilities
```
## Registration Pattern
Each category exports a `register[Category]Tools()` function:
```typescript
// Example: content/index.ts
import { toolRegistry, ToolCategory } from '../../tool-registry/index.js';
export function registerContentTools() {
toolRegistry.register({
definition: {
name: 'wpnav_list_posts',
description: 'List WordPress posts with filtering',
inputSchema: { ... },
},
handler: async (args, context) => { ... },
category: ToolCategory.CONTENT,
});
// ... more tools
}
```
## Handler Signature
```typescript
async function handler(
args: Record<string, any>,
context: ToolExecutionContext
): Promise<ToolResult>
```
### Context Object
```typescript
interface ToolExecutionContext {
wpRequest: (endpoint: string, options?: RequestInit) => Promise<any>;
config: WPConfig;
logger: Logger;
clampText: (text: string) => string;
}
```
## Common Patterns
### List Endpoint
```typescript
const { page, per_page } = validatePagination(args);
const response = await context.wpRequest(`/wp/v2/posts?page=${page}&per_page=${per_page}`);
return { content: [{ type: 'text', text: JSON.stringify(response, null, 2) }] };
```
### Get by ID
```typescript
validateRequired(args, ['id']);
const id = validateId(args.id);
const response = await context.wpRequest(`/wp/v2/posts/${id}`);
```
### Create/Update (Write Operation)
```typescript
validateRequired(args, ['title']);
const response = await context.wpRequest('/wp/v2/posts', {
method: 'POST',
body: JSON.stringify({ title: args.title, content: args.content }),
});
```
## Naming Convention
- Tool names: `wpnav_[verb]_[noun]` (e.g., `wpnav_list_posts`, `wpnav_create_page`)
- Verbs: `list`, `get`, `create`, `update`, `delete`, `activate`, `deactivate`
- Aliases supported for backward compatibility