|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package tools |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + _ "embed" |
| 9 | + "fmt" |
| 10 | + "os" |
| 11 | + "strings" |
| 12 | + "time" |
| 13 | + |
| 14 | + "github.com/mark3labs/mcp-go/mcp" |
| 15 | + "github.com/mark3labs/mcp-go/server" |
| 16 | +) |
| 17 | + |
| 18 | +//go:embed resources/app-spec-template.md |
| 19 | +var appSpecTemplateContent string |
| 20 | + |
| 21 | +// NewGenerateProjectSpecTemplateTool creates a new MCP tool for generating project specification templates |
| 22 | +func NewGenerateProjectSpecTemplateTool() server.ServerTool { |
| 23 | + return server.ServerTool{ |
| 24 | + Tool: mcp.NewTool( |
| 25 | + "azd_generate_project_spec_template", |
| 26 | + mcp.WithReadOnlyHintAnnotation(false), |
| 27 | + mcp.WithIdempotentHintAnnotation(true), |
| 28 | + mcp.WithDestructiveHintAnnotation(false), |
| 29 | + mcp.WithOpenWorldHintAnnotation(false), |
| 30 | + mcp.WithDescription( |
| 31 | + `Generate a project specification template file (app-spec.md) in the current workspace. |
| 32 | +This tool creates the initial template file that other tools will populate with actual |
| 33 | +project information during the planning and implementation process. |
| 34 | +
|
| 35 | +The template will be created at 'app-spec.md' in the current directory if it doesn't |
| 36 | +already exist. No parameters required.`, |
| 37 | + ), |
| 38 | + ), |
| 39 | + Handler: handleGenerateProjectSpecTemplate, |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func handleGenerateProjectSpecTemplate(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 44 | + const outputPath = "app-spec.md" |
| 45 | + |
| 46 | + // Check if file already exists |
| 47 | + if _, err := os.Stat(outputPath); err == nil { |
| 48 | + return mcp.NewToolResultText(fmt.Sprintf("Template file '%s' already exists in the workspace. No action taken.", outputPath)), nil |
| 49 | + } |
| 50 | + |
| 51 | + // Generate current timestamp |
| 52 | + currentTime := time.Now() |
| 53 | + generatedDate := currentTime.Format("2006-01-02 15:04:05 MST") |
| 54 | + |
| 55 | + // Create the template with placeholder project name and current timestamp |
| 56 | + templateContent := strings.ReplaceAll(appSpecTemplateContent, "{{.ProjectName}}", "[PROJECT_NAME]") |
| 57 | + templateContent = strings.ReplaceAll(templateContent, "{{.GeneratedDate}}", generatedDate) |
| 58 | + templateContent = strings.ReplaceAll(templateContent, "{{.LastUpdated}}", generatedDate) |
| 59 | + |
| 60 | + // Write the template file to the workspace |
| 61 | + if err := os.WriteFile(outputPath, []byte(templateContent), 0644); err != nil { |
| 62 | + return mcp.NewToolResultText(fmt.Sprintf("Error writing template file: %v", err)), nil |
| 63 | + } |
| 64 | + |
| 65 | + // Create success response |
| 66 | + response := fmt.Sprintf(`# Project Specification Template Created |
| 67 | +
|
| 68 | +✅ **Template File Successfully Created** |
| 69 | +
|
| 70 | +**File Path**: %s |
| 71 | +**Generated**: %s |
| 72 | +
|
| 73 | +## Template Overview |
| 74 | +
|
| 75 | +A comprehensive project specification template has been created in your workspace with the following structure: |
| 76 | +
|
| 77 | +- **Project Overview**: Basic project information and classification |
| 78 | +- **Project Requirements**: Sections for requirements discovery findings |
| 79 | +- **Technology Stack Selection**: Documentation of stack decisions and rationale |
| 80 | +- **Application Architecture**: Component definitions and data architecture |
| 81 | +- **Azure Service Mapping**: Infrastructure and service configurations |
| 82 | +- **Implementation Plan**: Development approach and deployment strategy |
| 83 | +- **Security and Compliance**: Security architecture and requirements |
| 84 | +- **Monitoring and Operations**: Operational procedures and monitoring |
| 85 | +- **Project Status and Next Steps**: Implementation roadmap and success criteria |
| 86 | +
|
| 87 | +## Next Steps |
| 88 | +
|
| 89 | +The template is ready! Other tools will now populate the template sections as they discover and plan project details: |
| 90 | +
|
| 91 | +1. User intent discovery will fill the "Project Requirements" section |
| 92 | +2. Stack selection will complete the "Technology Stack Selection" section |
| 93 | +3. Architecture planning will populate the "Application Architecture" and "Azure Service Mapping" sections |
| 94 | +4. Implementation planning will complete the remaining sections |
| 95 | +
|
| 96 | +The template serves as the living documentation for your AZD project throughout the planning and implementation process.`, outputPath, generatedDate) |
| 97 | + |
| 98 | + return mcp.NewToolResultText(response), nil |
| 99 | +} |
0 commit comments