Rename _fastmcp metadata namespace to fastmcp and make non-optional#2895
Rename _fastmcp metadata namespace to fastmcp and make non-optional#2895
Conversation
- Rename meta namespace from `_fastmcp` to `fastmcp` - Always include fastmcp metadata (remove `include_fastmcp_meta` setting) - Add component version to metadata when available
WalkthroughThis pull request removes the Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ 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.
Actionable comments posted: 1
🧹 Nitpick comments (5)
docs/clients/prompts.mdx (1)
45-50: Consider simplifying redundant dictionary access.The filter logic calls
prompt.meta.get('fastmcp', {})twice on the same object. This is slightly inefficient and harder to read.♻️ Suggested improvement
analysis_prompts = [ prompt for prompt in prompts - if prompt.meta and - prompt.meta.get('fastmcp', {}) and - 'analysis' in prompt.meta.get('fastmcp', {}).get('tags', []) + if prompt.meta + and 'analysis' in prompt.meta.get('fastmcp', {}).get('tags', []) ]The intermediate check
prompt.meta.get('fastmcp', {})is unnecessary since the final.get('tags', [])already handles the empty dict case gracefully.docs/clients/resources.mdx (1)
73-78: Same redundant access pattern as in prompts.mdx.The filter logic duplicates the
.get('fastmcp', {})call unnecessarily.♻️ Suggested improvement
config_resources = [ resource for resource in resources - if resource.meta and - resource.meta.get('fastmcp', {}) and - 'config' in resource.meta.get('fastmcp', {}).get('tags', []) + if resource.meta + and 'config' in resource.meta.get('fastmcp', {}).get('tags', []) ]docs/clients/tools.mdx (1)
45-50: Same redundant access pattern.Consider simplifying to match the suggested pattern from other client docs for consistency.
♻️ Suggested improvement
analysis_tools = [ tool for tool in tools - if tool.meta and - tool.meta.get('fastmcp', {}) and - 'analysis' in tool.meta.get('fastmcp', {}).get('tags', []) + if tool.meta + and 'analysis' in tool.meta.get('fastmcp', {}).get('tags', []) ]docs/development/upgrade-guide.mdx (1)
11-15: Consider adding a version badge to indicate which version introduces this change.Other sections in this upgrade guide are organized by version (e.g., "## v3.0.0", "## v2.14.0"). This new section lacks a version indicator, which may confuse users trying to determine when they need to apply this migration.
♻️ Suggested structure
Either add a version heading:
-## FastMCP Metadata Namespace Change +## v2.X.X (or appropriate version) + +### FastMCP Metadata Namespace ChangeOr add a VersionBadge component:
## FastMCP Metadata Namespace Change + +<VersionBadge version="2.X.X" /> ### Metadata Namespace Renamedsrc/fastmcp/resources/resource.py (1)
372-374: Avoid eagerget_meta()evaluation when_metais overridden.
overrides.get("_meta", self.get_meta())always evaluatesself.get_meta(), even when_metais supplied, which can mutateself.metaand do extra work. Consider lazy evaluation.♻️ Proposed tweak
- _meta=overrides.get( # type: ignore[call-arg] # _meta is Pydantic alias for meta field - "_meta", self.get_meta() - ), + _meta=( + overrides["_meta"] + if "_meta" in overrides + else self.get_meta() + ), # type: ignore[call-arg] # _meta is Pydantic alias for meta field
- Add get_fastmcp_metadata() helper with fallback to legacy _fastmcp namespace - Update proxy.py to use helper for compatibility with older servers - Update get_meta() return type to dict[str, Any] (always returns dict) - Regenerate python-sdk API docs
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/fastmcp/utilities/components.py (1)
140-158: Type validation concern formeta["fastmcp"]remains unaddressed.If a caller sets
meta["fastmcp"]to a non-mapping value, the|operator on line 155 will raise aTypeError. This was flagged in a previous review.🛡️ Suggested guard
- if upstream_meta := meta.get("fastmcp"): - fastmcp_meta = upstream_meta | fastmcp_meta + if (upstream_meta := meta.get("fastmcp")) is not None: + if not isinstance(upstream_meta, dict): + raise TypeError("meta['fastmcp'] must be a mapping") + fastmcp_meta = upstream_meta | fastmcp_meta
🧹 Nitpick comments (2)
docs/python-sdk/fastmcp-server-middleware-authorization.mdx (1)
14-29: Split alternative examples and add expected outcome/error handling.Lines 14-29 combine two alternative configurations in one snippet, which makes the example less runnable and harder to follow. Consider using Tabs (global vs tag-based) and add a brief expected-outcome note plus minimal auth-failure handling to meet the MDX example requirements. As per coding guidelines.
docs/python-sdk/fastmcp-resources-resource.mdx (1)
169-172: Add a short description/returns forget_span_attributes.The section is signature-only; add a docstring in
src/fastmcp/resources/resource.pyso generated docs explain purpose and expected keys/values. As per coding guidelines, API docs should document parameters and return values.
| --- | ||
| title: authorization | ||
| sidebarTitle: authorization | ||
| --- |
There was a problem hiding this comment.
Add required description in frontmatter (update generator).
Line 1-4 is missing description, which is required for MDX pages. Since docs/python-sdk/** is auto-generated, please update the doc generator/template and regenerate the file rather than editing it manually. As per coding guidelines.
🛠️ Suggested frontmatter output
---
title: authorization
sidebarTitle: authorization
+description: Authorization middleware for FastMCP servers.
---
Component metadata now uses a cleaner
fastmcpnamespace (instead of_fastmcp) and is always included in responses.Changes:
meta._fastmcp.tags→meta.fastmcp.tagsmeta.fastmcp.versionnow included when component has a versioninclude_fastmcp_metasetting/parameter (metadata always present)