|
| 1 | +# Migration Guide: v1 to v2 |
| 2 | + |
| 3 | +This guide covers the breaking changes introduced in v2 of the MCP Python SDK and how to update your code. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Version 2 of the MCP Python SDK introduces several breaking changes to improve the API, align with the MCP specification, and provide better type safety. |
| 8 | + |
| 9 | +## Breaking Changes |
| 10 | + |
| 11 | +### `streamablehttp_client` removed |
| 12 | + |
| 13 | +The deprecated `streamablehttp_client` function has been removed. Use `streamable_http_client` instead. |
| 14 | + |
| 15 | +**Before (v1):** |
| 16 | + |
| 17 | +```python |
| 18 | +from mcp.client.streamable_http import streamablehttp_client |
| 19 | + |
| 20 | +async with streamablehttp_client( |
| 21 | + url="http://localhost:8000/mcp", |
| 22 | + headers={"Authorization": "Bearer token"}, |
| 23 | + timeout=30, |
| 24 | + sse_read_timeout=300, |
| 25 | + auth=my_auth, |
| 26 | +) as (read_stream, write_stream, get_session_id): |
| 27 | + ... |
| 28 | +``` |
| 29 | + |
| 30 | +**After (v2):** |
| 31 | + |
| 32 | +```python |
| 33 | +import httpx |
| 34 | +from mcp.client.streamable_http import streamable_http_client |
| 35 | + |
| 36 | +# Configure headers, timeout, and auth on the httpx.AsyncClient |
| 37 | +http_client = httpx.AsyncClient( |
| 38 | + headers={"Authorization": "Bearer token"}, |
| 39 | + timeout=httpx.Timeout(30, read=300), |
| 40 | + auth=my_auth, |
| 41 | +) |
| 42 | + |
| 43 | +async with http_client: |
| 44 | + async with streamable_http_client( |
| 45 | + url="http://localhost:8000/mcp", |
| 46 | + http_client=http_client, |
| 47 | + ) as (read_stream, write_stream, get_session_id): |
| 48 | + ... |
| 49 | +``` |
| 50 | + |
| 51 | +### `StreamableHTTPTransport` parameters removed |
| 52 | + |
| 53 | +The `headers`, `timeout`, `sse_read_timeout`, and `auth` parameters have been removed from `StreamableHTTPTransport`. Configure these on the `httpx.AsyncClient` instead (see example above). |
| 54 | + |
| 55 | +## Deprecations |
| 56 | + |
| 57 | +<!-- Add deprecations below --> |
| 58 | + |
| 59 | +## New Features |
| 60 | + |
| 61 | +<!-- Add new features below --> |
| 62 | + |
| 63 | +## Need Help? |
| 64 | + |
| 65 | +If you encounter issues during migration: |
| 66 | + |
| 67 | +1. Check the [API Reference](api.md) for updated method signatures |
| 68 | +2. Review the [examples](https://github.com/modelcontextprotocol/python-sdk/tree/main/examples) for updated usage patterns |
| 69 | +3. Open an issue on [GitHub](https://github.com/modelcontextprotocol/python-sdk/issues) if you find a bug or need further assistance |
0 commit comments