MCP Server
The Model Context Protocol (MCP) server bridges AI assistants like Claude to your indexed codebase, enabling intelligent code search, pattern recognition, and Wikit-aware development.
Overview
The MCP server provides:
- Semantic Code Search: Find code by meaning across all projects
- WordPress Pattern Recognition: Understand hooks, filters, custom post types
- Wikit Block Discovery: Search 60+ Gutenberg blocks
- Project Management: Create and manage WordPress projects
- Repository Integration: Access git repositories and history
Architecture
%%{init: {'theme':'neutral'}}%%
graph TB
subgraph "AI Layer"
Claude[Claude Desktop]
Cursor[Cursor IDE]
Other[Other AI Tools]
end
subgraph "MCP Server"
Server[MCP Server<br/>Port 8765]
Tools[MCP Tools]
end
subgraph "Data Layer"
Qdrant[(Vector DB<br/>Qdrant)]
Git[Git Repositories]
Projects[WordPress Projects]
end
Claude -->|MCP Protocol| Server
Cursor -->|MCP Protocol| Server
Other -->|MCP Protocol| Server
Server --> Tools
Tools --> Qdrant
Tools --> Git
Tools --> Projects
Available Tools
Code Search Tools
search_codebase
Semantic search across all indexed repositories.
# Example usage in Claude
search_codebase(
query="custom post type registration",
project="my-site",
file_types=["php"],
limit=10
)Parameters:
query(string): Search queryproject(string, optional): Project name to scope searchfile_types(list, optional): Filter by file extensionscomponent_type(string, optional): Filter by function, class, hooklimit(int): Maximum results (default: 20)
Returns:
[
{
"file_path": "wp-content/themes/custom/functions.php",
"component_type": "function",
"component_name": "register_portfolio_post_type",
"content": "function register_portfolio_post_type() {...}",
"line_start": 45,
"line_end": 65,
"score": 0.89
}
]search_functions
Find specific functions by name.
search_functions(
function_name="get_user",
project="my-site",
language="php"
)search_classes
Find PHP or JavaScript classes.
search_classes(
class_name="CustomPostType",
project="my-site"
)WordPress-Specific Tools
search_wordpress_hooks
Find WordPress actions and filters.
search_wordpress_hooks(
hook_name="init",
hook_type="action",
project="my-site"
)Hook Types:
action- do_action() callsfilter- apply_filters() callsadd_action- Hook registrationsadd_filter- Filter registrations
wordpress_docs
Search WordPress core documentation.
wordpress_docs(
query="register_post_type",
type="function",
get_details=True
)Wikit-Specific Tools
search_wikit_blocks
Search Wikit's 60+ Gutenberg blocks.
search_wikit_blocks(
block_name="hero" # Optional
)Returns:
[
{
"name": "wdg/hero",
"title": "Hero Section",
"category": "wdg-layout",
"description": "Full-width hero with image/video background",
"attributes": {
"backgroundType": "image",
"overlayOpacity": 0.5
},
"example_usage": "..."
}
]get_wikit_component
Get detailed Wikit component information.
get_wikit_component(
component_name="Button"
)Project Management Tools
get_project_info
Get project details and indexing status.
get_project_info(
project_name="my-site"
)Returns:
{
"name": "my-site",
"status": "running",
"php_version": "8.2",
"url": "https://my-site.localhost:8443",
"database": "wp_my_site",
"collection": "project_my_site",
"vectors": 1450,
"last_indexed": "2024-10-14T10:30:00Z",
"repositories": [
{
"name": "my-site",
"branch": "main",
"last_commit": "abc123"
}
]
}list_collections
List all vector database collections.
list_collections()Recent Changes Tools
search_recent_changes
Get recently indexed code.
search_recent_changes(
project="my-site",
limit=10
)Configuration
Server Configuration
The MCP server runs on port 8765 by default:
# docker-compose.yml
mcp-server:
ports:
- "8765:8765"
environment:
- MCP_HOST=0.0.0.0
- MCP_PORT=8765
- VECTOR_DB_HOST=qdrant
- VECTOR_DB_PORT=6333Client Configuration
Claude Desktop
Add to Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"wdg": {
"url": "http://localhost:8765"
}
}
}Cursor IDE
Add to Cursor settings (.cursor/mcp.json):
{
"servers": {
"wdg": {
"url": "http://localhost:8765",
"name": "WDG AI Dev Environment"
}
}
}Usage Examples
Example 1: Finding Similar Code
User prompt to AI:
"Find all places where we validate email addresses"
AI uses MCP:
search_codebase(
query="email validation",
file_types=["php", "js"]
)Result:
is_valid_email()in utils.phpvalidateEmailAddress()in forms.js- Email regex patterns
- WordPress sanitize_email() usage
Example 2: Understanding Wikit Blocks
User prompt:
"What Wikit blocks are available for layout?"
AI uses MCP:
search_wikit_blocks()AI responds with:
- Hero block
- Grid block
- Columns block
- Section block
- Container block
Example 3: Project Context Search
User prompt:
"In the client-website project, show me how we handle custom post types"
AI uses MCP:
search_codebase(
query="custom post type registration",
project="client-website",
component_type="function"
)Advanced Features
Contextual Awareness
The MCP server understands:
- Project context: Scopes searches to active project
- File relationships: Knows which files depend on others
- Git history: Can reference specific commits
- WordPress conventions: Understands hooks, filters, CPTs
Multi-Project Search
Search across multiple projects:
# Search in all projects
search_codebase(
query="user authentication",
project=None # Searches all projects
)
# Compare implementations across projects
search_functions(
function_name="get_user",
project=None
)Pattern Recognition
The MCP server identifies:
- Wikit patterns: Recognizes WDG's standard implementations
- WordPress best practices: Identifies secure coding patterns
- Code reusability: Finds similar implementations
Performance
Response Times
| Operation | Average Time | Notes |
|---|---|---|
search_codebase | 50-100ms | Depends on collection size |
search_functions | 20-50ms | Direct lookup |
search_wikit_blocks | 10-20ms | Small collection |
get_project_info | <10ms | Cached |
list_collections | <10ms | Direct query |
Caching
The MCP server implements caching for:
- Project metadata (15 min TTL)
- Collection lists (5 min TTL)
- Wikit block catalog (1 hour TTL)
Optimization
# Limit result count for faster responses
search_codebase(query="...", limit=5)
# Use filters to reduce search space
search_codebase(
query="...",
project="my-site",
file_types=["php"],
component_type="function"
)Security
Network Security
# Bind only to localhost (default)
MCP_HOST=127.0.0.1 # Local only
# Or bind to all interfaces (be careful!)
MCP_HOST=0.0.0.0 # Accessible on networkAuthentication
Currently, the MCP server runs locally without authentication. For production deployments:
# Add API key authentication
MCP_API_KEY=your-secret-key
# Or use JWT tokens
MCP_JWT_SECRET=your-jwt-secretData Privacy
- All queries stay local
- No external API calls for search
- Code never leaves your machine
- Project data is isolated
Troubleshooting
Server Not Responding
# Check if server is running
curl http://localhost:8765/health
# View server logs
docker logs wdg-mcp-server
# Restart server
docker-compose restart mcp-serverConnection Refused
# Check port is not in use
lsof -i :8765
# Verify Docker network
docker network inspect wdg-network
# Check firewall settings
sudo ufw statusSlow Responses
# Check Qdrant status
curl http://localhost:6333/collections
# Monitor server resources
docker stats wdg-mcp-server
# Reduce search limits
# Use more specific queriesEmpty Results
# Verify collections exist
curl http://localhost:6333/collections
# Check indexing status
wdg status
# Re-index if needed
wdg index my-siteAPI Reference
Health Check
curl http://localhost:8765/healthResponse:
{
"status": "healthy",
"version": "1.0.0",
"uptime": 3600,
"collections": 5,
"total_vectors": 20450
}List Tools
curl http://localhost:8765/toolsResponse:
{
"tools": [
{
"name": "search_codebase",
"description": "Semantic search across repositories",
"parameters": {...}
},
...
]
}Best Practices
1. Use Specific Queries
# Good: Specific and contextual
search_codebase(
query="WordPress REST API endpoint registration",
component_type="function"
)
# Bad: Too vague
search_codebase(query="api")2. Scope to Project
# Good: Scoped search
search_codebase(
query="user authentication",
project="client-website"
)
# Bad: Unscoped (slower)
search_codebase(query="user authentication")3. Use Appropriate Tools
# Good: Use specific tool
search_functions(function_name="get_user")
# Bad: Generic search
search_codebase(query="get_user")4. Limit Results
# Good: Limited results
search_codebase(query="...", limit=5)
# Bad: Too many results
search_codebase(query="...", limit=100)Integration Examples
Claude Desktop
Create a custom slash command:
// ~/Library/Application Support/Claude/commands/search-code.json
{
"command": "/search-code",
"description": "Search WDG codebase",
"handler": {
"tool": "search_codebase",
"parameters": {
"query": "$input"
}
}
}Cursor IDE
Use in Cursor's chat:
User: "@wdg Find email validation in my-site project"
Cursor: [Uses MCP search_codebase tool]
Found 3 implementations:
1. is_valid_email() in utils.php
2. validateEmail() in forms.js
3. Email validation in checkout.phpMonitoring
View Real-Time Logs
# Follow MCP server logs
docker logs -f wdg-mcp-server
# Filter for searches
docker logs wdg-mcp-server | grep "search_codebase"Usage Metrics
# Get server stats
curl http://localhost:8765/metricsResponse:
{
"requests_total": 1250,
"requests_by_tool": {
"search_codebase": 800,
"search_functions": 300,
"search_wikit_blocks": 150
},
"average_response_time": "75ms",
"cache_hit_rate": "45%"
}Next Steps:
- Learn about Code Indexing
- Review MCP API Reference
- Configure Claude Code Setup