yuqi1129 commented on code in PR #8018: URL: https://github.com/apache/gravitino/pull/8018#discussion_r2272389693
########## mcp-server/mcp_server/client/fileset_operation.py: ########## @@ -0,0 +1,102 @@ +# 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 FilesetOperation(ABC): + """ + Abstract base class for Gravitino fileset operations. + """ + + @abstractmethod + async def get_list_of_filesets( + self, catalog_name: str, schema_name: str + ) -> str: + """ + Retrieve the list of filesets within a specified catalog. + + Args: + catalog_name: Name of the catalog + schema_name: Name of the schema + + Returns: + str: JSON-formatted string containing fileset list information + """ + pass + + @abstractmethod + async def load_fileset( + self, catalog_name: str, schema_name: str, fileset_name: str + ) -> str: + """ + Load detailed information of a specific fileset. + + Args: + catalog_name: Name of the catalog + schema_name: Name of the schema + fileset_name: Name of the fileset + + Returns: + str: JSON-formatted string containing full fileset metadata + """ + pass + + @abstractmethod + async def list_files_in_fileset( + self, + catalog_name: str, + schema_name: str, + fileset_name: str, + location_name: str, + sub_path: str = "/", + ) -> str: + """ + List files in a specific fileset. + + Args: + catalog_name: Name of the catalog + schema_name: Name of the schema + fileset_name: Name of the fileset + sub_path: Sub-path within the fileset to list files from (default is root "/") + location_name: Name of the location + + Returns: + str: JSON-formatted string containing list of files in the fileset + """ + pass + + @abstractmethod + async def get_fileset_location( Review Comment: done ########## mcp-server/mcp_server/client/plain/plain_rest_client_model_operation.py: ########## @@ -0,0 +1,68 @@ +# 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 ModelOperation + + +class PlainRESTClientModelOperation(ModelOperation): + """ + Implementation of ModelOperation 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_models( + self, catalog_name: str, schema_name: str + ) -> str: + response = await self.rest_client.get( + f"/api/metalakes/{self.metalake_name}/catalogs/{catalog_name}/schemas/{schema_name}/models" + ) + return response.json().get("identifiers", []) + + async def load_model( + self, catalog_name: str, schema_name: str, model_name: str + ) -> str: + response = await self.rest_client.get( + f"/api/metalakes/{self.metalake_name}/catalogs/{catalog_name}/schemas/{schema_name}/models/{model_name}" + ) + return response.json().get("model", {}) + + async def list_model_versions( + self, catalog_name: str, schema_name: str, model_name: str + ) -> str: + response = await self.rest_client.get( + f"/api/metalakes/{self.metalake_name}/catalogs/{catalog_name}/schemas/{schema_name}/models/{model_name}/versions" + ) + return response.json().get("versions", []) Review Comment: done ########## mcp-server/mcp_server/tools/fileset.py: ########## @@ -0,0 +1,177 @@ +# 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_fileset_tools(mcp: FastMCP): + @mcp.tool(tags={"fileset"}) + async def get_list_of_filesets( + ctx: Context, + catalog_name: str, + schema_name: str, + ): + """ + Retrieve a list of filesets within a specific catalog and schema. + + Parameters: + ctx (Context): The request context object containing lifespan context + and connector information. + catalog_name (str): The name of the catalog to filter filesets by. + schema_name (str): The name of the schema to filter filesets by. + + Returns: + str: A JSON string representing an array of fileset identifiers. + + Example Return Value: + [ + { + "namespace": [ + "test", + "fileset_catalog", + "fileset_schema1" + ], + "name": "fileset1" + } + ] + """ + client = ctx.request_context.lifespan_context.rest_client() + return await client.as_fileset_operation().get_list_of_filesets( + catalog_name, schema_name + ) + + @mcp.tool(tags={"fileset"}) + async def load_fileset( + ctx: Context, + catalog_name: str, + schema_name: str, + fileset_name: str, + ): + """ + Load detailed information of a specific fileset. + + Parameters: + ctx (Context): The request context object containing lifespan context + and connector information. + catalog_name (str): The name of the catalog containing the fileset. + schema_name (str): The name of the schema containing the fileset. + fileset_name (str): The name of the fileset to load. + + Returns: + str: A JSON string containing full metadata of the specified fileset. + + Example Return Value: + { + "name": "fileset1", + "comment": "", + "type": "managed", + "storageLocations": { + "location1": "file:/tmp/fileset1" + }, + "properties": { + "default-location-name": "location1" + }, + "audit": { + "creator": "anonymous", + "createTime": "2025-08-07T07:52:56.656313Z" + } + } + """ + client = ctx.request_context.lifespan_context.rest_client() + return await client.as_fileset_operation().load_fileset( + catalog_name, schema_name, fileset_name + ) + + @mcp.tool(tags={"fileset"}) + async def list_files_in_fileset( + ctx: Context, + catalog_name: str, + schema_name: str, + fileset_name: str, + location_name: str, + sub_path: str = "/", + ): + """ + List files in a specific fileset. + + Parameters: + ctx (Context): The request context object containing lifespan context + and connector information. + catalog_name (str): The name of the catalog containing the fileset. + schema_name (str): The name of the schema containing the fileset. + fileset_name (str): The name of the fileset to list files from. + location_name (str): The name of the location within the fileset. + sub_path (str): Sub-path within the fileset to list files from (default is root "/"). + + Returns: + str: A JSON string containing a list of files in the specified fileset. + + Example Return Value: + [ + { + "name": "2.txt", + "isDir": false, + "size": 2, + "lastModified": 1754911672329, + "path": "/fileset/fileset_catalog/fileset_schema1/fileset1/" + }, + { + "name": "1.txt", + "isDir": false, + "size": 2, + "lastModified": 1754911668512, + "path": "/fileset/fileset_catalog/fileset_schema1/fileset1/" + } + ] + """ + client = ctx.request_context.lifespan_context.rest_client() + return await client.as_fileset_operation().list_files_in_fileset( + catalog_name, schema_name, fileset_name, location_name, sub_path + ) + + @mcp.tool(tags={"fileset"}) + async def get_fileset_location( + ctx: Context, + catalog_name: str, + schema_name: str, + fileset_name: str, + sub_path: str, + location_name: str, + ): + """ + Get the location of a specific fileset. + + Parameters: + ctx (Context): The request context object containing lifespan context + and connector information. + catalog_name (str): The name of the catalog containing the fileset. + schema_name (str): The name of the schema containing the fileset. + fileset_name (str): The name of the fileset to get the location for. + sub_path (str): Sub-path within the fileset. + location_name (str): The name of the location within the fileset. + + Returns: + str: A JSON string containing the location information of the specified fileset. + + Example Return Value: + file:/tmp/fileset1 + + """ + client = ctx.request_context.lifespan_context.rest_client() + return await client.as_fileset_operation().get_fileset_location( + catalog_name, schema_name, fileset_name, sub_path, location_name + ) 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-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org