返回博客

How to manage multiple Drupal sites with one MCP server

2025-10-258 min read

The problem with context switching

I work on a few Drupal sites. Every time I switch between them, there's this mental overhead: Which modules does this one have? What fields are on the article type? I need to pull some data from the database to display it. Should I create a new view, or does one already exist?

Even with AI assistants like Claude Code, Cursor, or Windsurf, getting answers meant waiting while they ran multiple drush commands sequentially, piecing together fragments of information. So I built Drupal Scout, an MCP server that gives AI assistants instant, comprehensive knowledge about your Drupal site. It's open source on GitHub. Scout is read-only. It analyzes your site but never modifies your database or files.

Without Scout, your AI runs commands like this:

AI: Running drush field:list node article...
AI: Running drush config:get field.field.node.article.field_image...
AI: Running drush config:get field.field.node.article.field_category...
# ...and so on, waiting between each command

With Scout, you just ask: "What fields are on the article type?"

One call. Instant answer. Everything cross-referenced. This saves 70-90% of tokens compared to running commands sequentially, and your AI responds instantly instead of waiting for multiple drush operations.

The multi-project trick

Here's what I learned: You can use the same MCP server for all your projects. Each one gets its own context automatically.

When I figured this out, it changed everything. No more switching configs. No more wondering which site I'm looking at. The AI just knows.

How it works

Drupal Scout looks for a config.json file in your project directory. When you're in project A, it reads A's config. Switch to project B? It reads B's config. Simple.

The MCP server itself lives in one place (I keep mine in ~/.local/drupal-scout-mcp), but each project tells it which Drupal installation to index.

Setting it up

Install Drupal Scout once:

git clone https://github.com/davo20019/drupal-scout-mcp.git ~/.local/drupal-scout-mcp
cd ~/.local/drupal-scout-mcp
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Then in each Drupal project, drop two files in the root:

config.json (tells Scout where your Drupal lives):

{
"drupal_root": "/path/to/your/drupal",
"modules_path": "web/modules"
}

.claude.json (connects the MCP server):

claude mcp add --transport stdio drupal-scout -- \
~/.local/drupal-scout-mcp/venv/bin/python \
~/.local/drupal-scout-mcp/server.py

That's it. When you cd into that project and start coding, Scout indexes those modules. Switch projects? It indexes the new ones.

What can Drupal Scout do?

Now that you have it set up, what can you actually do with it? Let me show you some real examples.

Analyzing fields and content types

You: "I need to add a phone number field to the staff content type"
AI: Let me check if a phone field already exists...
AI: Using drupal-scout get_field_info(field_name="phone")

Result: Found 2 phone fields:
• Phone Number (field_phone_number) Type: telephone, Used in: contact, vendor
• Mobile Phone (field_mobile_phone) Type: telephone, Used in: employee

AI: "You can reuse field_phone_number on the staff content type!"

This saved you from creating a duplicate field with a different name. One query showed you all phone-related fields and where they're used.

Finding views and displays

You: "Do we have any views that display user data?"
AI: Using drupal-scout get_views_summary(entity_type="users")

Result: Found 2 views:
• User List (user_list) Displays: page, block
• Staff Directory (staff_directory) Displays: page, block

AI: "Yes! The Staff Directory view already exists with filters for department and role."

Instead of creating a new view, you discovered an existing one that does what you need.

Cleaning up taxonomy terms

You: "Can I safely delete the 'Old Category' term?"
AI: Using drupal-scout get_taxonomy_info(term_name="Old Category")

Result: Term: Old Category (tid: 75)
Usage: 0 content items, 0 views
Children: None

SAFE TO DELETE - This term is not used anywhere.

AI: "Yes, it's safe to delete. The term isn't used in any content or views."

Now try asking about a term that is used:

You: "What about the 'Technology' term?"
AI: Using drupal-scout get_taxonomy_info(term_name="Technology")

Result: Term: Technology (tid: 42)
Usage: 87 content items
Children: AI/ML, Web Development
Sample content:
• How AI is Changing Development (nid: 123)
• Tech Trends 2024 (nid: 156)
... and 84 more

WARNING: Has child terms (2 children will become orphaned)
CAUTION: Used in 87 pieces of content

AI: "This term is heavily used. Deleting it would affect 87 articles and orphan 2 child terms. Consider merging instead."

This analysis would have taken dozens of drush commands and database queries. Drupal Scout did it in one call.

Debugging with watchdog logs

You: "The site is showing errors, can you check what's wrong?"
AI: Using drupal-scout get_watchdog_logs()

Result: Found 12 PHP errors:
[2024-01-15 14:32:21] Undefined array key 'field_category'
Location: /modules/custom/custom_module/custom_module.module:45

[2024-01-15 14:30:15] Call to undefined method getCategory()
Location: /modules/custom/custom_module/src/Service/CategoryService.php:78

AI: "I found two related errors in custom_module. Let me read those files and fix them..."

The AI can immediately jump to the problem files and suggest fixes.

Getting module recommendations

Here's something I find really useful: Drupal Scout can search the Drupal.org API and recommend modules based on what you're trying to do.

You: "I need a way to manage workflow and content moderation"
AI: Using drupal-scout search_drupal_modules(keyword="workflow")

Result: Found relevant modules:
• Workbench Moderation - Provides editorial workflow for content
• Content Moderation - Core workflow solution for Drupal 8+
• Workflow - Flexible content workflow management

AI: "Based on your Drupal version and needs, I recommend Content Moderation since it's in core for Drupal 8+. Want me to check if it's already enabled?"

Instead of googling for modules or asking around, the AI can search Drupal.org, compare options, and make recommendations based on your specific setup.

Tips for getting the most out of Drupal Scout

1. Ask broad questions first

Instead of diving into implementation, ask Drupal Scout to check what exists:

  • Instead of: "Create a view showing recent articles"
  • Try: "Do we have any views showing articles?"

You might discover you already have what you need.

2. Let the AI use the tools

You don't need to specify which MCP tool to use. Just ask natural questions:

  • "What fields are on the article content type?"
  • "Can I safely delete this module?"
  • "Are there any recent errors in the logs?"

The AI knows which tool to call based on your question.

3. Combine analysis with action

Drupal Scout provides read-only analysis. When you need to make changes, the AI can use that information to execute commands safely:

You: "Clean up unused modules"
AI: Using drupal-scout find_unused_contrib()
Result: Found 3 installed but unused modules: devel, kint, admin_toolbar_tools

AI: "I found 3 unused modules. Should I uninstall them?"
You: "Yes"
AI: Running: drush pmu devel kint admin_toolbar_tools
AI: Running: composer remove drupal/devel drupal/kint drupal/admin_toolbar_tools
AI: Using drupal-scout reindex_modules()

The AI uses Drupal Scout for analysis, then executes the necessary commands to make changes.

How does MCP actually work?

You might be wondering: "How does the AI know when to use Drupal Scout?" Great question! Understanding this helps you appreciate why MCP is so powerful.

The tool description is the AI's instruction manual

When Drupal Scout connects to your AI assistant, it doesn't just provide functions-it provides documentation about those functions. Each tool has a description that tells the AI:

  • What the tool does
  • When to use it
  • What parameters it accepts
  • What kind of results it returns

For example, the get_field_info tool has a description like:

Get comprehensive information about Drupal fields.

**USE THIS TOOL** for questions about fields, where they're used,
field types, and data structure.

Examples:
• "What fields does the article content type have?"
• "Where is field_image used?"
• "Do we have a phone number field?"

This description becomes part of the AI's knowledge. When you ask "What fields are on my article content type?", the AI recognizes this matches the pattern and calls the appropriate tool.

The conversation flow

Here's what actually happens when you interact with Drupal Scout:

  1. You ask: "What fields does my article content type have?"
  2. AI thinks: "This is a question about fields. I have get_field_info for that."
  3. AI calls tool: get_field_info(...)
  4. MCP server executes: Runs drush commands, parses configs, analyzes usage
  5. MCP returns data: "Fields Summary (15 fields found)..."
  6. AI formats response: "I found 15 fields on your node entity types..."

The beauty is that you never see steps 2-5. You just get the answer.

Why this is better than traditional prompting

Without MCP, you'd have to tell the AI exactly what to do:

You: "Run drush field-list, then for each field run drush config:get,
then parse the YAML and tell me which are phone fields"

With MCP, you just ask naturally:

You: "Do we have a phone field?"

The tool descriptions taught the AI how to handle Drupal-specific questions. You don't need to be a drush expert-the MCP server already is.

It's declarative, not imperative

Here's a key insight: MCP tool descriptions are declarative (describing what exists) rather than imperative (forcing specific actions).

This means:

  • The MCP doesn't override your prompts
  • It tells the AI what capabilities are available
  • The AI still decides when and how to use them
  • You maintain full control through natural conversation

Think of it like giving the AI a specialized toolkit. You still tell it what to build, but now it has better tools to build with.

What Scout can analyze

Drupal Scout provides deep analysis across your entire Drupal installation with 23+ specialized tools:

Modules & Dependencies (8 tools):

  • Search for functionality across custom and contrib modules
  • List all modules with capabilities and hook implementations
  • Get detailed module information (services, routes, classes, hooks)
  • Analyze dependencies (forward, reverse, circular)
  • Find unused contrib modules (with installation status)
  • Check redundancy before building new features
  • Find all implementations of a specific Drupal hook
  • Force reindex when modules change

Entities, Fields & Content (multiple tools):

  • Complete entity structure with bundle information
  • Comprehensive field analysis with usage tracking
  • Entity references showing where content is used
  • Display configurations for view modes
  • Search entities by any field value
  • Get entity info by ID or path

Views Analysis (1 tool):

  • List all views with displays (page, block, feed, etc.)
  • Display paths and settings
  • Filters, sorts, and relationships
  • Fields being displayed
  • Filter by entity type

Taxonomy (2 tools):

  • All vocabularies with term counts and referencing fields
  • Complete term hierarchies (parent/child relationships)
  • Detailed usage analysis (content, views, fields)
  • Safe-to-delete assessment with warnings
  • Bulk analysis of entire vocabularies (optimized for large datasets)
  • Export taxonomy data to CSV/Excel

Security Scanning (11 tools):

  • SQL injection vulnerability detection
  • Cross-Site Scripting (XSS) checks
  • CSRF protection analysis
  • Command injection detection
  • Path traversal vulnerabilities
  • Hardcoded secrets and API keys
  • Access control issues
  • Deprecated API usage
  • Anonymous exploits (remotely exploitable)
  • Security audit (comprehensive report)
  • Verification guides (how to manually verify findings)

Code Analysis (4 tools):

  • Read module files with smart chunking for large files
  • List files in modules with size information
  • Get module directory tree visualization
  • Extract specific PHP functions from files

Drupal.org Integration (5 tools):

  • Search for modules on Drupal.org
  • Get popular modules by category
  • Module recommendations based on needs
  • Detailed module information with issue queue
  • Search module issue queues for problems

System Health & Monitoring (5 tools):

  • Watchdog logs with error patterns and diagnostics
  • Database connectivity verification
  • Available updates for core and contrib
  • Full status report (/admin/reports/status equivalent)
  • Configuration sync status

All 23+ tools work together seamlessly. The AI assistant automatically knows which tool to use based on your question.

Resources

保持更新

在您的收件箱中获取最新的文章和见解。

Unsubscribe anytime. No spam, ever.