Refactor transform list methods to pure function pattern#2942
Conversation
Change list_tools, list_resources, list_resource_templates, and list_prompts from middleware pattern (call_next) to pure function pattern (receive sequences directly). Get methods remain in middleware pattern.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis PR refactors list operations (list_tools, list_resources, list_resource_templates, list_prompts) from a call_next/middleware chain to a pure-function style: list methods now accept and return sequences directly. Providers and server code that previously built per-type call_next chains were simplified to iteratively apply each transform to the current sequences. ListXNext type aliases and their usages were removed; get operations retain the middleware call_next pattern. Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47626b9ece
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/fastmcp/server/providers/base.py (1)
439-474: Fix get_tasks list transform chaining (runtime TypeError).
Line 461 currently partialstransform.list_*withcall_next, but list_* no longer accepts that argument. This will throw at runtime when task registration runs.🛠️ Proposed fix (align with pure-sequence list_* APIs)
- # Apply provider's own transforms to components using the chain pattern - # For tasks, we need the fully-transformed names, so use the list_ chain - # Note: We build mini-chains for each component type - - async def tools_base() -> Sequence[Tool]: - return tools - - async def resources_base() -> Sequence[Resource]: - return resources - - async def templates_base() -> Sequence[ResourceTemplate]: - return templates - - async def prompts_base() -> Sequence[Prompt]: - return prompts - - # Apply transforms in order - tools_chain = tools_base - resources_chain = resources_base - templates_chain = templates_base - prompts_chain = prompts_base - - for transform in self.transforms: - tools_chain = partial(transform.list_tools, call_next=tools_chain) - resources_chain = partial( - transform.list_resources, call_next=resources_chain - ) - templates_chain = partial( - transform.list_resource_templates, call_next=templates_chain - ) - prompts_chain = partial(transform.list_prompts, call_next=prompts_chain) - - transformed_tools = await tools_chain() - transformed_resources = await resources_chain() - transformed_templates = await templates_chain() - transformed_prompts = await prompts_chain() + # Apply provider's own transforms in order (pure list transforms) + transformed_tools = tools + transformed_resources = resources + transformed_templates = templates + transformed_prompts = prompts + + for transform in self.transforms: + transformed_tools = await transform.list_tools(transformed_tools) + transformed_resources = await transform.list_resources(transformed_resources) + transformed_templates = await transform.list_resource_templates( + transformed_templates + ) + transformed_prompts = await transform.list_prompts(transformed_prompts)
- Update transforms.mdx to document new list method signatures - Fix Provider.get_tasks() which still used old call_next pattern
Refactors transform list methods (
list_tools,list_resources,list_resource_templates,list_prompts) from middleware pattern to pure function pattern.Changes
List methods now receive sequences directly instead of
call_nextcallables:Providers apply transforms sequentially instead of building middleware chains:
Impact
Get methods (
get_tool,get_resource, etc.) remain unchanged and continue using the middleware pattern, which is necessary for name/URI transformation and routing.