Problem/Motivation

The tools/list MCP request takes 84–106 seconds to respond when the Drush plugin is enabled.
This makes the MCP server timeout during wdrmcp initialization, preventing tool discovery.

Root cause: The DrushCaller::defaultConfiguration() method calls getTools(),
which in turn calls getDrushCommands(), executing drush list --format=json (~0.8s per execution).
During a tools/list request, the MCP framework invokes defaultConfiguration() once per tool
(typically 100+ times) to perform access checks, multiplying execution time to 94+ seconds total.

Steps to reproduce

  1. Install drupal/mcp and drupal/jsonrpc modules
  2. Enable the Drush MCP plugin at /admin/config/mcp
  3. Issue a JSON-RPC request to POST /mcp/post with method tools/list
  4. Observe: Response takes 84–106 seconds (or times out if client timeout is < 90s)

Proposed resolution

Cache the results of getDrushCommands() and defaultConfiguration() in protected instance properties,
ensuring drush list is executed only once per request instead of 100+ times.

Changes:

  • Add $defaultConfigurationCache and $drushCommandsCache protected properties
  • Check cache in defaultConfiguration() before calling parent; store result before returning
  • Check cache in getDrushCommands() before executing drush; store result before returning

Expected outcome: tools/list response time drops from 94s to < 2s.

Remaining tasks

  • Code review of caching implementation
  • Add test coverage for cache behavior (optional if not tested already)

User interface changes

None. This is a performance fix with no UI/UX changes.

API changes

None. Public API remains unchanged.

Data model changes

None. No database or configuration schema changes.

Issue fork mcp-3587789

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

merilainen created an issue. See original summary.

merilainen’s picture

Status: Active » Needs review