← MCP server and skill grades

python-sdk

modelcontextprotocol/python-sdk

B
Type
MCP server
Scanned
Nov 18, 2026
Version
77001c96f950
Files read
1721

This is the official Python toolkit and command-line tool for building and running Model Context Protocol (MCP) servers and clients that connect AI apps to data and tools. The biggest risks when using it are that resumable web sessions can leak data between different users, OAuth sign-ins can accidentally send your login tokens to an untrusted server, and some server setups silently turn off protections against malicious websites reaching local servers.

What it can reach

Network
Starts local or network web servers to host MCP services, and makes outbound web connections to remote MCP servers, OAuth login services, and configured URLs.
Files
Reads local files, folders, images, and audio that a server is configured to share, loads environment and JSON settings files, and updates Claude Desktop's configuration file during CLI setup.
Shell commands
Starts and communicates with local MCP server programs as background processes, and runs developer commands like uv and npx in the CLI and example scripts.
Secrets
Reads environment variables and settings files, and handles OAuth login tokens, client secrets, signing and encryption keys, and API keys.
Browser
Opens OAuth sign-in pages in your default web browser when running the included authentication client example.

Findings

2 medium12 low
  1. MediumCross-session response and notification leak in Streamable HTTP EventStore replay

    src/mcp/server/streamable_http.py:964

    StreamableHTTPSessionManager shares a single EventStore instance across all stateful client sessions, but StreamableHTTPServerTransport passes bare JSON-RPC request IDs (such as '1' or '2') and '_GET_stream' as the stream_id without scoping them to mcp_session_id, and replays Last-Event-ID without verifying session ownership. On a multi-user server with event_store enabled, one client (even under a different OAuth token) can obtain a priming event ID on its own session for stream '2' and reconnect with Last-Event-ID to receive another user's tool results and notifications stored under the colliding stream ID, or replay another session's event ID directly.

    Fix: Namespace every stored stream_id with mcp_session_id (for example f'{self.mcp_session_id}:{request_stream_id}'), buffer replayed events in _replay_events until replay_events_after returns stream_id, and discard the replay if stream_id does not belong to self.mcp_session_id.

  2. MediumOAuth client can send issuer-bound client secrets and refresh tokens to the MCP resource server

    src/mcp/client/auth/oauth2.py:450

    When self.context.oauth_metadata is None, _perform_authorization_code_grant, _get_token_endpoint, and _refresh_token fall back to /authorize and /token on self.context.server_url (the MCP server's origin) even when Protected Resource Metadata pointed to a separate authorization server or credentials are bound to a separate issuer. If a client starts with a stored refresh token before discovery runs, or if OAuth metadata discovery against the real authorization server returns 404 or 5xx (which breaks out of the discovery loop without raising), the client retains its issuer-bound client_secret and refresh_token and POSTs them directly to the MCP server's /token endpoint.

    Fix: Only allow the legacy /authorize and /token fallback on server_url when no separate authorization server was advertised by Protected Resource Metadata and stored credentials have no different bound issuer (and no configured issuer on ClientCredentialsOAuthProvider); otherwise raise OAuthFlowError when oauth_metadata is missing.

  3. LowDNS rebinding and Origin checks silently turn off for low-level HTTP transports and non-localhost host values

    src/mcp/server/transport_security.py:48

    Although TransportSecuritySettings sets enable_dns_rebinding_protection=True by default, TransportSecurityMiddleware(None) overrides it to False. High-level helpers (streamable_http_app and sse_app) only supply TransportSecuritySettings automatically when host is literally '127.0.0.1', 'localhost', or '::1'. Running with host='0.0.0.0' (standard inside local Docker containers mapped to 127.0.0.1 on the host) or constructing SseServerTransport or StreamableHTTPSessionManager directly (as in sse.py's docstring example) silently disables Host and Origin validation, allowing any visited website to call tools on an unauthenticated local server via DNS rebinding.

    Fix: Keep DNS rebinding and Origin protection enabled by default (or emit a prominent warning when transport_security is omitted with a wildcard bind address like 0.0.0.0), and configure localhost Host/Origin protection in SseServerTransport and StreamableHTTPSessionManager examples.

  4. LowOAuth discovery fetches arbitrary cross-origin and cleartext HTTP URLs from untrusted server responses

    src/mcp/client/auth/utils.py:83

    When an MCP server responds with 401 or 403, OAuthClientProvider extracts resource_metadata from the WWW-Authenticate header and immediately sends a GET request to that URL without checking its scheme, origin, or IP address. ProtectedResourceMetadata and OAuthMetadata also accept plain http:// URLs (AnyHttpUrl) for authorization_servers, registration_endpoint, and token_endpoint, allowing a malicious MCP server to trigger blind HTTP GET/POST SSRF requests inside the client's network or downgrade dynamic registration and token requests to cleartext HTTP.

    Fix: Require HTTPS (allowing HTTP only for explicit loopback hosts in local testing, matching server-side validate_issuer_url) for WWW-Authenticate resource_metadata URLs, authorization server issuers, and OAuth endpoints, and validate that resource_metadata matches the MCP server's origin or configured policy.

  5. LowDynamic Client Registration accepts javascript: and data: schemes in redirect_uris

    src/mcp/shared/auth.py:118

    OAuthClientMetadata types redirect_uris as list[AnyUrl] | None, which accepts dangerous browser pseudo-schemes such as javascript: and data: as well as non-loopback cleartext http:// URIs during RFC 7591 Dynamic Client Registration in RegistrationHandler. When ClientRegistrationOptions(enabled=True) is enabled on an MCP authorization server, an unauthenticated attacker can register a javascript: redirect_uri; error redirects in AuthorizationHandler or any consent page in provider.authorize() that links or navigates to params.redirect_uri can then trigger cross-site scripting on the authorization server origin.

    Fix: Validate redirect_uris in OAuthClientMetadata (or RegistrationHandler) to reject dangerous schemes such as javascript:, data:, and vbscript:, and restrict HTTP redirect URIs to loopback addresses while requiring HTTPS (or explicitly permitted native custom schemes) otherwise.

  6. Lowmcp dev downloads and runs unpinned @modelcontextprotocol/inspector via npx and uses shell=True on Windows

    src/mcp/cli/cli.py:277

    The mcp dev CLI command invokes npx @modelcontextprotocol/inspector without a version pin while forwarding the user's full environment variables, causing npx to download and execute the floating latest npm package if not already cached. On Windows, subprocess.run is also called with shell=True on the argument list, routing file paths and --with package specs through cmd.exe where %VAR% variables and shell metacharacters in unspaced arguments are expanded.

    Fix: Pin @modelcontextprotocol/inspector to a known-good version (or major range with an override option), and resolve npx.cmd via shutil.which on Windows so subprocess.run can execute with shell=False.

  7. LowDNS rebinding protection disabled in story example HTTP server runner

    examples/stories/_hosting.py:27

    When a developer runs one of the repository's example story servers over HTTP using --http, _serve_http() reuses the in-process test helper asgi_from(), which explicitly disables the SDK's default localhost DNS rebinding and Origin header checks. This example harness is not included in the published mcp package, so normal installations are unaffected, but while a developer runs a story server locally over HTTP, any website visited in a browser on the same computer could reach the local 127.0.0.1 server via DNS rebinding.

    Fix: Leave default DNS rebinding protection enabled in _serve_http() when binding a real Uvicorn TCP socket, and restrict NO_DNS_REBIND to in-process ASGI test runs.

  8. LowUnvalidated tool input interpolated into OAuth hostname in elicitation example

    examples/snippets/servers/elicitation.py:94

    In the example elicitation server, the connect_service tool inserts the agent-supplied service_name parameter directly into the hostname of an external authorization URL. If a user runs this example server or copies the pattern, prompt injection could trick the agent into passing a value such as 'attacker.example/login#', turning the URL into https://attacker.example/login#.example.com/... and directing the user's browser to an attacker-controlled site.

    Fix: Validate service_name against an allowlist of known service names or a strict alphanumeric pattern before placing it into a URL authority.

  9. LowRunnable HTTP story examples disable DNS rebinding protection and allow wildcard CORS

    examples/stories/legacy_routing/server.py:51

    Several runnable example HTTP servers pass transport_security=NO_DNS_REBIND, which turns off Host and Origin header checks, and legacy_routing additionally enables CORSMiddleware with allow_origins=['*'] and exposed session headers without authentication. While not run after a normal SDK install, starting these example servers locally or copying their setup lets any website open in the user's browser send cross-origin requests to the local MCP server.

    Fix: Keep default localhost DNS rebinding protection enabled in runnable examples and restrict allow_origins to an explicit trusted origin instead of '*'.

  10. LowClient-credentials example mints non-expiring access tokens despite advertising a 1-hour TTL

    examples/stories/oauth_client_credentials/server.py:74

    Because the SDK does not include a built-in server handler for the client_credentials grant, this example provides a custom /token route for developers to adapt, but stores AccessToken with expires_at=None while returning expires_in=3600 to the client. Tokens issued by this example therefore never expire on the server and remain in memory indefinitely, and client credentials are compared without a constant-time check.

    Fix: Set expires_at=int(time.time()) + 3600 on the stored AccessToken to match expires_in=3600, and verify Basic credentials using hmac.compare_digest with error handling for malformed Base64.

  11. LowReflected cross-site scripting (XSS) in example OAuth client callback server

    examples/clients/simple-auth-client/mcp_simple_auth_client/main.py:95

    When the example OAuth client listens on http://localhost:3030 for an authorization redirect, its HTTP handler inserts the 'error' URL query parameter directly into an HTML page without escaping it. If someone runs this example (or copies its callback handler) and visits an untrusted website while port 3030 is open, that site can navigate the browser to localhost:3030 with script code in 'error', executing JavaScript in the localhost origin. This code lives in examples/ and is never run by installing the mcp package.

    Fix: Escape the query parameter with html.escape() before placing it in HTML, or respond with Content-Type: text/plain.

  12. LowReflected cross-site scripting (XSS) in example OAuth server login page

    examples/servers/simple-auth/mcp_simple_auth/simple_auth_provider.py:118

    In the simple-auth demo server, GET /login takes the 'state' query parameter from the URL and places it unescaped inside an HTML input attribute without checking that the state came from an active authorization request. Anyone running this example server—or copying its login page into a custom OAuth provider—is exposed to JavaScript injection on the login page via a crafted link. This file is an example and is not included when installing the mcp package.

    Fix: Verify that 'state' exists in self.state_mapping before rendering the form, and escape it with html.escape(state, quote=True).

  13. LowUnrestricted internal network access and open redirects (SSRF) in example fetch server

    examples/servers/simple-tool/mcp_simple_tool/server.py:13

    The example 'fetch' tool is described as a website fetcher, but it does not block loopback, private-network, or cloud-metadata IP addresses and follows HTTP redirects automatically. If a user runs this example server, prompt injection—or a public webpage that redirects to 127.0.0.1 or 169.254.169.254—can read internal HTTP services reachable from the machine. This server is an example and is not installed or enabled with the mcp package.

    Fix: Allow only http and https schemes, resolve hostnames, and block loopback, link-local, and private IP ranges on both the initial request and every redirect hop.

  14. LowUntrusted tool output passed to the model with 'system' role in example chatbot

    examples/clients/simple-chatbot/mcp_simple_chatbot/main.py:385

    After executing an MCP tool (its sample config includes Puppeteer web browsing and SQLite), the example chatbot appends the raw tool output to the conversation history using the 'system' role. Giving untrusted webpage or database content system-prompt authority makes prompt injection much more likely to hijack subsequent tool calls in that chat session. This client is an example and is not installed with the mcp package.

    Fix: Pass tool results back using a 'tool' role or clearly delimited 'user' message rather than 'system', and require user confirmation before running sensitive tools.