Skip to content

Latest commit

 

History

History
200 lines (153 loc) · 5.69 KB

File metadata and controls

200 lines (153 loc) · 5.69 KB

Context-Aware Prompt Tools - Enabled ✅

Summary

Successfully enabled the context-aware prompt tools that were previously defined but never registered in the MCP server.

Changes Made

1. Added Import Statement

File: src/mcp_server/mcp_app.py
Line: 173

from src.mcp_server.tools.context_aware_prompt import register_context_aware_tools

2. Added Tool Registration

File: src/mcp_server/mcp_app.py
Line: 195

register_context_aware_tools(self.mcp)

New Tools Available

The following three context-aware prompt tools are now registered and available via MCP:

1. generate_contextual_prompt()

Purpose: Generate context-aware prompts based on query and context

Parameters:

  • query (str): User query or request
  • context (Optional[Dict]): Optional context information
  • prompt_type (str): Type of prompt - "search", "analysis", "explanation", "comparison", "recommendation"

Returns:

  • prompt: Generated context-aware prompt
  • prompt_type: Type of prompt used
  • has_context: Whether context was provided
  • context_length: Length of context
  • query_length: Length of query

Example Usage:

result = await generate_contextual_prompt(
    query="How does authentication work?",
    context={"framework": "FastAPI", "language": "Python"},
    prompt_type="explanation"
)

2. extract_context_keywords()

Purpose: Extract relevant keywords from text for context understanding

Parameters:

  • text (str): Text to analyze
  • max_keywords (int): Maximum number of keywords to extract (default: 10)

Returns:

  • keywords: List of extracted keywords
  • count: Number of keywords extracted
  • text_length: Length of input text
  • unique_words: Number of unique words found

Example Usage:

result = await extract_context_keywords(
    text="This is a Python FastAPI application with authentication and database integration",
    max_keywords=5
)
# Returns: ["python", "fastapi", "application", "authentication", "database"]

3. optimize_prompt_for_context()

Purpose: Optimize prompts based on context type and desired response format

Parameters:

  • prompt (str): Original prompt to optimize
  • context_type (str): Type of context - "code", "documentation", "analysis", "troubleshooting", "learning", "general"
  • response_format (str): Desired format - "detailed", "concise", "technical", "practical", "educational"

Returns:

  • optimized_prompt: Enhanced prompt with context guidelines
  • original_prompt: Original prompt
  • context_type: Context type used
  • response_format: Response format used
  • context_instruction: Context-specific instruction added
  • format_instruction: Format-specific instruction added

Example Usage:

result = await optimize_prompt_for_context(
    prompt="Explain how to implement authentication",
    context_type="code",
    response_format="practical"
)

Tool Count Update

Before: 10 tool categories registered
After: 11 tool categories registered

The MCP server now registers:

  1. ✅ Health Tools
  2. ✅ Capability Tools
  3. ✅ Indexing Tools
  4. ✅ Vector Tools
  5. ✅ Search Tools
  6. ✅ Pattern Search Tools
  7. ✅ Cross-Language Tools
  8. ✅ Query Understanding Tools
  9. ✅ Indexing Optimization Tools
  10. ✅ Prompt Tools
  11. Context-Aware Prompt Tools (NEW)

Testing Instructions

Step 1: Restart Docker Services

cd deployment/docker
docker-compose restart context-server

Step 2: Check Docker Logs

docker logs context-server | grep -i "context-aware"

Expected output:

INFO: Registered context-aware prompt tools

Step 3: Restart Claude Code CLI

  1. Close Claude Code CLI completely
  2. Wait 5 seconds
  3. Reopen Claude Code CLI

Step 4: Verify Tools are Available

Ask Claude:

What MCP tools are available from the Context server?

You should see the three new tools listed:

  • generate_contextual_prompt
  • extract_context_keywords
  • optimize_prompt_for_context

Step 5: Test the Tools

Test 1: Generate Contextual Prompt

Use the generate_contextual_prompt tool to create a search prompt for "authentication functions" with context about Python and FastAPI.

Test 2: Extract Keywords

Use the extract_context_keywords tool to extract keywords from this text: "This Python application uses FastAPI for REST API development with PostgreSQL database and Redis caching"

Test 3: Optimize Prompt

Use the optimize_prompt_for_context tool to optimize this prompt: "How do I implement caching?" for code context with practical response format.

Files Modified

  • src/mcp_server/mcp_app.py (added import and registration)
  • CONTEXT_AWARE_TOOLS_ENABLED.md (this documentation)

Files Referenced (No Changes)

  • src/mcp_server/tools/context_aware_prompt.py (existing tool definitions)
  • src/mcp_server/stdio_full_mcp.py (uses mcp_app.py's register_tools method)

Benefits

These tools enable:

  • Better prompt engineering for AI interactions
  • Context-aware query enhancement for more relevant results
  • Keyword extraction for understanding user intent
  • Prompt optimization for different use cases (code, docs, analysis, etc.)

Next Steps

After verifying the tools work correctly, you may want to:

  1. Test the tools with real queries in Claude Code CLI
  2. Integrate these tools into your workflow for enhanced code search
  3. Consider enabling other optional tools if needed (cache management, query optimization, etc.)

References