tools/list request hangs for 90+ seconds when drush plugin is enabled
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3587789. --> Reported by: [merilainen](https://www.drupal.org/user/304437) Related to !51 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p> The <code>tools/list</code> MCP request takes 84&ndash;106 seconds to respond when the Drush plugin is enabled.<br> This makes the MCP server timeout during wdrmcp initialization, preventing tool discovery. </p> <p> <strong>Root cause:</strong> The <code>DrushCaller::defaultConfiguration()</code> method calls <code>getTools()</code>,<br> which in turn calls <code>getDrushCommands()</code>, executing <code>drush list --format=json</code> (~0.8s per execution).<br> During a <code>tools/list</code> request, the MCP framework invokes <code>defaultConfiguration()</code> once per tool<br> (typically 100+ times) to perform access checks, multiplying execution time to 94+ seconds total. </p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <ol> <li>Install <code>drupal/mcp</code> and <code>drupal/jsonrpc</code> modules</li> <li>Enable the Drush MCP plugin at <code>/admin/config/mcp</code></li> <li>Issue a JSON-RPC request to <code>POST /mcp/post</code> with method <code>tools/list</code></li> <li>Observe: Response takes 84&ndash;106 seconds (or times out if client timeout is &lt; 90s)</li> </ol> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p> Cache the results of <code>getDrushCommands()</code> and <code>defaultConfiguration()</code> in protected instance properties,<br> ensuring <code>drush list</code> is executed only once per request instead of 100+ times. </p> <p> Changes: </p> <ul> <li>Add <code>$defaultConfigurationCache</code> and <code>$drushCommandsCache</code> protected properties</li> <li>Check cache in <code>defaultConfiguration()</code> before calling parent; store result before returning</li> <li>Check cache in <code>getDrushCommands()</code> before executing drush; store result before returning</li> </ul> <p> Expected outcome: <code>tools/list</code> response time drops from 94s to &lt; 2s. </p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <ul> <li>Code review of caching implementation</li> <li>Add test coverage for cache behavior (optional if not tested already)</li> </ul> <h3 id="summary-ui-changes">User interface changes</h3> <p>None. This is a performance fix with no UI/UX changes.</p> <h3 id="summary-api-changes">API changes</h3> <p>None. Public API remains unchanged.</p> <h3 id="summary-data-model-changes">Data model changes</h3> <p>None. No database or configuration schema changes.</p>
issue