# BookStack MCP Tool Consolidation Plan
**Version:** 1.0
**Date:** 2025-09-27
**Status:** ā
**COMPLETED** - Implemented in Python FastMCP server
**Objective:** Reduce tool count from 25 to 6 tools (76% reduction)
> **ā
Implementation Complete**: This consolidation plan has been fully implemented in the Python FastMCP server (`fastmcp_server/` directory). The TypeScript server with 25 individual tools is now deprecated.
---
## š Current State Analysis
### **Current Tool Inventory (25 Tools)**
#### **Content Management Tools (20 Tools)**
| Category | Tools | Count |
|----------|-------|-------|
| **Create** | `bookstack_create_book`, `bookstack_create_bookshelf`, `bookstack_create_chapter`, `bookstack_create_page` | 4 |
| **Read** | `bookstack_read_book`, `bookstack_read_bookshelf`, `bookstack_read_chapter`, `bookstack_read_page` | 4 |
| **Update** | `bookstack_update_book`, `bookstack_update_bookshelf`, `bookstack_update_chapter`, `bookstack_update_page` | 4 |
| **Delete** | `bookstack_delete_book`, `bookstack_delete_bookshelf`, `bookstack_delete_chapter`, `bookstack_delete_page` | 4 |
| **List** | `bookstack_list_books`, `bookstack_list_bookshelves`, `bookstack_list_chapters`, `bookstack_list_pages` | 4 |
#### **Specialized Tools (5 Tools)**
| Tool | Purpose | Status |
|------|---------|--------|
| `bookstack_search` | Global content search | ā
Keep (unique functionality) |
| `bookstack_manage_images` | Image CRUD operations | ā
Keep (already consolidated) |
| `bookstack_search_images` | Image discovery | ā
Keep (already consolidated) |
| `example_tool` | Example/demo tool | ā Remove (not needed) |
| `example_tool_duplicate` | Duplicate example | ā Remove (not needed) |
---
## šÆ Consolidation Strategy
### **Target Architecture: 6 Consolidated Tools**
#### **1. `bookstack_manage_content`**
**Replaces:** 16 content management tools (4 entities Ć 4 operations)
- **Operations:** `create`, `read`, `update`, `delete`
- **Entities:** `book`, `bookshelf`, `chapter`, `page`
- **Reduction:** 16 ā 1 tool (94% reduction)
#### **2. `bookstack_list_content`**
**Replaces:** 4 list tools
- **Entities:** `books`, `bookshelves`, `chapters`, `pages`
- **Features:** Pagination, filtering, sorting
- **Reduction:** 4 ā 1 tool (75% reduction)
#### **3. `bookstack_search`** *(Keep as-is)*
**Purpose:** Global content search across all entities
- **Status:** Already optimized
- **Reason:** Unique cross-entity search functionality
#### **4. `bookstack_manage_images`** *(Keep as-is)*
**Purpose:** Image gallery CRUD operations
- **Status:** Already consolidated (was 5 tools ā 1)
- **Reason:** Complex file upload handling
#### **5. `bookstack_search_images`** *(Keep as-is)*
**Purpose:** Advanced image discovery and filtering
- **Status:** Already consolidated
- **Reason:** Specialized image search capabilities
#### **6. `bookstack_batch_operations`** *(New)*
**Purpose:** Bulk operations across multiple entities
- **Operations:** Bulk create, update, delete
- **Features:** Transaction support, progress tracking
- **Benefit:** Enables efficient large-scale operations
---
## š Implementation Specifications
### **Tool 1: `bookstack_manage_content`**
```typescript
interface ContentManagementInput {
operation: 'create' | 'read' | 'update' | 'delete';
entity_type: 'book' | 'bookshelf' | 'chapter' | 'page';
// For create operations
name?: string;
description?: string;
content?: string; // For pages
markdown?: string; // For pages
// For read/update/delete operations
id?: number;
// For update operations
updates?: Record<string, any>;
// Entity-specific fields
book_id?: number; // For chapters/pages
chapter_id?: number; // For pages
books?: number[]; // For bookshelves
tags?: Array<{name: string, value: string}>;
image_id?: number; // For books
}
```
**Usage Examples:**
```typescript
// Create a book
await bookstack_manage_content({
operation: 'create',
entity_type: 'book',
name: 'API Guide',
description: 'Comprehensive API documentation'
});
// Update a page
await bookstack_manage_content({
operation: 'update',
entity_type: 'page',
id: 123,
updates: { markdown: '# Updated content' }
});
// Delete a chapter
await bookstack_manage_content({
operation: 'delete',
entity_type: 'chapter',
id: 456
});
```
### **Tool 2: `bookstack_list_content`**
```typescript
interface ContentListInput {
entity_type: 'books' | 'bookshelves' | 'chapters' | 'pages';
// Pagination
offset?: number;
count?: number;
// Filtering
filter?: Record<string, string>;
book_id?: number; // For chapters/pages
chapter_id?: number; // For pages
// Sorting
sort?: string;
}
```
**Usage Examples:**
```typescript
// List books with pagination
await bookstack_list_content({
entity_type: 'books',
count: 20,
offset: 0
});
// List pages in a specific chapter
await bookstack_list_content({
entity_type: 'pages',
chapter_id: 123
});
```
### **Tool 6: `bookstack_batch_operations`** *(New)*
```typescript
interface BatchOperationInput {
operation: 'bulk_create' | 'bulk_update' | 'bulk_delete';
entity_type: 'book' | 'bookshelf' | 'chapter' | 'page';
// For bulk operations
items: Array<{
id?: number; // For update/delete
data?: Record<string, any>; // For create/update
}>;
// Options
continue_on_error?: boolean;
batch_size?: number;
dry_run?: boolean;
}
```
---
## š Benefits Analysis
### **Quantitative Benefits**
| Metric | Before | After | Improvement |
|--------|--------|-------|-------------|
| **Total Tools** | 25 | 6 | 76% reduction |
| **Content Tools** | 20 | 2 | 90% reduction |
| **Maintenance Burden** | High | Low | 76% less code |
| **Learning Curve** | Steep | Gentle | 76% fewer APIs |
### **Qualitative Benefits**
#### **Developer Experience**
- ā
**Unified Interface**: Single tool for all CRUD operations per entity type
- ā
**Consistent Patterns**: Same operation parameter across all tools
- ā
**Reduced Cognitive Load**: 6 tools vs 25 to remember
- ā
**Better Documentation**: Fewer tools = more comprehensive docs per tool
#### **Maintenance & Testing**
- ā
**Centralized Logic**: Entity-specific logic in one place
- ā
**Shared Validation**: Common validation patterns
- ā
**Easier Testing**: Fewer test suites to maintain
- ā
**Consistent Error Handling**: Unified error patterns
#### **Performance & Reliability**
- ā
**Shared Caching**: Centralized cache management
- ā
**Connection Pooling**: Fewer HTTP clients
- ā
**Batch Operations**: New efficiency capabilities
- ā
**Transaction Support**: Atomic multi-entity operations
---
## š§ Migration Strategy
### **Phase 1: Core Consolidation (Week 1)**
1. **Implement `bookstack_manage_content`**
- Consolidate all CRUD operations
- Migrate existing validation logic
- Comprehensive testing
2. **Implement `bookstack_list_content`**
- Consolidate all list operations
- Preserve pagination and filtering
- Performance optimization
### **Phase 2: Advanced Features (Week 2)**
1. **Implement `bookstack_batch_operations`**
- Bulk operation support
- Transaction handling
- Progress tracking
2. **Enhanced Error Handling**
- Unified error responses
- Better validation messages
- Operation-specific guidance
### **Phase 3: Migration & Cleanup (Week 3)**
1. **Deprecation Notices**
- Add deprecation warnings to old tools
- Update documentation
- Migration guides
2. **Remove Legacy Tools**
- Clean up old tool files
- Update imports
- Final testing
---
## ā ļø Risk Assessment
### **Technical Risks**
| Risk | Impact | Mitigation |
|------|--------|------------|
| **Schema Complexity** | Medium | Comprehensive validation with clear error messages |
| **Backward Compatibility** | High | Gradual deprecation with migration period |
| **Performance Impact** | Low | Shared caching and optimized routing |
### **User Experience Risks**
| Risk | Impact | Mitigation |
|------|--------|------------|
| **Learning Curve** | Medium | Comprehensive documentation and examples |
| **Tool Discovery** | Low | Clear naming and descriptions |
| **Migration Effort** | High | Automated migration tools and guides |
---
## š® Future Considerations
### **Extensibility Patterns**
- **Plugin Architecture**: Easy addition of new entity types
- **Operation Extensions**: Custom operations for specific use cases
- **Middleware Support**: Cross-cutting concerns (auth, logging, caching)
### **Advanced Features Roadmap**
- **Workflow Operations**: Multi-step content creation workflows
- **Template System**: Standardized content creation patterns
- **Audit Trail**: Comprehensive operation logging
- **Real-time Sync**: WebSocket-based live updates
---
## š Implementation Checklist
### **Pre-Implementation**
- [ ] Stakeholder approval for consolidation plan
- [ ] Backup strategy for existing tools
- [ ] Test environment setup
### **Implementation**
- [ ] Create consolidated tool schemas
- [ ] Implement unified validation logic
- [ ] Migrate existing functionality
- [ ] Comprehensive test coverage
- [ ] Performance benchmarking
### **Migration**
- [ ] Create migration documentation
- [ ] Implement deprecation warnings
- [ ] User communication plan
- [ ] Support for migration period
### **Post-Implementation**
- [ ] Remove legacy tools
- [ ] Update all documentation
- [ ] Performance monitoring
- [ ] User feedback collection
---
## š§ Technical Implementation Details
### **Consolidated Tool Architecture**
```typescript
// Base interface for all consolidated tools
interface ConsolidatedToolInput {
operation: string;
entity_type?: string;
id?: number;
dry_run?: boolean;
}
// Shared validation patterns
const entityTypeSchema = z.enum(['book', 'bookshelf', 'chapter', 'page']);
const operationSchema = z.enum(['create', 'read', 'update', 'delete']);
const idSchema = z.number().int().positive();
```
### **Entity-Specific Logic Mapping**
#### **Books**
```typescript
interface BookOperations {
create: { name: string; description?: string; tags?: Tag[]; image_id?: number };
read: { id: number };
update: { id: number; updates: Partial<BookData> };
delete: { id: number };
}
```
#### **Chapters**
```typescript
interface ChapterOperations {
create: { book_id: number; name: string; description?: string };
read: { id: number };
update: { id: number; updates: Partial<ChapterData> };
delete: { id: number };
}
```
#### **Pages**
```typescript
interface PageOperations {
create: {
book_id?: number;
chapter_id?: number;
name: string;
markdown?: string;
html?: string
};
read: { id: number };
update: { id: number; updates: Partial<PageData> };
delete: { id: number };
}
```
### **Error Handling Strategy**
```typescript
class ConsolidatedToolError extends Error {
constructor(
public operation: string,
public entityType: string,
public code: string,
message: string,
public details?: Record<string, any>
) {
super(`${operation} ${entityType} failed: ${message}`);
}
}
// Standardized error responses
interface ErrorResponse {
success: false;
operation: string;
entity_type: string;
error: {
code: string;
message: string;
details?: Record<string, any>;
};
}
```
### **Caching Strategy**
```typescript
class ConsolidatedCache {
private static cache = new Map<string, CacheEntry>();
private static readonly TTL = 30_000; // 30 seconds
static buildKey(operation: string, entityType: string, params: Record<string, any>): string {
return `${operation}:${entityType}:${JSON.stringify(params)}`;
}
static invalidateEntity(entityType: string, id?: number) {
// Invalidate all cache entries for entity type
// Optionally target specific entity by ID
}
}
```
---
## š Comparison: Before vs After
### **Tool Count Reduction**
```
BEFORE (25 tools):
āāā Content CRUD (20 tools)
ā āāā Books: create, read, update, delete (4)
ā āāā Bookshelves: create, read, update, delete (4)
ā āāā Chapters: create, read, update, delete (4)
ā āāā Pages: create, read, update, delete (4)
āāā Content Lists (4 tools)
ā āāā list_books, list_bookshelves (2)
ā āāā list_chapters, list_pages (2)
āāā Search (1 tool)
āāā Images (2 tools) ā
Already consolidated
āāā Examples (2 tools) ā Removed
AFTER (6 tools):
āāā bookstack_manage_content (1) ā Replaces 16 CRUD tools
āāā bookstack_list_content (1) ā Replaces 4 list tools
āāā bookstack_search (1) ā Keep as-is
āāā bookstack_manage_images (1) ā Keep as-is
āāā bookstack_search_images (1) ā Keep as-is
āāā bookstack_batch_operations (1) ā New capability
```
### **API Complexity Reduction**
```
BEFORE: 25 different tool interfaces to learn
AFTER: 6 consistent tool interfaces
BEFORE: 25 different error handling patterns
AFTER: 6 unified error handling patterns
BEFORE: 25 different validation schemas
AFTER: 6 consolidated validation schemas
```
### **Code Maintenance Reduction**
```
BEFORE: ~25 tool files + ~25 test files = 50 files
AFTER: ~6 tool files + ~6 test files = 12 files
REDUCTION: 76% fewer files to maintain
```
---
## šÆ Success Metrics
### **Quantitative Goals**
- ā
**Tool Count**: Reduce from 25 to 6 tools (76% reduction)
- ā
**Code Coverage**: Maintain >90% test coverage
- ā
**Performance**: <100ms response time for all operations
- ā
**Memory Usage**: <50MB memory footprint
- ā
**API Consistency**: 100% consistent response formats
### **Qualitative Goals**
- ā
**Developer Experience**: Simplified tool discovery and usage
- ā
**Documentation Quality**: Comprehensive examples for all operations
- ā
**Error Messages**: Clear, actionable error guidance
- ā
**Backward Compatibility**: Smooth migration path
- ā
**Future Extensibility**: Easy addition of new entity types
---
## š Implementation Timeline
### **Week 1: Foundation**
- **Day 1-2**: Design consolidated schemas and interfaces
- **Day 3-4**: Implement `bookstack_manage_content` core logic
- **Day 5**: Implement `bookstack_list_content` core logic
### **Week 2: Advanced Features**
- **Day 1-2**: Add comprehensive validation and error handling
- **Day 3-4**: Implement `bookstack_batch_operations`
- **Day 5**: Performance optimization and caching
### **Week 3: Migration & Polish**
- **Day 1-2**: Create migration documentation and tools
- **Day 3**: Add deprecation warnings to legacy tools
- **Day 4**: Final testing and performance validation
- **Day 5**: Remove legacy tools and update documentation
---
**Next Steps:** Stakeholder review and approval for Phase 1 implementation.