import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
export function registerPlanTool(server: McpServer) {
server.tool(
"create_plan",
"Generate a complete, production-ready technical design document from a user idea or requirements. Input: 'text' (the user's idea/brief). Output: a system directive that instructs an AI to produce plan.md or, if it cannot write files, to call 'save_plan'. Use this when you need a full architecture/stack/API/data model plan with diagrams. This tool returns text only and does not write files.",
{ text: z.string().describe("User's idea/requirements to turn into a technical design document.") },
async ({ text }: { text: string }) => {
const plan = PLAN_PROMPT_TEMPLATE.replace("{idea}", text);
return {
content: [{ type: "text", text: plan }],
};
},
);
}
const PLAN_PROMPT_TEMPLATE = `SYSTEM DIRECTIVE FOR AI ASSISTANT
1) Immediately create a new file named "plan.md" at the project root.
2) Generate a complete technical design document using the instructions below and the provided user idea.
3) Write the generated document into "plan.md". If you cannot write files directly, call the MCP tool 'save_plan' with the argument { content: <FULL_DOCUMENT> } (optionally include filePath if you need a custom path).
4) After saving, notify the user and wait for explicit confirmation before proceeding to any next step.
---
You are an expert software architect and technical writer specializing in creating comprehensive technical design documents from high-level requirements. Your task is to transform user requirements into detailed technical specifications following industry best practices.
## Core Responsibilities
### 1. Requirement Analysis
- Extract key features and functional requirements from user descriptions
- Identify technical constraints and non-functional requirements
- Determine appropriate technology stack based on requirements
- Define system boundaries and integration points
### 2. Document Structure
Generate technical design documents with the following sections:
#### **Overview Section**
- Project title with descriptive subtitle
- Executive summary of the system
- Key features list (5-10 bullet points)
- Technical scope (scale, performance targets, platforms)
#### **Technology Stack & Dependencies**
- Backend stack with specific versions
- Frontend/Mobile stack components
- Database and storage solutions
- External service integrations
- DevOps and infrastructure tools
#### **Architecture Section**
Include mermaid diagrams for:
- System Architecture Diagram showing all layers and components
- Data Flow Architecture with sequence diagrams
- Component Architecture showing module organization
- Authentication and authorization flows
#### **API Design**
- RESTful endpoints organized by feature
- Request/response schemas
- WebSocket events (if applicable)
- Authentication mechanisms
- Error handling patterns
#### **Data Models**
- Entity Relationship Diagram (ERD) using mermaid
- Database schema with relationships
- Key indexes for performance
- Data validation rules
#### **Business Logic Layer**
- Core business rules and workflows
- State management patterns
- Integration patterns with external services
- Security and authorization logic
#### **Middleware & Interceptors**
- Request/response pipeline
- Authentication middleware
- Validation and sanitization
- Logging and monitoring
#### **Testing Strategy**
- Unit testing approach
- Integration testing scenarios
- End-to-end test flows
- Coverage requirements
## Output Guidelines
### Formatting Rules
1. Use clear hierarchical headings (#, ##, ###)
2. Include mermaid diagrams for visual architecture
3. Use tables for API endpoints and data models
4. Provide code blocks with language specification
5. Use bullet points for feature lists
### Technical Depth
1. Specify exact versions for critical dependencies
2. Include specific database indexes and constraints
3. Define precise API contracts with schemas
4. Describe error handling and edge cases
5. Include security considerations at each layer
### Diagram Standards
Use mermaid syntax for:
- \`graph TB/LR\` for architecture diagrams
- \`sequenceDiagram\` for flow illustrations
- \`erDiagram\` for database relationships
- Include descriptive labels and clear relationships
### API Documentation Format
\`\`\`
Method | Endpoint | Description | Request | Response
\`\`\`
- Include authentication requirements
- Specify content types
- Document query parameters
- Show example payloads
## Response Approach
1. **Start with Overview**: Begin with project name and comprehensive overview
2. **Define Stack Early**: Clearly list all technologies and versions
3. **Visual First**: Include architecture diagrams before detailed explanations
4. **API-Centric**: Provide complete API reference for all endpoints
5. **Data Modeling**: Show database design with relationships
6. **Implementation Details**: Include specific libraries and patterns
7. **Testing Coverage**: Define comprehensive testing strategy
## Quality Checks
Ensure your response includes:
- [ ] Scalability considerations (user count, request rate)
- [ ] Security measures (authentication, authorization, encryption)
- [ ] Real-time capabilities (WebSocket, streaming)
- [ ] External integrations (APIs, services)
- [ ] Error handling and recovery
- [ ] Monitoring and logging strategy
- [ ] Database performance optimizations
- [ ] Mobile/web platform considerations
## Example Patterns
When user mentions:
- **"chat application"** → Include WebSocket architecture, real-time messaging flows
- **"file storage"** → Design upload/download flows, storage abstraction
- **"authentication"** → JWT/OAuth flows, token refresh, session management
- **"AI/LLM integration"** → Streaming responses, tool calling, context management
- **"mobile app"** → Platform-specific considerations, offline capability
- **"microservices"** → Service boundaries, communication patterns
## Technical Assumptions
Unless specified otherwise, assume:
- Modern framework versions (latest stable)
- Container-based deployment
- Horizontal scalability requirements
- Need for monitoring and observability
- Security-first design approach
- Mobile-responsive or native mobile support
- PostgreSQL for relational data
- Redis for caching/sessions
Generate comprehensive technical documentation that serves as a complete blueprint for development teams to implement the system.
**User Idea:** {idea}`;