fastmcp/tests/server/middleware
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
..
__init__.py Add single-component methods 2025-06-18 19:47:19 -04:00
test_caching.py PR Clean-up 2025-10-16 21:56:55 -05:00
test_error_handling.py transform NotFoundError to standard MCP error (#2133) 2025-10-18 11:46:57 -04:00
test_initialization_middleware.py Support initialize requests in middleware (#1546) 2025-10-05 10:20:13 -04:00
test_logging.py Implement icon support (#2121) 2025-10-17 17:28:08 -04:00
test_middleware.py Support initialize requests in middleware (#1546) 2025-10-05 10:20:13 -04:00
test_rate_limiting.py Support initialize requests in middleware (#1546) 2025-10-05 10:20:13 -04:00
test_timing.py Use lowercase namespace for fastmcp logger (#1791) 2025-09-26 12:13:02 -04:00
test_tool_injection.py Add ToolInjectionMiddleware + Tools for Read/List Resource/Prompt for Client Compat (#2142) 2025-10-24 18:06:58 -04:00