Skip to content

Harden MCP tool input validation with strict server-side schemas #93

@sajeetharan

Description

@sajeetharan

The MCP Toolkit exposes multiple tools that accept input parameters, including some free-form strings. Current server-side validation appears minimal for several inputs.

This creates a risk that crafted input could trigger unintended behavior, affect downstream components, expose sensitive information, or reduce service stability.

Why this matters

This should be treated as Important under the Security Weakness Bug Bar because it:

  • could partly compromise the service
  • could cause disclosure of sensitive information
  • reflects a common service-boundary antipattern in JSON-based tool interfaces

This does not appear to be a Critical issue because it does not by itself bypass core authN/authZ or Cosmos DB RBAC, or imply full service takeover.

Recommendation

Enforce strict server-side validation for every MCP tool request before execution.

At minimum:

  • define a strict JSON schema per tool
  • enforce allowed fields, required properties, types, and size limits
  • reject unknown properties
  • fail closed on validation errors
  • apply maximum lengths to all string inputs
  • normalize free-form text consistently
  • reject control characters where not required
  • treat all unstructured input as untrusted
  • contextually encode input immediately before use in logging, telemetry, query construction, or other downstream sinks

For intentionally free-form inputs, validation should focus on boundary and safety constraints rather than semantic correctness.

Acceptance Criteria

  • Every tool has an explicit request schema.
  • Invalid, missing, oversized, or unexpected inputs are rejected before execution.
  • Free-form strings have explicit limits and normalization rules.
  • Logging/telemetry do not reuse raw untrusted input unsafely.
  • Tests cover valid and invalid payloads for each tool.

Notes

Some mitigations already exist, including the lower exposure to classic SQL injection patterns in the Cosmos DB NoSQL query model, but that does not remove the need for strict boundary validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions