Commit graph

83 commits

Author SHA1 Message Date
Jeremiah Lowin
96d4b1b606 Add pagination documentation 2026-01-17 19:30:33 -05:00
Jeremiah Lowin
33c371cb37
Add version discovery and calling a certain version for components (#2897) 2026-01-17 08:27:39 -05:00
Jeremiah Lowin
53e220a99e
Rename _fastmcp metadata namespace to fastmcp and make non-optional (#2895) 2026-01-16 21:35:53 -05:00
Jeremiah Lowin
4de06d7f73
Fix documentation to use 'meta' instead of '_meta' for MCP spec field (#2735) 2025-12-25 21:05:11 -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
8771f290bd
Rewrite background tasks documentation (#2567)
- Lead with concepts instead of code
- Explain MCP background tasks vs general Python concurrency
- Document Docket's Prefect origins and battle-tested infrastructure
- Add sections on graceful degradation and embedded workers
- Fix version badge to 2.14.0
- Link to SEP-1686 spec
2025-12-06 19:28:14 -05:00
Chris Guidry
66aaf420c9
[2.14] SEP-1686 tasks (#2378)
* Implement MCP background tasks (SEP-1686) using Docket

Adds support for background task execution via the MCP task protocol,
powered by Docket for task queue management.

- Tools, resources, and prompts can be marked with `task=True` to run async
- Progress dependency for tracking task progress
- CurrentDocket and CurrentWorker dependencies for advanced use cases
- Client API with `.call_tool(..., task=True)` returns task handles
- Task status notifications via subscriptions
- CLI worker command for distributed task processing

Configuration via environment:
- FASTMCP_ENABLE_DOCKET=true
- FASTMCP_ENABLE_TASKS=true
- FASTMCP_DOCKET_URL=redis://... (or memory:// for single-process)

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

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix tasks example import (TaskStatusResponse → GetTaskResult)

The example was using a non-existent TaskStatusResponse type.
Updated to use mcp.types.GetTaskResult which is what the
on_status_change callback actually receives.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix env var name in Docket error messages

The error messages referenced FASTMCP_EXPERIMENTAL_ENABLE_DOCKET but the
actual setting is FASTMCP_ENABLE_DOCKET.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* Remove deprecated code re-added from pre-#2329 branch

- Remove ExtendedEnvSettingsSource (FASTMCP_SERVER_ prefix support)
- Remove dependencies parameter from FastMCP.__init__

* Replace fakeredis git pin with PyPI release

* Remove redundant fakeredis dev dep (pulled via pydocket)

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
2025-12-04 20:10:35 -05:00
Jeremiah Lowin
a359b0b28d
Document client meta parameter for sending ancillary request data (#2367) 2025-11-04 11:32:31 -05:00
Jeremiah Lowin
9c861b232b
Add manual initialization control to Client (#2355)
* Add manual initialization control to Client

- Add auto_initialize parameter (default True) to control automatic initialization
- Make initialize() method public with idempotent caching
- Add comprehensive test suite for initialization behavior

* Document client initialization control and server instructions

- Expand documentation to cover auto_initialize parameter
- Show manual initialization for advanced use cases
- Document accessing server instructions via initialize_result

* Update client.mdx
2025-11-03 16:01:30 -05:00
claude[bot]
237f0decd2 Add maturity warnings for py-key-value backends
Add warning notes to documentation directing users to review
py-key-value documentation for backend maturity and limitations
before production use.

Co-authored-by: William Easton <strawgate@users.noreply.github.com>
2025-10-29 21:43:31 +00:00
Jon Zeolla
11277f6e21 fix(docs): correct the key_value repo link 2025-10-27 07:35:10 -04:00
Jeremiah Lowin
5ceafe425c
Fix OAuth token storage documentation (#2272)
Correct imports (DiskStore not FileStore) and simplify structure.
2025-10-26 21:07:54 -04:00
Jeremiah Lowin
f5bdf8f6d3
Improve OAuth client token storage security documentation (#2270)
* Update docs for required scopes

* add scopes

* Fix Azure scope validation

Azure returns unprefixed scopes in JWT tokens but requires prefixed scopes in authorization requests. The previous implementation incorrectly validated tokens against prefixed scopes, causing "invalid_token" errors.

Simplified AzureProvider to use standard JWTVerifier with unprefixed scopes for validation. Scopes are only prefixed when building the Azure authorization URL via _build_upstream_authorize_url() override.

Closes #2263

* Improve OAuth client token storage security documentation

Updated warning message and documentation to address security concerns
around storing OAuth credentials for multiple MCP servers.
2025-10-26 20:04:54 -04:00
Jeremiah Lowin
4d609ce74b
Move sampling fallback handler docs to server section (#2163) 2025-10-21 10:02:11 -04:00
Jeremiah Lowin
b362444ddf
Add storage backend documentation (#2137)
* Add storage backend documentation

* Add storage patterns documentation for wrapper caching strategies

- Add PassthroughCacheWrapper section for multi-tier caching
- Document TTL clamping strategy for optimized memory usage
- Add example for wrapping custom storage implementations
- Explain how to combine fast in-memory caches with persistent remote stores

* Update docs
2025-10-19 19:24:13 -04:00
William Easton
d32a2b953e
Fallback to a Completions API when Sampling is not available (#1145) 2025-08-21 07:49:29 -04:00
Marsley
fbbd8ef999
Fix #1506: Update tool filtering documentation from _meta to meta (#1511) 2025-08-15 10:46:05 -04:00
Jeremiah Lowin
71fb4ab671
docs(client/logging): reflect corrected default log level mapping (#1403)
Co-authored-by: opencode <noreply@opencode.ai>
2025-08-08 11:49:58 -04:00
Jeremiah Lowin
a965d0d836
Docs updates (#1336) 2025-08-01 20:39:55 -04:00
Jeremiah Lowin
b46d4934a8
Add comprehensive OAuth 2.1 authentication system with WorkOS integration (#1327) 2025-08-01 17:06:55 -04:00
Colin Jermain
7f3c3cc24b
Structured client-side logging (#1326) 2025-08-01 14:47:21 -04:00
Jeremiah Lowin
0691701951
Add _fastmcp meta namespace (#1290) 2025-07-29 15:07:53 -04:00
Jeremiah Lowin
6b8a62c127 Add client docs 2025-07-28 17:49:32 -04:00
William Easton
3be8f5ea93
Add UV Transport (#1270)
Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
2025-07-28 15:41:36 -04:00
William Easton
1b953820b3
[🐶] Transform MCP Server Tools (#1132)
Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
2025-07-19 15:52:47 -04:00
Jeremiah Lowin
68cbb470ef Update transport docs 2025-07-09 12:14:33 -04:00
Neil Conway
fe1eddc252
Docs: add example of more concise way to use bearer auth (#1055) 2025-07-06 10:26:02 -04:00
Jeremiah Lowin
5ddb54bbd4 Clean up docs 2025-07-03 11:24:53 -04:00
Jeremiah Lowin
eaf27c710d Support "no response" elicitation requests 2025-06-30 13:03:57 -04:00
Jeremiah Lowin
ecfbf5de00 Support implicit Elicitation acceptance 2025-06-28 20:15:23 -04:00
Jeremiah Lowin
cc98298e6e Add new tag 2025-06-28 15:15:35 -04:00
Jeremiah Lowin
3805ac9b44 Provide a response type to client 2025-06-28 09:47:14 -04:00
Jeremiah Lowin
e22267142e
Merge pull request #901 from jlowin/output-schema
MCP 6/18/25: Add output schema to tools
2025-06-28 08:16:06 -04:00
城城
2a30208245 Add a comma 2025-06-28 15:55:16 +08:00
Jeremiah Lowin
c412a63d4e Update docs 2025-06-27 22:38:55 -04:00
Jeremiah Lowin
5fc82f4fef Fix version badge for messages 2025-06-26 09:40:49 -04:00
Jeremiah Lowin
38036b1f42 Add automatic MCP list change notifications and client message handling
Implements comprehensive notification system for tools, resources, and prompts with automatic client updates and flexible message handlers.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-24 22:33:06 -04:00
Jeremiah Lowin
44f14b1f7b Clean up parameter documentation 2025-06-22 20:59:53 -04:00
Jeremiah Lowin
ffe0c92d63 Alias streamable-http as http 2025-06-22 20:00:11 -04:00
Jeremiah Lowin
133254ee25 Update docs 2025-06-22 13:34:36 -04:00
Jeremiah Lowin
3d2e2a5954 Update client features 2025-06-22 13:30:25 -04:00
Jeremiah Lowin
1adca653e3 Update overview
Co-Authored-By: Claude <claude@users.noreply.github.com>
2025-06-22 13:23:52 -04:00
Jeremiah Lowin
8e98d711fc Update client docs
Co-Authored-By: Claude <claude@users.noreply.github.com>
2025-06-22 13:18:28 -04:00
Jeremiah Lowin
dbf125b6ac Update client.mdx
Co-Authored-By: Claude <claude@users.noreply.github.com>
2025-06-22 10:20:03 -04:00
Jeremiah Lowin
e245155bc5 Simplify docs nav 2025-06-20 20:48:42 -04:00
Jeremiah Lowin
45d031a577 Update headers in docs 2025-06-11 20:20:14 -04:00
Jeremiah Lowin
9913f304f7 update import 2025-06-10 16:43:02 -04:00
JeremyCraigMartinez
b7256fef3c
Update oauth.mdx 2025-06-10 13:23:01 -07:00