Jeremiah Lowin commited on
Commit
ef94547
·
unverified ·
2 Parent(s): 5496833657c314

Merge pull request #793 from jlowin/tag-docs

Browse files
Files changed (1) hide show
  1. docs/servers/fastmcp.mdx +43 -0
docs/servers/fastmcp.mdx CHANGED
@@ -96,6 +96,49 @@ def analyze_data(data_points: list[float]) -> str:
96
 
97
  See [Prompts](/servers/prompts) for detailed documentation.
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  ## Running the Server
100
 
101
  FastMCP servers need a transport mechanism to communicate with clients. You typically start your server by calling the `mcp.run()` method on your `FastMCP` instance, often within an `if __name__ == "__main__":` block in your main server script. This pattern ensures compatibility with various MCP clients.
 
96
 
97
  See [Prompts](/servers/prompts) for detailed documentation.
98
 
99
+ ## Tag-Based Filtering
100
+
101
+ <VersionBadge version="2.8.0" />
102
+
103
+ FastMCP supports tag-based filtering to selectively expose components based on configurable include/exclude tag sets. This is useful for creating different views of your server for different environments or users.
104
+
105
+ Components can be tagged when defined using the `tags` parameter:
106
+
107
+ ```python
108
+ @mcp.tool(tags={"public", "utility"})
109
+ def public_tool() -> str:
110
+ return "This tool is public"
111
+
112
+ @mcp.tool(tags={"internal", "admin"})
113
+ def admin_tool() -> str:
114
+ return "This tool is for admins only"
115
+ ```
116
+
117
+
118
+ The filtering logic works as follows:
119
+ - **Include tags**: If specified, only components with at least one matching tag are exposed
120
+ - **Exclude tags**: Components with any matching tag are filtered out
121
+ - **Precedence**: Exclude tags always take priority over include tags
122
+
123
+ <Tip>
124
+ To ensure a component is never exposed, you can set `enabled=False` on the component itself. To learn more, see the component-specific documentation.
125
+ </Tip>
126
+
127
+ You configure tag-based filtering when creating your server:
128
+
129
+ ```python
130
+ # Only expose components tagged with "public"
131
+ mcp = FastMCP(include_tags={"public"})
132
+
133
+ # Hide components tagged as "internal" or "deprecated"
134
+ mcp = FastMCP(exclude_tags={"internal", "deprecated"})
135
+
136
+ # Combine both: show admin tools but hide deprecated ones
137
+ mcp = FastMCP(include_tags={"admin"}, exclude_tags={"deprecated"})
138
+ ```
139
+
140
+ This filtering applies to all component types (tools, resources, resource templates, and prompts) and affects both listing and access.
141
+
142
  ## Running the Server
143
 
144
  FastMCP servers need a transport mechanism to communicate with clients. You typically start your server by calling the `mcp.run()` method on your `FastMCP` instance, often within an `if __name__ == "__main__":` block in your main server script. This pattern ensures compatibility with various MCP clients.