Conversation
| return | ||
|
|
||
| # Handle None context (e.g., in stateless HTTP mode outside handlers) | ||
| # Stateless mode: run identify on every request, return identity directly |
There was a problem hiding this comment.
Yeah, I mean, in TypeScript we run it on every request. And we only actually send the MCPCat identify events to our servers if the identity of the user has changed. So I feel like you should change this to run on every request.
There was a problem hiding this comment.
Yeah. So the TS SDK seems like it:
- Runs identify on every request.
- Compares against cached identity
- Only emits
mcpcat:identifywhen it changes
That's a pretty big change to include into this PR though, so I can do it as a follow-up PR before we take this stateless stuff out of beta.
src/mcpcat/__init__.py
Outdated
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("ignore", DeprecationWarning) | ||
| return server.settings.stateless_http |
There was a problem hiding this comment.
Also, is this a new way of logging a warning? I don't think we've ever done it before. We should log warnings to the mcpcat.log file.
There was a problem hiding this comment.
No, this is to suppress the deprecation warning that comes from accessing a FastMCP server's .settings field.
I'll add some comments/logging so it's clear when we do this. But in general, we tell users to manually pass stateless=True to the MCPcat settings, since autodetecting doesn't seem very reliable.
Summary
Fixes session cross-contamination in stateless MCP servers (e.g. FastMCP with
stateless_http=True) where concurrent users shared one session_id and the first user's identity stuck for everyone.SDK now sends
session_id=nullin stateless mode, letting the server handle session assignment. Identity runs on every request and gets attached directly to each event.Depends on
mcpcat-api0.1.9 (published)Test plan
pytest tests/test_stateless.py— 11 passpytest tests/— 347 pass