Commit graph

35 commits

Author SHA1 Message Date
Bill Easton
376a4a57e2
Docs: add FileTreeStore sanitization warnings and update examples (#3661)
Co-authored-by: Marvin Context Protocol <41898282+Marvin Context Protocol@users.noreply.github.com>
Co-authored-by: Bill Easton <strawgate@users.noreply.github.com>
2026-03-27 21:41:56 -04:00
Jeremiah Lowin
e3b6b0c470
Deprecate PromptToolMiddleware and ResourceToolMiddleware (#3389)
* Deprecate PromptToolMiddleware and ResourceToolMiddleware

* Remove deprecated middleware from docs entirely

* Remove entire Tool Injection section from middleware docs
2026-03-06 17:17:01 -05:00
Jeremiah Lowin
8bc31360e8
Restructure docs navigation: CLI section, Composition, More (#3361)
* WIP: Move mounting docs to servers/composition, remove deprecated import_server content

* WIP: Add CLI section under More, move testing to Features, restructure nav

* WIP: Rename querying to client, remove factory functions from CLI overview

* WIP: Promote CLI to top-level section, move Upgrading to More

* WIP: Rename CLI installing page to install-mcp

* WIP

* Add Google Gemini sampling handler docs, fix version badges
2026-03-02 21:09:48 -05:00
Jeremiah Lowin
62804e2f06
Add cache key identity note to middleware docs 2026-02-16 08:52:28 -05:00
Jeremiah Lowin
32c6826e13
Add note about output_schema incongruity when responses are truncated (#3099) 2026-02-06 18:15:57 -05:00
Diogo Santos
30832ced1c
Add ResponseLimitingMiddleware for tool response size control (#3072) 2026-02-06 18:13:26 -05:00
Jeremiah Lowin
6dba73b69d
Restructure docs: move transforms to dedicated section (#2956) 2026-01-20 00:38:35 -05:00
Jeremiah Lowin
3af9de197a
Restructure documentation for FastMCP 3.0 (#2951) 2026-01-19 21:33:35 -05:00
Jeremiah Lowin
07d89c4038
Add transform system for modifying components in provider chains (#2836)
* Consolidate tool transformation logic into TransformingProvider

Tool transformations were previously scattered across LocalProvider,
ProxyProvider, and MCPConfig. This consolidates all transformation
logic into TransformingProvider via with_transforms(tool_transforms={...}).

- Add tool_transforms parameter to TransformingProvider
- Add tool_transforms to Provider.with_transforms()
- Remove transformation storage from LocalProvider and ProxyProvider
- Remove add_tool_transformation() and remove_tool_transformation() from FastMCP
- Add tool_transforms parameter to factory methods (from_openapi, from_fastapi, create_proxy)
- Update tests to use new patterns

* Fix: reject tool lookups by pre-transform name

* Add collision validation for tool_transforms and fix docstring examples

- Validate duplicate target names in tool_transforms raise ValueError
- Fix docstring examples to use arguments/ArgTransformConfig (not args/ArgTransform)
- Add test for collision validation

* Add server-level tool transform APIs and fix task registration

- Add AggregateProvider to present multiple providers as one
- Add _get_root_provider() to apply server-level transforms uniformly
- Fix _docket_lifespan to use root provider (ensures renamed tools
  register with correct keys for background execution)
- Add tool_transforms kwarg to __init__ (non-deprecated)
- Add add_tool_transform(), remove_tool_transform(), tool_transforms property
- Deprecate old API names (tool_transformations, add_tool_transformation, etc.)
- Update tests to use new API

* Add graceful degradation for provider errors in AggregateProvider

* Match original behavior: parallel queries with DEBUG logging

* Refactor transforms to middleware-style call_next pattern

Replaces the ad-hoc transformation system with a unified Transform
abstraction using the same call_next pattern as server middleware.

Key changes:
- New src/fastmcp/server/transforms/ module with Transform base class
- Namespace, ToolTransform, Visibility all implement the same interface
- Transforms compose via functools.partial chain building
- Visibility is now just the first transform in provider._transforms
- Server-level transforms apply after provider aggregation
- Task registration now applies full transform chain

Removes TransformingProvider, _BoundTransform, ComponentSource protocol.
User-facing API unchanged: mount(), add_transform(), enable/disable all
work as before.

* Add comprehensive transforms and visibility documentation

New docs/servers/providers/transforms.mdx covering:
- Mental model for middleware-style transform pattern
- Built-in transforms (Namespace, ToolTransform)
- Server vs provider-level transforms and ordering
- Tool modification (immediate vs deferred)
- Custom transform creation

New docs/servers/visibility.mdx covering:
- Enable/disable API for runtime visibility control
- Keys and tags for targeting components
- Allowlist mode with only=True
- Server vs provider visibility layering

Updates existing docs to reference new pages and simplifies
redundant content. Visibility is documented as a user feature,
not as an implementation detail.

* Restructure transforms docs and delete tool-transformation pattern

* Cleanup: simplify get_tasks and remove unused Provider.get_component

* Update loq

* Update loq limits and add loq note to AGENTS.md

* Deprecate add_tool_transformation and tool_transformations param

* Address PR review feedback: remove redundant imports, fix path reference

* Add missing imports to code examples in v3-features.mdx
2026-01-12 22:11:16 -05:00
Jeremiah Lowin
4765f5725a
Add PingMiddleware for keepalive connections (#2838) 2026-01-10 16:12:35 -05:00
Jeremiah Lowin
1d17334803
Reorganize docs around provider architecture (#2723) 2025-12-25 09:00:20 -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
bc076cba12
Handle request_context availability during MCP initialization (#2400)
The on_initialize hook (2.13.0) runs before the MCP session is established, causing request_context
to be unavailable. Changed request_context to return None instead of raising, allowing middleware to
check availability and use HTTP helpers when needed. Updated docs to guide this pattern.

Closes #2393
2025-11-15 10:50:24 -05:00
William Easton
f5dbabff4e
Add ToolInjectionMiddleware + Tools for Read/List Resource/Prompt for Client Compat (#2142)
* Add compatibility tools contrib module

Implements four standalone tools that expose resources and prompts
as callable tools for clients that only support the tools capability.

Features:
- list_resources: List all available resources
- get_resource: Read a resource by URI
- list_prompts: List all available prompts
- get_prompt: Get a prompt with optional arguments

The tools use Context to access the server instance and can be easily
added to any FastMCP server using the add_compatibility_tools helper
or by adding individual tool instances directly.

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

Co-authored-by: William Easton <strawgate@users.noreply.github.com>

* Simplify compatibility tools to return raw MCP protocol objects

Return raw MCP protocol objects (ListResourcesResult, ReadResourceResult,
ListPromptsResult, GetPromptResult) instead of custom dictionaries. This
makes the tools simpler and more predictable by directly exposing what
the client methods return.

Co-authored-by: William Easton <strawgate@users.noreply.github.com>

* Add tool injection middleware

* cleanup contrib module

* More clean-up

* Clean up tool injection middleware.

* Update src/fastmcp/server/middleware/tool_injection.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add tool injection docs

* Small cleanup of prompt middleware

* PR Feedback

* Fix tool injection tests

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: William Easton <strawgate@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-24 18:06:58 -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
5831c4bb60
PR Clean-up 2025-10-16 21:56:55 -05:00
William Easton
28370827dc
Merge branch 'main' into responsecachingmiddleware 2025-10-10 17:37:34 -04:00
Jeremiah Lowin
9cb47e12dd
Add version badge to on_initialize docs (#2029) 2025-10-08 20:10:12 -04:00
Jeremiah Lowin
ba1ba86a64
Support initialize requests in middleware (#1546) 2025-10-05 10:20:13 -04:00
William Easton
a9113d0c9a
Refactor cache, add Elasticsearch cache backend as a contrib module with docs 2025-09-18 13:47:42 -05:00
William Easton
d5f01dae15
Add docs 2025-09-17 19:46:15 -05:00
Jeremiah Lowin
df284ba824
Add unit tests and docs for denying tool calls with middleware (#1333) 2025-08-01 16:55:42 -04:00
Jeremiah Lowin
4445c87bf4
Add 2.11 version badge for state management (#1289) 2025-07-29 10:41:13 -04:00
Jeremiah Lowin
160d50e3a5 Update documentation 2025-07-28 17:42:23 -04:00
Jeremiah Lowin
07655e6620
Fix typing, add tests for tool call middleware (#1269) 2025-07-25 18:46:48 -04:00
Jeremiah Lowin
f835d4b41a
Add docs for context state management (#1227) 2025-07-22 10:13:17 -04:00
Jeremiah Lowin
767de312f9
Fix middleware list result types (#1125)
* Catch more openapi changes

* Simplify middleware list operations to use lists directly

- Updated middleware signatures to work with list[Tool], list[Resource], etc instead of wrapper objects
- Removed unnecessary ListToolsResult, ListResourcesResult wrapper types
- Updated documentation to show simpler list-based filtering pattern
- Added tests for list-based middleware filtering

Closes #1121

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

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-11 18:04:20 -04:00
Jeremiah Lowin
2690878412 Update middleware imports and documentation 2025-06-30 18:35:16 -04:00
Jeremiah Lowin
ddb38bacc4 Fix middleware tests 2025-06-26 18:13:32 -04:00
Jeremiah Lowin
f821edb252 Remove production-ready language from middleware docs 2025-06-22 22:01:10 -04:00
Jeremiah Lowin
6d033eeaf1 Add production-ready middleware examples with comprehensive tests
Implements timing, logging, rate limiting, and error handling middleware to showcase
FastMCP's middleware capabilities as a headline feature. Each middleware includes:

- Production-ready implementations with full configurability
- Comprehensive unit and integration tests with real FastMCP servers
- Updated documentation with teaching examples and production usage patterns

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-22 21:57:49 -04:00
Jeremiah Lowin
dee2f33a81 Update doc icons 2025-06-19 17:28:00 -04:00
Jeremiah Lowin
085c5b765b Update docs and tests 2025-06-19 17:06:54 -04:00
Jeremiah Lowin
0beb79d11a Minor updates 2025-06-19 15:28:55 -04:00
Jeremiah Lowin
2e31b2704b Update tests 2025-06-19 14:05:19 -04:00