World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#8005] feat(mcp-server): Support read operations for fileset, topic and model in MCP server. (#8018)
Mini Yu278d10851607
diff --git a/mcp-server/.gitignore b/mcp-server/.gitignoreindex cc92df8da8..f2a99ec686 100644--- a/mcp-server/.gitignore+++ b/mcp-server/.gitignore@@ -27,6 +27,7 @@ venv.uvdistbuild+gravitino_mcp_server.egg-infologs/*.log@@ -51,3 +52,4 @@ cover/# Documentation Relateddocs/builddocs/source/generated+diff --git a/mcp-server/mcp_server/client/__init__.py b/mcp-server/mcp_server/client/__init__.pyindex 5b9c4dbbcb..01aba796f8 100644--- a/mcp-server/mcp_server/client/__init__.py+++ b/mcp-server/mcp_server/client/__init__.py@@ -17,6 +17,8 @@from mcp_server.client.catalog_operation import CatalogOperationfrom mcp_server.client.gravitino_operation import GravitinoOperation+from mcp_server.client.model_operation import ModelOperationfrom mcp_server.client.schema_operation import SchemaOperationfrom mcp_server.client.table_operation import TableOperationfrom mcp_server.client.tag_operation import TagOperation+from mcp_server.client.topic_operation import TopicOperationdiff --git a/mcp-server/mcp_server/client/fileset_operation.py b/mcp-server/mcp_server/client/fileset_operation.pynew file mode 100644index 0000000000..9350bc128d--- /dev/null+++ b/mcp-server/mcp_server/client/fileset_operation.py@@ -0,0 +1,81 @@+# 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+ """+ passdiff --git a/mcp-server/mcp_server/client/gravitino_operation.py b/mcp-server/mcp_server/client/gravitino_operation.pyindex a0c0ef8944..e8ca7fa5be 100644--- a/mcp-server/mcp_server/client/gravitino_operation.py+++ b/mcp-server/mcp_server/client/gravitino_operation.py@@ -18,9 +18,12 @@from abc import ABC, abstractmethodfrom mcp_server.client.catalog_operation import CatalogOperation+from mcp_server.client.fileset_operation import FilesetOperation+from mcp_server.client.model_operation import ModelOperationfrom mcp_server.client.schema_operation import SchemaOperationfrom mcp_server.client.table_operation import TableOperationfrom mcp_server.client.tag_operation import TagOperation+from mcp_server.client.topic_operation import TopicOperationclass GravitinoOperation(ABC):@@ -59,6 +62,35 @@ class GravitinoOperation(ABC):pass@abstractmethod+ def as_topic_operation(self) -> TopicOperation:+ """+ Access the topic operation interface of this Gravitino operation.++ Returns:+ TopicOperation: Interface for performing topic-level operations+ """+ pass++ @abstractmethod+ def as_model_operation(self) -> ModelOperation:+ """+ Access the model operation interface of this Gravitino operation.++ Returns:+ ModelOperation: Interface for performing model-level operations+ """+ pass++ @abstractmethod+ def as_fileset_operation(self) -> FilesetOperation:+ """+ Access the fileset operation interface of this Gravitino operation.++ Returns:+ FilesetOperation: Interface for performing fileset-level operations+ pass+ """+def as_tag_operation(self) -> TagOperation:"""Access the tag operation interface of this Gravitino operation.diff --git a/mcp-server/mcp_server/client/model_operation.py b/mcp-server/mcp_server/client/model_operation.pynew file mode 100644index 0000000000..9f6e4e9278--- /dev/null+++ b/mcp-server/mcp_server/client/model_operation.py@@ -0,0 +1,110 @@+# 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 ModelOperation(ABC):+ """+ Abstract base class for Gravitino model operations.+ """++ @abstractmethod+ async def get_list_of_models(+ self, catalog_name: str, schema_name: str+ ) -> str:+ """+ Retrieve the list of models within a specified catalog.++ Args:+ catalog_name: Name of the catalog+ schema_name: Name of the schema++ Returns:+ str: JSON-formatted string containing model list information+ """+ pass++ @abstractmethod+ async def load_model(+ self, catalog_name: str, schema_name: str, model_name: str+ ) -> str:+ """+ Load detailed information of a specific model.++ Args:+ catalog_name: Name of the catalog+ schema_name: Name of the schema+ model_name: Name of the model++ Returns:+ str: JSON-formatted string containing full model metadata+ """+ pass++ @abstractmethod+ async def list_model_versions(+ self, catalog_name: str, schema_name: str, model_name: str+ ) -> str:+ """+ List all versions of a specific model.++ Args:+ catalog_name: Name of the catalog+ schema_name: Name of the schema+ model_name: Name of the model++ Returns:+ str: JSON-formatted string containing model version information+ """+ pass++ @abstractmethod+ async def load_model_version(+ self, catalog_name: str, schema_name: str, model_name: str, version: int+ ) -> str:+ """+ Load detailed information of a specific version of a model.++ Args:+ catalog_name: Name of the catalog+ schema_name: Name of the schema+ model_name: Name of the model+ version: Version identifier of the model++ Returns:+ str: JSON-formatted string containing full model version metadata+ """+ pass++ @abstractmethod+ async def load_model_version_by_alias(+ self, catalog_name: str, schema_name: str, model_name: str, alias: str+ ) -> str:+ """+ Load detailed information of a specific version of a model by its alias.++ Args:+ catalog_name: Name of the catalog+ schema_name: Name of the schema+ model_name: Name of the model+ alias: Alias identifier of the model version++ Returns:+ str: JSON-formatted string containing full model version metadata+ """+ passdiff --git a/mcp-server/mcp_server/client/plain/plain_rest_client_fileset_operation.py b/mcp-server/mcp_server/client/plain/plain_rest_client_fileset_operation.pynew file mode 100644index 0000000000..3d53be529e--- /dev/null+++ b/mcp-server/mcp_server/client/plain/plain_rest_client_fileset_operation.py@@ -0,0 +1,53 @@+# 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.fileset_operation import FilesetOperation+++class PlainRESTClientFilesetOperation(FilesetOperation):+ def __init__(self, metalake_name: str, rest_client):+ self.metalake_name = metalake_name+ self.rest_client = rest_client++ async def get_list_of_filesets(+ 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}/filesets"+ )+ return response.json().get("identifiers", [])++ async def load_fileset(+ self, catalog_name: str, schema_name: str, fileset_name: str+ ) -> str:+ response = await self.rest_client.get(+ f"/api/metalakes/{self.metalake_name}/catalogs/{catalog_name}/schemas/{schema_name}/filesets/{fileset_name}"+ )+ return response.json().get("fileset", {})++ async def list_files_in_fileset(+ self,+ catalog_name: str,+ schema_name: str,+ fileset_name: str,+ location_name: str,+ sub_path: str = "/",+ ) -> str:+ response = await self.rest_client.get(+ f"/api/metalakes/{self.metalake_name}/catalogs/{catalog_name}/schemas/{schema_name}/filesets/{fileset_name}/files?sub_path={sub_path}&location_name={location_name}"+ )+ return response.json().get("files", [])diff --git a/mcp-server/mcp_server/client/plain/plain_rest_client_model_operation.py b/mcp-server/mcp_server/client/plain/plain_rest_client_model_operation.pynew file mode 100644index 0000000000..3b63c63d75--- /dev/null+++ b/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?details=true"+ )+ return response.json().get("infos", [])++ async def load_model_version(+ self, catalog_name: str, schema_name: str, model_name: str, version: int+ ) -> str:+ response = await self.rest_client.get(+ f"/api/metalakes/{self.metalake_name}/catalogs/{catalog_name}/schemas/{schema_name}/models/{model_name}/versions/{version}"+ )+ return response.json().get("modelVersion", {})++ async def load_model_version_by_alias(+ self, catalog_name: str, schema_name: str, model_name: str, alias: str+ ) -> str:+ response = await self.rest_client.get(+ f"/api/metalakes/{self.metalake_name}/catalogs/{catalog_name}/schemas/{schema_name}/models/{model_name}/aliases/{alias}"+ )+ return response.json().get("modelVersion", {})diff --git a/mcp-server/mcp_server/client/plain/plain_rest_client_operation.py b/mcp-server/mcp_server/client/plain/plain_rest_client_operation.pyindex 2bdc37b46b..f95aebda9f 100644--- a/mcp-server/mcp_server/client/plain/plain_rest_client_operation.py+++ b/mcp-server/mcp_server/client/plain/plain_rest_client_operation.py@@ -27,6 +27,12 @@ from mcp_server.client import (from mcp_server.client.plain.plain_rest_client_catalog_operation import (PlainRESTClientCatalogOperation,)+from mcp_server.client.plain.plain_rest_client_fileset_operation import (+ PlainRESTClientFilesetOperation,+)+from mcp_server.client.plain.plain_rest_client_model_operation import (+ PlainRESTClientModelOperation,+)from mcp_server.client.plain.plain_rest_client_schema_operation import (PlainRESTClientSchemaOperation,)@@ -36,6 +42,10 @@ from mcp_server.client.plain.plain_rest_client_table_operation import (from mcp_server.client.plain.plain_rest_client_tag_operation import (PlainRESTClientTagOperation,)+from mcp_server.client.plain.plain_rest_client_topic_operation import (+ PlainRESTClientTopicOperation,+)+from mcp_server.client.topic_operation import TopicOperationclass PlainRESTClientOperation(GravitinoOperation):@@ -58,6 +68,21 @@ class PlainRESTClientOperation(GravitinoOperation):metalake_name=self.metalake_name, rest_client=self.rest_client)+ def as_topic_operation(self) -> TopicOperation:+ return PlainRESTClientTopicOperation(+ metalake_name=self.metalake_name, rest_client=self.rest_client+ )++ def as_model_operation(self):+ return PlainRESTClientModelOperation(+ metalake_name=self.metalake_name, rest_client=self.rest_client+ )++ def as_fileset_operation(self):+ return PlainRESTClientFilesetOperation(+ metalake_name=self.metalake_name, rest_client=self.rest_client+ )+def as_tag_operation(self) -> TagOperation:return PlainRESTClientTagOperation(metalake_name=self.metalake_name, rest_client=self.rest_clientdiff --git a/mcp-server/mcp_server/client/plain/plain_rest_client_topic_operation.py b/mcp-server/mcp_server/client/plain/plain_rest_client_topic_operation.pynew file mode 100644index 0000000000..e9a4b26bc9--- /dev/null+++ b/mcp-server/mcp_server/client/plain/plain_rest_client_topic_operation.py@@ -0,0 +1,44 @@+# 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.topic_operation import TopicOperation+++class PlainRESTClientTopicOperation(TopicOperation):+ """+ Implementation of TopicOperation 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_topics(+ 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}/topics"+ )+ return response.json().get("identifiers", [])++ async def load_topic(+ self, catalog_name: str, schema_name: str, topic_name: str+ ) -> str:+ response = await self.rest_client.get(+ f"/api/metalakes/{self.metalake_name}/catalogs/{catalog_name}/schemas/{schema_name}/topics/{topic_name}"+ )+ return response.json().get("topic", {})diff --git a/mcp-server/mcp_server/client/topic_operation.py b/mcp-server/mcp_server/client/topic_operation.pynew file mode 100644index 0000000000..47a2f4f3b6--- /dev/null+++ b/mcp-server/mcp_server/client/topic_operation.py@@ -0,0 +1,57 @@+# 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 TopicOperation(ABC):+ """+ Abstract base class for Gravitino topic operations.+ """++ @abstractmethod+ async def get_list_of_topics(+ self, catalog_name: str, schema_name: str+ ) -> str:+ """+ Retrieve the list of topics within a specified catalog.++ Args:+ catalog_name: Name of the catalog+ schema_name: Name of the schema++ Returns:+ str: JSON-formatted string containing topic list information+ """+ pass++ @abstractmethod+ async def load_topic(+ self, catalog_name: str, schema_name: str, topic_name: str+ ) -> str:+ """+ Load detailed information of a specific topic.++ Args:+ catalog_name: Name of the catalog+ schema_name: Name of the schema+ topic_name: Name of the topic++ Returns:+ str: JSON-formatted string containing full topic metadata+ """+ passdiff --git a/mcp-server/mcp_server/tools/__init__.py b/mcp-server/mcp_server/tools/__init__.pyindex 38170e214a..6e900fc225 100644--- a/mcp-server/mcp_server/tools/__init__.py+++ b/mcp-server/mcp_server/tools/__init__.py@@ -18,15 +18,21 @@from fastmcp import FastMCPfrom mcp_server.tools.catalog import load_catalog_tools+from mcp_server.tools.fileset import load_fileset_toolsfrom mcp_server.tools.metadata import load_metadata_tool+from mcp_server.tools.model import load_model_toolsfrom mcp_server.tools.schema import load_schema_toolsfrom mcp_server.tools.table import load_table_toolsfrom mcp_server.tools.tag import load_tag_tool+from mcp_server.tools.topic import load_topic_toolsdef load_tools(mcp: FastMCP):load_catalog_tools(mcp)load_schema_tools(mcp)load_table_tools(mcp)+ load_topic_tools(mcp)+ load_model_tools(mcp)+ load_fileset_tools(mcp)load_tag_tool(mcp)load_metadata_tool(mcp)diff --git a/mcp-server/mcp_server/tools/fileset.py b/mcp-server/mcp_server/tools/fileset.pynew file mode 100644index 0000000000..2bfc53734d--- /dev/null+++ b/mcp-server/mcp_server/tools/fileset.py@@ -0,0 +1,144 @@+# 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+ )diff --git a/mcp-server/mcp_server/tools/model.py b/mcp-server/mcp_server/tools/model.pynew file mode 100644index 0000000000..9e3ac18dc7--- /dev/null+++ b/mcp-server/mcp_server/tools/model.py@@ -0,0 +1,231 @@+# 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_model_tools(mcp: FastMCP):+ @mcp.tool(tags={"model"})+ async def get_list_of_models(+ ctx: Context,+ catalog_name: str,+ schema_name: str,+ ):+ """+ Retrieve a list of models within a specific catalog and schema.+ This function returns a JSON-formatted string containing model identifiers+ filtered by the specified catalog and schema names.++ Parameters:+ ctx (Context): The request context object containing lifespan context+ and connector information.+ catalog_name (str): The name of the catalog to filter models by.+ schema_name (str): The name of the schema to filter models by.++ Returns:+ str: A JSON string representing an array of model objects with the following structure:+ - namespace: An array of strings representing the hierarchical namespace of the model.+ - name: The name of the model.++ Example Return Value:+ [+ {+ "namespace": [+ "test",+ "model_catalog",+ "schema1"+ ],+ "name": "model1"+ },+ {+ "namespace": [+ "test",+ "model_catalog",+ "schema1"+ ],+ "name": "model2"+ }+ ]+ """+ client = ctx.request_context.lifespan_context.rest_client()+ return await client.as_model_operation().get_list_of_models(+ catalog_name, schema_name+ )++ @mcp.tool(tags={"model"})+ async def load_model(+ ctx: Context,+ catalog_name: str,+ schema_name: str,+ model_name: str,+ ):+ """+ Load detailed information of a specific model.++ Parameters:+ ctx (Context): The request context object containing lifespan context+ and connector information.+ catalog_name (str): The name of the catalog to filter models by.+ schema_name (str): The name of the schema to filter models by.+ model_name (str): The name of the model to load.++ Returns:+ str: A JSON string containing full model metadata.++ Example Return Value:+ {+ "name": "model1",+ "comment": "",+ "properties": {},+ "latestVersion": 0,+ "audit": {+ "creator": "anonymous",+ "createTime": "2025-08-11T06:50:04.403532Z"+ }+ }+ """+ client = ctx.request_context.lifespan_context.rest_client()+ return await client.as_model_operation().load_model(+ catalog_name, schema_name, model_name+ )++ @mcp.tool(tags={"model"})+ async def list_model_versions(+ ctx: Context,+ catalog_name: str,+ schema_name: str,+ model_name: str,+ ):+ """+ List all versions of a specific model.++ Parameters:+ ctx (Context): The request context object containing lifespan context+ and connector information.+ catalog_name (str): The name of the catalog to filter models by.+ schema_name (str): The name of the schema to filter models by.+ model_name (str): The name of the model to list versions for.++ Returns:+ str: A JSON string containing model version information. The string represents an array of version information.++ Example Return Value:+ [+ {+ "version": 1,+ "comment": "this is version2",+ "aliases": [+ "alias2"+ ],+ "uri": "/tmp/version2",+ "properties": {},+ "audit": {+ "creator": "anonymous",+ "createTime": "2025-08-11T06:56:06.340031Z"+ }+ }+ ]++ """+ client = ctx.request_context.lifespan_context.rest_client()+ return await client.as_model_operation().list_model_versions(+ catalog_name, schema_name, model_name+ )++ @mcp.tool(tags={"model"})+ async def load_model_version(+ ctx: Context,+ catalog_name: str,+ schema_name: str,+ model_name: str,+ version: int,+ ):+ """+ Load detailed information of a specific version of a model.++ Parameters:+ ctx (Context): The request context object containing lifespan context+ and connector information.+ catalog_name (str): The name of the catalog to filter models by.+ schema_name (str): The name of the schema to filter models by.+ model_name (str): The name of the model to load.+ version (int): Version identifier of the model.++ Returns:+ str: A JSON string containing full model version metadata.++ Example Return Value:+ {+ "version": 1,+ "comment": "this is version2",+ "aliases": [+ "alias2"+ ],+ "uri": "/tmp/version2",+ "properties": {},+ "audit": {+ "creator": "anonymous",+ "createTime": "2025-08-11T06:56:06.340031Z"+ }+ }+ """+ client = ctx.request_context.lifespan_context.rest_client()+ return await client.as_model_operation().load_model_version(+ catalog_name, schema_name, model_name, version+ )++ @mcp.tool(tags={"model"})+ async def load_model_version_by_alias(+ ctx: Context,+ catalog_name: str,+ schema_name: str,+ model_name: str,+ alias: str,+ ):+ """+ Load detailed information of a specific version of a model by its alias.++ Parameters:+ ctx (Context): The request context object containing lifespan context+ and connector information.+ catalog_name (str): The name of the catalog to filter models by.+ schema_name (str): The name of the schema to filter models by.+ model_name (str): The name of the model to load.+ alias (str): Alias of the model version.++ Returns:+ str: A JSON string containing full model version metadata.++ Example Return Value:+ {+ "version": 1,+ "comment": "this is version2",+ "aliases": [+ "alias2"+ ],+ "uri": "/tmp/version2",+ "properties": {},+ "audit": {+ "creator": "anonymous",+ "createTime": "2025-08-11T06:56:06.340031Z"+ }+ }+ """+ client = ctx.request_context.lifespan_context.rest_client()+ return await client.as_model_operation().load_model_version_by_alias(+ catalog_name, schema_name, model_name, alias+ )diff --git a/mcp-server/mcp_server/tools/topic.py b/mcp-server/mcp_server/tools/topic.pynew file mode 100644index 0000000000..552b79956a--- /dev/null+++ b/mcp-server/mcp_server/tools/topic.py@@ -0,0 +1,134 @@+# 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_topic_tools(mcp: FastMCP):+ @mcp.tool(tags={"topic"})+ async def get_list_of_topic(+ ctx: Context,+ catalog_name: str,+ schema_name: str,+ ):+ """+ Retrieve a list of topics within a specific catalog and schema.+ This function returns a JSON-formatted string containing topic identifiers+ filtered by the specified catalog and schema names.+++ Parameters:+ ctx (Context): The request context object containing lifespan context+ and connector information.+ catalog_name (str): The name of the catalog to filter topics by.+ schema_name (str): The name of the schema to filter topics by.+ Returns:+ str: A JSON string representing an array of topic objects with the following structure:+ - namespace: An array of strings representing the hierarchical namespace of the topic.+ - name: The name of the topic.++ [+ {+ "namespace": [+ "test",+ "kafka_catalog",+ "default"+ ],+ "name": "topic1"+ },+ {+ "namespace": [+ "test",+ "kafka_catalog",+ "default"+ ],+ "name": "topic2"+ }+ ]+ Example Return Value:+ [+ {+ "namespace": [+ "test",+ "kafka_catalog",+ "default"+ ],+ "name": "topic1"+ },+ {+ "namespace": [+ "test",+ "kafka_catalog",+ "default"+ ],+ "name": "topic2"+ }+ ]+ """+ client = ctx.request_context.lifespan_context.rest_client()+ return await client.as_topic_operation().get_list_of_topics(+ catalog_name, schema_name+ )++ @mcp.tool(tags={"topic"})+ async def load_topic(+ ctx: Context,+ catalog_name: str,+ schema_name: str,+ topic_name: str,+ ):+ """+ Load detailed information of a specific topic.+ This function retrieves metadata for a topic identified by its name within the specified catalog and schema.++ Parameters:+ ctx (Context): The request context object containing lifespan context+ and connector information.+ catalog_name (str): The name of the catalog containing the topic.+ schema_name (str): The name of the schema containing the topic.+ topic_name (str): The name of the topic to load.++ Returns:+ str: A JSON string containing full topic metadata.++ Example Return Value:+ {+ "name": "test-topic_925a2038",+ "properties": {+ "compression.type": "producer",+ "leader.replication.throttled.replicas": "",+ "remote.storage.enable": "false",+ "message.downconversion.enable": "true",+ "min.insync.replicas": "1",+ "segment.jitter.ms": "0",+ "local.retention.ms": "-2",+ "cleanup.policy": "delete",+ "flush.ms": "9223372036854775807",+ "follower.replication.throttled.replicas": "",+ "segment.bytes": "1073741824",+ "preallocate": "false"+ },+ "audit": {+ "creator": "anonymous",+ "createTime": "2025-08-11T03:31:53.100944Z"+ }+ }+ """+ client = ctx.request_context.lifespan_context.rest_client()+ return await client.as_topic_operation().load_topic(+ catalog_name, schema_name, topic_name+ )diff --git a/mcp-server/tests/unit/tools/mock_operation.py b/mcp-server/tests/unit/tools/mock_operation.pyindex 4539686042..be0fa2120e 100644--- a/mcp-server/tests/unit/tools/mock_operation.py+++ b/mcp-server/tests/unit/tools/mock_operation.py@@ -18,9 +18,12 @@from mcp_server.client import (CatalogOperation,GravitinoOperation,+ ModelOperation,SchemaOperation,TableOperation,+ TopicOperation,)+from mcp_server.client.fileset_operation import FilesetOperationfrom mcp_server.client.tag_operation import TagOperation@@ -37,6 +40,15 @@ class MockOperation(GravitinoOperation):def as_catalog_operation(self) -> CatalogOperation:return MockCatalogOperation()+ def as_fileset_operation(self) -> FilesetOperation:+ return MockFilesetOperation()++ def as_topic_operation(self) -> TopicOperation:+ return MockTopicOperation()++ def as_model_operation(self) -> ModelOperation:+ return MockModelOperation()+def as_tag_operation(self) -> TagOperation:return MockTagOperation()@@ -63,6 +75,67 @@ class MockTableOperation(TableOperation):return "mock_table"+class MockFilesetOperation(FilesetOperation):+ async def get_list_of_filesets(+ self, catalog_name: str, schema_name: str+ ) -> str:+ return "mock_filesets"++ async def load_fileset(+ self, catalog_name: str, schema_name: str, fileset_name: str+ ) -> str:+ return "mock_fileset"++ async def list_files_in_fileset(+ self,+ catalog_name: str,+ schema_name: str,+ fileset_name: str,+ location_name: str,+ sub_path: str = "/",+ ) -> str:+ return "mock_files_in_fileset"+++class MockModelOperation(ModelOperation):+ async def get_list_of_models(+ self, catalog_name: str, schema_name: str+ ) -> str:+ return "mock_models"++ async def load_model(+ self, catalog_name: str, schema_name: str, model_name: str+ ) -> str:+ return "mock_model"++ async def list_model_versions(+ self, catalog_name: str, schema_name: str, model_name: str+ ) -> str:+ return "mock_model_versions"++ async def load_model_version(+ self, catalog_name: str, schema_name: str, model_name: str, version: int+ ) -> str:+ return "mock_model_version"++ async def load_model_version_by_alias(+ self, catalog_name: str, schema_name: str, model_name: str, alias: str+ ) -> str:+ return "mock_model_version_by_alias"+++class MockTopicOperation(TopicOperation):+ async def get_list_of_topics(+ self, catalog_name: str, schema_name: str+ ) -> str:+ return "mock_topics"++ async def load_topic(+ self, catalog_name: str, schema_name: str, topic_name: str+ ) -> str:+ return "mock_topic"++class MockTagOperation(TagOperation):async def get_list_of_tags(self) -> str:return "mock_tags"