Spaces:
Sleeping
Sleeping
File size: 4,258 Bytes
d557d77 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
"""MCP prompt templates for CodeRAG."""
from mcp.types import PromptMessage, TextContent
from coderag.mcp.server import mcp
@mcp.prompt()
async def analyze_repository(repo_url: str) -> list[PromptMessage]:
"""Guide for comprehensive repository analysis.
Args:
repo_url: GitHub repository URL to analyze
Returns:
List of prompt messages guiding the analysis workflow
"""
return [
PromptMessage(
role="user",
content=TextContent(
type="text",
text=f"""Please analyze the repository at {repo_url}. Follow these steps:
1. First, use the `index_repository` tool to index the repository:
- URL: {repo_url}
2. Once indexed, use `get_repository_info` to understand the repository structure:
- Note the number of files and chunks indexed
- Review the list of indexed files
3. Use `query_code` to answer these questions:
- What is the main purpose of this codebase?
- What are the key components or modules?
- What design patterns are used?
- What external dependencies does it have?
4. Use `search_code` to find:
- Entry points (main functions, CLI handlers)
- Configuration handling
- Core business logic
5. Provide a comprehensive summary including:
- Purpose and functionality
- Architecture overview
- Key components
- Notable patterns or practices
- Potential areas for improvement
""",
),
)
]
@mcp.prompt()
async def find_implementation(repo_id: str, feature: str) -> list[PromptMessage]:
"""Guide for finding feature implementations.
Args:
repo_id: Repository ID to search in
feature: Feature or functionality to find
Returns:
List of prompt messages guiding the search workflow
"""
return [
PromptMessage(
role="user",
content=TextContent(
type="text",
text=f"""Please find the implementation of "{feature}" in repository {repo_id}. Follow these steps:
1. Use `search_code` to find relevant code:
- Query: "{feature}"
- Try different search terms if initial results aren't helpful
2. For each relevant result, use `query_code` to understand:
- How is this feature implemented?
- What are the key functions/classes involved?
- What is the data flow?
3. Trace the implementation:
- Find the entry point
- Follow the call chain
- Identify helper functions and utilities
4. Provide a detailed explanation:
- Location of the implementation (files and line numbers)
- Key components and their roles
- How data flows through the system
- Any notable patterns or design decisions
""",
),
)
]
@mcp.prompt()
async def code_review(repo_id: str, focus_area: str = "") -> list[PromptMessage]:
"""Guide for performing code reviews.
Args:
repo_id: Repository ID to review
focus_area: Optional specific area to focus on (e.g., "security", "performance")
Returns:
List of prompt messages guiding the review workflow
"""
focus_text = f' with focus on "{focus_area}"' if focus_area else ""
return [
PromptMessage(
role="user",
content=TextContent(
type="text",
text=f"""Please perform a code review of repository {repo_id}{focus_text}. Follow these steps:
1. Use `get_repository_info` to understand the repository structure
2. Use `search_code` to find key areas to review:
- Entry points and main functions
- Error handling patterns
- Data validation
- Security-sensitive code (if applicable)
3. For each area, use `query_code` to analyze:
- Code quality and readability
- Error handling completeness
- Security considerations
- Performance implications
- Test coverage (if tests are indexed)
4. Check for common issues:
- Hardcoded credentials or secrets
- SQL injection vulnerabilities
- Input validation gaps
- Resource leaks
- Race conditions
5. Provide a structured review:
- Summary of findings
- Critical issues (if any)
- Recommendations for improvement
- Positive observations
- Priority of fixes
""",
),
)
]
|