fastmcp/tests/server
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
..
auth Fix Azure scope mismatch causing MCP client validation errors (#2243) 2025-10-24 17:45:49 -04:00
http Make CORS opt-in via middleware parameter (#2150) 2025-10-20 15:33:13 -04:00
middleware Add ToolInjectionMiddleware + Tools for Read/List Resource/Prompt for Client Compat (#2142) 2025-10-24 18:06:58 -04:00
openapi Upgrade to MCP 1.17+ with RFC 9728 compliance (#2122) 2025-10-17 09:29:23 -04:00
proxy Internal refactor of MCP handlers (#2005) 2025-10-05 08:45:10 -04:00
__init__.py restore 1.x code 2025-04-09 11:54:42 -04:00
test_app_state.py Update docs and test 2025-06-20 13:06:48 -04:00
test_auth_integration.py Add audio support 2025-06-14 08:59:48 -04:00
test_context.py Replace subprocess tests with in-process async servers (#2006) 2025-10-19 10:47:54 -04:00
test_experimental_openapi_feature_flag.py Introduce experimental OpenAPI parser with improved performance and maintainability (#1209) 2025-07-21 16:17:36 -04:00
test_file_server.py Internal refactor of MCP handlers (#2005) 2025-10-05 08:45:10 -04:00
test_icons.py Implement icon support (#2121) 2025-10-17 17:28:08 -04:00
test_import_server.py Enable more type checking rules (#1775) 2025-09-07 11:11:44 -04:00
test_input_validation.py Add Pydantic-compatible input validation (#2073) 2025-10-14 11:49:30 -07:00
test_log_level.py Add log level support for stdio and HTTP transports (#1840) 2025-09-19 13:46:30 -04:00
test_logging.py Use anyio.event 2025-05-31 18:12:17 -04:00
test_mount.py Switch Lifespan to being a Server Lifespan (#2013) 2025-10-14 11:49:53 -07:00
test_resource_prefix_formats.py Update tests 2025-06-19 14:05:19 -04:00
test_run_server.py Update tests for prompts 2025-06-04 16:37:41 -04:00
test_server.py Use abstract types for FastMCP class instantiation (#2219) 2025-10-24 17:50:07 -04:00
test_server_interactions.py Add Pydantic-compatible input validation (#2073) 2025-10-14 11:49:30 -07:00
test_server_lifespan.py Switch Lifespan to being a Server Lifespan (#2013) 2025-10-14 11:49:53 -07:00
test_streamable_http_no_redirect.py Improve redirect handling to address 307's (#1387) 2025-08-08 11:55:30 -04:00
test_tool_annotations.py Internal refactor of MCP handlers (#2005) 2025-10-05 08:45:10 -04:00
test_tool_exclude_args.py Add structured content & update almost all tests 2025-06-27 15:40:52 -04:00
test_tool_transformation.py Internal refactor of MCP handlers (#2005) 2025-10-05 08:45:10 -04:00