# Tool Registry Context
## Purpose
Central registry for MCP tools. Replaces monolithic switch statement with scalable pattern.
## Key Components
| File | Purpose |
|------|---------|
| `registry.ts` | `ToolRegistry` class + singleton `toolRegistry` |
| `types.ts` | TypeScript interfaces (`RegisteredTool`, `ToolCategory`, `ToolExecutionContext`) |
| `utils.ts` | Shared validation utilities |
| `index.ts` | Module exports |
## ToolCategory Enum
```typescript
enum ToolCategory {
CORE, // introspect, help
CONTENT, // posts, pages, media, comments
TAXONOMY, // categories, tags
USERS, // user management
PLUGINS, // plugin management
THEMES, // theme management
WORKFLOWS, // AI-powered workflows (feature-flagged)
}
```
## Registry API
```typescript
// Register tool
toolRegistry.register(registeredTool);
// Execute tool
const result = await toolRegistry.execute(name, args, context);
// Query
toolRegistry.getTool(name);
toolRegistry.getAllDefinitions();
toolRegistry.getByCategory(ToolCategory.CONTENT);
toolRegistry.isEnabled(name);
// Feature flags
toolRegistry.setFeatureFlag('WORKFLOWS_ENABLED', true);
```
## Validation Utilities
```typescript
import { validateRequired, validatePagination, validateId, validateEnum, parseBoolean } from './utils.js';
validateRequired(args, ['id', 'title']); // Throws if missing
const { page, per_page } = validatePagination(args); // With defaults
const id = validateId(args.id); // Positive integer
const status = validateEnum(args.status, ['publish', 'draft'], 'status', 'publish');
const featured = parseBoolean(args.featured); // Handles '1', 'true', 'yes'
```
## Feature Flags
Used to gate experimental tools:
- `WORKFLOWS_ENABLED`
- `WP_BULK_VALIDATOR_ENABLED`
- `WP_SEO_AUDIT_ENABLED`
Set via env: `WPNAV_FLAG_WORKFLOWS_ENABLED=1`
## Test Files
- `registry.test.ts` - Registry unit tests
- `utils.test.ts` - Utility function tests