Skip to content

default-value is applied over REST and ignored over MCP #124

Closed

Description

@jrosskopf

What

An endpoint's default-value on a request field is applied when the parameter is absent over REST, and not over MCP. The same endpoint therefore behaves differently depending on which protocol called it.

REST — src/request_handler.cpp:

for (const auto& field : endpoint.request_fields) {
    if (!field.defaultValue.empty() && params.find(field.fieldName) == params.end()) {
        params[field.fieldName] = field.defaultValue;
    }
}

MCP — src/mcp_tool_handler.cpp, prepareParameters, before this was removed:

for (const auto& field : endpoint_config.request_fields) {
    if (field.defaultValue.empty() && params.find(field.fieldName) == params.end()) {
        // No default and no provided value - could add validation here
    }
}

Note the condition is inverted (defaultValue.empty()) and the body is empty. It applied nothing, while reading as though it applied defaults.

Consequence

A template written as

LIMIT {{ params.limit }}

with default-value: 100 renders LIMIT 100 over REST and LIMIT over MCP — a template error or an unbounded query, depending on the SQL. Any endpoint exposed as both a REST route and an MCP tool is affected.

Status

The empty loop has been deleted (it was provably a no-op, so removing it is behaviour-preserving) with a comment pointing here. Closing the divergence itself changes observable MCP behaviour, so it needs its own decision: apply defaults on the MCP path too — almost certainly what was intended — and accept that tools which currently receive no value will start receiving one.

Found during an architecture review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions