graylog2-server icon indicating copy to clipboard operation
graylog2-server copied to clipboard

MCP server: $defs/DateTime output schema is {type: object} but values serialize as ISO-8601 strings → strict MCP clients reject all search_messages/aggregate_messages responses

Open Shyrka973 opened this issue 5 months ago • 1 comments

Graylog 7.1.3, built-in MCP server (/api/mcp).

The generated outputSchema for aggregate_messages and search_messages (any tool returning metadata.effective_timerange) defines the shared DateTime type as a bare object:

"$defs": { "DateTime": { "type": "object" } }

with effective_timerange.from / .to referencing #/$defs/DateTime:

"effective_timerange": {
  "allOf": [
    { "type": "object", "properties": {
        "from": { "$ref": "#/$defs/DateTime" },
        "to":   { "$ref": "#/$defs/DateTime" },
        "type": { "type": "string" } } },
    ...
  ]
}

But the server serializes these as ISO-8601 strings, e.g. "2026-06-18T11:08:56.483Z".

Impact

MCP clients that validate a tool's structuredContent against its advertised outputSchema (the official MCP SDK does this — e.g. Claude Code) reject every response from these tools:

Invalid structured content returned by tool aggregate_messages:
'2026-06-18T11:08:56.483Z' is not of type 'object'

Failed validating 'type' in schema['properties']['metadata']['properties']['effective_timerange']['allOf'][0]['properties']['to']:
    {'type': 'object'}
On instance['metadata']['effective_timerange']['to']:
    '2026-06-18T11:08:56.483Z'

This makes both core search tools (search_messages, aggregate_messages) unusable from any schema-validating MCP client. Tools that do not return a timerange in their output (get_current_time, list_streams, system/cluster status, notifications) are unaffected.

Root cause

The JSON-Schema generator maps the server's DateTime type to {"type": "object"} instead of a string type, while the actual JSON serialization is an ISO-8601 string. The data is correct; only its schema description is wrong.

Expected

$defs/DateTime should be:

{ "type": "string", "format": "date-time" }

Reproduction

  1. POST /api/mcp with {"jsonrpc":"2.0","id":1,"method":"tools/list"} → inspect the aggregate_messages / search_messages outputSchema: $defs/DateTime is {"type":"object"}.
  2. Call aggregate_messages (e.g. groupings:[{field:"source"}], metrics:[{function:"count"}], range_seconds:3600) and observe that structuredContent.metadata.effective_timerange.to is a string while the schema declares it an object.

Workaround

Consume the REST endpoint POST /api/search/aggregate directly instead of the MCP tool, which returns clean datarows without the schema mismatch.

Shyrka973 avatar Jun 18 '26 11:06 Shyrka973

Auditing the other MCP tools, I found a second instance of the same class of bug (output schema not matching the serialized value) in list_fields — different field, different root cause (nullability rather than type), but same effect (strict MCP clients reject the response).

list_fields declares each field's unit as a required object:

"unit": {
  "type": "object",
  "properties": { "abbrev": {"type": "string"}, "unit_type": {"type": "string"} },
  "required": ["abbrev", "unit_type"]
}

But fields without a unit serialize unit as null, so a validating client rejects:

Invalid structured content returned by tool list_fields:
None is not of type 'object'
Failed validating 'type' in schema['properties']['fields']['items']['properties']['unit']
On instance['fields'][37]['unit']: None

Expected: unit should be nullable, e.g. {"type": ["object", "null"], ...} (and likely not in required, or required only when present).

Together with the $defs/DateTime issue above, this suggests the MCP outputSchema generation should be validated end-to-end against actual tool output. In a full sweep of this Graylog 7.1.3 MCP server, the affected tools were search_messages, aggregate_messages (DateTime), and list_fields (unit). The other tools either omit an outputSchema or have a correct one (e.g. get_system_status works fine).

Shyrka973 avatar Jun 18 '26 11:06 Shyrka973