diff --git a/docs/integrations/openapi.mdx b/docs/integrations/openapi.mdx index e229bf247..ec7a15796 100644 --- a/docs/integrations/openapi.mdx +++ b/docs/integrations/openapi.mdx @@ -332,6 +332,38 @@ mcp = FastMCP.from_openapi( ) ``` +#### OpenAPI Tags in Client Meta + +FastMCP automatically includes OpenAPI tags from your specification in the component's metadata. These tags are available to MCP clients through the `_meta` field, allowing clients to filter and organize components based on the original OpenAPI tagging: + + +```json {5} OpenAPI spec with tags +{ + "paths": { + "/users": { + "get": { + "tags": ["users", "public"], + "operationId": "list_users", + "summary": "List all users" + } + } + } +} +``` +```python {6-8} Access OpenAPI tags in MCP client +async with client: + tools = await client.list_tools() + for tool in tools: + if hasattr(tool, '_meta') and tool._meta: + # OpenAPI tags are now available! + openapi_tags = tool._meta.get('tags', []) + if 'users' in openapi_tags: + print(f"Found user-related tool: {tool.name}") +``` + + +This makes it easy for clients to understand and organize API endpoints based on their original OpenAPI categorization. + ### Advanced Customization diff --git a/tests/server/openapi/test_basic_functionality.py b/tests/server/openapi/test_basic_functionality.py index 4fd2d2221..29e67360f 100644 --- a/tests/server/openapi/test_basic_functionality.py +++ b/tests/server/openapi/test_basic_functionality.py @@ -97,7 +97,7 @@ class TestTools: assert tools[0].model_dump() == dict( name="create_user_users_post", - meta=None, + meta={"tags": ["users", "create"]}, title=None, annotations=None, description=IsStr(regex=r"^Create a new user\..*$", regex_flags=re.DOTALL), @@ -122,7 +122,7 @@ class TestTools: ) assert tools[1].model_dump() == dict( name="update_user_name_users", - meta=None, + meta={"tags": ["users", "update"]}, title=None, annotations=None, description=IsStr(