You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "FANNG1 (via GitHub)" <gi...@apache.org> on 2025/08/19 02:10:43 UTC
[PR] Mcp policy [gravitino]
FANNG1 opened a new pull request, #8151:
URL: https://github.com/apache/gravitino/pull/8151
<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
Examples:
- "[#123] feat(operator): support xxx"
- "[#233] fix: check null before access result in xxx"
- "[MINOR] refactor: fix typo in variable name"
- "[MINOR] docs: fix typo in README"
- "[#255] test: fix flaky test NameOfTheTest"
Reference: https://www.conventionalcommits.org/en/v1.0.0/
2. If the PR is unfinished, please mark this PR as draft.
-->
### What changes were proposed in this pull request?
(Please outline the changes and how this PR fixes the issue.)
### Why are the changes needed?
(Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, describe the bug.)
Fix: #(issue)
### Does this PR introduce _any_ user-facing change?
(Please list the user-facing changes introduced by your change, including
1. Change in user-facing APIs.
2. Addition or removal of property keys.)
### How was this patch tested?
(Please test your changes, and provide instructions on how to test it:
1. If you add a feature or fix a bug, add a test to cover your changes.
2. If you fix a flaky test, repeat it for many times to prove it works.)
--
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] Mcp policy [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#issuecomment-3199061989
@yuqi1129 @mchades @jerryshao PTAL, thx
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2288052444
##########
mcp-server/mcp_server/client/policy_operation.py:
##########
@@ -0,0 +1,116 @@
+# 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 abc import ABC, abstractmethod
+
+
+class PolicyOperation(ABC):
+ """
+ Abstract base class for Gravitino policy operations.
+ """
+
+ @abstractmethod
+ async def get_list_of_policies(self) -> str:
+ """
+ Retrieve the list of policies.
+
+ Returns:
+ str: JSON-formatted string containing policy list information
+ """
+ pass
+
+ @abstractmethod
+ async def load_policy(self, policy_name: str) -> str:
+ """
+ Load detailed information of a specific policy.
+
+ Args:
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON-formatted string containing full policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def associate_policy_with_metadata(
+ self,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_associate: list,
+ policies_to_disassociate: list,
+ ) -> str:
+ """
+ Associate policies with metadata.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
+ metadata_type: Type of the metadata (e.g., "table", "column")
+ policies_to_associate: List of policy names to associate with the metadata
+ policies_to_disassociate: List of policy names to disassociate from the metadata
+
+ Returns:
+ str: JSON formatted string containing list of policy names that were
+ successfully associated with the metadata
+ """
+ pass
+
+ @abstractmethod
+ async def get_policy_for_metadata(
+ self, metadata_full_name: str, metadata_type: str, policy_name: str
+ ) -> str:
+ """
+ Get the policy with are associated with a specific metadata item.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
+ metadata_type: Type of the metadata (e.g., "table", "column")
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON formatted string containing policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def list_policies_for_metadata(
+ self, metadata_full_name: str, metadata_type: str
+ ) -> str:
+ """
+ List all policies associated with a specific metadata item.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
Review Comment:
About the `metadata_full_name`, it's better to add a reference to tool `metadata_type_to_fullname_formats`.
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2286861360
##########
mcp-server/mcp_server/client/plain/plain_rest_client_policy_operation.py:
##########
@@ -0,0 +1,43 @@
+# 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 import PolicyOperation
+
+
+class PlainRESTClientPolicyOperation(PolicyOperation):
+ """
+ Implementation of PolicyOperation using a plain REST client.
+ """
+
+ def __init__(self, metalake_name: str, rest_client):
+ self.metalake_name = metalake_name
+ self.rest_client = rest_client
+
+ async def get_list_of_policies(self) -> str:
+ response = await self.rest_client.get(
+ f"/api/metalakes/{self.metalake_name}/policies"
+ )
+ return response.json().get("names", [])
Review Comment:
updated
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2289835169
##########
mcp-server/mcp_server/tools/policy.py:
##########
@@ -0,0 +1,368 @@
+# 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_policy_tools(mcp: FastMCP):
+ @mcp.tool(tags={"policy"})
+ async def get_list_of_policies(
+ ctx: Context,
+ ) -> str:
+ """
+ Retrieve the list of available policy information.
+
+ Parameters:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ Returns:
+ str: A JSON string representing an array of policy information objects, each object
+ contains the policy name, comment, policy type, enabled status, content, supported object types,
+ inherited policy, and audit information.
+
+ Example Response:
+ [
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().get_list_of_policies()
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_detail_information(
+ ctx: Context,
+ policy_name: str,
+ ) -> str:
+ """
+ Retrieve detailed information for a specific policy by policy name.
+
+ Parameters:
+ ctx : Context
+ The request context object containing lifespan context and connector
+ information.
+ policy_name : str
+ The unique identifier for the policy. Must be one of the names
+ returned by `get_list_of_policies`.
+
+ Returns:
+ str : A structured JSON object containing the policy configuration with the following fields:
+ name: Unique policy identifier (string)
+ comment: Descriptive text about the policy (string)
+ policyType: Classification of policy (e.g., "custom") (string)
+ enabled: Activation status (boolean)
+ content: Rule definitions and scope settings (dict)
+ - customRules: Key-value pairs of rule identifiers and settings (dict)
+ - properties: Additional configuration properties (dict)
+ - supportedObjectTypes: Entities this policy applies to (list of string)
+ inherited: Whether the policy is inherited from parent metadata (boolean)
+ audit: Creation metadata (dict)
+ - creator: User or service that created the policy (string)
+ - createTime: ISO 8601 timestamp of creation (string)
+
+ Example Response:
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ """
+
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().load_policy(policy_name)
+
+ @mcp.tool(tags={"policy"}, enabled=False)
Review Comment:
Why do we disable these two tools?
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2289675466
##########
mcp-server/mcp_server/client/policy_operation.py:
##########
@@ -0,0 +1,116 @@
+# 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 abc import ABC, abstractmethod
+
+
+class PolicyOperation(ABC):
+ """
+ Abstract base class for Gravitino policy operations.
+ """
+
+ @abstractmethod
+ async def get_list_of_policies(self) -> str:
+ """
+ Retrieve the list of policies.
+
+ Returns:
+ str: JSON-formatted string containing policy list information
+ """
+ pass
+
+ @abstractmethod
+ async def load_policy(self, policy_name: str) -> str:
+ """
+ Load detailed information of a specific policy.
+
+ Args:
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON-formatted string containing full policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def associate_policy_with_metadata(
+ self,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_associate: list,
+ policies_to_disassociate: list,
+ ) -> str:
+ """
+ Associate policies with metadata.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
+ metadata_type: Type of the metadata (e.g., "table", "column")
+ policies_to_associate: List of policy names to associate with the metadata
+ policies_to_disassociate: List of policy names to disassociate from the metadata
+
+ Returns:
+ str: JSON formatted string containing list of policy names that were
+ successfully associated with the metadata
+ """
+ pass
+
+ @abstractmethod
+ async def get_policy_for_metadata(
+ self, metadata_full_name: str, metadata_type: str, policy_name: str
+ ) -> str:
+ """
+ Get the policy with are associated with a specific metadata item.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
+ metadata_type: Type of the metadata (e.g., "table", "column")
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON formatted string containing policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def list_policies_for_metadata(
+ self, metadata_full_name: str, metadata_type: str
+ ) -> str:
+ """
+ List all policies associated with a specific metadata item.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
Review Comment:
I have included it in another PR. What I mean here is that you may add a sentence to describe what is full name and entity 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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #8151:
URL: https://github.com/apache/gravitino/pull/8151
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2287638998
##########
mcp-server/mcp_server/tools/policy.py:
##########
@@ -0,0 +1,368 @@
+# 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_policy_tools(mcp: FastMCP):
+ @mcp.tool(tags={"policy"})
+ async def get_list_of_policies(
+ ctx: Context,
+ ) -> str:
+ """
+ Retrieve the list of available policy information.
+
+ Parameters:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ Returns:
+ str: A JSON string representing an array of policy information objects, each object
+ contains the policy name, comment, policy type, enabled status, content, supported object types,
+ inherited policy, and audit information.
+
+ Example Response:
+ [
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().get_list_of_policies()
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_detail_information(
+ ctx: Context,
+ policy_name: str,
+ ) -> str:
+ """
+ Retrieve detailed information for a specific policy by policy name.
+
+ Parameters:
+ ctx : Context
+ The request context object containing lifespan context and connector
+ information.
+ policy_name : str
+ The unique identifier for the policy. Must be one of the names
+ returned by `get_list_of_policies`.
+
+ Returns:
+ str : A structured JSON object containing the policy configuration with the following fields:
+ name: Unique policy identifier (string)
+ comment: Descriptive text about the policy (string)
+ policyType: Classification of policy (e.g., "custom", "system") (string)
Review Comment:
There is no policy type named "system."
##########
docs/gravitino-mcp-server.md:
##########
@@ -55,12 +55,17 @@ Or start a HTTP MCP server by `uv run mcp_server --metalake test --uri http://12
Gravitino MCP server supports the following tools, and you could export tool by tag.
-| Tool name | Description | Tag | Since version |
-|------------------------------|-----------------------------------------------------------------|-----------|---------------|
-| `get_list_of_catalogs` | Retrieve a list of all catalogs in the system. | `catalog` | 1.0.0 |
-| `get_list_of_schemas` | Retrieve a list of schemas belonging to a specific catalog. | `schema` | 1.0.0 |
-| `get_list_of_tables` | Retrieve a list of tables within a specific catalog and schema. | `table` | 1.0.0 |
-| `get_table_metadata_details` | Retrieve comprehensive metadata details for a specific table. | `table` | 1.0.0 |
+| Tool name | Description | Tag | Since version |
+|---------------------------------|---------------------------------------------------------------------|-----------|---------------|
+| `get_list_of_catalogs` | Retrieve a list of all catalogs in the system. | `catalog` | 1.0.0 |
+| `get_list_of_schemas` | Retrieve a list of schemas belonging to a specific catalog. | `schema` | 1.0.0 |
+| `get_list_of_tables` | Retrieve a list of tables within a specific catalog and schema. | `table` | 1.0.0 |
+| `get_table_metadata_details` | Retrieve comprehensive metadata details for a specific table. | `table` | 1.0.0 |
+| `get_list_of_policies` | Retrieve a list of policies in the system. | `policy` | 1.0.0 |
+| `get_policy_detail_information` | Retrieve detailed information for a specific policy by policy name. | `policy` | 1.0.0 |
+| `list_policies_for_metadata` | List all policies associated with a specific metadata item. | `policy` | 1.0.0 |
+| `list_metadata_by_policy` | List all metadata items associated with a specific policy. | `policy` | 1.0.0 |
+| `get_policy_for_metadata` | Get a policy associated with a specific metadata item. | `policy` | 1.0.0 |
Review Comment:
missing tag-related operations?
##########
mcp-server/mcp_server/client/plain/plain_rest_client_operation.py:
##########
@@ -96,3 +101,8 @@ def as_job_operation(self) -> JobOperation:
return PlainRESTClientJobOperation(
metalake_name=self.metalake_name, rest_client=self.rest_client
)
+
+ def as_policy_operation(self) -> PolicyOperation:
+ return PlainRESTClientPolicyOperation(
+ metalake_name=self.metalake_name, rest_client=self.rest_client
Review Comment:
This will result in a new object being created every time the method is called; it's better to use a member variable here.
##########
mcp-server/mcp_server/client/policy_operation.py:
##########
@@ -0,0 +1,116 @@
+# 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 abc import ABC, abstractmethod
+
+
+class PolicyOperation(ABC):
+ """
+ Abstract base class for Gravitino policy operations.
+ """
+
+ @abstractmethod
+ async def get_list_of_policies(self) -> str:
+ """
+ Retrieve the list of policies.
+
+ Returns:
+ str: JSON-formatted string containing policy list information
+ """
+ pass
+
+ @abstractmethod
+ async def load_policy(self, policy_name: str) -> str:
+ """
+ Load detailed information of a specific policy.
+
+ Args:
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON-formatted string containing full policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def associate_policy_with_metadata(
+ self,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_associate: list,
+ policies_to_disassociate: list,
+ ) -> str:
+ """
+ Associate policies with metadata.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
+ metadata_type: Type of the metadata (e.g., "table", "column")
+ policies_to_associate: List of policy names to associate with the metadata
+ policies_to_disassociate: List of policy names to disassociate from the metadata
+
+ Returns:
+ str: JSON formatted string containing list of policy names that were
+ successfully associated with the metadata
+ """
+ pass
+
+ @abstractmethod
+ async def get_policy_for_metadata(
+ self, metadata_full_name: str, metadata_type: str, policy_name: str
+ ) -> str:
+ """
+ Get the policy with are associated with a specific metadata item.
Review Comment:
Get the policy associated with a specific metadata item.
##########
mcp-server/mcp_server/tools/policy.py:
##########
@@ -0,0 +1,368 @@
+# 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_policy_tools(mcp: FastMCP):
+ @mcp.tool(tags={"policy"})
+ async def get_list_of_policies(
+ ctx: Context,
+ ) -> str:
+ """
+ Retrieve the list of available policy information.
+
+ Parameters:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ Returns:
+ str: A JSON string representing an array of policy information objects, each object
+ contains the policy name, comment, policy type, enabled status, content, supported object types,
+ inherited policy, and audit information.
+
+ Example Response:
+ [
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().get_list_of_policies()
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_detail_information(
+ ctx: Context,
+ policy_name: str,
+ ) -> str:
+ """
+ Retrieve detailed information for a specific policy by policy name.
+
+ Parameters:
+ ctx : Context
+ The request context object containing lifespan context and connector
+ information.
+ policy_name : str
+ The unique identifier for the policy. Must be one of the names
+ returned by `get_list_of_policies`.
+
+ Returns:
+ str : A structured JSON object containing the policy configuration with the following fields:
+ name: Unique policy identifier (string)
+ comment: Descriptive text about the policy (string)
+ policyType: Classification of policy (e.g., "custom", "system") (string)
+ enabled: Activation status (boolean)
+ content: Rule definitions and scope settings (dict)
+ - customRules: Key-value pairs of rule identifiers and settings (dict)
+ - properties: Additional configuration properties (dict)
+ - supportedObjectTypes: Entities this policy applies to (list of string)
+ inherited: Parent policy reference if applicable (null or dict)
+ audit: Creation metadata (dict)
+ - creator: User or service that created the policy (string)
+ - createTime: ISO 8601 timestamp of creation (string)
+
+ Example Response:
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ """
+
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().load_policy(policy_name)
+
+ @mcp.tool(tags={"policy"}, enabled=False)
+ async def associate_policy_with_metadata(
+ ctx: Context,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_associate: list,
+ ) -> str:
+ """
+ Associate policies 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 policies 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". For more, please see tool
+ `get_metadata_fullname_formats`.
+
+ metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+ "fileset", "model", "topic"). For More information, please see
+ tool `list_all_metadata_types`.
+ policies_to_associate (list): List of policy names to associate with the metadata.
+
+ Example input:
+ metadata_full_name: "catalog.schema.table"
+ metadata_type: "table"
+ policies_to_associate: ["policy1", "policy2"]
+
+ Returns:
+ str: JSON-formatted string containing the names of associated policies.
+
+ Example Return Value:
+ [
+ "policy1",
+ "policy2"
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return (
+ await client.as_policy_operation().associate_policy_with_metadata(
+ metadata_full_name,
+ metadata_type,
+ policies_to_associate,
+ [],
+ )
+ )
+
+ @mcp.tool(tags={"policy"}, enabled=False)
+ async def disassociate_policy_from_metadata(
+ ctx: Context,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_disassociate: list,
+ ) -> str:
+ """
+ Disassociate policies 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 policies from.
+ For more, please see tool `get_metadata_fullname_formats`.
+ metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+ "fileset", "model", "topic"). For More information, please see
+ tool `list_all_metadata_types`.
+ policies_to_disassociate (list): List of policy names to disassociate from the metadata.
+
+ Example input:
+ metadata_full_name: "catalog.schema.table"
+ metadata_type: "table"
+ policies_to_disassociate: ["policy1", "policy2"]
+
+ Returns:
+ str: JSON-formatted string containing the names of associated policies.
+
+ Example Return Value:
+ [
+ "policy3"
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return (
+ await client.as_policy_operation().associate_policy_with_metadata(
+ metadata_full_name, metadata_type, [], policies_to_disassociate
+ )
+ )
+
+ @mcp.tool(tags={"policy"})
+ async def list_policies_for_metadata(
+ ctx: Context, metadata_full_name: str, metadata_type: str
+ ) -> str:
+ """
+ List all policies 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). For more, please see tool
+ `get_metadata_fullname_formats`.
+ metadata_type (str): Type of the metadata (e.g., "table", "column"). For More information, please see
+ tool `list_all_metadata_types`.
+
+ Example input:
+ metadata_full_name: "catalog.schema.table"
+ metadata_type: "table"
+
+ Returns:
+ str: JSON-formatted string containing the list of policies associated with the metadata.
+
+ Example Return Value:
+ [
+ "policy1",
+ "policy2"
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().list_policies_for_metadata(
+ metadata_full_name, metadata_type
+ )
+
+ @mcp.tool(tags={"policy"})
+ async def list_metadata_by_policy(ctx: Context, policy_name: str) -> str:
+ """
+ List all metadata items associated with a specific policy.
+
+ The child metadata items which inherited the associate from the parent metadata
+ will be excluded in the result. For example, if the policy is associated with
+ the catalog, the catalog's child metadata items will be excluded in the result.
+
+ Args:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ policy_name (str): Name of the policy to filter metadata by.
+
+ Returns:
+ str: JSON-formatted string containing the list of metadata items associated with the policy.
+
+ Example Return Value:
+ [
+ {
+ "fullName": "model_catalog",
+ "type": "catalog"
+ },
+ {
+ "fullName": "catalog.schema.table",
+ "type": "table"
+ },
+ {
+ "fullName": "catalog.schema.fileset",
+ "type": "fileset"
+ },
+ {
+ "fullName": "catalog.schema.model",
+ "type": "model"
+ },
+ {
+ "fullName": "catalog.schema.topic",
+ "type": "topic"
+ }
+ {
+ "fullName": "catalog.schema",
+ "type": "schema"
+ }
+ ...
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().list_metadata_by_policy(
+ policy_name
+ )
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_for_metadata(
+ ctx: Context,
+ metadata_full_name: str,
+ metadata_type: str,
+ policy_name: str,
+ ) -> str:
+ """
+ Get the policy associated with a specific metadata item by policy name.
+
+ This tool is used to check whether a policy is associated with the 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). For more, please see tool
+ `get_metadata_fullname_formats`.
+ metadata_type (str): Type of the metadata (e.g., "table", "column"). For More information, please see
+ tool `list_all_metadata_types`.
+ policy_name (str): Name of the policy to filter metadata by.
+
+ Example input:
+ metadata_full_name: "catalog.schema.table"
+ metadata_type: "table"
+ policy_name: "policy_a"
+
+ Returns:
+ str: JSON-formatted string containing the detailed policy information associated with the metadata.
+
+ Example Return Value:
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
Review Comment:
the value will not be `null` in this response
##########
mcp-server/mcp_server/client/policy_operation.py:
##########
@@ -0,0 +1,116 @@
+# 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 abc import ABC, abstractmethod
+
+
+class PolicyOperation(ABC):
+ """
+ Abstract base class for Gravitino policy operations.
+ """
+
+ @abstractmethod
+ async def get_list_of_policies(self) -> str:
+ """
+ Retrieve the list of policies.
+
+ Returns:
+ str: JSON-formatted string containing policy list information
+ """
+ pass
+
+ @abstractmethod
+ async def load_policy(self, policy_name: str) -> str:
+ """
+ Load detailed information of a specific policy.
+
+ Args:
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON-formatted string containing full policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def associate_policy_with_metadata(
+ self,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_associate: list,
+ policies_to_disassociate: list,
Review Comment:
Is it better to use `policies_to_add` and `policies_to_remove` to align with the original function's parameter names
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2288097172
##########
mcp-server/mcp_server/client/policy_operation.py:
##########
@@ -0,0 +1,116 @@
+# 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 abc import ABC, abstractmethod
+
+
+class PolicyOperation(ABC):
+ """
+ Abstract base class for Gravitino policy operations.
+ """
+
+ @abstractmethod
+ async def get_list_of_policies(self) -> str:
+ """
+ Retrieve the list of policies.
+
+ Returns:
+ str: JSON-formatted string containing policy list information
+ """
+ pass
+
+ @abstractmethod
+ async def load_policy(self, policy_name: str) -> str:
+ """
+ Load detailed information of a specific policy.
+
+ Args:
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON-formatted string containing full policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def associate_policy_with_metadata(
+ self,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_associate: list,
+ policies_to_disassociate: list,
+ ) -> str:
+ """
+ Associate policies with metadata.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
+ metadata_type: Type of the metadata (e.g., "table", "column")
+ policies_to_associate: List of policy names to associate with the metadata
+ policies_to_disassociate: List of policy names to disassociate from the metadata
+
+ Returns:
+ str: JSON formatted string containing list of policy names that were
+ successfully associated with the metadata
+ """
+ pass
+
+ @abstractmethod
+ async def get_policy_for_metadata(
+ self, metadata_full_name: str, metadata_type: str, policy_name: str
+ ) -> str:
+ """
+ Get the policy with are associated with a specific metadata item.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
+ metadata_type: Type of the metadata (e.g., "table", "column")
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON formatted string containing policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def list_policies_for_metadata(
+ self, metadata_full_name: str, metadata_type: str
+ ) -> str:
+ """
+ List all policies associated with a specific metadata item.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
Review Comment:
This is not the doc for LLM, do we need to add tool reference too?
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2289675916
##########
docs/gravitino-mcp-server.md:
##########
@@ -55,12 +55,17 @@ Or start a HTTP MCP server by `uv run mcp_server --metalake test --uri http://12
Gravitino MCP server supports the following tools, and you could export tool by tag.
-| Tool name | Description | Tag | Since version |
-|------------------------------|-----------------------------------------------------------------|-----------|---------------|
-| `get_list_of_catalogs` | Retrieve a list of all catalogs in the system. | `catalog` | 1.0.0 |
-| `get_list_of_schemas` | Retrieve a list of schemas belonging to a specific catalog. | `schema` | 1.0.0 |
-| `get_list_of_tables` | Retrieve a list of tables within a specific catalog and schema. | `table` | 1.0.0 |
-| `get_table_metadata_details` | Retrieve comprehensive metadata details for a specific table. | `table` | 1.0.0 |
+| Tool name | Description | Tag | Since version |
+|---------------------------------|---------------------------------------------------------------------|-----------|---------------|
+| `get_list_of_catalogs` | Retrieve a list of all catalogs in the system. | `catalog` | 1.0.0 |
+| `get_list_of_schemas` | Retrieve a list of schemas belonging to a specific catalog. | `schema` | 1.0.0 |
+| `get_list_of_tables` | Retrieve a list of tables within a specific catalog and schema. | `table` | 1.0.0 |
+| `get_table_metadata_details` | Retrieve comprehensive metadata details for a specific table. | `table` | 1.0.0 |
+| `get_list_of_policies` | Retrieve a list of policies in the system. | `policy` | 1.0.0 |
+| `get_policy_detail_information` | Retrieve detailed information for a specific policy by policy name. | `policy` | 1.0.0 |
+| `list_policies_for_metadata` | List all policies associated with a specific metadata item. | `policy` | 1.0.0 |
+| `list_metadata_by_policy` | List all metadata items associated with a specific policy. | `policy` | 1.0.0 |
+| `get_policy_for_metadata` | Get a policy associated with a specific metadata item. | `policy` | 1.0.0 |
Review Comment:
I added it in #8214
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2283967256
##########
mcp-server/mcp_server/client/plain/plain_rest_client_policy_operation.py:
##########
@@ -0,0 +1,43 @@
+# 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 import PolicyOperation
+
+
+class PlainRESTClientPolicyOperation(PolicyOperation):
+ """
+ Implementation of PolicyOperation using a plain REST client.
+ """
+
+ def __init__(self, metalake_name: str, rest_client):
+ self.metalake_name = metalake_name
+ self.rest_client = rest_client
+
+ async def get_list_of_policies(self) -> str:
+ response = await self.rest_client.get(
+ f"/api/metalakes/{self.metalake_name}/policies"
+ )
+ return response.json().get("names", [])
Review Comment:
1. For list policies, we should get the detailed information of each policy, not just names.
2. We should add interface to get/list policies for metadata object, get/list metadata objects for policy, and associate/disassociate policies, please refer to the tag code in mcp module.
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#issuecomment-3208965344
@jerryshao PTAL
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#issuecomment-3204340310
@yuqi1129 @mchades please also help to review.
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2288088790
##########
mcp-server/mcp_server/client/policy_operation.py:
##########
@@ -0,0 +1,116 @@
+# 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 abc import ABC, abstractmethod
+
+
+class PolicyOperation(ABC):
+ """
+ Abstract base class for Gravitino policy operations.
+ """
+
+ @abstractmethod
+ async def get_list_of_policies(self) -> str:
+ """
+ Retrieve the list of policies.
+
+ Returns:
+ str: JSON-formatted string containing policy list information
+ """
+ pass
+
+ @abstractmethod
+ async def load_policy(self, policy_name: str) -> str:
+ """
+ Load detailed information of a specific policy.
+
+ Args:
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON-formatted string containing full policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def associate_policy_with_metadata(
+ self,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_associate: list,
+ policies_to_disassociate: list,
Review Comment:
updated
##########
mcp-server/mcp_server/tools/policy.py:
##########
@@ -0,0 +1,368 @@
+# 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_policy_tools(mcp: FastMCP):
+ @mcp.tool(tags={"policy"})
+ async def get_list_of_policies(
+ ctx: Context,
+ ) -> str:
+ """
+ Retrieve the list of available policy information.
+
+ Parameters:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ Returns:
+ str: A JSON string representing an array of policy information objects, each object
+ contains the policy name, comment, policy type, enabled status, content, supported object types,
+ inherited policy, and audit information.
+
+ Example Response:
+ [
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().get_list_of_policies()
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_detail_information(
+ ctx: Context,
+ policy_name: str,
+ ) -> str:
+ """
+ Retrieve detailed information for a specific policy by policy name.
+
+ Parameters:
+ ctx : Context
+ The request context object containing lifespan context and connector
+ information.
+ policy_name : str
+ The unique identifier for the policy. Must be one of the names
+ returned by `get_list_of_policies`.
+
+ Returns:
+ str : A structured JSON object containing the policy configuration with the following fields:
+ name: Unique policy identifier (string)
+ comment: Descriptive text about the policy (string)
+ policyType: Classification of policy (e.g., "custom", "system") (string)
Review Comment:
updated
##########
mcp-server/mcp_server/client/plain/plain_rest_client_operation.py:
##########
@@ -96,3 +101,8 @@ def as_job_operation(self) -> JobOperation:
return PlainRESTClientJobOperation(
metalake_name=self.metalake_name, rest_client=self.rest_client
)
+
+ def as_policy_operation(self) -> PolicyOperation:
+ return PlainRESTClientPolicyOperation(
+ metalake_name=self.metalake_name, rest_client=self.rest_client
Review Comment:
updated
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2290163180
##########
mcp-server/mcp_server/tools/policy.py:
##########
@@ -0,0 +1,368 @@
+# 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_policy_tools(mcp: FastMCP):
+ @mcp.tool(tags={"policy"})
+ async def get_list_of_policies(
+ ctx: Context,
+ ) -> str:
+ """
+ Retrieve the list of available policy information.
+
+ Parameters:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ Returns:
+ str: A JSON string representing an array of policy information objects, each object
+ contains the policy name, comment, policy type, enabled status, content, supported object types,
+ inherited policy, and audit information.
+
+ Example Response:
+ [
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().get_list_of_policies()
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_detail_information(
+ ctx: Context,
+ policy_name: str,
+ ) -> str:
+ """
+ Retrieve detailed information for a specific policy by policy name.
+
+ Parameters:
+ ctx : Context
+ The request context object containing lifespan context and connector
+ information.
+ policy_name : str
+ The unique identifier for the policy. Must be one of the names
+ returned by `get_list_of_policies`.
+
+ Returns:
+ str : A structured JSON object containing the policy configuration with the following fields:
+ name: Unique policy identifier (string)
+ comment: Descriptive text about the policy (string)
+ policyType: Classification of policy (e.g., "custom") (string)
+ enabled: Activation status (boolean)
+ content: Rule definitions and scope settings (dict)
+ - customRules: Key-value pairs of rule identifiers and settings (dict)
+ - properties: Additional configuration properties (dict)
+ - supportedObjectTypes: Entities this policy applies to (list of string)
+ inherited: Whether the policy is inherited from parent metadata (boolean)
+ audit: Creation metadata (dict)
+ - creator: User or service that created the policy (string)
+ - createTime: ISO 8601 timestamp of creation (string)
+
+ Example Response:
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ """
+
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().load_policy(policy_name)
+
+ @mcp.tool(tags={"policy"}, enabled=False)
Review Comment:
done
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2290064189
##########
mcp-server/mcp_server/tools/policy.py:
##########
@@ -0,0 +1,368 @@
+# 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_policy_tools(mcp: FastMCP):
+ @mcp.tool(tags={"policy"})
+ async def get_list_of_policies(
+ ctx: Context,
+ ) -> str:
+ """
+ Retrieve the list of available policy information.
+
+ Parameters:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ Returns:
+ str: A JSON string representing an array of policy information objects, each object
+ contains the policy name, comment, policy type, enabled status, content, supported object types,
+ inherited policy, and audit information.
+
+ Example Response:
+ [
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().get_list_of_policies()
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_detail_information(
+ ctx: Context,
+ policy_name: str,
+ ) -> str:
+ """
+ Retrieve detailed information for a specific policy by policy name.
+
+ Parameters:
+ ctx : Context
+ The request context object containing lifespan context and connector
+ information.
+ policy_name : str
+ The unique identifier for the policy. Must be one of the names
+ returned by `get_list_of_policies`.
+
+ Returns:
+ str : A structured JSON object containing the policy configuration with the following fields:
+ name: Unique policy identifier (string)
+ comment: Descriptive text about the policy (string)
+ policyType: Classification of policy (e.g., "custom") (string)
+ enabled: Activation status (boolean)
+ content: Rule definitions and scope settings (dict)
+ - customRules: Key-value pairs of rule identifiers and settings (dict)
+ - properties: Additional configuration properties (dict)
+ - supportedObjectTypes: Entities this policy applies to (list of string)
+ inherited: Whether the policy is inherited from parent metadata (boolean)
+ audit: Creation metadata (dict)
+ - creator: User or service that created the policy (string)
+ - createTime: ISO 8601 timestamp of creation (string)
+
+ Example Response:
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ """
+
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().load_policy(policy_name)
+
+ @mcp.tool(tags={"policy"}, enabled=False)
Review Comment:
ok
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2290022320
##########
mcp-server/mcp_server/tools/policy.py:
##########
@@ -0,0 +1,368 @@
+# 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_policy_tools(mcp: FastMCP):
+ @mcp.tool(tags={"policy"})
+ async def get_list_of_policies(
+ ctx: Context,
+ ) -> str:
+ """
+ Retrieve the list of available policy information.
+
+ Parameters:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ Returns:
+ str: A JSON string representing an array of policy information objects, each object
+ contains the policy name, comment, policy type, enabled status, content, supported object types,
+ inherited policy, and audit information.
+
+ Example Response:
+ [
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().get_list_of_policies()
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_detail_information(
+ ctx: Context,
+ policy_name: str,
+ ) -> str:
+ """
+ Retrieve detailed information for a specific policy by policy name.
+
+ Parameters:
+ ctx : Context
+ The request context object containing lifespan context and connector
+ information.
+ policy_name : str
+ The unique identifier for the policy. Must be one of the names
+ returned by `get_list_of_policies`.
+
+ Returns:
+ str : A structured JSON object containing the policy configuration with the following fields:
+ name: Unique policy identifier (string)
+ comment: Descriptive text about the policy (string)
+ policyType: Classification of policy (e.g., "custom") (string)
+ enabled: Activation status (boolean)
+ content: Rule definitions and scope settings (dict)
+ - customRules: Key-value pairs of rule identifiers and settings (dict)
+ - properties: Additional configuration properties (dict)
+ - supportedObjectTypes: Entities this policy applies to (list of string)
+ inherited: Whether the policy is inherited from parent metadata (boolean)
+ audit: Creation metadata (dict)
+ - creator: User or service that created the policy (string)
+ - createTime: ISO 8601 timestamp of creation (string)
+
+ Example Response:
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ """
+
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().load_policy(policy_name)
+
+ @mcp.tool(tags={"policy"}, enabled=False)
Review Comment:
I follow the behaviors in tag tools. Should we enable this?
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2290160815
##########
mcp-server/mcp_server/client/plain/plain_rest_client_operation.py:
##########
@@ -52,47 +57,61 @@
from mcp_server.client.topic_operation import TopicOperation
+# pylint: disable=too-many-instance-attributes
class PlainRESTClientOperation(GravitinoOperation):
def __init__(self, metalake_name: str, uri: str):
- self.metalake_name = metalake_name
- self.rest_client = httpx.AsyncClient(base_url=uri)
+ rest_client = httpx.AsyncClient(base_url=uri)
+ self.catalog_operation = PlainRESTClientCatalogOperation(
+ metalake_name, rest_client
+ )
+ self.table_operation = PlainRESTClientTableOperation(
+ metalake_name, rest_client
+ )
+ self.schema_operation = PlainRESTClientSchemaOperation(
+ metalake_name, rest_client
+ )
+ self.topic_operation = PlainRESTClientTopicOperation(
+ metalake_name, rest_client
+ )
+ self.model_operation = PlainRESTClientModelOperation(
+ metalake_name, rest_client
+ )
+ self.tag_operation = PlainRESTClientTagOperation(
+ metalake_name, rest_client
+ )
+ self.fileset_operation = PlainRESTClientFilesetOperation(
+ metalake_name, rest_client
+ )
+ self.job_operation = PlainRESTClientJobOperation(
+ metalake_name, rest_client
+ )
+ self.policy_operation = PlainRESTClientPolicyOperation(
+ metalake_name, rest_client
+ )
Review Comment:
done
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2289733126
##########
mcp-server/mcp_server/client/policy_operation.py:
##########
@@ -0,0 +1,116 @@
+# 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 abc import ABC, abstractmethod
+
+
+class PolicyOperation(ABC):
+ """
+ Abstract base class for Gravitino policy operations.
+ """
+
+ @abstractmethod
+ async def get_list_of_policies(self) -> str:
+ """
+ Retrieve the list of policies.
+
+ Returns:
+ str: JSON-formatted string containing policy list information
+ """
+ pass
+
+ @abstractmethod
+ async def load_policy(self, policy_name: str) -> str:
+ """
+ Load detailed information of a specific policy.
+
+ Args:
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON-formatted string containing full policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def associate_policy_with_metadata(
+ self,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_associate: list,
+ policies_to_disassociate: list,
+ ) -> str:
+ """
+ Associate policies with metadata.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
+ metadata_type: Type of the metadata (e.g., "table", "column")
+ policies_to_associate: List of policy names to associate with the metadata
+ policies_to_disassociate: List of policy names to disassociate from the metadata
+
+ Returns:
+ str: JSON formatted string containing list of policy names that were
+ successfully associated with the metadata
+ """
+ pass
+
+ @abstractmethod
+ async def get_policy_for_metadata(
+ self, metadata_full_name: str, metadata_type: str, policy_name: str
+ ) -> str:
+ """
+ Get the policy with are associated with a specific metadata item.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
+ metadata_type: Type of the metadata (e.g., "table", "column")
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON formatted string containing policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def list_policies_for_metadata(
+ self, metadata_full_name: str, metadata_type: str
+ ) -> str:
+ """
+ List all policies associated with a specific metadata item.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
Review Comment:
Oh, got it, update with the sentence
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2288089587
##########
mcp-server/mcp_server/tools/policy.py:
##########
@@ -0,0 +1,368 @@
+# 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_policy_tools(mcp: FastMCP):
+ @mcp.tool(tags={"policy"})
+ async def get_list_of_policies(
+ ctx: Context,
+ ) -> str:
+ """
+ Retrieve the list of available policy information.
+
+ Parameters:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ Returns:
+ str: A JSON string representing an array of policy information objects, each object
+ contains the policy name, comment, policy type, enabled status, content, supported object types,
+ inherited policy, and audit information.
+
+ Example Response:
+ [
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().get_list_of_policies()
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_detail_information(
+ ctx: Context,
+ policy_name: str,
+ ) -> str:
+ """
+ Retrieve detailed information for a specific policy by policy name.
+
+ Parameters:
+ ctx : Context
+ The request context object containing lifespan context and connector
+ information.
+ policy_name : str
+ The unique identifier for the policy. Must be one of the names
+ returned by `get_list_of_policies`.
+
+ Returns:
+ str : A structured JSON object containing the policy configuration with the following fields:
+ name: Unique policy identifier (string)
+ comment: Descriptive text about the policy (string)
+ policyType: Classification of policy (e.g., "custom", "system") (string)
+ enabled: Activation status (boolean)
+ content: Rule definitions and scope settings (dict)
+ - customRules: Key-value pairs of rule identifiers and settings (dict)
+ - properties: Additional configuration properties (dict)
+ - supportedObjectTypes: Entities this policy applies to (list of string)
+ inherited: Parent policy reference if applicable (null or dict)
+ audit: Creation metadata (dict)
+ - creator: User or service that created the policy (string)
+ - createTime: ISO 8601 timestamp of creation (string)
+
+ Example Response:
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ """
+
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().load_policy(policy_name)
+
+ @mcp.tool(tags={"policy"}, enabled=False)
+ async def associate_policy_with_metadata(
+ ctx: Context,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_associate: list,
+ ) -> str:
+ """
+ Associate policies 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 policies 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". For more, please see tool
+ `get_metadata_fullname_formats`.
+
+ metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+ "fileset", "model", "topic"). For More information, please see
+ tool `list_all_metadata_types`.
+ policies_to_associate (list): List of policy names to associate with the metadata.
+
+ Example input:
+ metadata_full_name: "catalog.schema.table"
+ metadata_type: "table"
+ policies_to_associate: ["policy1", "policy2"]
+
+ Returns:
+ str: JSON-formatted string containing the names of associated policies.
+
+ Example Return Value:
+ [
+ "policy1",
+ "policy2"
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return (
+ await client.as_policy_operation().associate_policy_with_metadata(
+ metadata_full_name,
+ metadata_type,
+ policies_to_associate,
+ [],
+ )
+ )
+
+ @mcp.tool(tags={"policy"}, enabled=False)
+ async def disassociate_policy_from_metadata(
+ ctx: Context,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_disassociate: list,
+ ) -> str:
+ """
+ Disassociate policies 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 policies from.
+ For more, please see tool `get_metadata_fullname_formats`.
+ metadata_type (str): Type of the metadata object (e.g., "table", "schema", "catalog",
+ "fileset", "model", "topic"). For More information, please see
+ tool `list_all_metadata_types`.
+ policies_to_disassociate (list): List of policy names to disassociate from the metadata.
+
+ Example input:
+ metadata_full_name: "catalog.schema.table"
+ metadata_type: "table"
+ policies_to_disassociate: ["policy1", "policy2"]
+
+ Returns:
+ str: JSON-formatted string containing the names of associated policies.
+
+ Example Return Value:
+ [
+ "policy3"
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return (
+ await client.as_policy_operation().associate_policy_with_metadata(
+ metadata_full_name, metadata_type, [], policies_to_disassociate
+ )
+ )
+
+ @mcp.tool(tags={"policy"})
+ async def list_policies_for_metadata(
+ ctx: Context, metadata_full_name: str, metadata_type: str
+ ) -> str:
+ """
+ List all policies 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). For more, please see tool
+ `get_metadata_fullname_formats`.
+ metadata_type (str): Type of the metadata (e.g., "table", "column"). For More information, please see
+ tool `list_all_metadata_types`.
+
+ Example input:
+ metadata_full_name: "catalog.schema.table"
+ metadata_type: "table"
+
+ Returns:
+ str: JSON-formatted string containing the list of policies associated with the metadata.
+
+ Example Return Value:
+ [
+ "policy1",
+ "policy2"
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().list_policies_for_metadata(
+ metadata_full_name, metadata_type
+ )
+
+ @mcp.tool(tags={"policy"})
+ async def list_metadata_by_policy(ctx: Context, policy_name: str) -> str:
+ """
+ List all metadata items associated with a specific policy.
+
+ The child metadata items which inherited the associate from the parent metadata
+ will be excluded in the result. For example, if the policy is associated with
+ the catalog, the catalog's child metadata items will be excluded in the result.
+
+ Args:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ policy_name (str): Name of the policy to filter metadata by.
+
+ Returns:
+ str: JSON-formatted string containing the list of metadata items associated with the policy.
+
+ Example Return Value:
+ [
+ {
+ "fullName": "model_catalog",
+ "type": "catalog"
+ },
+ {
+ "fullName": "catalog.schema.table",
+ "type": "table"
+ },
+ {
+ "fullName": "catalog.schema.fileset",
+ "type": "fileset"
+ },
+ {
+ "fullName": "catalog.schema.model",
+ "type": "model"
+ },
+ {
+ "fullName": "catalog.schema.topic",
+ "type": "topic"
+ }
+ {
+ "fullName": "catalog.schema",
+ "type": "schema"
+ }
+ ...
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().list_metadata_by_policy(
+ policy_name
+ )
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_for_metadata(
+ ctx: Context,
+ metadata_full_name: str,
+ metadata_type: str,
+ policy_name: str,
+ ) -> str:
+ """
+ Get the policy associated with a specific metadata item by policy name.
+
+ This tool is used to check whether a policy is associated with the 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). For more, please see tool
+ `get_metadata_fullname_formats`.
+ metadata_type (str): Type of the metadata (e.g., "table", "column"). For More information, please see
+ tool `list_all_metadata_types`.
+ policy_name (str): Name of the policy to filter metadata by.
+
+ Example input:
+ metadata_full_name: "catalog.schema.table"
+ metadata_type: "table"
+ policy_name: "policy_a"
+
+ Returns:
+ str: JSON-formatted string containing the detailed policy information associated with the metadata.
+
+ Example Return Value:
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
Review Comment:
updated
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2287996988
##########
docs/gravitino-mcp-server.md:
##########
@@ -55,12 +55,17 @@ Or start a HTTP MCP server by `uv run mcp_server --metalake test --uri http://12
Gravitino MCP server supports the following tools, and you could export tool by tag.
-| Tool name | Description | Tag | Since version |
-|------------------------------|-----------------------------------------------------------------|-----------|---------------|
-| `get_list_of_catalogs` | Retrieve a list of all catalogs in the system. | `catalog` | 1.0.0 |
-| `get_list_of_schemas` | Retrieve a list of schemas belonging to a specific catalog. | `schema` | 1.0.0 |
-| `get_list_of_tables` | Retrieve a list of tables within a specific catalog and schema. | `table` | 1.0.0 |
-| `get_table_metadata_details` | Retrieve comprehensive metadata details for a specific table. | `table` | 1.0.0 |
+| Tool name | Description | Tag | Since version |
+|---------------------------------|---------------------------------------------------------------------|-----------|---------------|
+| `get_list_of_catalogs` | Retrieve a list of all catalogs in the system. | `catalog` | 1.0.0 |
+| `get_list_of_schemas` | Retrieve a list of schemas belonging to a specific catalog. | `schema` | 1.0.0 |
+| `get_list_of_tables` | Retrieve a list of tables within a specific catalog and schema. | `table` | 1.0.0 |
+| `get_table_metadata_details` | Retrieve comprehensive metadata details for a specific table. | `table` | 1.0.0 |
+| `get_list_of_policies` | Retrieve a list of policies in the system. | `policy` | 1.0.0 |
+| `get_policy_detail_information` | Retrieve detailed information for a specific policy by policy name. | `policy` | 1.0.0 |
+| `list_policies_for_metadata` | List all policies associated with a specific metadata item. | `policy` | 1.0.0 |
+| `list_metadata_by_policy` | List all metadata items associated with a specific policy. | `policy` | 1.0.0 |
+| `get_policy_for_metadata` | Get a policy associated with a specific metadata item. | `policy` | 1.0.0 |
Review Comment:
seems not related to this PR, we could do this in another 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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2288098952
##########
mcp-server/mcp_server/client/policy_operation.py:
##########
@@ -0,0 +1,116 @@
+# 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 abc import ABC, abstractmethod
+
+
+class PolicyOperation(ABC):
+ """
+ Abstract base class for Gravitino policy operations.
+ """
+
+ @abstractmethod
+ async def get_list_of_policies(self) -> str:
+ """
+ Retrieve the list of policies.
+
+ Returns:
+ str: JSON-formatted string containing policy list information
+ """
+ pass
+
+ @abstractmethod
+ async def load_policy(self, policy_name: str) -> str:
+ """
+ Load detailed information of a specific policy.
+
+ Args:
+ policy_name: Name of the policy
+
+ Returns:
+ str: JSON-formatted string containing full policy metadata
+ """
+ pass
+
+ @abstractmethod
+ async def associate_policy_with_metadata(
+ self,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_associate: list,
+ policies_to_disassociate: list,
+ ) -> str:
+ """
+ Associate policies with metadata.
+
+ Args:
+ metadata_full_name: Full name of the metadata item (e.g., table, column)
+ metadata_type: Type of the metadata (e.g., "table", "column")
+ policies_to_associate: List of policy names to associate with the metadata
+ policies_to_disassociate: List of policy names to disassociate from the metadata
+
+ Returns:
+ str: JSON formatted string containing list of policy names that were
+ successfully associated with the metadata
+ """
+ pass
+
+ @abstractmethod
+ async def get_policy_for_metadata(
+ self, metadata_full_name: str, metadata_type: str, policy_name: str
+ ) -> str:
+ """
+ Get the policy with are associated with a specific metadata item.
Review Comment:
updated
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2290160196
##########
mcp-server/mcp_server/client/plain/plain_rest_client_policy_operation.py:
##########
@@ -0,0 +1,82 @@
+# 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 import PolicyOperation
+from mcp_server.client.plain.utils import extract_content_from_response
+
+
+class PlainRESTClientPolicyOperation(PolicyOperation):
+ """
+ Implementation of PolicyOperation using a plain REST client.
+ """
+
+ def __init__(self, metalake_name: str, rest_client):
+ self.metalake_name = metalake_name
+ self.rest_client = rest_client
+
+ async def get_list_of_policies(self) -> str:
+ response = await self.rest_client.get(
+ f"/api/metalakes/{self.metalake_name}/policies?details=true"
+ )
+ return extract_content_from_response(response, "policies", [])
+
+ async def load_policy(
+ self,
+ policy_name: str,
+ ) -> str:
+ response = await self.rest_client.get(
+ f"/api/metalakes/{self.metalake_name}/policies/{policy_name}"
+ )
+ return extract_content_from_response(response, "policy", {})
+
+ async def associate_policy_with_metadata(
+ self,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_add: list,
+ policies_to_remove: list,
+ ) -> str:
+ response = await self.rest_client.post(
+ f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/policies",
+ json={
+ "policiesToAdd": policies_to_add,
+ "policiesToRemove": policies_to_remove,
+ },
+ )
+ return extract_content_from_response(response, "names", [])
+
+ async def get_policy_for_metadata(
+ self, metadata_full_name: str, metadata_type: str, policy_name: str
+ ) -> str:
+ response = await self.rest_client.get(
+ f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/policies/{policy_name}",
+ )
+ return extract_content_from_response(response, "policy", {})
+
+ async def list_policies_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}/policies/",
+ )
+ return extract_content_from_response(response, "names", [])
Review Comment:
done
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2289833951
##########
mcp-server/mcp_server/client/plain/plain_rest_client_policy_operation.py:
##########
@@ -0,0 +1,82 @@
+# 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 import PolicyOperation
+from mcp_server.client.plain.utils import extract_content_from_response
+
+
+class PlainRESTClientPolicyOperation(PolicyOperation):
+ """
+ Implementation of PolicyOperation using a plain REST client.
+ """
+
+ def __init__(self, metalake_name: str, rest_client):
+ self.metalake_name = metalake_name
+ self.rest_client = rest_client
+
+ async def get_list_of_policies(self) -> str:
+ response = await self.rest_client.get(
+ f"/api/metalakes/{self.metalake_name}/policies?details=true"
+ )
+ return extract_content_from_response(response, "policies", [])
+
+ async def load_policy(
+ self,
+ policy_name: str,
+ ) -> str:
+ response = await self.rest_client.get(
+ f"/api/metalakes/{self.metalake_name}/policies/{policy_name}"
+ )
+ return extract_content_from_response(response, "policy", {})
+
+ async def associate_policy_with_metadata(
+ self,
+ metadata_full_name: str,
+ metadata_type: str,
+ policies_to_add: list,
+ policies_to_remove: list,
+ ) -> str:
+ response = await self.rest_client.post(
+ f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/policies",
+ json={
+ "policiesToAdd": policies_to_add,
+ "policiesToRemove": policies_to_remove,
+ },
+ )
+ return extract_content_from_response(response, "names", [])
+
+ async def get_policy_for_metadata(
+ self, metadata_full_name: str, metadata_type: str, policy_name: str
+ ) -> str:
+ response = await self.rest_client.get(
+ f"/api/metalakes/{self.metalake_name}/objects/{metadata_type}/{metadata_full_name}/policies/{policy_name}",
+ )
+ return extract_content_from_response(response, "policy", {})
+
+ async def list_policies_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}/policies/",
+ )
+ return extract_content_from_response(response, "names", [])
Review Comment:
We should also list the detailed policies for this API if supported.
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2289830854
##########
mcp-server/mcp_server/client/plain/plain_rest_client_operation.py:
##########
@@ -52,47 +57,61 @@
from mcp_server.client.topic_operation import TopicOperation
+# pylint: disable=too-many-instance-attributes
class PlainRESTClientOperation(GravitinoOperation):
def __init__(self, metalake_name: str, uri: str):
- self.metalake_name = metalake_name
- self.rest_client = httpx.AsyncClient(base_url=uri)
+ rest_client = httpx.AsyncClient(base_url=uri)
+ self.catalog_operation = PlainRESTClientCatalogOperation(
+ metalake_name, rest_client
+ )
+ self.table_operation = PlainRESTClientTableOperation(
+ metalake_name, rest_client
+ )
+ self.schema_operation = PlainRESTClientSchemaOperation(
+ metalake_name, rest_client
+ )
+ self.topic_operation = PlainRESTClientTopicOperation(
+ metalake_name, rest_client
+ )
+ self.model_operation = PlainRESTClientModelOperation(
+ metalake_name, rest_client
+ )
+ self.tag_operation = PlainRESTClientTagOperation(
+ metalake_name, rest_client
+ )
+ self.fileset_operation = PlainRESTClientFilesetOperation(
+ metalake_name, rest_client
+ )
+ self.job_operation = PlainRESTClientJobOperation(
+ metalake_name, rest_client
+ )
+ self.policy_operation = PlainRESTClientPolicyOperation(
+ metalake_name, rest_client
+ )
Review Comment:
Can you please add the `_` prefix for all the internal variables.
--
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] [#8137] feat(mcp): support policy read operations for Gravitino MCP server [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #8151:
URL: https://github.com/apache/gravitino/pull/8151#discussion_r2290039798
##########
mcp-server/mcp_server/tools/policy.py:
##########
@@ -0,0 +1,368 @@
+# 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_policy_tools(mcp: FastMCP):
+ @mcp.tool(tags={"policy"})
+ async def get_list_of_policies(
+ ctx: Context,
+ ) -> str:
+ """
+ Retrieve the list of available policy information.
+
+ Parameters:
+ ctx (Context): The request context object containing lifespan context
+ and connector information.
+ Returns:
+ str: A JSON string representing an array of policy information objects, each object
+ contains the policy name, comment, policy type, enabled status, content, supported object types,
+ inherited policy, and audit information.
+
+ Example Response:
+ [
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ ]
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().get_list_of_policies()
+
+ @mcp.tool(tags={"policy"})
+ async def get_policy_detail_information(
+ ctx: Context,
+ policy_name: str,
+ ) -> str:
+ """
+ Retrieve detailed information for a specific policy by policy name.
+
+ Parameters:
+ ctx : Context
+ The request context object containing lifespan context and connector
+ information.
+ policy_name : str
+ The unique identifier for the policy. Must be one of the names
+ returned by `get_list_of_policies`.
+
+ Returns:
+ str : A structured JSON object containing the policy configuration with the following fields:
+ name: Unique policy identifier (string)
+ comment: Descriptive text about the policy (string)
+ policyType: Classification of policy (e.g., "custom") (string)
+ enabled: Activation status (boolean)
+ content: Rule definitions and scope settings (dict)
+ - customRules: Key-value pairs of rule identifiers and settings (dict)
+ - properties: Additional configuration properties (dict)
+ - supportedObjectTypes: Entities this policy applies to (list of string)
+ inherited: Whether the policy is inherited from parent metadata (boolean)
+ audit: Creation metadata (dict)
+ - creator: User or service that created the policy (string)
+ - createTime: ISO 8601 timestamp of creation (string)
+
+ Example Response:
+ {
+ "name": "my_policy1",
+ "comment": "This is a test policy",
+ "policyType": "custom",
+ "enabled": true,
+ "content": {
+ "customRules": {
+ "rule1": 123
+ },
+ "properties": {
+ "key1": "value1"
+ },
+ "supportedObjectTypes": [
+ "fileset",
+ "schema",
+ "topic",
+ "table",
+ "model",
+ "catalog"
+ ]
+ },
+ "inherited": null,
+ "audit": {
+ "creator": "anonymous",
+ "createTime": "2025-08-18T08:29:30.016501Z"
+ }
+ }
+ """
+
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_policy_operation().load_policy(policy_name)
+
+ @mcp.tool(tags={"policy"}, enabled=False)
Review Comment:
Yes, we should. For tag, I think associate and disassociate are enabled by default. If not, please also enable them.
--
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