Skip to content

Conversation

SmartManoj
Copy link

Introduces CORS middleware to the Starlette app instances in FastMCP to allow requests from local web frontends. This enables compatibility with web clients running on localhost and related origins, supporting credentials and common HTTP methods and headers.

Motivation and Context

Fixes #187 (comment)

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Introduces CORS middleware to the Starlette app instances in FastMCP to allow requests from local web frontends. This enables compatibility with web clients running on localhost and related origins, supporting credentials and common HTTP methods and headers.
@SmartManoj SmartManoj requested review from a team and dsp-ant July 26, 2025 12:27
Copy link
Member

@dsp-ant dsp-ant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to add this by default. If we do want to allow for certain types of starlette middlewares. We likely want to mimic what FastMCP 2.0 does here. We want support for a proper middleware stack and a default set for auth, with a pre-defined order.

@SmartManoj
Copy link
Author

I don't think we want to add this by default.

Is this wrong?

punkpeye/fastmcp@fe39e7a

@felixweinberger
Copy link
Contributor

I don't think we want to add this by default.

Is this wrong?

punkpeye/fastmcp@fe39e7a

That's looking at the Typescript implementation of FastMCP - if you look at FastMCP 2.0 @dsp-ant was referring to here: #1245

That shows the middleware support in the Python SDK. Tentatively going to mark this as a v2 idea that we'd like to have for tracking

@felixweinberger felixweinberger added enhancement New feature or request v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes needs more work Not ready to be merged yet, needs additional changes. labels Sep 22, 2025
@felixweinberger felixweinberger added this to the Middleware milestone Sep 23, 2025
@felixweinberger felixweinberger marked this pull request as draft September 30, 2025 10:46
@felixweinberger
Copy link
Contributor

Converting this to a draft for now to remove it from the review queue - keeping this around for future work on v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs more work Not ready to be merged yet, needs additional changes. v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better CORS defaults for SSE transport
3 participants