Skip to content

[BUG][PERFORMANCE]: SSL context created for non-SSL tool invocationsΒ #3629

@sco3

Description

@sco3

🐞 Bug Summary

The ssl context is created explicitly even for non-ssl tools


🧩 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. Run with compose-up or serve (single worker)
  2. Run sudo uv py-spy --pid
  3. Run tool call multiple times
  4. Collect the output (svg or speedscope format)

Check the "heavy left" or "sandwich": create_default_context takes 49% (depends on the test, 1000 tool call requests)


πŸ€” Expected Behavior

The 49% is too much, should be less.


πŸ““ Logs / Error Output

Paste any relevant stack traces or logs here.
⚠️ Do not paste secrets, credentials, or tokens.


🧠 Environment Info

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

Image Image
Key Value
Version or commit commit a02ac5e
Runtime Python 3.12, Uvicorn`
Platform / OS Fedora 43
Container make dev

🧩 Additional Context (optional)

tool_service.py creates ssl context on every tool call and for plain http connections as well.
The MCP_SESSION_POOL_ENABLED=true does not help, it seems.
The probable fix is to avoid creating context at least for plain http, ideally use pooled connection.
The line: async def connect_to_sse_server(server_url: str, headers: dict = headers) looks like anti-pattern with possible data leak - shared headers the suggested fix is to use None as default and create copy of headers in function body.

Metadata

Metadata

Assignees

Labels

SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releasebugSomething isn't workingperformancePerformance related items

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions