Skip to content

Count Queries not working in Built-in MCP server #4529

@saravanan30erd

Description

@saravanan30erd

Problem Statement

I am experimenting with the Built-in MCP server for query-based search, following this blog post:
https://opensearch.org/blog/introducing-mcp-in-opensearch/

While basic search works, count-style queries do not work as expected when using SearchIndexTool, because the tool does not return search metadata, specifically hits.total.value.

Example query,

{
  "size": 0,
  "track_total_hits": true,
  "query": {
    "range": {
      "product_id": {
        "gt": 8
      }
    }
  }
}

When using "track_total_hits": true directly with OpenSearch, the response includes total hit metadata like:

"hits": {
    "total": {
      "value": 17000,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  }

Actual behavior with Built-in MCP SearchIndexTool
But Built-in MCP SearchIndexTool only returns document-level results as described in the documentation: https://docs.opensearch.org/latest/ml-commons-plugin/agents-tools/tools/search-index-tool/

Example tool response shape:

{
"_index": "test",
"_source": {}
}

There is no hits.total.value or equivalent metadata, which makes it impossible to implement count queries using SearchIndexTool.

Implementation

I registered the SearchIndexTool using the zero-configuration example in MCP registration API described here:
https://docs.opensearch.org/latest/ml-commons-plugin/api/mcp-server-apis/register-mcp-tools/#example-request-zero-configuration-tools

It is unclear whether:

  • the input_schema is missing required fields, or
  • the Built-in MCP server intentionally strips search metadata from the response

There does not appear to be a documented way to request hits.total or other search metadata from SearchIndexTool.

How it worked before

Previously, I was using the Standalone MCP server instead of the Built-in MCP server.

Key differences:

  • The Standalone MCP server provides a dedicated CountTool, implemented using the _count API.
  • Also the Standalone MCP SearchIndexTool returns full search responses, including hits.total.value.

Summary / Issue

  • Built-in MCP SearchIndexTool does not return hits.total.value
  • Count-style queries (size: 0, track_total_hits: true) are not supported in practice
  • There is no Built-in MCP equivalent of CountTool

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions