MCP Python SDK ImportError: RequestContext Fix (2026)
Fix cannot import name 'RequestContext' from 'mcp.shared.context' after mcp 2.0: update the import or pin mcp<2. Tested on 1.30.0 and 2.3.0.
Weir Team
Published · Updated · 6 min read
The error "cannot import name 'RequestContext' from 'mcp.shared.context'" means you now run mcp version 2, which moved that class. Either update the import, or pin mcp<2.
This guide is for Python developers whose MCP server or client broke after pip install -U mcp. We reproduced each error below in a clean environment, and we run Weir, the server in the client example.
The two-minute fix is to go back to the last 1.x release:
pip install "mcp<2"
pip show mcp | grep Version # Version: 1.30.0
- Read the errorMatch the text to the table below.
- Pick a fixPin mcp<2 now, or update the imports.
- Check the installpip show mcp tells you which major version you have.
- Test a clientRun the short remote client below.
Why did pip install -U mcp break my imports?
A major version can break old code, and mcp 2.0.0 did. The official migration guide lists every change by the error you see first.
PyPI shows 2.0.0 uploaded on 28 July 2026, the same day as 1.29.0. As of 16 November 2026 the latest 2.x release is 2.3.0, from 2 October. If your pyproject.toml says only mcp, a fresh install picks version 2.
A DeepLearning.AI course forum thread from 11 August 2026 shows how it happens. A course project had no upper bound on mcp, so uv installed 2.0 and the code failed. The fix there was mcp>=1.2,<2.
cannot import name 'RequestContext' from 'mcp.shared.context' and six more errors
Here is each error with its fix, as of 16 November 2026. The last column says how we know. "Reproduced" means we ran the import on mcp 2.3.0 and got the error shown.
| Error | What changed | Fix | Proof |
|---|---|---|---|
| cannot import name 'RequestContext' | Split in two | ClientRequestContext, ServerRequestContext | Reproduced |
| No module named 'mcp.server.fastmcp' | FastMCP is now MCPServer | mcp.server.mcpserver | Reproduced |
| cannot import name 'streamablehttp_client' | Renamed | streamable_http_client | Reproduced |
| cannot import name 'McpError' | Now MCPError | from mcp import MCPError | Reproduced |
| No module named 'httpx' | Replaced by httpx2 | import httpx2 | Reproduced |
| cannot import name 'Content' from 'mcp.types' | Types removed | See the guide's removed-types list | Reproduced |
| 'Tool' object has no attribute 'inputSchema' | Fields are snake_case | tool.input_schema | Guide only |
Those names match the migration guide's "Find your changes" table. The guide also says an SDK API it does not list behaves as it did in v1.
The import fixes look like this:
# v1 (fails on mcp 2.x)
from mcp.shared.context import RequestContext
from mcp.server.fastmcp import FastMCP
# v2 (ran on mcp 2.3.0)
from mcp.client.context import ClientRequestContext
from mcp.server.context import ServerRequestContext
from mcp.server.mcpserver import MCPServer
Pick ClientRequestContext for sampling, elicitation and roots callbacks. Pick ServerRequestContext inside server handlers. The guide notes that mcp.shared.context still exists but now holds an unrelated internal class, so only the one name is gone.
McpError and MCPError: the rename in one line
The class is now MCPError, and it is exported from the top-level package. Change from mcp import McpError to from mcp import MCPError, and every except McpError to except MCPError.
We ran both names on 16 November 2026. On 1.30.0, McpError imports and MCPError fails. On 2.3.0 it is the other way round.
Here is the real text from the failing imports on mcp 2.3.0:
ImportError: cannot import name 'RequestContext' from 'mcp.shared.context'
ImportError: cannot import name 'streamablehttp_client' from 'mcp.client.streamable_http'
ImportError: cannot import name 'McpError' from 'mcp'
ModuleNotFoundError: No module named 'mcp.server.fastmcp'. This is mcp 2.x, where FastMCP was renamed to MCPServer ...
The last message points you to the guide itself. Newer 2.x releases add that hint, according to the guide.
MCP Python SDK 2 migration: a remote client that works
A client is the quickest proof that your install is healthy. This one connects to Weir's remote MCP server over streamable HTTP and sends the key in an Authorization header.
Version 2 moved headers and timeouts onto an httpx2.AsyncClient. Set WEIR_API_KEY first, and never paste the key into code.
import asyncio, os, httpx2
from mcp import Client
from mcp.client.streamable_http import streamable_http_client
async def main():
headers = {"Authorization": f"Bearer {os.environ['WEIR_API_KEY']}"}
timeout = httpx2.Timeout(30, read=300)
async with httpx2.AsyncClient(headers=headers, timeout=timeout) as http:
async with Client(streamable_http_client("https://api.weirapp.io/mcp", http_client=http)) as client:
tools = (await client.list_tools()).tools
print(len(tools), "tools, e.g.", [t.name for t in tools[:2]])
usage = await client.call_tool("get_usage", {})
print("is_error:", usage.is_error, usage.structured_content["meta"]["creditsCharged"])
asyncio.run(main())
We ran it on 16 November 2026 with mcp 2.3.0 and a research key. It listed the tools and called get_usage. Output, trimmed:
40 tools, e.g. ['get_usage', 'get_limits']
is_error: False 0
The tool count depends on the scopes your key has. Our get_usage result also showed the tier as free.
For errors, retries and a search call, see our MCP Python client guide. To use the same server in a chat app, see how to add a remote MCP server URL.
When not to use Weir (or this fix)
- Your server is your own code. This post fixes imports. You do not need Weir for that, and the migration guide covers servers in full.
- You need to post or act on X (Twitter). Weir is read-only and reads public data. It is not licensed by X, so access can change.
- You cannot touch the code yet. Pinning
mcp<2is fine for now, but plan the move, because new fixes land in 2.x. - Your framework pins the SDK. A package such as an adapter may need its own upgrade first, so check its release notes.
Weir has an X MCP server page and a page on the X API for AI agents. The tools and prices are in the Weir MCP docs.
FAQ
How do I fix ImportError mcp after upgrading to version 2?
Run pip show mcp to see the version. If it is 2.x, match your error to the table above and change that import. For a quick fix, run pip install "mcp<2" and restart your app.
How do I fix cannot import name 'streamablehttp_client'?
Use streamable_http_client from mcp.client.streamable_http. It no longer takes headers or timeout. You pass an httpx2.AsyncClient as http_client and set those there, as in the client above.
What is the difference between McpError and MCPError?
MCPError is the new name for McpError in mcp 2.x. We confirmed on 16 November 2026 that from mcp import McpError fails on 2.3.0 and from mcp import MCPError works.
How do I fix No module named 'mcp.server.fastmcp'?
FastMCP is now MCPServer. Change the import to from mcp.server.mcpserver import MCPServer, and every mcp.server.fastmcp.* path to mcp.server.mcpserver.*. Or pin mcp<2.
Sources
All checked on 16 November 2026:
- Python SDK v1 to v2 migration guide: https://py.sdk.modelcontextprotocol.io/migration/
- mcp on PyPI (version list and upload dates): https://pypi.org/pypi/mcp/json
- Python SDK releases on GitHub: https://github.com/modelcontextprotocol/python-sdk/releases
- DeepLearning.AI forum thread on mcp 2.0 breaking a course project (11 August 2026): https://community.deeplearning.ai/t/l7-mcp-chatbot-py-fails-with-no-module-named-mcp-server-fastmcp/894529
- Weir MCP docs: https://docs.weirapp.io/mcp
- Our runs on mcp 1.30.0 and 2.3.0, Python 3.12, and against https://api.weirapp.io/mcp, 16 November 2026