v2.14.1: 'Tis a Gift to Be Sample
FastMCP 2.14.1 adds support for sampling with tools (SEP-1577). This exciting new feature lets servers pass tools to ctx.sample(), enabling agentic workflows where the server borrows the client's LLM and controls tool execution automatically. Pass any callable as a tool and FastMCP handles the loop: calling the LLM, executing tools, and feeding results back until a final response is produced. For fine-grained control, ctx.sample_step() makes a single LLM call and returns a SampleStep, letting you inspect tool calls, add custom logic, or build your own execution loop. Structured output via result_type returns validated Pydantic models instead of raw text. This release also adds AnthropicSamplingHandler alongside the existing OpenAI handler (newly promoted out of the experimental module), so clients and servers can provide sampling capability across major providers with ease.
What's Changed
New Features ๐
- SEP-1577: Sampling with tools by @jlowin in https://github.com/jlowin/fastmcp/pull/2551
- Add AnthropicSamplingHandler by @jlowin in https://github.com/jlowin/fastmcp/pull/2617
Enhancements ๐ง
- Add Python 3.13 to Ubuntu CI tests by @jlowin in https://github.com/jlowin/fastmcp/pull/2606
- Remove legacy _task_capable_initialize() workaround by @jlowin in https://github.com/jlowin/fastmcp/pull/2612
- Consolidate session state reset logic and improve cancellation cleanup by @jlowin in https://github.com/jlowin/fastmcp/pull/2615
- Unify SamplingHandler and promote OpenAI handler by @jlowin in https://github.com/jlowin/fastmcp/pull/2616
- Add tool_names parameter to mount() for name overrides by @jlowin in https://github.com/jlowin/fastmcp/pull/2619
- Adopt streamable_http_client API from MCP SDK by @jlowin in https://github.com/jlowin/fastmcp/pull/2620
- Deprecate exclude_args in favor of Depends() by @jlowin in https://github.com/jlowin/fastmcp/pull/2621
Fixes ๐
- fix: prompt tasks returning mcp.types.PromptMessage now work by @chrisguidry in https://github.com/jlowin/fastmcp/pull/2603
- Use WindowsSelectorEventLoopPolicy to fix Windows test warnings by @jlowin in https://github.com/jlowin/fastmcp/pull/2607
- Clean up cancelled connection startup by @shawnthapa in https://github.com/jlowin/fastmcp/pull/2614
- Consolidate sampling examples and fix tool_choice bug by @jlowin in https://github.com/jlowin/fastmcp/pull/2618
Docs ๐
- docs: simplify Docket tip wording by @jlowin in https://github.com/jlowin/fastmcp/pull/2599
Dependencies ๐ฆ
- chore: bump pydocket to >=0.15.5 by @chrisguidry in https://github.com/jlowin/fastmcp/pull/2605
New Contributors
- @shawnthapa made their first contribution in https://github.com/jlowin/fastmcp/pull/2614
Full Changelog: https://github.com/jlowin/fastmcp/compare/v2.14.0...v2.14.1