Jeremiah Lowin commited on
Commit
1bfd496
·
1 Parent(s): 194b8dd
Files changed (1) hide show
  1. docs/servers/openapi.mdx +77 -3
docs/servers/openapi.mdx CHANGED
@@ -51,6 +51,7 @@ Each `RouteMap` specifies a combination of methods, patterns, and tags, as well
51
  - **Pattern**: Regex pattern to match the route path (e.g. `r"^/users/.*"` or `r".*"` for all)
52
  - **Tags**: A set of OpenAPI tags that must all be present. An empty set (`{}`) means no tag filtering, so the route matches regardless of its tags.
53
  - **MCP type**: What MCP component type to create (`TOOL`, `RESOURCE`, `RESOURCE_TEMPLATE`, or `EXCLUDE`)
 
54
 
55
  Here is FastMCP's default rule:
56
 
@@ -206,9 +207,76 @@ mcp = FastMCP.from_openapi(
206
 
207
  ## Customizing MCP Components
208
 
 
209
 
 
210
 
211
- ### Component Names
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
 
213
  <VersionBadge version="2.5.0" />
214
 
@@ -421,10 +489,16 @@ mcp = FastMCP.from_fastapi(
421
  app=app,
422
  name="My Custom Server",
423
  timeout=5.0,
 
424
  mcp_names={"operationId": "friendly_name"}, # Custom component names
425
  route_maps=[
426
- # Admin endpoints become tools
427
- RouteMap(methods="*", pattern=r"^/admin/.*", mcp_type=MCPType.TOOL),
 
 
 
 
 
428
  # Internal endpoints are excluded
429
  RouteMap(methods="*", pattern=r".*", mcp_type=MCPType.EXCLUDE, tags={"internal"}),
430
  ],
 
51
  - **Pattern**: Regex pattern to match the route path (e.g. `r"^/users/.*"` or `r".*"` for all)
52
  - **Tags**: A set of OpenAPI tags that must all be present. An empty set (`{}`) means no tag filtering, so the route matches regardless of its tags.
53
  - **MCP type**: What MCP component type to create (`TOOL`, `RESOURCE`, `RESOURCE_TEMPLATE`, or `EXCLUDE`)
54
+ - **MCP tags** A set of custom tags to add to components created from matching routes
55
 
56
  Here is FastMCP's default rule:
57
 
 
207
 
208
  ## Customizing MCP Components
209
 
210
+ ### Tags
211
 
212
+ <VersionBadge version="2.8.0" />
213
 
214
+ FastMCP provides several ways to add tags to your MCP components, allowing you to categorize and organize them for better discoverability and filtering. Tags are combined from multiple sources to create the final set of tags on each component.
215
+
216
+ #### RouteMap Tags
217
+
218
+ You can add custom tags to components created from specific routes using the `mcp_tags` parameter in `RouteMap`. These tags will be applied to all components created from routes that match that particular route map.
219
+
220
+ ```python {12, 20, 28}
221
+ from fastmcp import FastMCP
222
+ from fastmcp.server.openapi import RouteMap, MCPType
223
+
224
+ mcp = FastMCP.from_openapi(
225
+ ...,
226
+ route_maps=[
227
+ # Add custom tags to all POST endpoints
228
+ RouteMap(
229
+ methods=["POST"],
230
+ pattern=r".*",
231
+ mcp_type=MCPType.TOOL,
232
+ mcp_tags={"write-operation", "api-mutation"}
233
+ ),
234
+
235
+ # Add different tags to detail view endpoints
236
+ RouteMap(
237
+ methods=["GET"],
238
+ pattern=r".*\{.*\}.*",
239
+ mcp_type=MCPType.RESOURCE_TEMPLATE,
240
+ mcp_tags={"detail-view", "parameterized"}
241
+ ),
242
+
243
+ # Add tags to list endpoints
244
+ RouteMap(
245
+ methods=["GET"],
246
+ pattern=r".*",
247
+ mcp_type=MCPType.RESOURCE,
248
+ mcp_tags={"list-data", "collection"}
249
+ ),
250
+ ],
251
+ )
252
+ ```
253
+
254
+ #### Global Tags
255
+
256
+ You can add tags to **all** components by providing a `tags` parameter when creating your FastMCP server with `from_openapi` or `from_fastapi`. These global tags will be applied to every component created from your OpenAPI specification.
257
+
258
+ <CodeGroup>
259
+ ```python {6} from_openapi()
260
+ from fastmcp import FastMCP
261
+
262
+ mcp = FastMCP.from_openapi(
263
+ openapi_spec=spec,
264
+ client=client,
265
+ tags={"api-v2", "production", "external"}
266
+ )
267
+ ```
268
+ ```python {5} from_fastapi()
269
+ from fastmcp import FastMCP
270
+
271
+ mcp = FastMCP.from_fastapi(
272
+ app=app,
273
+ tags={"internal-api", "microservice"}
274
+ )
275
+ ```
276
+ </CodeGroup>
277
+
278
+
279
+ ### Names
280
 
281
  <VersionBadge version="2.5.0" />
282
 
 
489
  app=app,
490
  name="My Custom Server",
491
  timeout=5.0,
492
+ tags={"api-v1", "fastapi"}, # Global tags for all components
493
  mcp_names={"operationId": "friendly_name"}, # Custom component names
494
  route_maps=[
495
+ # Admin endpoints become tools with custom tags
496
+ RouteMap(
497
+ methods="*",
498
+ pattern=r"^/admin/.*",
499
+ mcp_type=MCPType.TOOL,
500
+ mcp_tags={"admin", "privileged"}
501
+ ),
502
  # Internal endpoints are excluded
503
  RouteMap(methods="*", pattern=r".*", mcp_type=MCPType.EXCLUDE, tags={"internal"}),
504
  ],