"""MCP Prompts for xcsift server.
Prompts provide reusable templates for common workflows.
"""
from mcp.server.fastmcp import FastMCP
from mcp.server.fastmcp.prompts import base
def register_prompts(mcp: FastMCP) -> None:
"""Register prompts with the MCP server."""
@mcp.prompt(title="Analyze Build Failure")
def analyze_build_failure(
errors: str,
code_context: str = "",
) -> list[base.Message]:
"""Template for analyzing and fixing build failures.
Use this prompt when you have build errors and need help
understanding and fixing them.
Args:
errors: The errors from the build (paste xcsift output).
code_context: Optional relevant code snippets.
"""
messages = [
base.UserMessage(
"""I have a build failure in my Xcode/Swift project. Please analyze these errors and help me fix them.
## Build Errors
```
"""
+ errors
+ """
```
"""
),
]
if code_context:
messages.append(
base.UserMessage(
"""## Relevant Code
```swift
"""
+ code_context
+ """
```
"""
)
)
messages.append(
base.AssistantMessage(
"""I'll analyze these build errors and provide solutions.
Let me examine each error and suggest fixes:"""
)
)
return messages
@mcp.prompt(title="Fix Compiler Errors")
def fix_compiler_errors(
errors: str,
file_content: str,
) -> list[base.Message]:
"""Template for fixing Swift/Objective-C compiler errors.
Use this prompt when you have specific compiler errors and
the source file that contains them.
Args:
errors: The compiler errors (paste xcsift output).
file_content: The source file content with errors.
"""
return [
base.UserMessage(
"""I have compiler errors in my Swift/Objective-C code. Please fix them.
## Compiler Errors
```
"""
+ errors
+ """
```
## Source File
```swift
"""
+ file_content
+ """
```
Please provide the corrected code with explanations for each fix."""
),
base.AssistantMessage(
"""I'll fix these compiler errors. Here's the corrected code:"""
),
]
@mcp.prompt(title="Improve Test Coverage")
def improve_test_coverage(
coverage_report: str,
target_coverage: int = 80,
) -> list[base.Message]:
"""Template for improving test coverage.
Use this prompt when you have a coverage report and want
suggestions for improving test coverage.
Args:
coverage_report: The coverage report from xcsift.
target_coverage: Target coverage percentage (default: 80).
"""
return [
base.UserMessage(
f"""I need to improve the test coverage for my project. The target is {target_coverage}%.
## Current Coverage Report
```
"""
+ coverage_report
+ """
```
Please analyze which areas need more tests and suggest specific test cases to write."""
),
base.AssistantMessage(
f"""I'll analyze the coverage report and suggest tests to reach {target_coverage}% coverage.
Based on the report, here are my recommendations:"""
),
]
@mcp.prompt(title="Debug Test Failures")
def debug_test_failures(
test_output: str,
test_code: str = "",
) -> list[base.Message]:
"""Template for debugging test failures.
Use this prompt when you have failing tests and need help
understanding why they fail.
Args:
test_output: The test output with failures (paste xcsift output).
test_code: Optional test code that's failing.
"""
messages = [
base.UserMessage(
"""I have failing tests in my project. Please help me debug them.
## Test Output
```
"""
+ test_output
+ """
```
"""
),
]
if test_code:
messages.append(
base.UserMessage(
"""## Test Code
```swift
"""
+ test_code
+ """
```
"""
)
)
messages.append(
base.AssistantMessage(
"""I'll analyze the test failures and help you fix them.
Looking at the test output:"""
)
)
return messages
@mcp.prompt(title="Fix Linker Errors")
def fix_linker_errors(
linker_errors: str,
project_structure: str = "",
) -> list[base.Message]:
"""Template for fixing linker errors.
Use this prompt when you have linker errors (undefined symbols,
missing frameworks, duplicate symbols, etc.).
Args:
linker_errors: The linker errors from xcsift output.
project_structure: Optional project structure or Podfile/Package.swift.
"""
messages = [
base.UserMessage(
"""I have linker errors in my Xcode project. Please help me fix them.
## Linker Errors
```
"""
+ linker_errors
+ """
```
"""
),
]
if project_structure:
messages.append(
base.UserMessage(
"""## Project Dependencies
```
"""
+ project_structure
+ """
```
"""
)
)
messages.append(
base.AssistantMessage(
"""I'll analyze these linker errors and suggest solutions.
Linker errors typically occur due to:
- Missing frameworks or libraries
- Undefined symbols (implementation not found)
- Duplicate symbols (same symbol defined multiple times)
- Architecture mismatches
Let me examine your specific errors:"""
)
)
return messages
@mcp.prompt(title="Analyze Build Performance")
def analyze_build_performance(
build_info: str,
) -> list[base.Message]:
"""Template for analyzing and improving build performance.
Use this prompt when you have build timing information and
want to optimize build times.
Args:
build_info: Build info from xcsift with --build-info flag.
"""
return [
base.UserMessage(
"""I want to improve my project's build time. Please analyze this build info.
## Build Information
```
"""
+ build_info
+ """
```
Please identify bottlenecks and suggest optimizations to reduce build time."""
),
base.AssistantMessage(
"""I'll analyze the build performance and suggest optimizations.
Looking at the build timing data:"""
),
]