-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add list_resources, list_prompts, and get_prompt methods to Context #2249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add Context.list_resources() to list all available resources - Add Context.list_prompts() to list all available prompts - Add Context.get_prompt() to get a specific prompt with arguments - Update ToolInjectionMiddleware to use new Context methods instead of creating temporary Client instances - Remove unused Client and FastMCPTransport imports from tool_injection.py This improves API consistency by allowing middleware/tools to use Context methods directly without needing to create temporary Client instances. Fixes #2245 Co-authored-by: William Easton <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds three new methods to the Context class (list_resources(), list_prompts(), and get_prompt()) to improve API consistency and eliminate the need for middleware to create temporary Client instances. The change streamlines the API by allowing all resource and prompt operations to be performed directly through the Context object.
Key changes:
- Added
list_resources(),list_prompts(), andget_prompt()methods to theContextclass - Updated
ToolInjectionMiddlewareto use the new Context methods instead of creating temporary Client instances - Removed unused
ClientandFastMCPTransportimports from the middleware
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/fastmcp/server/context.py | Added three new methods to Context class for listing resources, listing prompts, and getting prompts with proper error handling and documentation |
| src/fastmcp/server/middleware/tool_injection.py | Replaced temporary Client instance creation with direct Context method calls and removed unused imports |
|
/marvin the ctx.fastmcp property can't return none anyway |
|
Claude finished @strawgate's task —— View job Task completed
Removed unnecessary None checks from these methods:
The All tests and linting passed. Changes have been committed and pushed. --- | |
|
🤦 sorry marvin |
Enhancement
Adds
list_resources(),list_prompts(), andget_prompt()methods to theContextclass to improve API consistency.Previously, the Context object had
read_resource()but lackedlist_resources()andlist_prompts()methods. This created an inconsistency where middleware/tools needed to create temporary Client instances to list resources/prompts but could use context methods to read/get them.Changes
Context.list_resources()to list all available resourcesContext.list_prompts()to list all available promptsContext.get_prompt()to get a specific prompt with argumentsThese methods follow the same pattern as
read_resource()and delegate to the FastMCP server's internal MCP methods.Example
Fixes #2245
🤖 Generated with Claude Code