Skip to content

[BUG]: Server ID Context Dropped During Stateful Session/ Session Affinity Processing #2973

@kevalmahajan

Description

@kevalmahajan

🐞 Bug Summary

When use_stateful_sessions and mcpgateway_session_affinity_enabled are enabled, the
list_tools endpoint incorrectly returns tools from all servers instead of filtering by the specific server_id in the URL. This happens because the server ID context is lost during request processing in stateful sessions.


🧩 Affected Component

Select the area of the project impacted:

  • mcpgateway - API
  • mcpgateway - UI (admin panel)
  • mcpgateway.wrapper - stdio wrapper
  • Federation or Transports
  • CLI, Makefiles, or shell scripts
  • Container setup (Docker/Podman/Compose)
  • Other (explain below)

🔁 Steps to Reproduce

  1. Enable stateful sessions in .env:
MCPGATEWAY_USE_STATEFUL_SESSIONS=true
MCPGATEWAY_SESSION_AFFINITY_ENABLED=true
  1. Start the gateway.
  2. Make a request to a specific server's tools endpoint (e.g., http://localhost:8000/servers/server-id/mcp) and list the tools.
  3. Keep the session alive (or make enough requests to trigger session affinity).
  4. Observe that the response contains tools from other servers or an empty list (if default context is used), instead of the tools specific to .

🤔 Expected Behavior

The gateway should correctly identify the server_id from the URL, even in stateful sessions, and return ONLY the tools belonging to that specific server.

🧠 Environment Info

You can retrieve most of this from the /version endpoint.

Key Value
Version or commit e.g. v0.9.0 or main@a1b2c3d
Runtime e.g. Python 3.11, Gunicorn
Platform / OS e.g. Ubuntu 22.04, macOS
Container e.g. Docker, Podman, none

🧩 Additional Context (optional)

Add any configuration details, flags, or related issues.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpythonPython / backend development (FastAPI)

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions