MCP Content Search Tool Fails with "Unknown field: status" Error

Created on 25 May 2025, 12 days ago

Summary

The MCP Content plugin's search-content tool consistently fails with an "Unknown field: status" error when attempting to search for any content, even with empty filters. This affects all content searches through the MCP interface.

Steps to Reproduce

  1. Install MCP module (tested with latest dev version)
  2. Enable the Content plugin in MCP Extra
  3. Attempt to search for any content using the MCP content search tool:
    {
      "contentType": "daily_tasks",
      "filters": [],
      "limit": 10
    }
  4. Error occurs: "Unknown field: status"

Expected Behavior

Content search should work without errors and return matching nodes.

Actual Behavior

All content searches fail with "Unknown field: status" error, making the MCP content search functionality unusable.

Root Cause Analysis

The issue is in web/modules/contrib/mcp/modules/mcp_extra/src/Plugin/Mcp/Content.php in the searchContent() method around line 430:

$query = $this->entityTypeManager->getStorage('node')->getQuery()
  ->accessCheck(TRUE)
  ->condition('type', $contentType)
  ->condition('status', 1)  // <-- This line adds a status condition
  ->range($offset, $limit)
  ->sort('created', 'DESC'); // <-- This line sorts by created field

The method automatically adds conditions for status (to show only published content) and sorts by created, but the isSupportedField() method only recognizes title, body, and custom fields starting with field_. Core Drupal fields like status, created, nid, etc. are not included in the supported fields list.

Later in the code, when processing user filters, it validates all fields (including the automatically added ones) against isSupportedField(), causing the error.

Proposed Solution

Modify the isSupportedField() method to include core Drupal node fields that are used by the system:

private function isSupportedField(
  FieldDefinitionInterface $fieldDefinition,
): bool {
  $supportedTypes = [
    'string',
    'string_long',
    'list_string',
    'datetime',
    'boolean',
    'text_long',
  ];
  $fieldName = $fieldDefinition->getName();

  // Core fields that are used by the system automatically
  if (in_array($fieldName, ['title', 'body', 'status', 'created', 'changed', 'nid', 'uid', 'type'])) {
    return TRUE;
  }

  if (str_starts_with($fieldName, 'field_')
    && in_array(
      $fieldDefinition->getType(), $supportedTypes
    )
  ) {
    return TRUE;
  }

  return FALSE;
}

Additional Notes

  • This affects the latest dev version as of the time of this report
  • The issue makes the entire MCP content search functionality unusable
  • The fix is minimal and only adds recognition for core Drupal fields that the system already uses
  • Core fields added: status, created, changed, nid, uid, type

Environment

  • Drupal version: 10.4.3
  • MCP module: Latest dev version
  • PHP version: 8.3

Patch

The fix involves changing line ~560 in Content.php from:

if (in_array($fieldName, ['title', 'body'])) {

to:

if (in_array($fieldName, ['title', 'body', 'status', 'created', 'changed', 'nid', 'uid', 'type'])) {

This ensures that core Drupal fields used by the search system are recognized as supported fields.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇦🇹Austria roromedia Linz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @roromedia
  • Merge request !13Adds Core Drupal fields to validation → (Open) created by roromedia
  • Pipeline finished with Failed
    12 days ago
    Total: 277s
    #506112
  • 🇬🇪Georgia gagosha

    Summary

    The MCP Content plugin's search-content tool consistently fails with an "Unknown field: status" error when attempting to search for any content, even with empty filters. This affects all content searches through the MCP interface.

    Steps to Reproduce

    1. Install MCP module (tested with latest dev version)
    2. Enable the Content plugin in MCP Extra
    3. Attempt to search for any content using the MCP content search tool:
      {
        "contentType": "YOUR_CONTENT_TYPE",
        "filters": [],
        "limit": 10
      }
    4. Error occurs: "Unknown field: status"

    Expected Behavior

    Content search should work without errors and return matching nodes.

    Actual Behavior

    All content searches fail with "Unknown field: status" error, making the MCP content search functionality unusable.

    Root Cause Analysis

    The issue is in web/modules/contrib/mcp/modules/mcp_extra/src/Plugin/Mcp/Content.php in the searchContent() method around line 430:

    $query = $this->entityTypeManager->getStorage('node')->getQuery()
      ->accessCheck(TRUE)
      ->condition('type', $contentType)
      ->condition('status', 1)  // <-- This line adds a status condition
      ->range($offset, $limit)
      ->sort('created', 'DESC'); // <-- This line sorts by created field

    The method automatically adds conditions for status (to show only published content) and sorts by created, but the isSupportedField() method only recognizes title, body, and custom fields starting with field_. Core Drupal fields like status, created, nid, etc. are not included in the supported fields list.

    Later in the code, when processing user filters, it validates all fields (including the automatically added ones) against isSupportedField(), causing the error.

    Proposed Solution

    Modify the isSupportedField() method to include core Drupal node fields that are used by the system:

    private function isSupportedField(
      FieldDefinitionInterface $fieldDefinition,
    ): bool {
      $supportedTypes = [
        'string',
        'string_long',
        'list_string',
        'datetime',
        'boolean',
        'text_long',
      ];
      $fieldName = $fieldDefinition->getName();
    
      // Core fields that are used by the system automatically
      if (in_array($fieldName, ['title', 'body', 'status', 'created', 'changed', 'nid', 'uid', 'type'])) {
        return TRUE;
      }
    
      if (str_starts_with($fieldName, 'field_')
        && in_array(
          $fieldDefinition->getType(), $supportedTypes
        )
      ) {
        return TRUE;
      }
    
      return FALSE;
    }

    Additional Notes

    • This affects the latest dev version as of the time of this report
    • The issue makes the entire MCP content search functionality unusable
    • The fix is minimal and only adds recognition for core Drupal fields that the system already uses
    • Core fields added: status, created, changed, nid, uid, type

    Environment

    • Drupal version: 10.4.3
    • MCP module: Latest dev version
    • PHP version: 8.3

    Patch

    The fix involves changing line ~560 in Content.php from:

    if (in_array($fieldName, ['title', 'body'])) {

    to:

    if (in_array($fieldName, ['title', 'body', 'status', 'created', 'changed', 'nid', 'uid', 'type'])) {

    This ensures that core Drupal fields used by the search system are recognized as supported fields.

Production build 0.71.5 2024