UNPKG

@skyramp/mcp

Version:

Skyramp MCP (Model Context Protocol) Server - AI-powered test generation and execution

294 lines (247 loc) 8.49 kB
/** * Repository Analysis Prompt * Comprehensive prompt for analyzing code repositories */ export function getRepositoryAnalysisPrompt(repositoryPath) { return ` Analyze this repository systematically using the guide below. REPOSITORY PATH: ${repositoryPath} IMPORTANT OUTPUT FORMAT: - Return analysis as valid JSON matching the RepositoryAnalysis interface - Use empty arrays [] for unavailable data rather than omitting fields - Use "unknown" for unknown string values - Provide evidence (file paths, line numbers) where possible ## CRITICAL RULES - If user flows are defined in documentation explicitly, follow them strictly and do not generate new ones. # Repository Analysis Guide ## 1. Initial Repository Analysis ### Documentation Review documentation files for any project-specific details and instructions ### Project Type Identify what kind of application this is: - REST API service - Frontend application (React/Vue/Angular) - Full-stack application - Library/SDK - CLI tool - Microservices - Other (describe) ### Primary Technology Stack - **Language**: Identify the primary programming language(s) - **Framework**: Identify the main framework(s) used - **Key Dependencies**: List critical dependencies from package files ### Main Purpose Describe what this application does in 1-2 sentences. ### Business Logic - **Common User Flows**: How do users typically interact with this system? - Infer from documentation, endpoint analysis, and code structure - **Common Data Flows**: How does data move through the system? - **Common Integration Patterns**: How does this system integrate with other services? ## 2. Artifact Discovery ### OpenAPI/Swagger Specifications **Search Patterns:** - \`**/*{openapi,swagger}*.{yaml,yml,json}\` - \`**/api-spec.{yaml,yml,json}\` - \`**/docs/**/*.{yaml,yml,json}\` **Extract:** - OpenAPI/Swagger version - Total endpoint count - Base URL(s) - Authentication schemes - Paths and operations ### Playwright Recordings **Search Patterns:** - \`**/*.zip\` in \`/recordings/\`, \`/tests/\`, \`/e2e/\` directories ### API Trace Files **Search Patterns:** - \`**/*trace*.json\` - JSON trace files - \`**/*.har\` - HAR (HTTP Archive) files - \`**/traces/**/*.json\` - Trace directories ## 3. API Endpoint Discovery ### If OpenAPI Spec Available - Parse all paths and operations - Extract: path, HTTP methods, authentication requirements, path parameters - Count total endpoints - Identify base URL from servers section - Detect authentication type (bearer, api_key, oauth2, basic) ### If No OpenAPI Spec Scan code for route definitions based on framework: **Express (Node.js):** - Patterns: \`app.get(\`, \`app.post(\`, \`router.get(\`, \`router.post(\` **FastAPI (Python):** - Patterns: \`@app.get(\`, \`@router.post(\`, \`@app.put(\` **Spring (Java):** - Patterns: \`@GetMapping\`, \`@PostMapping\`, \`@RestController\`, \`@RequestMapping\` **Django (Python):** - Patterns: \`path(\`, \`url(\` in \`urls.py\` files **Flask (Python):** - Patterns: \`@app.route(\`, \`@blueprint.route(\` ## 4. Authentication Analysis Investigate how the application handles authentication and authorization. ### Look For: - Environment variables: \`API_KEY\`, \`TOKEN\`, \`SECRET\`, \`AUTH_\`, \`JWT_\` - Authentication middleware or decorators - JWT handling libraries - OAuth configuration files - API key validation logic - Session management ### Identify: 1. **Authentication Method**: Bearer token, API key, OAuth 2.0, Basic Auth, JWT, etc. 2. **Configuration Location**: Where auth is configured (env files, config files, middleware) 3. **Credential Setup**: How to set authentication credentials ## 5. Infrastructure Analysis Analyze deployment and infrastructure configuration. ### Containerization **Check for:** - \`Dockerfile\` - \`docker-compose.yml\` - \`.dockerignore\` ### Orchestration **Kubernetes:** - Check for manifests in \`k8s/\`, \`kubernetes/\`, or \`.yaml\` files with \`kind: Deployment\` **Docker Compose:** - Check for multi-service setup ### CI/CD **Identify platforms from config files:** - GitHub Actions: \`.github/workflows/\` - GitLab CI: \`.gitlab-ci.yml\` - Jenkins: \`Jenkinsfile\` - CircleCI: \`.circleci/config.yml\` - Travis CI: \`.travis.yml\` ### Deployment Pattern Inference - **Microservices**: Kubernetes AND multiple services detected - **Full-stack**: Docker Compose AND both API and Frontend components detected - **Containerized Monolith**: Single Dockerfile only (no compose, no K8s) - **Traditional**: No container configurations found ## 6. Existing Test Analysis Analyze the testing infrastructure and coverage. ### Test Directory Detection **Search Patterns:** - \`**/test/**\` - \`**/tests/**\` - \`**/__tests__/**\` - \`**/spec/**\` **Count test files:** - \`**/*{.test,.spec}.{ts,js,tsx,jsx,py,java,go}\` ### Test Framework Detection **Configuration Files:** - \`pytest.ini\`, \`setup.cfg\` (pytest) - \`jest.config.js\`, \`jest.config.ts\` (Jest) - \`karma.conf.js\` (Karma) - \`playwright.config.ts\` (Playwright) - \`cypress.config.js\` (Cypress) ### Test Type Inference **File Name Patterns:** - **Unit Tests**: \`*unit*.{test,spec}\`, \`*.unit.*\` - **Integration Tests**: \`*integration*.{test,spec}\`, \`*.integration.*\` - **E2E Tests**: \`*e2e*.{test,spec}\`, \`*end-to-end*\`, \`*.e2e.*\` - **Smoke Tests**: \`*smoke*.{test,spec}\` - **Load Tests**: \`*load*.{test,spec}\`, \`*performance*\` ## OUTPUT STRUCTURE Return a JSON object with this exact structure: \`\`\`json { "metadata": { "repositoryName": "name-from-path", "analysisDate": "2025-10-15T14:30:00Z", "scanDepth": "full" }, "projectClassification": { "projectType": "rest-api | frontend | full-stack | microservices | library | cli | other", "primaryLanguage": "language", "primaryFramework": "framework", "deploymentPattern": "microservices | full-stack | containerized-monolith | traditional | unknown" }, "technologyStack": { "languages": ["language1", "language2"], "frameworks": ["framework1", "framework2"], "runtime": "runtime version", "keyDependencies": [ { "name": "dep1", "version": "1.0.0", "purpose": "description" } ] }, "businessContext": { "mainPurpose": "1-2 sentence description", "userFlows": ["flow1", "flow2"], "dataFlows": ["flow1", "flow2"], "integrationPatterns": ["pattern1", "pattern2"] }, "artifacts": { "openApiSpecs": [ { "path": "./docs/openapi.yaml", "version": "3.0.0", "endpointCount": 18, "baseUrl": "http://localhost:3000/api/v1", "authType": "bearer" } ], "playwrightRecordings": [], "traceFiles": [ { "path": "./traces/user-session.json", "format": "json" } ], "notFound": ["Playwright recordings"] }, "apiEndpoints": { "totalCount": 18, "baseUrl": "http://localhost:3000/api", "endpoints": [ { "path": "/users", "method": "GET", "resourceGroup": "Users", "authRequired": true, "sourceFile": "src/routes/user.js:10" } ] }, "authentication": { "method": "bearer | api-key | oauth2 | basic | jwt | none", "configLocation": "path/to/config", "envVarsRequired": ["VAR1", "VAR2"], "setupExample": "export API_KEY=value" }, "infrastructure": { "isContainerized": true, "hasDockerCompose": true, "hasKubernetes": false, "hasCiCd": true, "ciCdPlatform": "github-actions" }, "existingTests": { "frameworks": ["jest", "supertest"], "coverage": { "unit": 45, "integration": 0, "e2e": 0, "ui": 0, "load": 0, "contract": 0, "smoke": 0 }, "testLocations": { "unit": "src/tests/unit/" }, "hasCoverageReports": true, "estimatedCoverage": 78 } } \`\`\` VALIDATION CHECKLIST: - [ ] Project type identified with evidence - [ ] All artifacts searched with file paths - [ ] API endpoints counted and categorized - [ ] Authentication method determined - [ ] Infrastructure flags verified - [ ] Existing tests catalogued **CRITICAL INSTRUCTIONS**: - Return the JSON object directly in your response text. - DO NOT create or save any files (no repository_analysis.json or .md files). - DO NOT use file write tools or save analysis to disk. - Output the complete analysis JSON inline in your response. Begin analysis now. Return the JSON object directly in your response text. `; }