Commit graph

2,628 commits

Author SHA1 Message Date
Adam Azzam
99832a9faf
Merge pull request #2787 from jlowin/confernece-to-2.x-branch v2.14.2
conference to 2.x branch
2025-12-30 22:09:15 -06:00
Adam Azzam
7fd365c868 Update docs.json 2025-12-30 21:41:01 -05:00
Jeremiah Lowin
9cf9aa9b37
Lazy import DiskStore to avoid sqlite3 dependency on import (#2785) 2025-12-30 19:20:10 -05:00
Jeremiah Lowin
1b637522d1
Fix base_url fallback when url is not set (#2776) (#2782)
Co-authored-by: Taisei Mima <bhbstar.me@gmail.com>
fix for httpx.URL("") being truthy but stringifying to empty string.
2025-12-30 17:51:57 -05:00
Jeremiah Lowin
33ff356c0f
Fix titled enum elicitation schema to comply with MCP spec (#2774) 2025-12-29 09:46:20 -05:00
Jeremiah Lowin
820f74e8ed
[BugFix] Fix openapi_version Check So 3.1 Is Included (#2768) (#2769)
Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
2025-12-28 07:39:21 -05:00
Jeremiah Lowin
bbf6c200ee
Update CLI banner with FastMCP 3.0 notice (#2765) 2025-12-26 22:13:05 -05:00
Jeremiah Lowin
97327893bb
Fix OAuth Proxy resource parameter validation (#2763) 2025-12-26 21:24:08 -05:00
Jeremiah Lowin
6bade1cbd9
Add auth_route parameter to SupabaseProvider (#2760)
Co-authored-by: Eloi Zalczer <eloi@entropia.io>
2025-12-26 16:23:41 -05:00
Jeremiah Lowin
4963b516c2
Fix: resolve root-level $ref in outputSchema for MCP spec compliance (#2720) (#2727)
Co-authored-by: lif <1835304752@qq.com>
2025-12-25 08:53:52 -05:00
Jeremiah Lowin
7f56291204
Add changelog entries for v2.13.1 through v2.14.1 (#2724) 2025-12-25 08:22:24 -05:00
Jeremiah Lowin
ee9ee777c5
Add v3 breaking changes notice to README and docs (#2713) 2025-12-24 16:04:46 -05:00
Jeremiah Lowin
39c4855580
Pin MCP under 2 (#2709) 2025-12-24 15:28:31 -05:00
Jeremiah Lowin
88349bd68f
Fix Prefect website URL in docs footer (#2705) 2025-12-24 08:30:26 -05:00
Chris Guidry
53b609f262
Merge pull request #2700 from jlowin/2679-task-cancel-fix-2.x
Bump pydocket to 0.16.3 to fix worker cleanup race condition
2025-12-23 18:54:32 -05:00
Chris Guidry
34112a17df Bump pydocket to 0.16.3 to fix worker cleanup race condition
pydocket 0.16.3 fixes a race condition in `_worker_loop` where cancellation
arriving between `_worker_done.clear()` and the try block would cause
`_worker_done.set()` to never run, blocking `Worker.__aexit__` forever.

Also fixes:
- Simplified `_docket_lifespan` cleanup (timeout wrapper no longer needed)
- Fixed `nested_server` test fixture to use graceful uvicorn shutdown
- Fixed uv transport tests to use local fastmcp in dev mode

Closes #2679

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 18:45:42 -05:00
Jeremiah Lowin
5daabf0b84
Fix test cleanup for uvicorn 0.39+ context isolation (#2696) 2025-12-23 18:40:20 -05:00
Jeremiah Lowin
7a46e2130b
Let FastMCPError propagate unchanged from managers (#2697) 2025-12-23 18:29:36 -05:00
Jeremiah Lowin
bf60ac4e44 Fix task execution for tools with custom names (#2645)
Uses pydocket 0.16.0's `names=` parameter for explicit registration keys:
- Tools/prompts: registered by `.key`
- Resources/templates: registered by `.name`

Removes `_create_named_fn_wrapper` function.

Closes #2642
2025-12-23 18:05:29 -05:00
Chris Guidry
afb22c4a74 Let FastMCPError propagate from dependencies
When a dependency raises ToolError or other FastMCPError subclasses, they
were getting wrapped in RuntimeError with a generic "Failed to resolve
dependency" message. This made it hard to use ToolError for validation
in dependencies.

Now FastMCPError subclasses propagate unchanged, matching the pattern
used elsewhere in the codebase.

Closes #2633

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 18:00:40 -05:00
Rafi Olaverria
6a434e4005 fix: check the cause of the tool error (#2674) 2025-12-23 18:00:25 -05:00
Jeremiah Lowin
2f561ec98d
Deprecate exclude_args in favor of Depends() (#2621) v2.14.1
* Deprecate exclude_args in favor of Depends()

* Add version badge to Hiding Parameters section
2025-12-14 21:24:08 -05:00
Jeremiah Lowin
076ec0c84b
Adopt streamable_http_client API from MCP SDK (#2620)
* Adopt streamable_http_client API from MCP SDK

- Update import to use new streamable_http_client function
- Convert httpx_client_factory to httpx.AsyncClient before passing to new API
- Maintain backward compatibility by continuing to accept factories
- Add deprecation warning for sse_read_timeout parameter

The new API accepts httpx.AsyncClient directly instead of factories.
We continue accepting factories for OAuth compatibility, converting
them to clients at the boundary with the MCP SDK.

* Fix timeout type conversion for streamable_http_client

Convert read_timeout_seconds from timedelta to float before passing
to httpx, matching the pattern used in the SSE transport.

* Enable redirect following in httpx client

* Fix httpx client resource leak
2025-12-14 21:18:01 -05:00
Jeremiah Lowin
b8ae95a4bb
Add tool_names parameter to mount() for name overrides (#2619)
* Add tool_names parameter to mount() for name overrides

* Fix Docket registration to use tool_names overrides
2025-12-14 20:56:42 -05:00
Jeremiah Lowin
577f4d1bdf
Consolidate sampling examples and fix tool_choice bug (#2618)
* Fix tool_choice to always require tools when result_type is set

* Consolidate sampling examples with rich output

* Replace eval() with explicit add/multiply tools
2025-12-14 20:47:00 -05:00
Jeremiah Lowin
c91c43e280
Add AnthropicSamplingHandler (#2617)
* Add AnthropicSamplingHandler

Adds a sampling handler for the Anthropic API at
fastmcp.client.sampling.handlers.anthropic, alongside the existing
OpenAI handler. Includes full support for tool calling.

Install with: pip install fastmcp[anthropic]

* Update default model

* Update sampling docs to cover both OpenAI and Anthropic handlers

* Use AsyncAnthropic, fix falsy value handling, handle tool_choice none

* Propagate isError to Anthropic, join multiple text blocks, fix docs
2025-12-14 16:07:22 -05:00
Jeremiah Lowin
da77cfa73f
Unify SamplingHandler and promote OpenAI handler (#2616)
* Unify SamplingHandler and promote OpenAI handler

Consolidates ServerSamplingHandler and ClientSamplingHandler into a single
SamplingHandler type alias. Moves OpenAISamplingHandler from experimental
to fastmcp.client.sampling.handlers.openai as the canonical location.

Backwards compatibility maintained for imports from experimental.

* Remove unreachable code paths in OpenAI handler

* Fix docstring and use elif for mutually exclusive branches
2025-12-14 15:22:43 -05:00
Jeremiah Lowin
41ec7ee06d
SEP-1577: Sampling with tools (#2551)
* MCP → SDK (vocab change only)

* WIP: Sampling API with SamplingResult[T] and result_type

* SEP-1577: Sampling with tools

- Add tools and result_type parameters to ctx.sample()
- Update OpenAI handler for tool content types
- Client advertises sampling.tools capability by default
- Collect tool results into single message with list content

* Fix tool result content handling in OpenAI handler

* Remove @sampling_tool decorator - pass functions directly to sample()

Functions passed to ctx.sample(tools=[...]) are now auto-converted
via SamplingTool.from_function(). Users can still use that method
directly for custom name/description overrides.

* Remove auto-conversion of MCP tools to sampling tools

Users want MCP tools passed to ctx.sample() to go through the full MCP
machinery (middleware, native responses) rather than being auto-converted
to direct function calls. Now only SamplingTool and plain callables are
accepted - passing a FastMCP Tool raises a clear TypeError.

Also bumps mcp dependency to >=1.24.0 for required sampling features.

* Refactor sampling API: replace sample_iter() with sample_step()

Replace the mutable SampleRun/sample_iter() pattern with a simpler stateless
sample_step() function. sample_step() makes a single LLM call and returns a
SampleStep with the response and history. sample() now loops sample_step()
internally.

Key changes:
- Add sample_step() for fine-grained control over the sampling loop
- Remove SampleRun class and sample_iter() method
- Structured output uses tool description only (no prompt modification)
- execute_tools parameter controls automatic vs manual tool execution

* Address CodeRabbit nitpicks

* Address CodeRabbit review feedback for sampling tools

- Fix temperature=0.0 being dropped due to falsy evaluation
- Add ToolChoice.name support for forcing specific tools
- Replace assert statements with explicit RuntimeError checks
- Add mask_error_details parameter to sample()/sample_step() with ToolError escape hatch
- Fix hasattr patterns with proper isinstance checks
- Document mask_error_details and add OpenAI prerequisites to docs

* Address additional CodeRabbit review feedback

- Catch ValidationError specifically instead of bare Exception
- Update result_type docs to mention dataclasses and basic types
- Raise ValueError for unknown tool_choice modes
- Validate sampling_handler_behavior to catch typos
- Remove ToolChoice.name handling (not part of MCP spec)
- Validate tool_choice string in sample_step()

* Review fixes for sampling tools PR

- Remove internal functions from sampling __init__.py exports
- Remove fragile is_text property, use not is_tool_use instead
- Inline call_client into context.py, remove from run.py
- Fix SamplingMessage docs to use TextContent
- Handle result.text being None in doc examples
- Simplify client sampling docs to recommend OpenAISamplingHandler
- Add sampling_capabilities override documentation
- Raise iteration limit from 50 to 100
- Remove _parse_model_preferences duplication
- Use AsyncOpenAI in OpenAISamplingHandler
- Fix tool_choice docstring

* Fix OpenAI handler tests to use AsyncOpenAI

* Address remaining CodeRabbit review comments

- Fix message ordering in OpenAI handler: tool results now correctly
  follow assistant message with tool_calls
- sample_step() now always includes assistant message in history
- Raise ValueError on JSON parse errors instead of silent {}
- Add has_sampling capability check when behavior is None
- Raise RuntimeError when structured output receives text response
- Wrap primitive result_type schemas in object wrapper
- Fix docs example using invalid SamplingMessage construction
- Add comprehensive client_sampling_test.py example

* Add return type annotation to OpenAISamplingHandler.__init__

* Use explicit 'is not None' check for sampling_capabilities defaulting

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Bill Easton <strawgate@users.noreply.github.com>
2025-12-14 13:51:05 -05:00
Jeremiah Lowin
0cd3690aef
Consolidate session state reset logic and improve cancellation cleanup (#2615) 2025-12-14 09:11:30 -05:00
Shawn Thapa
d26b04f80e
Clean up cancelled connection startup (#2614) 2025-12-14 08:45:05 -05:00
Jeremiah Lowin
08d092be57
Use WindowsSelectorEventLoopPolicy to fix Windows test warnings (#2607)
* fix: skip TextIO log file test on Windows

Avoids PytestUnraisableExceptionWarning caused by ProactorEventLoop
cleanup timing issues with subprocess pipe transports.

* Use WindowsSelectorEventLoopPolicy to fix Windows test warnings

Re-add the SelectorEventLoop fix from bcd2e594 that was inadvertently
removed in cf101c2a. This fixes ProactorEventLoop cleanup warnings
on Windows CI without needing to skip individual tests.
2025-12-14 08:39:44 -05:00
Jeremiah Lowin
ff4e3bb131
Remove legacy _task_capable_initialize() workaround (#2612)
The function set experimental={"tasks": {}} but per the MCP spec:
1. Tasks belong in capabilities.tasks, not capabilities.experimental
2. Clients only need to declare task capabilities if receiving task-augmented
   requests from the server (bi-directional support)

For client→server task requests (tools/call with task=True), only the server
needs to declare task capabilities. The SDK's native session.initialize()
handles this correctly.
2025-12-13 20:29:06 -05:00
Jeremiah Lowin
1efc4bc3ff
Revert "Refactor resource behavior and add meta support (#2598)" (#2609)
This reverts commit 12f2422e18.
2025-12-13 15:02:18 -05:00
Jeremiah Lowin
f9e29cf58e
Revert "Refactor prompt behavior and add meta support (#2600)" (#2608)
This reverts commit edb9d5ab65.
2025-12-13 14:57:50 -05:00
Jeremiah Lowin
edb9d5ab65
Refactor prompt behavior and add meta support (#2600)
* feat: add PromptResult as canonical internal type for prompts

Applies the same pattern as ResourceContent to prompts. PromptResult
wraps messages with description and meta. Public render() can return
either list[PromptMessage] or PromptResult (backwards compatible),
while private _render() always returns PromptResult.

* docs: fix incorrect PromptResult return type in example

* feat: add PromptResult canonical type with meta support

* fix: address PR #2600 review comments

Fixes test failures and code quality issues identified in PR review:

- Update 3 tests in test_server_interactions.py to access PromptResult.messages[0] instead of indexing directly
- Fix ProxyPromptManager to preserve meta field when converting GetPromptResult to PromptResult
- Fix ProxyPrompt.render() to return PromptResult instead of deprecated list[PromptMessage], preventing fastmcp tags from leaking into runtime meta
- Fix mask_error_details initialization to respect explicit False values
- Fix exception re-raising to preserve tracebacks (use bare raise instead of raise e)
- Update testing documentation to use pytest -n auto for parallel execution
2025-12-13 12:08:41 -05:00
Jeremiah Lowin
d73f05d7e2
chore: add Python 3.13 to Ubuntu CI tests (#2606) 2025-12-13 12:03:46 -05:00
Jeremiah Lowin
12f2422e18
Refactor resource behavior and add meta support (#2598)
* feat: make ResourceContent the canonical internal type for resources

Add Resource._read() private method that always returns ResourceContent,
maintaining backwards compatibility for custom resources returning str/bytes
from read(). Includes deprecation warning when str/bytes is returned.

* fix: address review feedback for ResourceContent

- Remove ResourceContent from root exports (import from fastmcp.resources)
- Fix FunctionResource.read() return type to str | bytes | ResourceContent
- Decode base64 blobs in proxy when receiving from remote servers
- Preserve meta in ProxyResource cached content

* fix: add empty result guards in proxy resource reads
2025-12-13 11:45:38 -05:00
Chris Guidry
896eb12374
Merge pull request #2605 from jlowin/bump-pydocket-0.15.5
chore: bump pydocket to >=0.15.5
2025-12-12 17:37:29 -05:00
Chris Guidry
ece38b8d04 chore: bump pydocket to >=0.15.5
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-12 17:31:08 -05:00
Chris Guidry
be726d743f
Merge pull request #2603 from jlowin/fix-prompt-task-to-mcp
fix: prompt tasks returning mcp.types.PromptMessage now work
2025-12-12 14:11:28 -05:00
Chris Guidry
f2006804d2 fix: prompt tasks returning mcp.types.PromptMessage now work
When a prompt function returned `mcp.types.PromptMessage` objects directly
and was executed as a task, the result serialization failed with
"'PromptMessage' object has no attribute 'to_mcp'".

The task result converter was calling `.to_mcp()` on what it thought was a
FastMCP wrapper type, but the import actually pulls in `mcp.types.PromptMessage`
directly, which is already the final MCP type. Removed the unnecessary
conversion.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-12 12:57:04 -05:00
marvin-context-protocol[bot]
9ddea52d93
chore: Update SDK documentation (#2592)
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
2025-12-11 21:43:51 -05:00
Jeremiah Lowin
c2ab2c3db4
docs: simplify Docket tip wording (#2599) 2025-12-11 21:08:37 -05:00
Jeremiah Lowin
3d6fd4650c
chore: remove tests/test_examples.py (#2593) v2.14.0 2025-12-10 15:52:07 -05:00
Xing
03b62d2e3d
feat: handle error from the initialize middleware (#2531)
* feat: handle error from the initialize middleware

In some situation, the initialize middleware can check the status of the
server and decide to raise an error.

Example use case: in a FastMCPProxy, an initialization middleware
overrides the on_initialize method and connect to the underlying proxied
client. When client respond with error, I want to pass this error to the
client.

* docs update

* test: use McpError assertions now that exception propagation is fixed

- Update tests to catch McpError specifically instead of generic Exception
- Remove commented-out code in low_level.py

---------

Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
2025-12-10 15:51:51 -05:00
Jeremiah Lowin
95e58e87aa
fix: preserve exception propagation through transport cleanup (#2591)
anyio task groups suppress exceptions when cancel_scope.cancel() is
called during cleanup. Capture exceptions before cleanup and re-raise
after task group exits cleanly.

Also preserve McpError type in client _connect() so callers can catch
protocol-level errors specifically.
2025-12-10 15:37:03 -05:00
marvin-context-protocol[bot]
855e01ed21
chore: Update SDK documentation (#2588)
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
2025-12-09 22:08:03 -05:00
Jeremiah Lowin
d56f55a12a
Add smart fallback for missing access token expiry (#2587)
When upstream OAuth providers don't return expires_in (like GitHub OAuth
Apps), use smart defaults: 1 hour if refresh token available, 1 year if
not. Adds fallback_access_token_expiry_seconds parameter to override.
2025-12-09 21:31:17 -05:00
marvin-context-protocol[bot]
d35b867b10
chore: Update SDK documentation (#2517)
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
2025-12-09 21:07:20 -05:00
Jeremiah Lowin
080ffa578a
Fix nested server mount routing for 3+ levels deep (#2586)
Tools, resources, and prompts from servers mounted more than 2 levels
deep failed to invoke even though they were correctly listed.

The bug was in the routing methods which used manager methods that only
search locally, not through nested mounted servers. Changed to use
server-level methods that search recursively.

Fixes #2583
2025-12-09 21:06:47 -05:00