python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

Streamable HTTP client performance regression starting with v1.12.0

Open rcxwhiz opened this issue 1 year ago • 2 comments

Initial Checks

  • [x] I confirm that I'm using the latest version of MCP Python SDK
  • [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue

Description

Summary

I have experienced a major performance degradation with streamable HTTP clients on certain servers starting in version 1.12.0 which is still present in the current version (1.13.0). I see this issue with the Notion remote MCP server on streamable HTTP transport (https://mcp.notion.com/mcp). While other servers work fine, there is a ~10 second delay with any operation on an established client session to this server after v1.11.0. The performance is fine at v1.11.0, and is fine with the current version of inspector.

Steps to Reproduce

I have a repo containing my code to reproduce the issue and more details: repo

Test Results

Testing results, copied from the above repo:

SDK Version 1.11.0 (latest without bug)

Starting tests with official Python MCP SDK version 1.11.0

Running simple client connection tests...
Test results: 0.0614 0.0136 0.0120 0.0116 0.0106 (avg 0.0219s)

Running simple tool list tests...
Test results: 0.0042 0.0041 0.0041 0.0041 0.0047 (avg 0.0042s)

Running simple tool call tests...
Test results: 0.0080 0.0067 0.0068 0.0072 0.0246 (avg 0.0107s)

Starting callback server... done
Running in memory OAuth provider construction tests...
Test results: 0.0016 0.0001 0.0000 0.0000 0.0000 (avg 0.0004s)

Running Notion client connection tests (OAuth)...
Test results: 6.0797 0.9399 0.9005 0.8184 1.0262 (avg 1.9529s)

Running Notion list tools tests...
Test results: 0.3850 0.1293 0.1308 0.1496 0.1233 (avg 0.1836s)

Running Notion call tool tests...
Test results: 0.4083 0.6162 0.8519 0.1946 0.6942 (avg 0.5530s)

Stopping callback server... done
Running GitHub client connection tests (PAT)...
Test results: 0.5784 0.2820 0.2962 0.2857 0.3079 (avg 0.3500s)

Running GitHub list tools tests...
Test results: 0.5216 0.1121 0.1129 0.1286 0.1175 (avg 0.1986s)

Running GitHub call tool tests...
Test results: 0.2627 0.3505 0.2029 0.2623 0.3536 (avg 0.2864s)

Finished!

SDK Version 1.12.1 (earliest with bug)

Starting tests with official Python MCP SDK version 1.12.1

Running simple client connection tests...
Test results: 0.0593 0.0138 0.0120 0.0111 0.0105 (avg 0.0213s)

Running simple tool list tests...
Test results: 0.0039 0.0036 0.0034 0.0050 0.0033 (avg 0.0039s)

Running simple tool call tests...
Test results: 0.0072 0.0058 0.0063 0.0063 0.0062 (avg 0.0064s)

Starting callback server... done
Running in memory OAuth provider construction tests...
Test results: 0.0009 0.0001 0.0000 0.0000 0.0001 (avg 0.0002s)

Running Notion client connection tests (OAuth)...
Test results: 6.3121 11.7071 11.6994 11.6963 11.7797 (avg 10.6389s)

Running Notion list tools tests...
Test results: 10.6288 10.4737 10.3595 10.3114 10.5529 (avg 10.4652s)

Running Notion call tool tests...
Test results: 10.6931 11.1187 13.4962 11.9530 10.8899 (avg 11.6302s)

Stopping callback server... done
Running GitHub client connection tests (PAT)...
Test results: 0.4818 0.2940 0.2908 0.2831 0.2908 (avg 0.3281s)

Running GitHub list tools tests...
Test results: 0.5536 0.1563 0.1076 0.1102 0.1399 (avg 0.2135s)

Running GitHub call tool tests...
Test results: 0.2749 0.2801 0.2645 0.3661 0.3368 (avg 0.3045s)

Finished!

SDK Version 1.13.0 (latest)

Starting tests with official Python MCP SDK version 1.13.0

Running simple client connection tests...
Test results: 0.0596 0.0133 0.0116 0.0108 0.0104 (avg 0.0212s)

Running simple tool list tests...
Test results: 0.0040 0.0035 0.0035 0.0053 0.0036 (avg 0.0040s)

Running simple tool call tests...
Test results: 0.0072 0.0060 0.0064 0.0058 0.0064 (avg 0.0064s)

Starting callback server... done
Running in memory OAuth provider construction tests...
Test results: 0.0021 0.0001 0.0000 0.0000 0.0000 (avg 0.0005s)

Running Notion client connection tests (OAuth)...
Test results: 5.4729 11.4962 11.8369 11.6574 11.5804 (avg 10.4088s)

Running Notion list tools tests...
Test results: 10.5502 10.4495 10.4619 10.3530 10.4236 (avg 10.4476s)

Running Notion call tool tests...
Test results: 10.5274 10.8830 10.5276 11.6691 10.5476 (avg 10.8309s)

Stopping callback server... done
Running GitHub client connection tests (PAT)...
Test results: 0.4458 0.2909 0.2915 0.2900 0.2837 (avg 0.3204s)

Running GitHub list tools tests...
Test results: 0.5327 0.1121 0.1792 0.1069 0.1083 (avg 0.2079s)

Running GitHub call tool tests...
Test results: 0.2469 0.2270 0.2424 0.3186 0.2323 (avg 0.2534s)

Finished!

Comments

As written in my testing repo, I have profiled the OAuthClientProvider and don't believe there is an issue with that. This issue is present when establishing client sessions and calling established client sessions. I believe there must be an underlying issue with the streamable HTTP transport that is only manifest with some servers, but that is beyond my expertise.

Example Code


Python & MCP Python SDK

Python 3.12.11 used for all testing.

Issue present in version 1.12.1 to 1.13.0.

Issue NOT present in version 1.11.0.

No results for version 1.12.0 due to unrelated (as far as I can tell) bug.

rcxwhiz avatar Aug 14 '25 20:08 rcxwhiz

https://github.com/modelcontextprotocol/python-sdk/compare/v1.11.0...v1.12.0

Maybe https://github.com/modelcontextprotocol/python-sdk/commit/49991fd2c78cded9f70e25871a006f9bab693d4b ?

Kludex avatar Dec 04 '25 10:12 Kludex

Fix submitted in #2078.

Root cause: Between v1.11.0 and v1.12.0, the client OAuth flow changed from eager discovery (discover → auth → send MCP request) to lazy discovery (send unauthenticated MCP request → get 401 → discover → auth → retry). This causes a slow unauthenticated roundtrip that servers like Notion handle very slowly (~10s).

Fix: Restores eager OAuth when is_token_valid() returns False — the full discovery/registration/authorization flow runs before the MCP request is sent. Both eager and reactive (post-401) paths now share a single _perform_oauth_discovery_and_auth() helper, keeping code DRY while preserving RFC 9728 WWW-Authenticate header support on the 401 path. If the eager flow fails (e.g. resource mismatch), it gracefully falls back to the reactive path.

BabyChrist666 avatar Feb 18 '26 00:02 BabyChrist666