Skip to content

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.

python
# Example usage in Claude
search_codebase(
    query="custom post type registration",
    project="my-site",
    file_types=["php"],
    limit=10
)

Parameters:

  • query (string): Search query
  • project (string, optional): Project name to scope search
  • file_types (list, optional): Filter by file extensions
  • component_type (string, optional): Filter by function, class, hook
  • limit (int): Maximum results (default: 20)

Returns:

json
[
  {
    "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.

python
search_functions(
    function_name="get_user",
    project="my-site",
    language="php"
)

search_classes

Find PHP or JavaScript classes.

python
search_classes(
    class_name="CustomPostType",
    project="my-site"
)

WordPress-Specific Tools

search_wordpress_hooks

Find WordPress actions and filters.

python
search_wordpress_hooks(
    hook_name="init",
    hook_type="action",
    project="my-site"
)

Hook Types:

  • action - do_action() calls
  • filter - apply_filters() calls
  • add_action - Hook registrations
  • add_filter - Filter registrations

wordpress_docs

Search WordPress core documentation.

python
wordpress_docs(
    query="register_post_type",
    type="function",
    get_details=True
)

Wikit-Specific Tools

search_wikit_blocks

Search Wikit's 60+ Gutenberg blocks.

python
search_wikit_blocks(
    block_name="hero"  # Optional
)

Returns:

json
[
  {
    "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.

python
get_wikit_component(
    component_name="Button"
)

Project Management Tools

get_project_info

Get project details and indexing status.

python
get_project_info(
    project_name="my-site"
)

Returns:

json
{
  "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.

python
list_collections()

Recent Changes Tools

search_recent_changes

Get recently indexed code.

python
search_recent_changes(
    project="my-site",
    limit=10
)

Configuration

Server Configuration

The MCP server runs on port 8765 by default:

yaml
# 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=6333

Client Configuration

Claude Desktop

Add to Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

json
{
  "mcpServers": {
    "wdg": {
      "url": "http://localhost:8765"
    }
  }
}

Cursor IDE

Add to Cursor settings (.cursor/mcp.json):

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:

python
search_codebase(
    query="email validation",
    file_types=["php", "js"]
)

Result:

  • is_valid_email() in utils.php
  • validateEmailAddress() 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:

python
search_wikit_blocks()

AI responds with:

  • Hero block
  • Grid block
  • Columns block
  • Section block
  • Container block

User prompt:

"In the client-website project, show me how we handle custom post types"

AI uses MCP:

python
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

Search across multiple projects:

python
# 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

OperationAverage TimeNotes
search_codebase50-100msDepends on collection size
search_functions20-50msDirect lookup
search_wikit_blocks10-20msSmall collection
get_project_info<10msCached
list_collections<10msDirect 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

python
# 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

yaml
# 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 network

Authentication

Currently, the MCP server runs locally without authentication. For production deployments:

python
# Add API key authentication
MCP_API_KEY=your-secret-key

# Or use JWT tokens
MCP_JWT_SECRET=your-jwt-secret

Data Privacy

  • All queries stay local
  • No external API calls for search
  • Code never leaves your machine
  • Project data is isolated

Troubleshooting

Server Not Responding

bash
# Check if server is running
curl http://localhost:8765/health

# View server logs
docker logs wdg-mcp-server

# Restart server
docker-compose restart mcp-server

Connection Refused

bash
# Check port is not in use
lsof -i :8765

# Verify Docker network
docker network inspect wdg-network

# Check firewall settings
sudo ufw status

Slow Responses

bash
# Check Qdrant status
curl http://localhost:6333/collections

# Monitor server resources
docker stats wdg-mcp-server

# Reduce search limits
# Use more specific queries

Empty Results

bash
# Verify collections exist
curl http://localhost:6333/collections

# Check indexing status
wdg status

# Re-index if needed
wdg index my-site

API Reference

Health Check

bash
curl http://localhost:8765/health

Response:

json
{
  "status": "healthy",
  "version": "1.0.0",
  "uptime": 3600,
  "collections": 5,
  "total_vectors": 20450
}

List Tools

bash
curl http://localhost:8765/tools

Response:

json
{
  "tools": [
    {
      "name": "search_codebase",
      "description": "Semantic search across repositories",
      "parameters": {...}
    },
    ...
  ]
}

Best Practices

1. Use Specific Queries

python
# 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

python
# Good: Scoped search
search_codebase(
    query="user authentication",
    project="client-website"
)

# Bad: Unscoped (slower)
search_codebase(query="user authentication")

3. Use Appropriate Tools

python
# Good: Use specific tool
search_functions(function_name="get_user")

# Bad: Generic search
search_codebase(query="get_user")

4. Limit Results

python
# 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:

json
// ~/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.php

Monitoring

View Real-Time Logs

bash
# Follow MCP server logs
docker logs -f wdg-mcp-server

# Filter for searches
docker logs wdg-mcp-server | grep "search_codebase"

Usage Metrics

bash
# Get server stats
curl http://localhost:8765/metrics

Response:

json
{
  "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:

Released under the MIT License.