Real-world examples of using the Context Engine MCP Server with Codex CLI and other MCP clients.
User Query:
"Search for authentication logic in the codebase"
What Happens:
- Codex calls
semantic_searchtool - Query: "authentication logic"
- Returns relevant files with auth code
Expected Response:
Found 5 results for: "authentication logic"
1. src/auth/login.ts
Lines: 15-45
Relevance: 92.3%
export async function authenticateUser(credentials) {
const user = await validateCredentials(credentials);
...
2. src/middleware/auth.ts
Lines: 8-30
Relevance: 88.7%
export function requireAuth(req, res, next) {
const token = req.headers.authorization;
...
User Query:
"Show me the package.json file"
What Happens:
- Codex calls
get_filetool - Path: "package.json"
- Returns complete file contents
Expected Response:
File: package.json
Lines: 35
Size: 1247 bytes
================================================================================
{
"name": "my-project",
"version": "1.0.0",
...
}
User Query:
"I need to add a new API endpoint for user profiles. Get me relevant context."
What Happens:
- Codex calls
get_context_for_prompttool - Query: "API endpoint user profiles"
- Returns comprehensive context bundle
Expected Response:
# Context for: "API endpoint user profiles"
## Key Insights
- Found code in: .ts, .js
- 5 relevant files found
## Relevant Code
### 1. src/routes/api.ts
Lines: 10-50
```typescript
export const apiRouter = express.Router();
apiRouter.get('/users/:id', async (req, res) => {
const user = await getUserById(req.params.id);
res.json(user);
});Lines: 5-30
export async function getUserProfile(userId: string) {
const profile = await db.users.findOne({ id: userId });
return formatUserProfile(profile);
}
## Advanced Usage
### Example 4: Code Review Assistance
**User Query:**
> "Review the error handling patterns in this codebase"
**Codex's Workflow:**
1. Calls `semantic_search` with query "error handling try catch"
2. Analyzes results
3. Calls `get_file` for specific files
4. Provides comprehensive review
**User Benefits:**
- Finds all error handling code
- Identifies inconsistencies
- Suggests improvements
### Example 5: Bug Investigation
**User Query:**
> "There's a bug in the payment processing. Help me find the relevant code."
**Codex's Workflow:**
1. Calls `get_context_for_prompt` with "payment processing"
2. Reviews context bundle
3. Asks clarifying questions
4. Calls `get_file` for specific files
5. Helps debug
### Example 6: Learning Codebase
**User Query:**
> "I'm new to this codebase. Explain how the database layer works."
**Codex's Workflow:**
1. Calls `get_context_for_prompt` with "database layer schema models"
2. Analyzes structure
3. Calls `semantic_search` for specific patterns
4. Provides explanation with code examples
## Tool-Specific Examples
### semantic_search Tool
**Use Cases:**
- Finding specific patterns
- Locating similar code
- Discovering implementations
**Example Queries:**
```json
{
"name": "semantic_search",
"arguments": {
"query": "database connection pool",
"top_k": 5
}
}
{
"name": "semantic_search",
"arguments": {
"query": "error handling middleware",
"top_k": 10
}
}Use Cases:
- Reading configuration files
- Reviewing specific implementations
- Getting complete context
Example Queries:
{
"name": "get_file",
"arguments": {
"path": "src/config/database.ts"
}
}{
"name": "get_file",
"arguments": {
"path": "README.md"
}
}Use Cases:
- Feature development
- Understanding subsystems
- Comprehensive code review
Example Queries:
{
"name": "get_context_for_prompt",
"arguments": {
"query": "authentication and authorization system",
"max_files": 5
}
}{
"name": "get_context_for_prompt",
"arguments": {
"query": "API rate limiting implementation",
"max_files": 3
}
}The enhance_prompt tool transforms simple prompts into detailed, structured prompts enriched with relevant codebase context. This is particularly useful for RAG (Retrieval-Augmented Generation) pipelines and preparing prompts for external LLMs.
Use Cases:
- Preparing prompts for external LLM APIs with codebase context
- RAG pipeline enhancement
- Context enrichment before sending prompts to other services
- Generating detailed prompts from simple user queries
Example 1: Basic Usage with AI Mode (Default)
{
"name": "enhance_prompt",
"arguments": {
"prompt": "How should we implement user authentication?",
"max_files": 5,
"use_ai": true
}
}This uses AI to intelligently select and summarize the most relevant code context, producing a well-structured prompt suitable for external LLMs.
Example 2: Template Mode
{
"name": "enhance_prompt",
"arguments": {
"prompt": "Show me the database schema",
"max_files": 3,
"use_ai": false
}
}Template mode returns raw code snippets in a structured format without AI summarization, useful when you want direct access to the code.
Example 3: Custom max_files Parameter
{
"name": "enhance_prompt",
"arguments": {
"prompt": "Explain the payment processing workflow",
"max_files": 10
}
}Output Format Differences:
- AI Mode (
use_ai: true): Returns a narrative-style enhanced prompt with AI-generated summaries and context integration - Template Mode (
use_ai: false): Returns structured code snippets with metadata, suitable for programmatic processing
When to Use Each Mode:
- Use AI Mode when sending prompts to external LLMs or when you need human-readable context
- Use Template Mode when building automated pipelines or when you need raw code for further processing
The index_workspace tool indexes workspace files for semantic search. This tool should be called during initial setup or after major codebase changes to ensure search results are accurate and up-to-date.
Use Cases:
- First-time setup of the MCP server
- After major codebase changes or file reorganization
- When semantic search returns no results or incomplete results
- Periodic re-indexing for large codebases
Example 1: Basic Indexing
{
"name": "index_workspace",
"arguments": {
"force": false
}
}This performs incremental indexing, only processing files that have changed since the last index.
Example 2: Force Re-indexing
{
"name": "index_workspace",
"arguments": {
"force": true
}
}Force re-indexing rebuilds the entire index from scratch, useful when the index may be corrupted or out of sync.
Expected Output Format:
Indexing workspace...
Indexed X files in Y seconds
When to Use Force Re-indexing:
- After major codebase restructuring
- If search results seem incomplete or inaccurate
- When troubleshooting search functionality
- After upgrading the MCP server
❌ Bad: "Show me code" ✅ Good: "Show me the authentication middleware code"
❌ Bad: "Find functions" ✅ Good: "Find database query functions in the user service"
- semantic_search: When you know what you're looking for
- get_file: When you know the exact file
- get_context_for_prompt: When you need comprehensive context
Start broad, then narrow down:
get_context_for_prompt- Get overviewsemantic_search- Find specific patternsget_file- Read complete files
For broad exploration:
{
"query": "authentication",
"max_files": 10
}For focused investigation:
{
"query": "JWT token validation in auth middleware",
"max_files": 3
}-
Understand existing patterns
- Query: "Get context for similar feature X"
-
Find implementation examples
- Query: "Search for pattern Y"
-
Review specific files
- Query: "Show me file Z"
-
Locate problem area
- Query: "Get context for module with bug"
-
Find related code
- Query: "Search for error handling in module"
-
Review implementation
- Query: "Show me the specific file"
-
Get overview
- Query: "Get context for the PR changes"
-
Check patterns
- Query: "Search for similar implementations"
-
Verify specific files
- Query: "Show me each changed file"
-
Index your workspace first
node dist/index.js --workspace /path/to/project --index
-
Use domain-specific terms
- Instead of "code that handles users"
- Use "user authentication service"
-
Combine tools
- Start with
get_context_for_prompt - Follow up with
semantic_search - Finish with
get_file
- Start with
-
Re-index after major changes
auggie index /path/to/project
Problem: Query returns no results
Solutions:
- Make query more general
- Check if workspace is indexed
- Verify file types are supported
Problem: Query returns too many irrelevant results
Solutions:
- Make query more specific
- Reduce
top_kormax_files - Use more technical terms
Problem: Results don't match expectation
Solutions:
- Rephrase query with different terms
- Use
get_context_for_promptinstead ofsemantic_search - Check if files are actually indexed
For more examples and use cases, see the TESTING.md guide.