Fix empty enum in `content_search_content` tool schema when no content types are enabled
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3550693. -->
Reported by: [robertoperuzzo](https://www.drupal.org/user/2661375)
Related to !35
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>
When running the MCP Content Search tool (<code>content_search_content</code>), the MCP server throws a JSON Schema validation error:
</p>
<pre>
Tool `content_search_content` has invalid JSON parameters:
- Array has too few items. Expected 1 or more. (at /properties/contentType/enum)
- Schema: {"type":"object","properties":{"contentType":{"type":"string","description":"Content type machine name","enum":[]}, ... }
</pre><p><br></p>
<p>
This happens because the <code>contentType</code> property in the generated JSON Schema has an empty <code>enum</code> array when no content types are enabled in the MCP Content plugin configuration.<br>
According to the JSON Schema specification, an <code>enum</code> must contain at least one valid value, so an empty array violates schema validation.
</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ol>
<li>Install and enable the <strong>MCP Content</strong> plugin.</li>
<li>Leave all content types disabled in its configuration.</li>
<li>Start the MCP Drupal server using the <code>mcp.json</code> below.</li>
<li>Open Copilot (GPT-5 mini) or trigger tool discovery.</li>
<li>Observe validation error in the extension output.</li>
<li>The VSCode logs show the following error for the <code>content_search_content</code> tool:<br>
<pre>
Tool `content_search_content` has invalid JSON parameters:
Array has too few items. Expected 1 or more. (at /properties/contentType/enum)
</pre></li>
</ol>
<p>Environment
</p><ul>
<li>MCP server image: <code>ghcr.io/omedia/mcp-server-drupal:latest</code></li>
<li>Started via docker in <code>mcp.json</code> (see below)</li>
<li>VSCode LocalProcess extension (discovered 74 tools)</li>
<li>macOS</li>
</ul>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>
Update the <code>Content.php</code> implementation in the MCP Content plugin to handle cases where no content types are configured.
</p>
<p><strong>Proposed fix:</strong></p>
<ul>
<li>In the <code>getTools()</code> method, check if the <code>$contentTypes</code> array is empty before creating the tool schema.</li>
<li>If no content types are available:
<ul>
<li>Either return an empty tools array (so the <code>content_search_content</code> tool is not registered), <strong>or</strong></li>
<li>Provide a fallback message instead of an empty <code>enum</code>.</li>
</ul>
</li>
</ul>
<pre><div class="codeblock"><code class="language-php">if (empty($contentTypes)) {<br> return [];<br>}<p><strong>Alternative (admin fix):</strong><br><br>
Enable at least one content type in the MCP Content plugin configuration.<br><br>
Path: <code>/admin/config/mcp/plugins</code> → “Content” plugin → enable one or more content types (e.g., Article, Page).
</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<ul>
<li>[ ] Implement the conditional check for empty content type arrays.</li>
<li>[ ] Test the MCP server startup when no content types are configured.</li>
<li>[ ] Confirm that enabling one content type correctly registers the <code>content_search_content</code> tool.</li>
<li>[ ] Update documentation for the MCP Content plugin to mention this requirement.</li>
</ul>
<h3 id="summary-ui-changes">User interface changes</h3>
<p>None.<br><br>
The change affects the MCP backend behavior only and does not modify any Drupal admin UI elements.
</p>
<h3 id="summary-api-changes">API changes</h3>
<p>
The <code>content_search_content</code> tool definition will no longer expose an invalid schema when no content types are enabled.<br><br>
If no content types exist, the tool will be omitted entirely from the tool list returned by the MCP server.
</p>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>
None.<br><br>
This fix only alters schema generation logic for the MCP tool configuration and does not modify or store any data entities.
</p>
</code></div></pre>
issue