Python SDK 1.3.0 - 2025-02-20
Breaking Changes
- Context API Changes: The Context logging methods (info, debug, warning, error) are now async and must be awaited. (#172)
New Features
Lifespan Support
Added comprehensive server lifecycle management through the lifespan API:
@dataclass
class AppContext:
db: Database
@asynccontextmanager
async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
try:
await db.connect()
yield AppContext(db=db)
finally:
await db.disconnect()
mcp = FastMCP("My App", lifespan=app_lifespan)
@mcp.tool()
def query_db(ctx: Context) -> str:
db = ctx.request_context.lifespan_context["db"]
return db.query()
(#203)
Async Resources
Added support for async resource functions in FastMCP:
@mcp.resource("users://{user_id}")
async def get_user(user_id: str) -> str:
async with client.session() as session:
response = await session.get(f"/users/{user_id}")
return await response.text()
(#157)
Concurrent Request Handling
Made message handling concurrent, allowing multiple requests to be processed simultaneously. (#206)
Request Cancellation
Added support for canceling in-flight requests and cleaning up resources. (#167)
Server Instructions
Added support for the instructions
field in server initialization, allowing servers to provide usage guidance. (#150)
Bug Fixes
- Fixed progress reporting for first tool call by correcting progress_token handling (#176)
- Fixed server crash when using debug logging (#158)
- Fixed resource template handling in FastMCP server (#137)
- Fixed MIME type preservation in resource responses (#170)
- Fixed documentation for environment variables in CLI commands (#149)
- Fixed request ID preservation in JSON-RPC responses (#205)
Dependency Updates
- Relaxed version constraints for better compatibility:
pydantic
: Changed from>=2.10.1,<3.0.0
to>=2.7.2,<3.0.0
pydantic-settings
: Changed from>=2.6.1
to>=2.5.2
uvicorn
: Changed from>=0.30
to>=0.23.1
(#180)
Examples
- Added a simple chatbot example client to demonstrate SDK usage (#98)
Client Improvements
- Added client support for sampling, list roots, and ping requests (#218)
- Added flexible type system for tool result returns (#222)
Compatibility and Platform Support
- Updated URL validation to allow file and other nonstandard schemas (#68fcf92)
- Force stdin/stdout encoding to UTF-8 for cross-platform compatibility (#d92ee8f)
Internal Improvements
- Improved type annotations for better IDE support (#181)
- Added comprehensive tests for SSE transport (#151)
- Updated types to match 2024-11-05 MCP schema (#165)
- Refactored request and notification handling for better code organization (#166)
New Contributors
- @salman1993 made their first contribution in #150
- @micpst made their first contribution in #158
- @3choff made their first contribution in #98
- @cr7258 made their first contribution in #149
- @sheffler made their first contribution in #172
- @jeremydanielfox made their first contribution in #180
- @zzstoatzz made their first contribution in #181
Full Changelog: v1.2.1...v1.3.0