You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "yuqi1129 (via GitHub)" <gi...@apache.org> on 2025/08/07 08:22:41 UTC

[PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

yuqi1129 opened a new pull request, #7963:
URL: https://github.com/apache/gravitino/pull/7963

   ### What changes were proposed in this pull request?
   
   Support tag operations for MCP server
   
   ### Why are the changes needed?
   
   To support more feature.
   
   Fix: #7949
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   N/A
   
   ### How was this patch tested?
   
   Test locally. please see 
   <img width="1016" height="925" alt="image" src="https://github.com/user-attachments/assets/f24c5bef-355c-4743-a11f-6bf32fa0a1cf" />
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2262764795


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:

Review Comment:
   We don't have to support create, alter and delete for now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2262768762


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def association_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,

Review Comment:
   Gravitino is designed to be leveraged by UI easily. But when used in LLM, you should keep it simple and self-explanatory.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2262467335


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def association_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,

Review Comment:
   This is an API provided by Gravitino. If it's not well designed, I can split it into two.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269603610


##########
mcp-server/mcp_server/tools/tag.py:
##########
@@ -0,0 +1,353 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from fastmcp import Context, FastMCP
+
+
+def load_tag_tool(mcp: FastMCP):
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def create_tag(
+        ctx: Context, name: str, comment: str, properties: dict
+    ) -> str:
+        """
+        Create a new tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be created
+            comment (str): Description or comment for the tag
+            properties (dict): Dictionary of key-value pairs representing tag properties
+
+        Returns:
+            str: JSON-formatted string containing the created tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().create_tag(
+            name, comment, properties
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def get_tag_by_name(ctx: Context, name: str) -> str:
+        """
+        Load a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to get
+
+        Returns:
+            str: JSON-formatted string containing the tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_tag_by_name(name)
+
+    @mcp.tool(tags={"tag"})
+    async def get_list_of_tags(ctx: Context) -> str:
+        """
+        Retrieve the list of tags within the metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+
+        Returns:
+            str: JSON-formatted string containing tag list information
+
+        Example Return Value:
+            [
+              {
+                "name": "tag1",
+                "comment": "This is a tag",
+                "properties": {
+                  "key1": "value1",
+                  "key2": "value2"
+                },
+                "audit": {
+                  "creator": "anonymous",
+                  "createTime": "2025-08-07T06:20:18.330570Z"
+                },
+                "inherited": null
+              },
+              ...
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_list_of_tags()
+
+    # Disable the alter_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def alter_tag(ctx: Context, name: str, updates: list) -> str:
+        """
+        Alter an existing tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be altered
+            updates (list): List of update operations to be applied to the tag
+
+        Example input for updates:
+            [
+                {
+                  "@type": "rename",
+                  "newName": "tag2"
+                },
+                {
+                  "@type": "updateComment",
+                  "newComment": "This is an updated tag"
+                },
+                {
+                  "@type": "setProperty",
+                  "property": "key3",
+                  "value": "value3"
+                },
+                {
+                  "@type": "removeProperty",
+                  "property": "key1"
+                }
+            ]
+
+        Returns:
+            str: JSON-formatted string containing the altered tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "Updated comment",
+              "properties": {
+                "key1": "new_value1"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().alter_tag(name, updates)
+
+    # Disable the delete_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def delete_tag(ctx: Context, name: str) -> None:
+        """
+        Delete a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to delete
+
+        Returns:
+            None
+
+        Raises:
+            Exception: If the deletion fails, an exception is raised with an error message.
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().delete_tag(name)
+
+    # Disable the associate_tag_with_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def associate_tag_with_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+    ) -> str:
+        """
+        Associate or disassociate tags with metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to associate tags with.
+            It's typically in the format "catalog.schema.table" or "catalog.schema" or "catalog".
+            or "catalog.schema.fileset". The "model", "topic" are also supported and the format
+            is the same as for "catalog.schema.table".
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_associate (list): List of tag names to associate with the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_associate: ["tag1", "tag2"]
+            tags_to_disassociate: ["tag3"]
+
+        Returns:
+            str: JSON-formatted string containing the names of associated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name,
+            metadata_type,
+            tags_to_associate,
+            [],
+        )
+
+    # Disable the disassociate_tag_from_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def disassociate_tag_from_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_disassociate: list,
+    ) -> str:
+        """
+        Disassociate tags from metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to disassociate tags from.
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_disassociate (list): List of tag names to disassociate from the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_disassociate: ["tag1", "tag2"]
+
+        Returns:
+            str: JSON-formatted string containing the names of disassociated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name, metadata_type, [], tags_to_disassociate
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def list_tags_for_metadata(
+        ctx: Context, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        """
+        List all tags associated with a specific metadata item.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata item (e.g., table, column).
+            metadata_type (str): Type of the metadata (e.g., "table", "column").

Review Comment:
   Yes, I have tried it
   
   <img width="1501" height="497" alt="image" src="https://github.com/user-attachments/assets/2e114962-6f57-4208-82e6-d9ac20408ba0" />
   <img width="1524" height="492" alt="image" src="https://github.com/user-attachments/assets/adf39163-8549-4804-8482-e5459520878e" />
   <img width="1472" height="534" alt="image" src="https://github.com/user-attachments/assets/ab578035-9d4d-4617-af92-74bbdeb3084d" />
   <img width="1481" height="533" alt="image" src="https://github.com/user-attachments/assets/88e27a15-f3ca-490d-8677-f2b1579fcbce" />
   <img width="1477" height="795" alt="image" src="https://github.com/user-attachments/assets/bbc5e886-a0e8-40fb-b80c-5592ef25bd9d" />
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269812754


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def associate_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/tags",
+            json={
+                "tagsToAdd": tags_to_associate,
+                "tagsToRemove": tags_to_disassociate,
+            },
+        )
+        return extract_content_from_response(response, "names", [])
+
+    async def list_tags_for_metadata(
+        self, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/tags"
+        )
+        return extract_content_from_response(response, "names", [])

Review Comment:
   Let me try to resolve it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269540017


##########
mcp-server/mcp_server/tools/tag.py:
##########
@@ -0,0 +1,353 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from fastmcp import Context, FastMCP
+
+
+def load_tag_tool(mcp: FastMCP):
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def create_tag(
+        ctx: Context, name: str, comment: str, properties: dict
+    ) -> str:
+        """
+        Create a new tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be created
+            comment (str): Description or comment for the tag
+            properties (dict): Dictionary of key-value pairs representing tag properties
+
+        Returns:
+            str: JSON-formatted string containing the created tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().create_tag(
+            name, comment, properties
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def get_tag_by_name(ctx: Context, name: str) -> str:
+        """
+        Load a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to get
+
+        Returns:
+            str: JSON-formatted string containing the tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_tag_by_name(name)
+
+    @mcp.tool(tags={"tag"})
+    async def get_list_of_tags(ctx: Context) -> str:
+        """
+        Retrieve the list of tags within the metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+
+        Returns:
+            str: JSON-formatted string containing tag list information
+
+        Example Return Value:
+            [
+              {
+                "name": "tag1",
+                "comment": "This is a tag",
+                "properties": {
+                  "key1": "value1",
+                  "key2": "value2"
+                },
+                "audit": {
+                  "creator": "anonymous",
+                  "createTime": "2025-08-07T06:20:18.330570Z"
+                },
+                "inherited": null
+              },
+              ...
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_list_of_tags()
+
+    # Disable the alter_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def alter_tag(ctx: Context, name: str, updates: list) -> str:
+        """
+        Alter an existing tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be altered
+            updates (list): List of update operations to be applied to the tag
+
+        Example input for updates:
+            [
+                {
+                  "@type": "rename",
+                  "newName": "tag2"
+                },
+                {
+                  "@type": "updateComment",
+                  "newComment": "This is an updated tag"
+                },
+                {
+                  "@type": "setProperty",
+                  "property": "key3",
+                  "value": "value3"
+                },
+                {
+                  "@type": "removeProperty",
+                  "property": "key1"
+                }
+            ]
+
+        Returns:
+            str: JSON-formatted string containing the altered tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "Updated comment",
+              "properties": {
+                "key1": "new_value1"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().alter_tag(name, updates)
+
+    # Disable the delete_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def delete_tag(ctx: Context, name: str) -> None:
+        """
+        Delete a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to delete
+
+        Returns:
+            None
+
+        Raises:
+            Exception: If the deletion fails, an exception is raised with an error message.
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().delete_tag(name)
+
+    # Disable the associate_tag_with_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def associate_tag_with_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+    ) -> str:
+        """
+        Associate or disassociate tags with metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to associate tags with.
+            It's typically in the format "catalog.schema.table" or "catalog.schema" or "catalog".
+            or "catalog.schema.fileset". The "model", "topic" are also supported and the format
+            is the same as for "catalog.schema.table".
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_associate (list): List of tag names to associate with the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_associate: ["tag1", "tag2"]
+            tags_to_disassociate: ["tag3"]
+
+        Returns:
+            str: JSON-formatted string containing the names of associated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name,
+            metadata_type,
+            tags_to_associate,
+            [],
+        )
+
+    # Disable the disassociate_tag_from_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def disassociate_tag_from_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_disassociate: list,
+    ) -> str:
+        """
+        Disassociate tags from metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to disassociate tags from.
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_disassociate (list): List of tag names to disassociate from the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_disassociate: ["tag1", "tag2"]
+
+        Returns:
+            str: JSON-formatted string containing the names of disassociated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name, metadata_type, [], tags_to_disassociate
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def list_tags_for_metadata(
+        ctx: Context, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        """
+        List all tags associated with a specific metadata item.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata item (e.g., table, column).
+            metadata_type (str): Type of the metadata (e.g., "table", "column").

Review Comment:
   I plan to add the following tool to inform LLM about the details of metadata type and full name, thus LLM can know the type of metadata it supports. Would that be acceptable to you? 
   
   ```python
       @mcp.tool(tags={"metadata"})
       async def list_all_metadata_types(
           ctx: Context
       ) -> list:
           """
           List all metadata types available in the MCP server.
   
           Args:
               ctx: Context object containing request metadata.
   
           Returns:
               str: JSON formatted string containing list of metadata types.
           """
           return [
               "catalog",
               "schema",
               "table",
               "column",
               "model",
               "topic",
               "fileset"
           ]
   
       @mcp.tool(tags={"metadata"})
       async def get_metadata_fullname_formats(
           ctx: Context) -> dict:
           """
           Get the formats for metadata full names.
           Args:
               ctx: Context object containing request metadata.
           Returns:
               dict: Dictionary containing formats for different metadata types. Key
               is the metadata type and value is the format string.
           """
           return {
               "catalog": "{catalog}",
               "schema": "{catalog}.{schema}",
               "table": "{catalog}.{schema}.{table}",
               "column": "{catalog}.{schema}.{table}.{column}",
               "model": "{catalog}.{model}",
               "topic": "{catalog}.{topic}",
               "fileset": "{catalog}.{fileset}"
           }
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269794139


##########
mcp-server/mcp_server/tools/metadata.py:
##########
@@ -0,0 +1,30 @@
+
+from fastmcp import Context, FastMCP
+
+
+def load_metadata_tool(mcp: FastMCP):
+    @mcp.tool(tags={"metadata"})
+    async def metadata_type_to_fullname_formats(
+        ctx: Context) -> dict:
+
+        """
+        Get metadata type to full name formats.

Review Comment:
   Please be aware that if you're using metadata (rather than metadata object), then all the places should be unified, otherwise it will be confused to LLM. The terminology should be consistent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "shaofengshi (via GitHub)" <gi...@apache.org>.
shaofengshi commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2262350947


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:

Review Comment:
   Delete operation is dangerous, and not idempotent; In my opinion, we don't need to expose such operation as MCP tool at this moment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2262371152


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:

Review Comment:
   OK, I will raise another PR to temporarily disable it. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2262467773


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def association_tag_with_metadata(

Review Comment:
   sure



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #7963:
URL: https://github.com/apache/gravitino/pull/7963


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269672826


##########
mcp-server/mcp_server/tools/tag.py:
##########
@@ -0,0 +1,353 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from fastmcp import Context, FastMCP
+
+
+def load_tag_tool(mcp: FastMCP):
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def create_tag(
+        ctx: Context, name: str, comment: str, properties: dict
+    ) -> str:
+        """
+        Create a new tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be created
+            comment (str): Description or comment for the tag
+            properties (dict): Dictionary of key-value pairs representing tag properties
+
+        Returns:
+            str: JSON-formatted string containing the created tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().create_tag(
+            name, comment, properties
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def get_tag_by_name(ctx: Context, name: str) -> str:
+        """
+        Load a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to get
+
+        Returns:
+            str: JSON-formatted string containing the tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_tag_by_name(name)
+
+    @mcp.tool(tags={"tag"})
+    async def get_list_of_tags(ctx: Context) -> str:
+        """
+        Retrieve the list of tags within the metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+
+        Returns:
+            str: JSON-formatted string containing tag list information
+
+        Example Return Value:
+            [
+              {
+                "name": "tag1",
+                "comment": "This is a tag",
+                "properties": {
+                  "key1": "value1",
+                  "key2": "value2"
+                },
+                "audit": {
+                  "creator": "anonymous",
+                  "createTime": "2025-08-07T06:20:18.330570Z"
+                },
+                "inherited": null
+              },
+              ...
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_list_of_tags()
+
+    # Disable the alter_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def alter_tag(ctx: Context, name: str, updates: list) -> str:
+        """
+        Alter an existing tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be altered
+            updates (list): List of update operations to be applied to the tag
+
+        Example input for updates:
+            [
+                {
+                  "@type": "rename",
+                  "newName": "tag2"
+                },
+                {
+                  "@type": "updateComment",
+                  "newComment": "This is an updated tag"
+                },
+                {
+                  "@type": "setProperty",
+                  "property": "key3",
+                  "value": "value3"
+                },
+                {
+                  "@type": "removeProperty",
+                  "property": "key1"
+                }
+            ]
+
+        Returns:
+            str: JSON-formatted string containing the altered tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "Updated comment",
+              "properties": {
+                "key1": "new_value1"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().alter_tag(name, updates)
+
+    # Disable the delete_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def delete_tag(ctx: Context, name: str) -> None:
+        """
+        Delete a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to delete
+
+        Returns:
+            None
+
+        Raises:
+            Exception: If the deletion fails, an exception is raised with an error message.
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().delete_tag(name)
+
+    # Disable the associate_tag_with_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def associate_tag_with_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+    ) -> str:
+        """
+        Associate or disassociate tags with metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to associate tags with.
+            It's typically in the format "catalog.schema.table" or "catalog.schema" or "catalog".
+            or "catalog.schema.fileset". The "model", "topic" are also supported and the format
+            is the same as for "catalog.schema.table".
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_associate (list): List of tag names to associate with the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_associate: ["tag1", "tag2"]
+            tags_to_disassociate: ["tag3"]
+
+        Returns:
+            str: JSON-formatted string containing the names of associated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name,
+            metadata_type,
+            tags_to_associate,
+            [],
+        )
+
+    # Disable the disassociate_tag_from_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def disassociate_tag_from_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_disassociate: list,
+    ) -> str:
+        """
+        Disassociate tags from metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to disassociate tags from.
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_disassociate (list): List of tag names to disassociate from the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_disassociate: ["tag1", "tag2"]
+
+        Returns:
+            str: JSON-formatted string containing the names of disassociated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name, metadata_type, [], tags_to_disassociate
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def list_tags_for_metadata(
+        ctx: Context, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        """
+        List all tags associated with a specific metadata item.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata item (e.g., table, column).
+            metadata_type (str): Type of the metadata (e.g., "table", "column").

Review Comment:
   I see.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269603610


##########
mcp-server/mcp_server/tools/tag.py:
##########
@@ -0,0 +1,353 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from fastmcp import Context, FastMCP
+
+
+def load_tag_tool(mcp: FastMCP):
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def create_tag(
+        ctx: Context, name: str, comment: str, properties: dict
+    ) -> str:
+        """
+        Create a new tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be created
+            comment (str): Description or comment for the tag
+            properties (dict): Dictionary of key-value pairs representing tag properties
+
+        Returns:
+            str: JSON-formatted string containing the created tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().create_tag(
+            name, comment, properties
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def get_tag_by_name(ctx: Context, name: str) -> str:
+        """
+        Load a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to get
+
+        Returns:
+            str: JSON-formatted string containing the tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_tag_by_name(name)
+
+    @mcp.tool(tags={"tag"})
+    async def get_list_of_tags(ctx: Context) -> str:
+        """
+        Retrieve the list of tags within the metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+
+        Returns:
+            str: JSON-formatted string containing tag list information
+
+        Example Return Value:
+            [
+              {
+                "name": "tag1",
+                "comment": "This is a tag",
+                "properties": {
+                  "key1": "value1",
+                  "key2": "value2"
+                },
+                "audit": {
+                  "creator": "anonymous",
+                  "createTime": "2025-08-07T06:20:18.330570Z"
+                },
+                "inherited": null
+              },
+              ...
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_list_of_tags()
+
+    # Disable the alter_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def alter_tag(ctx: Context, name: str, updates: list) -> str:
+        """
+        Alter an existing tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be altered
+            updates (list): List of update operations to be applied to the tag
+
+        Example input for updates:
+            [
+                {
+                  "@type": "rename",
+                  "newName": "tag2"
+                },
+                {
+                  "@type": "updateComment",
+                  "newComment": "This is an updated tag"
+                },
+                {
+                  "@type": "setProperty",
+                  "property": "key3",
+                  "value": "value3"
+                },
+                {
+                  "@type": "removeProperty",
+                  "property": "key1"
+                }
+            ]
+
+        Returns:
+            str: JSON-formatted string containing the altered tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "Updated comment",
+              "properties": {
+                "key1": "new_value1"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().alter_tag(name, updates)
+
+    # Disable the delete_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def delete_tag(ctx: Context, name: str) -> None:
+        """
+        Delete a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to delete
+
+        Returns:
+            None
+
+        Raises:
+            Exception: If the deletion fails, an exception is raised with an error message.
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().delete_tag(name)
+
+    # Disable the associate_tag_with_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def associate_tag_with_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+    ) -> str:
+        """
+        Associate or disassociate tags with metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to associate tags with.
+            It's typically in the format "catalog.schema.table" or "catalog.schema" or "catalog".
+            or "catalog.schema.fileset". The "model", "topic" are also supported and the format
+            is the same as for "catalog.schema.table".
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_associate (list): List of tag names to associate with the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_associate: ["tag1", "tag2"]
+            tags_to_disassociate: ["tag3"]
+
+        Returns:
+            str: JSON-formatted string containing the names of associated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name,
+            metadata_type,
+            tags_to_associate,
+            [],
+        )
+
+    # Disable the disassociate_tag_from_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def disassociate_tag_from_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_disassociate: list,
+    ) -> str:
+        """
+        Disassociate tags from metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to disassociate tags from.
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_disassociate (list): List of tag names to disassociate from the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_disassociate: ["tag1", "tag2"]
+
+        Returns:
+            str: JSON-formatted string containing the names of disassociated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name, metadata_type, [], tags_to_disassociate
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def list_tags_for_metadata(
+        ctx: Context, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        """
+        List all tags associated with a specific metadata item.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata item (e.g., table, column).
+            metadata_type (str): Type of the metadata (e.g., "table", "column").

Review Comment:
   Yes, I have tried it
   
   <img width="1501" height="497" alt="image" src="https://github.com/user-attachments/assets/2e114962-6f57-4208-82e6-d9ac20408ba0" />
   <img width="1524" height="492" alt="image" src="https://github.com/user-attachments/assets/adf39163-8549-4804-8482-e5459520878e" />
   <img width="1472" height="534" alt="image" src="https://github.com/user-attachments/assets/ab578035-9d4d-4617-af92-74bbdeb3084d" />
   <img width="1481" height="533" alt="image" src="https://github.com/user-attachments/assets/88e27a15-f3ca-490d-8677-f2b1579fcbce" />
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2265579784


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:

Review Comment:
   No, that is mainly user people and UI, not for LLM.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2265580862


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def association_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,

Review Comment:
   Where is the code?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2262809026


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:

Review Comment:
   These APIs have been disabled and can be enabled if needed.



##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def association_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,

Review Comment:
   I see.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2265557462


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:

Review Comment:
   @jerryshao 
   API like `associate/disassociate` tags with metadata can also make changes to Gravitino, do we need to disable them at the same time?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269117316


##########
mcp-server/mcp_server/tools/tag.py:
##########
@@ -0,0 +1,353 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from fastmcp import Context, FastMCP
+
+
+def load_tag_tool(mcp: FastMCP):
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def create_tag(
+        ctx: Context, name: str, comment: str, properties: dict
+    ) -> str:
+        """
+        Create a new tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be created
+            comment (str): Description or comment for the tag
+            properties (dict): Dictionary of key-value pairs representing tag properties
+
+        Returns:
+            str: JSON-formatted string containing the created tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().create_tag(
+            name, comment, properties
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def get_tag_by_name(ctx: Context, name: str) -> str:
+        """
+        Load a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to get
+
+        Returns:
+            str: JSON-formatted string containing the tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_tag_by_name(name)
+
+    @mcp.tool(tags={"tag"})
+    async def get_list_of_tags(ctx: Context) -> str:
+        """
+        Retrieve the list of tags within the metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+
+        Returns:
+            str: JSON-formatted string containing tag list information
+
+        Example Return Value:
+            [
+              {
+                "name": "tag1",
+                "comment": "This is a tag",
+                "properties": {
+                  "key1": "value1",
+                  "key2": "value2"
+                },
+                "audit": {
+                  "creator": "anonymous",
+                  "createTime": "2025-08-07T06:20:18.330570Z"
+                },
+                "inherited": null
+              },
+              ...
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_list_of_tags()
+
+    # Disable the alter_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def alter_tag(ctx: Context, name: str, updates: list) -> str:
+        """
+        Alter an existing tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be altered
+            updates (list): List of update operations to be applied to the tag
+
+        Example input for updates:
+            [
+                {
+                  "@type": "rename",
+                  "newName": "tag2"
+                },
+                {
+                  "@type": "updateComment",
+                  "newComment": "This is an updated tag"
+                },
+                {
+                  "@type": "setProperty",
+                  "property": "key3",
+                  "value": "value3"
+                },
+                {
+                  "@type": "removeProperty",
+                  "property": "key1"
+                }
+            ]
+
+        Returns:
+            str: JSON-formatted string containing the altered tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "Updated comment",
+              "properties": {
+                "key1": "new_value1"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().alter_tag(name, updates)
+
+    # Disable the delete_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def delete_tag(ctx: Context, name: str) -> None:
+        """
+        Delete a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to delete
+
+        Returns:
+            None
+
+        Raises:
+            Exception: If the deletion fails, an exception is raised with an error message.
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().delete_tag(name)
+
+    # Disable the associate_tag_with_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def associate_tag_with_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+    ) -> str:
+        """
+        Associate or disassociate tags with metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to associate tags with.
+            It's typically in the format "catalog.schema.table" or "catalog.schema" or "catalog".
+            or "catalog.schema.fileset". The "model", "topic" are also supported and the format
+            is the same as for "catalog.schema.table".
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_associate (list): List of tag names to associate with the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_associate: ["tag1", "tag2"]
+            tags_to_disassociate: ["tag3"]
+
+        Returns:
+            str: JSON-formatted string containing the names of associated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name,
+            metadata_type,
+            tags_to_associate,
+            [],
+        )
+
+    # Disable the disassociate_tag_from_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def disassociate_tag_from_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_disassociate: list,
+    ) -> str:
+        """
+        Disassociate tags from metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to disassociate tags from.
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_disassociate (list): List of tag names to disassociate from the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_disassociate: ["tag1", "tag2"]
+
+        Returns:
+            str: JSON-formatted string containing the names of disassociated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name, metadata_type, [], tags_to_disassociate
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def list_tags_for_metadata(
+        ctx: Context, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        """
+        List all tags associated with a specific metadata item.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata item (e.g., table, column).
+            metadata_type (str): Type of the metadata (e.g., "table", "column").

Review Comment:
   With this simple description, I don't think LLM can easily figure out what is the full name and what is the supported type.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269603610


##########
mcp-server/mcp_server/tools/tag.py:
##########
@@ -0,0 +1,353 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from fastmcp import Context, FastMCP
+
+
+def load_tag_tool(mcp: FastMCP):
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def create_tag(
+        ctx: Context, name: str, comment: str, properties: dict
+    ) -> str:
+        """
+        Create a new tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be created
+            comment (str): Description or comment for the tag
+            properties (dict): Dictionary of key-value pairs representing tag properties
+
+        Returns:
+            str: JSON-formatted string containing the created tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().create_tag(
+            name, comment, properties
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def get_tag_by_name(ctx: Context, name: str) -> str:
+        """
+        Load a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to get
+
+        Returns:
+            str: JSON-formatted string containing the tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_tag_by_name(name)
+
+    @mcp.tool(tags={"tag"})
+    async def get_list_of_tags(ctx: Context) -> str:
+        """
+        Retrieve the list of tags within the metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+
+        Returns:
+            str: JSON-formatted string containing tag list information
+
+        Example Return Value:
+            [
+              {
+                "name": "tag1",
+                "comment": "This is a tag",
+                "properties": {
+                  "key1": "value1",
+                  "key2": "value2"
+                },
+                "audit": {
+                  "creator": "anonymous",
+                  "createTime": "2025-08-07T06:20:18.330570Z"
+                },
+                "inherited": null
+              },
+              ...
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_list_of_tags()
+
+    # Disable the alter_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def alter_tag(ctx: Context, name: str, updates: list) -> str:
+        """
+        Alter an existing tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be altered
+            updates (list): List of update operations to be applied to the tag
+
+        Example input for updates:
+            [
+                {
+                  "@type": "rename",
+                  "newName": "tag2"
+                },
+                {
+                  "@type": "updateComment",
+                  "newComment": "This is an updated tag"
+                },
+                {
+                  "@type": "setProperty",
+                  "property": "key3",
+                  "value": "value3"
+                },
+                {
+                  "@type": "removeProperty",
+                  "property": "key1"
+                }
+            ]
+
+        Returns:
+            str: JSON-formatted string containing the altered tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "Updated comment",
+              "properties": {
+                "key1": "new_value1"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().alter_tag(name, updates)
+
+    # Disable the delete_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def delete_tag(ctx: Context, name: str) -> None:
+        """
+        Delete a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to delete
+
+        Returns:
+            None
+
+        Raises:
+            Exception: If the deletion fails, an exception is raised with an error message.
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().delete_tag(name)
+
+    # Disable the associate_tag_with_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def associate_tag_with_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+    ) -> str:
+        """
+        Associate or disassociate tags with metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to associate tags with.
+            It's typically in the format "catalog.schema.table" or "catalog.schema" or "catalog".
+            or "catalog.schema.fileset". The "model", "topic" are also supported and the format
+            is the same as for "catalog.schema.table".
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_associate (list): List of tag names to associate with the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_associate: ["tag1", "tag2"]
+            tags_to_disassociate: ["tag3"]
+
+        Returns:
+            str: JSON-formatted string containing the names of associated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name,
+            metadata_type,
+            tags_to_associate,
+            [],
+        )
+
+    # Disable the disassociate_tag_from_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def disassociate_tag_from_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_disassociate: list,
+    ) -> str:
+        """
+        Disassociate tags from metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to disassociate tags from.
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_disassociate (list): List of tag names to disassociate from the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_disassociate: ["tag1", "tag2"]
+
+        Returns:
+            str: JSON-formatted string containing the names of disassociated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name, metadata_type, [], tags_to_disassociate
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def list_tags_for_metadata(
+        ctx: Context, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        """
+        List all tags associated with a specific metadata item.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata item (e.g., table, column).
+            metadata_type (str): Type of the metadata (e.g., "table", "column").

Review Comment:
   Yes, I have tried it
   
   <img width="1501" height="497" alt="image" src="https://github.com/user-attachments/assets/2e114962-6f57-4208-82e6-d9ac20408ba0" />
   <img width="1524" height="492" alt="image" src="https://github.com/user-attachments/assets/adf39163-8549-4804-8482-e5459520878e" />
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269779255


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def associate_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/tags",
+            json={
+                "tagsToAdd": tags_to_associate,
+                "tagsToRemove": tags_to_disassociate,
+            },
+        )
+        return extract_content_from_response(response, "names", [])
+
+    async def list_tags_for_metadata(
+        self, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/tags"
+        )
+        return extract_content_from_response(response, "names", [])

Review Comment:
   If the list operations can support listing the details, we'd better always listing the details, so we can give more information to LLM.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269872673


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def associate_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/tags",
+            json={
+                "tagsToAdd": tags_to_associate,
+                "tagsToRemove": tags_to_disassociate,
+            },
+        )
+        return extract_content_from_response(response, "names", [])
+
+    async def list_tags_for_metadata(
+        self, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/tags"
+        )
+        return extract_content_from_response(response, "names", [])

Review Comment:
   Fix all list operations in this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2268445082


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def association_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,

Review Comment:
   ```python
       @mcp.tool(tags={"tag"}, enabled=False)
       async def disassociate_tag_from_metadata(
           ctx: Context,
           metadata_full_name: str,
           metadata_type: str,
           tags_to_disassociate: list,
       ) -> str:
   
       @mcp.tool(tags={"tag"}, enabled=False)
       async def associate_tag_with_metadata(
           ctx: Context,
           metadata_full_name: str,
           metadata_type: str,
           tags_to_associate: list,
       ) -> str:
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#issuecomment-3181937045

   I'm going to close this PR. You'd better fix the python style issue in the following issue.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269780489


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def associate_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/tags",
+            json={
+                "tagsToAdd": tags_to_associate,
+                "tagsToRemove": tags_to_disassociate,
+            },
+        )
+        return extract_content_from_response(response, "names", [])
+
+    async def list_tags_for_metadata(
+        self, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/tags"
+        )
+        return extract_content_from_response(response, "names", [])

Review Comment:
   Not just for this PR, but also for others.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#issuecomment-3163059806

   This PR depends on #7905 and is not ready to review until #7905 is merged.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "shaofengshi (via GitHub)" <gi...@apache.org>.
shaofengshi commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2262422121


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def association_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,

Review Comment:
   This is confusing that have disassociate here. I would suggest to use another method/tool for disassociate. Or you'd better give another name.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "shaofengshi (via GitHub)" <gi...@apache.org>.
shaofengshi commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2262419453


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def association_tag_with_metadata(

Review Comment:
   "association" is a noun, not a verb, please use "associate".



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269808775


##########
mcp-server/mcp_server/tools/metadata.py:
##########
@@ -0,0 +1,30 @@
+
+from fastmcp import Context, FastMCP
+
+
+def load_metadata_tool(mcp: FastMCP):
+    @mcp.tool(tags={"metadata"})
+    async def metadata_type_to_fullname_formats(
+        ctx: Context) -> dict:
+
+        """
+        Get metadata type to full name formats.

Review Comment:
   I see.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2265553925


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:
+        response = await self.rest_client.delete(
+            f"/api/metalakes/{self.metalake_name}/tags/{name}"
+        )
+        if response.status_code != 200:
+            raise Exception(f"Failed to delete tag {name}: {response.text}")
+        return None
+
+    async def association_tag_with_metadata(
+        self,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+        tags_to_disassociate: list,

Review Comment:
   I've divided it into two.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269564757


##########
mcp-server/mcp_server/tools/tag.py:
##########
@@ -0,0 +1,353 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from fastmcp import Context, FastMCP
+
+
+def load_tag_tool(mcp: FastMCP):
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def create_tag(
+        ctx: Context, name: str, comment: str, properties: dict
+    ) -> str:
+        """
+        Create a new tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be created
+            comment (str): Description or comment for the tag
+            properties (dict): Dictionary of key-value pairs representing tag properties
+
+        Returns:
+            str: JSON-formatted string containing the created tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().create_tag(
+            name, comment, properties
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def get_tag_by_name(ctx: Context, name: str) -> str:
+        """
+        Load a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to get
+
+        Returns:
+            str: JSON-formatted string containing the tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_tag_by_name(name)
+
+    @mcp.tool(tags={"tag"})
+    async def get_list_of_tags(ctx: Context) -> str:
+        """
+        Retrieve the list of tags within the metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+
+        Returns:
+            str: JSON-formatted string containing tag list information
+
+        Example Return Value:
+            [
+              {
+                "name": "tag1",
+                "comment": "This is a tag",
+                "properties": {
+                  "key1": "value1",
+                  "key2": "value2"
+                },
+                "audit": {
+                  "creator": "anonymous",
+                  "createTime": "2025-08-07T06:20:18.330570Z"
+                },
+                "inherited": null
+              },
+              ...
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_list_of_tags()
+
+    # Disable the alter_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def alter_tag(ctx: Context, name: str, updates: list) -> str:
+        """
+        Alter an existing tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be altered
+            updates (list): List of update operations to be applied to the tag
+
+        Example input for updates:
+            [
+                {
+                  "@type": "rename",
+                  "newName": "tag2"
+                },
+                {
+                  "@type": "updateComment",
+                  "newComment": "This is an updated tag"
+                },
+                {
+                  "@type": "setProperty",
+                  "property": "key3",
+                  "value": "value3"
+                },
+                {
+                  "@type": "removeProperty",
+                  "property": "key1"
+                }
+            ]
+
+        Returns:
+            str: JSON-formatted string containing the altered tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "Updated comment",
+              "properties": {
+                "key1": "new_value1"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().alter_tag(name, updates)
+
+    # Disable the delete_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def delete_tag(ctx: Context, name: str) -> None:
+        """
+        Delete a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to delete
+
+        Returns:
+            None
+
+        Raises:
+            Exception: If the deletion fails, an exception is raised with an error message.
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().delete_tag(name)
+
+    # Disable the associate_tag_with_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def associate_tag_with_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+    ) -> str:
+        """
+        Associate or disassociate tags with metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to associate tags with.
+            It's typically in the format "catalog.schema.table" or "catalog.schema" or "catalog".
+            or "catalog.schema.fileset". The "model", "topic" are also supported and the format
+            is the same as for "catalog.schema.table".
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_associate (list): List of tag names to associate with the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_associate: ["tag1", "tag2"]
+            tags_to_disassociate: ["tag3"]
+
+        Returns:
+            str: JSON-formatted string containing the names of associated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name,
+            metadata_type,
+            tags_to_associate,
+            [],
+        )
+
+    # Disable the disassociate_tag_from_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def disassociate_tag_from_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_disassociate: list,
+    ) -> str:
+        """
+        Disassociate tags from metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to disassociate tags from.
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_disassociate (list): List of tag names to disassociate from the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_disassociate: ["tag1", "tag2"]
+
+        Returns:
+            str: JSON-formatted string containing the names of disassociated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name, metadata_type, [], tags_to_disassociate
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def list_tags_for_metadata(
+        ctx: Context, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        """
+        List all tags associated with a specific metadata item.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata item (e.g., table, column).
+            metadata_type (str): Type of the metadata (e.g., "table", "column").

Review Comment:
   Did you try if it works by LLM?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269667698


##########
mcp-server/mcp_server/tools/tag.py:
##########
@@ -0,0 +1,353 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from fastmcp import Context, FastMCP
+
+
+def load_tag_tool(mcp: FastMCP):
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def create_tag(
+        ctx: Context, name: str, comment: str, properties: dict
+    ) -> str:
+        """
+        Create a new tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be created
+            comment (str): Description or comment for the tag
+            properties (dict): Dictionary of key-value pairs representing tag properties
+
+        Returns:
+            str: JSON-formatted string containing the created tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().create_tag(
+            name, comment, properties
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def get_tag_by_name(ctx: Context, name: str) -> str:
+        """
+        Load a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to get
+
+        Returns:
+            str: JSON-formatted string containing the tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_tag_by_name(name)
+
+    @mcp.tool(tags={"tag"})
+    async def get_list_of_tags(ctx: Context) -> str:
+        """
+        Retrieve the list of tags within the metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+
+        Returns:
+            str: JSON-formatted string containing tag list information
+
+        Example Return Value:
+            [
+              {
+                "name": "tag1",
+                "comment": "This is a tag",
+                "properties": {
+                  "key1": "value1",
+                  "key2": "value2"
+                },
+                "audit": {
+                  "creator": "anonymous",
+                  "createTime": "2025-08-07T06:20:18.330570Z"
+                },
+                "inherited": null
+              },
+              ...
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_list_of_tags()
+
+    # Disable the alter_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def alter_tag(ctx: Context, name: str, updates: list) -> str:
+        """
+        Alter an existing tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be altered
+            updates (list): List of update operations to be applied to the tag
+
+        Example input for updates:
+            [
+                {
+                  "@type": "rename",
+                  "newName": "tag2"
+                },
+                {
+                  "@type": "updateComment",
+                  "newComment": "This is an updated tag"
+                },
+                {
+                  "@type": "setProperty",
+                  "property": "key3",
+                  "value": "value3"
+                },
+                {
+                  "@type": "removeProperty",
+                  "property": "key1"
+                }
+            ]
+
+        Returns:
+            str: JSON-formatted string containing the altered tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "Updated comment",
+              "properties": {
+                "key1": "new_value1"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().alter_tag(name, updates)
+
+    # Disable the delete_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def delete_tag(ctx: Context, name: str) -> None:
+        """
+        Delete a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to delete
+
+        Returns:
+            None
+
+        Raises:
+            Exception: If the deletion fails, an exception is raised with an error message.
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().delete_tag(name)
+
+    # Disable the associate_tag_with_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def associate_tag_with_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+    ) -> str:
+        """
+        Associate or disassociate tags with metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to associate tags with.
+            It's typically in the format "catalog.schema.table" or "catalog.schema" or "catalog".
+            or "catalog.schema.fileset". The "model", "topic" are also supported and the format
+            is the same as for "catalog.schema.table".
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_associate (list): List of tag names to associate with the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_associate: ["tag1", "tag2"]
+            tags_to_disassociate: ["tag3"]
+
+        Returns:
+            str: JSON-formatted string containing the names of associated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name,
+            metadata_type,
+            tags_to_associate,
+            [],
+        )
+
+    # Disable the disassociate_tag_from_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def disassociate_tag_from_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_disassociate: list,
+    ) -> str:
+        """
+        Disassociate tags from metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to disassociate tags from.
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_disassociate (list): List of tag names to disassociate from the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_disassociate: ["tag1", "tag2"]
+
+        Returns:
+            str: JSON-formatted string containing the names of disassociated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name, metadata_type, [], tags_to_disassociate
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def list_tags_for_metadata(
+        ctx: Context, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        """
+        List all tags associated with a specific metadata item.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata item (e.g., table, column).
+            metadata_type (str): Type of the metadata (e.g., "table", "column").

Review Comment:
   Maybe you can merge this two APIs into one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269119285


##########
mcp-server/mcp_server/tools/tag.py:
##########
@@ -0,0 +1,353 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from fastmcp import Context, FastMCP
+
+
+def load_tag_tool(mcp: FastMCP):
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def create_tag(
+        ctx: Context, name: str, comment: str, properties: dict
+    ) -> str:
+        """
+        Create a new tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be created
+            comment (str): Description or comment for the tag
+            properties (dict): Dictionary of key-value pairs representing tag properties
+
+        Returns:
+            str: JSON-formatted string containing the created tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().create_tag(
+            name, comment, properties
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def get_tag_by_name(ctx: Context, name: str) -> str:
+        """
+        Load a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to get
+
+        Returns:
+            str: JSON-formatted string containing the tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_tag_by_name(name)
+
+    @mcp.tool(tags={"tag"})
+    async def get_list_of_tags(ctx: Context) -> str:
+        """
+        Retrieve the list of tags within the metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+
+        Returns:
+            str: JSON-formatted string containing tag list information
+
+        Example Return Value:
+            [
+              {
+                "name": "tag1",
+                "comment": "This is a tag",
+                "properties": {
+                  "key1": "value1",
+                  "key2": "value2"
+                },
+                "audit": {
+                  "creator": "anonymous",
+                  "createTime": "2025-08-07T06:20:18.330570Z"
+                },
+                "inherited": null
+              },
+              ...
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_list_of_tags()
+
+    # Disable the alter_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def alter_tag(ctx: Context, name: str, updates: list) -> str:
+        """
+        Alter an existing tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be altered
+            updates (list): List of update operations to be applied to the tag
+
+        Example input for updates:
+            [
+                {
+                  "@type": "rename",
+                  "newName": "tag2"
+                },
+                {
+                  "@type": "updateComment",
+                  "newComment": "This is an updated tag"
+                },
+                {
+                  "@type": "setProperty",
+                  "property": "key3",
+                  "value": "value3"
+                },
+                {
+                  "@type": "removeProperty",
+                  "property": "key1"
+                }
+            ]
+
+        Returns:
+            str: JSON-formatted string containing the altered tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "Updated comment",
+              "properties": {
+                "key1": "new_value1"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().alter_tag(name, updates)
+
+    # Disable the delete_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def delete_tag(ctx: Context, name: str) -> None:
+        """
+        Delete a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to delete
+
+        Returns:
+            None
+
+        Raises:
+            Exception: If the deletion fails, an exception is raised with an error message.
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().delete_tag(name)
+
+    # Disable the associate_tag_with_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def associate_tag_with_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+    ) -> str:
+        """
+        Associate or disassociate tags with metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to associate tags with.
+            It's typically in the format "catalog.schema.table" or "catalog.schema" or "catalog".
+            or "catalog.schema.fileset". The "model", "topic" are also supported and the format
+            is the same as for "catalog.schema.table".
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_associate (list): List of tag names to associate with the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_associate: ["tag1", "tag2"]
+            tags_to_disassociate: ["tag3"]
+
+        Returns:
+            str: JSON-formatted string containing the names of associated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name,
+            metadata_type,
+            tags_to_associate,
+            [],
+        )
+
+    # Disable the disassociate_tag_from_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def disassociate_tag_from_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_disassociate: list,
+    ) -> str:
+        """
+        Disassociate tags from metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to disassociate tags from.
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_disassociate (list): List of tag names to disassociate from the metadata.
+
+        Example input:
+            metadata_full_name: "catalog.schema.table"
+            metadata_type: "table"
+            tags_to_disassociate: ["tag1", "tag2"]
+
+        Returns:
+            str: JSON-formatted string containing the names of disassociated tags.
+
+        Example Return Value:
+            [
+              "tag1",
+              "tag2"
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().associate_tag_with_metadata(
+            metadata_full_name, metadata_type, [], tags_to_disassociate
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def list_tags_for_metadata(
+        ctx: Context, metadata_full_name: str, metadata_type: str
+    ) -> str:
+        """
+        List all tags associated with a specific metadata item.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata item (e.g., table, column).
+            metadata_type (str): Type of the metadata (e.g., "table", "column").

Review Comment:
   You should list all the supported metadata object type, and also the examples.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2269101756


##########
mcp-server/mcp_server/tools/tag.py:
##########
@@ -0,0 +1,353 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from fastmcp import Context, FastMCP
+
+
+def load_tag_tool(mcp: FastMCP):
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def create_tag(
+        ctx: Context, name: str, comment: str, properties: dict
+    ) -> str:
+        """
+        Create a new tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be created
+            comment (str): Description or comment for the tag
+            properties (dict): Dictionary of key-value pairs representing tag properties
+
+        Returns:
+            str: JSON-formatted string containing the created tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().create_tag(
+            name, comment, properties
+        )
+
+    @mcp.tool(tags={"tag"})
+    async def get_tag_by_name(ctx: Context, name: str) -> str:
+        """
+        Load a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to get
+
+        Returns:
+            str: JSON-formatted string containing the tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "This is a tag",
+              "properties": {
+                "key1": "value1",
+                "key2": "value2"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_tag_by_name(name)
+
+    @mcp.tool(tags={"tag"})
+    async def get_list_of_tags(ctx: Context) -> str:
+        """
+        Retrieve the list of tags within the metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+
+        Returns:
+            str: JSON-formatted string containing tag list information
+
+        Example Return Value:
+            [
+              {
+                "name": "tag1",
+                "comment": "This is a tag",
+                "properties": {
+                  "key1": "value1",
+                  "key2": "value2"
+                },
+                "audit": {
+                  "creator": "anonymous",
+                  "createTime": "2025-08-07T06:20:18.330570Z"
+                },
+                "inherited": null
+              },
+              ...
+            ]
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().get_list_of_tags()
+
+    # Disable the alter_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def alter_tag(ctx: Context, name: str, updates: list) -> str:
+        """
+        Alter an existing tag within the specified metalake.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to be altered
+            updates (list): List of update operations to be applied to the tag
+
+        Example input for updates:
+            [
+                {
+                  "@type": "rename",
+                  "newName": "tag2"
+                },
+                {
+                  "@type": "updateComment",
+                  "newComment": "This is an updated tag"
+                },
+                {
+                  "@type": "setProperty",
+                  "property": "key3",
+                  "value": "value3"
+                },
+                {
+                  "@type": "removeProperty",
+                  "property": "key1"
+                }
+            ]
+
+        Returns:
+            str: JSON-formatted string containing the altered tag information
+
+        Example Return Value:
+            {
+              "name": "tag1",
+              "comment": "Updated comment",
+              "properties": {
+                "key1": "new_value1"
+              },
+              "audit": {
+                "creator": "anonymous",
+                "createTime": "2025-08-07T06:20:18.330570Z"
+              },
+              "inherited": null
+            }
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().alter_tag(name, updates)
+
+    # Disable the delete_tag tool by default as it can be destructive.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def delete_tag(ctx: Context, name: str) -> None:
+        """
+        Delete a tag by its name.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            name (str): Name of the tag to delete
+
+        Returns:
+            None
+
+        Raises:
+            Exception: If the deletion fails, an exception is raised with an error message.
+        """
+        client = ctx.request_context.lifespan_context.rest_client()
+        return await client.as_tag_operation().delete_tag(name)
+
+    # Disable the associate_tag_with_metadata tool by default as it will change metadata state.
+    @mcp.tool(tags={"tag"}, enabled=False)
+    async def associate_tag_with_metadata(
+        ctx: Context,
+        metadata_full_name: str,
+        metadata_type: str,
+        tags_to_associate: list,
+    ) -> str:
+        """
+        Associate or disassociate tags with metadata.
+
+        Args:
+            ctx (Context): The request context object containing lifespan context
+                           and connector information.
+            metadata_full_name (str): Full name of the metadata object to associate tags with.
+            It's typically in the format "catalog.schema.table" or "catalog.schema" or "catalog".
+            or "catalog.schema.fileset". The "model", "topic" are also supported and the format
+            is the same as for "catalog.schema.table".
+            metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+             "fileset", "model", "topic").
+            tags_to_associate (list): List of tag names to associate with the metadata.

Review Comment:
   Here it is the same question as previously proposed by @FANNG1 . Using metadata object name "xx.xx.xx" may not be straightforward for LLM. @FANNG1 uses different parameters for catalog / schema / table when loading a table. I was thinking that for tag related operations, can we also make it like before, which will make LLM easy to understand.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7949] feat(mcp-server): Support tag operations for MCP server [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #7963:
URL: https://github.com/apache/gravitino/pull/7963#discussion_r2268446091


##########
mcp-server/mcp_server/client/plain/plain_rest_client_tag_operation.py:
##########
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from mcp_server.client.plain.utils import extract_content_from_response
+from mcp_server.client.tag_operation import TagOperation
+
+
+class PlainRESTClientTagOperation(TagOperation):
+    def __init__(self, metalake_name: str, rest_client):
+        self.metalake_name = metalake_name
+        self.rest_client = rest_client
+
+    async def get_list_of_tags(self) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags?details=true"
+        )
+        return extract_content_from_response(response, "tags", [])
+
+    async def get_tag_by_name(self, tag_name: str) -> str:
+        response = await self.rest_client.get(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}"
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def create_tag(
+        self, tag_name: str, tag_comment: str, tag_properties: dict
+    ) -> str:
+        response = await self.rest_client.post(
+            f"/api/metalakes/{self.metalake_name}/tags",
+            json={
+                "name": tag_name,
+                "comment": tag_comment,
+                "properties": tag_properties,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def alter_tag(self, tag_name: str, updates: list) -> str:
+        response = await self.rest_client.put(
+            f"/api/metalakes/{self.metalake_name}/tags/{tag_name}",
+            json={
+                "updates": updates,
+            },
+        )
+        return extract_content_from_response(response, "tag", {})
+
+    async def delete_tag(self, name: str) -> None:

Review Comment:
   I have disabled tag association and disassociation operations.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org