Skip to content

Consider removing or relaxing MIME type validation in FastMCP resources #1756

Description

@maxisbey

Summary

The MIME type validation regex in FastMCP's Resource class is more restrictive than RFC 2045 and diverges from the TypeScript SDK (which has no validation). We should consider aligning with the TypeScript SDK approach.

Background

PR #1755 fixed the immediate issue of MIME type parameters being rejected (e.g., text/html;profile=mcp-app), but the current regex still doesn't fully support RFC 2045:

Current regex (after #1755):

pattern=r"^[a-zA-Z0-9]+/[a-zA-Z0-9\-+.]+(;\s*[a-zA-Z0-9\-_.]+=[a-zA-Z0-9\-_.]+)*$"

Limitations:

  • Doesn't support quoted string values: text/plain; charset="utf-8" ❌
  • Doesn't allow all valid RFC 2045 token characters (e.g., !, #, *, +, etc.)

TypeScript SDK Comparison

The TypeScript SDK does not validate MIME types at all (types.ts:834):

mimeType: z.optional(z.string()),

MCP Spec

The MCP spec defines mimeType as an optional string with no format constraints.

Options

  1. Remove validation entirely (align with TypeScript SDK and spec)
  2. Improve the regex to support quoted strings and more token characters

AI Disclaimer

Activity

  1. added
    enhancementRequest for a new feature that's not currently supported
    ready for workEnough information for someone to start working on
    P3Nice to haves, rare edge cases
    on Dec 9, 2025
  2. BabyChrist666 commented on Feb 17, 2026

    @BabyChrist666
    Contributor

    Opened a PR to fix this: #2067

    The fix removes the restrictive regex pattern from Resource.mime_type and replaces it with a lightweight field_validator that only checks for the presence of / (basic type/subtype structure). This aligns with the MCP spec (mimeType is a plain string) and the TypeScript SDK (no validation). Includes comprehensive test coverage for quoted parameter values, wildcards, vendor types, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Nice to haves, rare edge casesenhancementRequest for a new feature that's not currently supportedready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions