Skip to main content
Glama

Drupal MCP Server

A secure Model Context Protocol (MCP) Server that exposes multiple DDEV-managed Drupal projects to LLMs (Claude, ChatGPT, etc.).

License: MIT TypeScript Node.js

English | Türkçe

📋 Table of Contents

Related MCP server: DBT Core MCP Server

✨ Features

🎯 Multi-Site Support

  • Auto-Discovery: Automatically finds all DDEV projects via ddev list

  • Manual Configuration: Add sites manually if needed

  • Site Filtering: Lists only Drupal projects (Drupal 8/9/10/11)

  • Status Tracking: Shows running/stopped status

🛠️ 11 Powerful MCP Tools

  1. drupal_list_sites - List discovered DDEV sites

  2. drupal_refresh_sites - Re-discover site list

  3. drupal_project_info - Get Drupal version, modules, environment info

  4. drupal_search_code - Search in custom code (ripgrep/grep)

  5. drupal_read_file - Read files with PII/secret masking

  6. drupal_list_custom_components - List custom modules and themes

  7. drupal_config_get - Read config (from sync directory or database)

  8. drupal_db_schema - Database schema introspection with PII tagging

  9. drupal_drush - Execute Drush commands (with safe allowlist)

  10. drupal_entity_schema_summary - Content model summary

  11. drupal_view_export - List and export Views

🔒 Comprehensive Security

  • Token Authentication: Bearer token API security

  • RBAC (Role-Based Access Control): Tool-level permissions

  • PII/Secret Redaction: Automatic sensitive data masking

  • Path Guard: Path traversal protection

  • Rate Limiting: Per-minute request limits

  • Audit Logging: Detailed operation logging

  • Safe Mode: Drush command allowlist

🚀 Performance and Flexibility

  • stdio Transport: Low latency, direct LLM integration

  • Async Operations: Non-blocking operations

  • Error Handling: Graceful degradation

  • Fallback Mechanisms: Uses grep if ripgrep unavailable

  • Auto-detection: Automatically finds config sync directory

🚀 Quick Start

Requirements

  • Node.js 18+

  • DDEV (local development environment)

  • At least one Drupal project (managed by DDEV)

5-Minute Setup

# 1. Clone the repository
git clone https://github.com/YOUR_USERNAME/drupal-mcp-server.git
cd drupal-mcp-server

# 2. Install dependencies
npm install

# 3. Build
npm run build

# 4. Create config files
cp config/config.yaml.example config/config.yaml
cp .env.example .env

# 5. Generate token (edit .env file)
echo "MCP_TOKEN=$(openssl rand -hex 32)" >> .env

# 6. Test
npm start

📦 Installation

Install with NPM

npm install
npm run build

Install with Yarn

yarn install
yarn build

Development Mode

npm run dev

⚙️ Configuration

Environment Variables (.env)

# MCP Server Token (required)
MCP_TOKEN=your-secure-token-here

# Optional: Drupal root path override
# DRUPAL_ROOT=/path/to/drupal

# Optional: Config sync directory override
# CONFIG_SYNC_DIR=config/sync

# Optional: Drush path override
# DRUSH_PATH=/path/to/drush

# Log level (debug|info|warn|error)
LOG_LEVEL=info

# Audit log path
AUDIT_LOG_PATH=./logs/audit.log

# Rate limit (requests per minute)
RATE_LIMIT_RPM=60

# Max response size (bytes)
MAX_RESPONSE_SIZE=1048576

# Environment
ENVIRONMENT=production

YAML Configuration (config/config.yaml)

server:
  name: drupal-mcp
  version: 1.0.0
  transport: stdio

rbac:
  enabled: true
  roles:
    admin:
      permissions: ['*']
    developer:
      permissions:
        - read_only
        - code_read
        - config_read
        - schema_read
        - content_read
    viewer:
      permissions:
        - read_only

  tokens:
    ${MCP_TOKEN}: admin

sites:
  auto_discover: true
  manual_sites: []

security:
  redaction:
    enabled: true
    secret_patterns:
      - 'password'
      - 'api[_-]?key'
      - 'secret'
      - 'token'
      - 'private[_-]?key'
    pii_patterns:
      - '\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
      - '\b\d{3}[-.]?\d{3}[-.]?\d{4}\b'

  path_guard:
    enabled: true
    allowed_paths:
      - 'web/modules/custom/**'
      - 'web/themes/custom/**'
      - 'web/sites/**/settings*.php'
      - 'web/sites/**/files/config_*/**'
      - 'config/sync/**'
      - 'config/**'
      - 'composer.json'
      - 'composer.lock'
    denied_paths:
      - '**/.git/**'
      - '**/node_modules/**'
      - '**/vendor/**'
      - '**/.env'

  rate_limit:
    enabled: true
    requests_per_minute: 60

drush:
  safe_mode: true
  allowed_commands:
    - 'core:status'
    - 'pm:list'
    - 'config:get'
    - 'config:export'
    - 'entity:info'
    - 'views:list'
    - 'views:export'

audit:
  enabled: true
  log_path: ./logs/audit.log

🔧 MCP Tools

1. drupal_list_sites

Lists all discovered DDEV Drupal sites.

Parameters: None

Example Response:

{
  "total": 3,
  "sites": [
    {
      "name": "site1",
      "path": "/path/to/drupal-site1",
      "type": "drupal10",
      "status": "running"
    }
  ]
}

2. drupal_refresh_sites

Re-discovers the site list.

Parameters: None

3. drupal_project_info

Retrieves Drupal project information.

Parameters:

  • site (string, required): Site name

Example Response:

{
  "site_name": "My Drupal Site",
  "drupal_version": "10.2.0",
  "php_version": "8.2.0",
  "database": "mysql",
  "enabled_modules_count": 89,
  "enabled_modules": ["node", "user", "system", "..."]
}

4. drupal_search_code

Searches in custom code (ripgrep or grep).

Parameters:

  • site (string, required): Site name

  • query (string, required): Search term

  • paths (array, optional): Search paths (default: custom modules/themes)

  • max_results (number, optional): Max results (default: 20)

  • regex (boolean, optional): Use regex (default: false)

Example Response:

{
  "query": "EntityInterface",
  "engine": "grep",
  "total_matches": 5,
  "results": [
    {
      "file": "web/modules/custom/my_module/src/Controller/MyController.php",
      "line": 12,
      "text": "use Drupal\\Core\\Entity\\EntityInterface;"
    }
  ]
}

5. drupal_read_file

Reads file content with PII/secret masking.

Parameters:

  • site (string, required): Site name

  • path (string, required): File path (relative to site root)

  • start_line (number, optional): Start line

  • end_line (number, optional): End line

6. drupal_list_custom_components

Lists custom modules and themes.

Parameters:

  • site (string, required): Site name

  • type (string, optional): "modules", "themes", or "all" (default: "all")

7. drupal_config_get

Reads Drupal configuration.

Parameters:

  • site (string, required): Site name

  • keys_or_prefix (string, required): Config key or prefix

  • source (string, optional): "sync" or "db" (default: "sync")

8. drupal_db_schema

Inspects database schema.

Parameters:

  • site (string, required): Site name

  • table (string, optional): Table name (lists all if empty)

Example Response:

{
  "table": "users_field_data",
  "columns": [
    {"name": "uid", "type": "int", "pii_risk": false},
    {"name": "name", "type": "varchar(60)", "pii_risk": true},
    {"name": "mail", "type": "varchar(254)", "pii_risk": true}
  ],
  "pii_columns": ["name", "mail"]
}

9. drupal_drush

Executes Drush commands (with safe mode).

Parameters:

  • site (string, required): Site name

  • command (string, required): Drush command

  • args (array, optional): Command arguments

  • safe_mode (boolean, optional): Allowlist check (default: true)

10. drupal_entity_schema_summary

Retrieves content model summary.

Parameters:

  • site (string, required): Site name

11. drupal_view_export

Lists views or exports a specific view.

Parameters:

  • site (string, required): Site name

  • name (string, optional): View machine name (lists all if empty)

🔐 Security

Token Authentication (Optional)

Not required for local use. Token is only needed for:

  • Remote network access

  • Multi-user scenarios

  • Production deployments

For local use with Windsurf or Claude Desktop, you can disable token checking:

# config.yaml
rbac:
  enabled: false  # Disable token authentication

RBAC (Role-Based Access Control)

Tools are grouped by permissions:

  • read_only: Site list, refresh

  • code_read: Code search, file reading

  • config_read: Config reading

  • schema_read: DB schema reading

  • content_read: Entity schema, views

  • drush_exec: Drush commands

PII/Secret Redaction

Automatically masks:

  • Email addresses

  • Phone numbers

  • API keys, tokens, passwords

  • Database credentials

Path Guard

Protection against path traversal attacks:

  • Allowed paths whitelist

  • Denied paths blacklist

  • Symlink checking

Rate Limiting

Per-minute request limit (default: 60 req/min).

Audit Logging

All tool calls are logged:

{
  "timestamp": "2026-03-03T13:06:22.627Z",
  "tool": "drupal_list_sites",
  "params": {},
  "status": "success",
  "duration_ms": 2
}

🐳 Docker Usage

Run with Docker Compose

docker compose up -d

Docker Build

docker build -t drupal-mcp-server .
docker run -v /var/run/docker.sock:/var/run/docker.sock \
  -v ~/.ddev:/root/.ddev \
  -e MCP_TOKEN=your-token \
  drupal-mcp-server

📚 Examples

Claude Desktop Integration

~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "drupal": {
      "command": "node",
      "args": ["/path/to/drupal-mcp-server/dist/index.js"],
      "env": {
        "MCP_TOKEN": "your-secure-token"
      }
    }
  }
}

Windsurf Integration

~/.windsurf/mcp_config.json:

{
  "mcpServers": {
    "drupal": {
      "command": "node",
      "args": ["/path/to/drupal-mcp-server/dist/index.js"],
      "env": {
        "MCP_TOKEN": "your-secure-token",
        "LOG_LEVEL": "info"
      }
    }
  }
}

Programmatic Usage

import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";

const transport = new StdioClientTransport({
  command: "node",
  args: ["/path/to/drupal-mcp-server/dist/index.js"],
  env: {
    MCP_TOKEN: "your-token"
  }
});

const client = new Client({
  name: "drupal-client",
  version: "1.0.0"
}, {
  capabilities: {}
});

await client.connect(transport);

// List sites
const sites = await client.callTool({
  name: "drupal_list_sites",
  arguments: {}
});

console.log(sites);

🔍 Troubleshooting

Server won't start

# Set log level to debug
LOG_LEVEL=debug npm start

# Check audit log
tail -f logs/audit.log

DDEV sites not found

# Check DDEV is running
ddev list

# Add site manually (config.yaml)
sites:
  manual_sites:
    - name: mysite
      path: /path/to/mysite
      type: drupal10

Permission errors

# Check token is correct
echo $MCP_TOKEN

# Check RBAC configuration (config.yaml)
rbac:
  tokens:
    your-token-here: admin

Drush commands not working

# Disable safe mode (use with caution!)
drush:
  safe_mode: false

# Or add to allowlist
drush:
  allowed_commands:
    - 'your:command'

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository

  2. Create a feature branch (git checkout -b feature/amazing-feature)

  3. Commit your changes (git commit -m 'feat: Add amazing feature')

  4. Push to the branch (git push origin feature/amazing-feature)

  5. Open a Pull Request

Development Guidelines

  • Use TypeScript strict mode

  • Follow ESLint rules

  • Write tests (coverage 80%+)

  • Use Conventional Commits for commit messages

Running Tests

npm test
npm run test:coverage

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

Available Tools

11 tools
drupal_config_getC

Get Drupal configuration from sync directory or database

Inputs: site (required), keys_or_prefix (required), source.

drupal_db_schemaB

Inspect database schema: tables, columns, indexes, FK, PII tags

Inputs: site (required), table.

drupal_drushB

Execute a drush command (safe_mode enforces allowlist)

Inputs: site (required), command (required), args, safe_mode.

drupal_entity_schema_summaryB

Get content model summary: content types, fields, paragraphs, vocabularies

Inputs: site (required).

drupal_list_custom_componentsC

List custom modules and themes with info.yml details

Inputs: site (required), type.

drupal_list_sitesA

List all discovered DDEV Drupal sites

Inputs: no named parameters.

drupal_project_infoC

Get Drupal project info: core version, enabled modules/themes, environment

Inputs: site (required).

drupal_read_fileB

Read a file from the Drupal project (with secret/PII masking)

Inputs: path (required), site (required), end_line, start_line.

drupal_refresh_sitesC

Re-discover DDEV Drupal sites

Inputs: no named parameters.

drupal_search_codeB

Search custom code using ripgrep

Inputs: site (required), query (required), paths, regex, +1 more.

drupal_view_exportB

List views or export a specific view configuration

Inputs: site (required), name.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 11 tools

    Disambiguation4/5

    Most tools have clearly distinct targets: config, DB schema, entity schema, views, sites, project info, code search, file read, and custom components are separate concerns. The broad drupal_drush escape hatch could subsume several specialized tools, but the descriptions and safe_mode allowlist make the intended split reasonably clear.

    Naming Consistency3/5

    All tools share the drupal_ prefix and snake_case, which is good, but the verb/noun ordering is mixed: verb-first names like drupal_list_sites and drupal_search_code coexist with noun-first names like drupal_config_get and drupal_view_export. It remains readable, but the pattern is only partially predictable.

    Tool Count5/5

    Eleven tools is well within the appropriate range for a Drupal inspection and management server. Each tool covers a distinct area—config, database, entities, views, sites, project metadata, code, files, and components—without obvious padding.

    Completeness4/5

    The surface provides strong read/inspection coverage across Drupal configuration, schema, content model, code, files, and sites, and drush can fill in many operational actions. Some gaps remain, such as dedicated write/update operations or direct log/query tools, but they are mostly workable via drush.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      Enables AI agents to interact with Magento 2 development environments through comprehensive tools for module management, database operations, cache control, configuration management, and system diagnostics. Supports complete development workflows from module creation to deployment and troubleshooting.
      28
      178 npm
      41
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to interact with DDEV local development environments by querying databases, managing project states, and executing container commands. It provides comprehensive control over local services with a security-first approach using whitelisted operations.
      5
      3
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to automate DDEV development environments, including project management, database operations, and executing commands for various CMS frameworks.
      14
      80 npm
      13
      GPL 2.0