Skip to content

Conversation

@jlowin
Copy link
Owner

@jlowin jlowin commented Aug 19, 2025

This PR adapts part of #1215 to support initialize requests in FastMCP middleware. In order to do this, we have to introduce a new low-level Session object because initialize is handled outside the normal handler approach that FastMCP generally relies on.

@marvin-context-protocol marvin-context-protocol bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. server Related to FastMCP server implementation or server-side functionality. labels Aug 19, 2025
@jlowin jlowin force-pushed the middleware-initialize branch from b780717 to 9c13ddf Compare August 19, 2025 21:29
@BrandonShar
Copy link
Contributor

Hey @jlowin this library has been amazing to use!

I'm working on figuring out a solution for horizontally scaling while still being able to log usage across sessions and my current plan is:

  1. set the server to stateless
  2. use starlette middleware to read/set mcp-session-id
  3. grab the initialize request and associate it with the session id.

This middleware looks perfect for step 3 (and I'd much rather stay within the FastMCP ecosystem), so I wanted to see if I could help with getting merged or if you were considering other approaches that might solve the same problem.

@rishid
Copy link

rishid commented Oct 2, 2025

Any help you need to get this merged? This is a feature I have been waiting for.

@jlowin jlowin merged commit ba1ba86 into main Oct 5, 2025
10 checks passed
@jlowin jlowin deleted the middleware-initialize branch October 5, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to existing functionality. For issues and smaller PR improvements. server Related to FastMCP server implementation or server-side functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants