tuhaihe commented on code in PR #1285:
URL: https://github.com/apache/cloudberry/pull/1285#discussion_r2252994386


##########
mcp-server/src/cbmcp/database.py:
##########
@@ -0,0 +1,773 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# 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.
+
+"""
+Database utilities for the PostgreSQL MCP server

Review Comment:
   ```suggestion
   Database utilities for the Cloudberry MCP server
   ```



##########
mcp-server/src/cbmcp/prompt.py:
##########
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# 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.
+
+"""Prompt templates for PostgreSQL database analysis."""
+
+ANALYZE_QUERY_PERFORMANCE_PROMPT = """Please help me analyze and optimize a 
PostgreSQL query.
+
+I'll provide you with:
+1. The SQL query: {sql}
+2. The EXPLAIN ANALYZE output: {explain}
+3. Table schema information: {table_info}
+
+Please analyze:
+- Query execution plan
+- Potential performance bottlenecks
+- Index usage
+- Suggested optimizations
+- Alternative query approaches
+"""
+
+SUGGEST_INDEXES_PROMPT = """Please help me suggest optimal indexes for your 
PostgreSQL tables.
+
+I'll provide you with:
+1. The table schema(s): {table_info}
+2. Common query patterns: {query}
+3. Current indexes: {table_info}
+4. Table size and row count: {table_stats}
+
+Please analyze:
+- Missing indexes based on query patterns
+- Index type recommendations (B-tree, GIN, GiST, etc.)
+- Composite index suggestions
+- Index maintenance considerations
+"""
+
+DATABASE_HEALTH_CHECK_PROMPT = """Let's perform a comprehensive health check 
of your PostgreSQL database.

Review Comment:
   ```suggestion
   DATABASE_HEALTH_CHECK_PROMPT = """Let's perform a comprehensive health check 
of your Cloudberry database.
   ```



##########
mcp-server/tests/README.md:
##########
@@ -0,0 +1,96 @@
+# Apache Cloudberry MCP Testing Guide
+
+## Test Structure
+
+This project uses the `pytest` framework for testing, supporting both 
asynchronous testing and parameterized testing.
+
+### Test Files
+- `test_cbmcp.py` - Main test file containing all MCP client functionality 
tests
+
+### Test Categories
+- **Unit Tests** - Test individual features independently
+- **Integration Tests** - Test overall system functionality
+- **Parameterized Tests** - Test both stdio and http modes simultaneously
+
+## Running Tests
+
+### Install Test Dependencies
+```bash
+pip install -e ".[dev]"
+```
+
+### Run All Tests
+```bash
+pytest tests/
+```
+
+### Run Specific Tests
+```bash
+# Run specific test file
+pytest tests/test_cbmcp.py
+
+# Run specific test class
+pytest tests/test_cbmcp.py::TestPostgreSQLMCPClient
+
+# Run specific test method
+pytest tests/test_cbmcp.py::TestPostgreSQLMCPClient::test_list_capabilities
+
+# Run tests for specific mode
+pytest tests/test_cbmcp.py -k "stdio"
+```
+
+### Verbose Output
+```bash
+pytest tests/ -v
+```
+
+### Coverage Testing
+```bash
+pytest tests/ --cov=src.cbmcp --cov-report=html --cov-report=term
+```
+
+## Test Features
+
+### 1. Server Capabilities Tests
+- `test_list_capabilities` - Test tool, resource, and prompt listings
+
+### 2. Resource Tests
+- `test_get_schemas_resource` - Get database schemas
+- `test_get_tables_resource` - Get table listings
+- `test_get_database_info_resource` - Get database information
+- `test_get_database_summary_resource` - Get database summary
+
+### 3. Tool Tests
+- `test_tools` - Parameterized testing of all tool calls
+  - list_tables
+  - list_views
+  - list_columns
+  - list_indexes
+  - execute_query
+  - list_large_tables
+  - get_table_stats
+  - explain_query
+
+### 4. Prompt Tests
+- `test_analyze_query_performance_prompt` - Query performance analysis prompts
+- `test_suggest_indexes_prompt` - Index suggestion prompts
+- `test_database_health_check_prompt` - Database health check prompts
+
+## Test Modes
+
+Tests support two modes:
+- **stdio** - Standard input/output mode
+- **http** - HTTP mode
+
+## Notes
+
+1. Tests will skip inaccessible features (e.g., when database is not connected)
+2. Ensure PostgreSQL service is started and configured correctly

Review Comment:
   ```suggestion
   2. Ensure Cloudberry service is started and configured correctly
   ```



##########
mcp-server/pyproject.toml:
##########
@@ -0,0 +1,51 @@
+[project]
+name = "cloudberry-mcp-server"
+version = "0.1.0"
+description = "MCP server for Apache Cloudberry database interaction"
+readme = "README.md"
+requires-python = ">=3.10"
+authors = [
+    {name = "HashML Team", email = "[email protected]"},
+]
+maintainers = [
+    {name = "Yangshengwen", email = "[email protected]"},
+]
+license = {text = "MIT"}
+keywords = ["mcp", "cloudberry", "postgresql", "database", "server", "ai"]
+classifiers = [
+    "Development Status :: 3 - Alpha",
+    "Intended Audience :: Developers",
+    "License :: OSI Approved :: MIT License",

Review Comment:
   ```suggestion
       "License :: OSI Approved :: Apache Software License",
   ```



##########
mcp-server/README.md:
##########


Review Comment:
   Seems this is one binary file? Might need to ajust the default file format 
to text?



##########
mcp-server/pyproject.toml:
##########
@@ -0,0 +1,51 @@
+[project]
+name = "cloudberry-mcp-server"
+version = "0.1.0"
+description = "MCP server for Apache Cloudberry database interaction"
+readme = "README.md"
+requires-python = ">=3.10"
+authors = [
+    {name = "HashML Team", email = "[email protected]"},
+]
+maintainers = [
+    {name = "Yangshengwen", email = "[email protected]"},
+]
+license = {text = "MIT"}
+keywords = ["mcp", "cloudberry", "postgresql", "database", "server", "ai"]
+classifiers = [
+    "Development Status :: 3 - Alpha",
+    "Intended Audience :: Developers",
+    "License :: OSI Approved :: MIT License",
+    "Programming Language :: Python :: 3",
+    "Programming Language :: Python :: 3.10",
+    "Programming Language :: Python :: 3.11",
+    "Programming Language :: Python :: 3.12",
+    "Programming Language :: Python :: 3.13",
+    "Topic :: Database",
+    "Topic :: Software Development :: Libraries :: Python Modules",
+    "Topic :: Database :: Front-Ends",
+]
+dependencies = [
+    "fastmcp>=2.10.6",
+    "psycopg2-binary==2.9.10",
+    "asyncpg>=0.29.0",
+    "pydantic>=2.0.0",
+    "python-dotenv>=1.0.0",
+    "aiohttp>=3.12.15",
+    "starlette>=0.27.0",
+]
+
+[project.optional-dependencies]
+dev = [
+    "pytest>=7.0.0",
+    "pytest-asyncio>=0.21.0",
+    "pytest-cov>=4.0.0",
+]
+
+[project.urls]
+Homepage = "https://github.com/apache/cloudberry/mcp-server";
+Repository = "https://github.com/apache/cloudberry";
+Documentation = "https://github.com/apache/cloudberry/mcp-server/README.md";

Review Comment:
   ```suggestion
   Documentation = 
"https://github.com/apache/cloudberry/tree/main/mcp-server/README.md";
   ```



##########
mcp-server/src/cbmcp/prompt.py:
##########
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# 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.
+
+"""Prompt templates for PostgreSQL database analysis."""
+
+ANALYZE_QUERY_PERFORMANCE_PROMPT = """Please help me analyze and optimize a 
PostgreSQL query.
+
+I'll provide you with:
+1. The SQL query: {sql}
+2. The EXPLAIN ANALYZE output: {explain}
+3. Table schema information: {table_info}
+
+Please analyze:
+- Query execution plan
+- Potential performance bottlenecks
+- Index usage
+- Suggested optimizations
+- Alternative query approaches
+"""
+
+SUGGEST_INDEXES_PROMPT = """Please help me suggest optimal indexes for your 
PostgreSQL tables.

Review Comment:
   ```suggestion
   SUGGEST_INDEXES_PROMPT = """Please help me suggest optimal indexes for your 
Cloudberry tables.
   ```



##########
mcp-server/pyproject.toml:
##########
@@ -0,0 +1,51 @@
+[project]
+name = "cloudberry-mcp-server"
+version = "0.1.0"
+description = "MCP server for Apache Cloudberry database interaction"
+readme = "README.md"
+requires-python = ">=3.10"
+authors = [
+    {name = "HashML Team", email = "[email protected]"},
+]
+maintainers = [
+    {name = "Yangshengwen", email = "[email protected]"},
+]
+license = {text = "MIT"}
+keywords = ["mcp", "cloudberry", "postgresql", "database", "server", "ai"]
+classifiers = [
+    "Development Status :: 3 - Alpha",
+    "Intended Audience :: Developers",
+    "License :: OSI Approved :: MIT License",
+    "Programming Language :: Python :: 3",
+    "Programming Language :: Python :: 3.10",
+    "Programming Language :: Python :: 3.11",
+    "Programming Language :: Python :: 3.12",
+    "Programming Language :: Python :: 3.13",
+    "Topic :: Database",
+    "Topic :: Software Development :: Libraries :: Python Modules",
+    "Topic :: Database :: Front-Ends",
+]
+dependencies = [
+    "fastmcp>=2.10.6",
+    "psycopg2-binary==2.9.10",
+    "asyncpg>=0.29.0",
+    "pydantic>=2.0.0",
+    "python-dotenv>=1.0.0",
+    "aiohttp>=3.12.15",
+    "starlette>=0.27.0",
+]
+
+[project.optional-dependencies]
+dev = [
+    "pytest>=7.0.0",
+    "pytest-asyncio>=0.21.0",
+    "pytest-cov>=4.0.0",
+]
+
+[project.urls]
+Homepage = "https://github.com/apache/cloudberry/mcp-server";

Review Comment:
   ```suggestion
   Homepage = "https://github.com/apache/cloudberry/tree/main/mcp-server";
   ```



##########
mcp-server/src/cbmcp/prompt.py:
##########
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# 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.
+
+"""Prompt templates for PostgreSQL database analysis."""

Review Comment:
   ```suggestion
   """Prompt templates for Cloudberry database analysis."""
   ```



##########
mcp-server/pyproject.toml:
##########
@@ -0,0 +1,51 @@
+[project]
+name = "cloudberry-mcp-server"
+version = "0.1.0"
+description = "MCP server for Apache Cloudberry database interaction"
+readme = "README.md"
+requires-python = ">=3.10"
+authors = [
+    {name = "HashML Team", email = "[email protected]"},
+]
+maintainers = [
+    {name = "Yangshengwen", email = "[email protected]"},

Review Comment:
   ```suggestion
       {name = "Apache Cloudberry", email = "[email protected]"},
   ```



##########
mcp-server/pyproject.toml:
##########
@@ -0,0 +1,51 @@
+[project]
+name = "cloudberry-mcp-server"
+version = "0.1.0"
+description = "MCP server for Apache Cloudberry database interaction"
+readme = "README.md"
+requires-python = ">=3.10"

Review Comment:
   Many users will use Cloudberry under Python 3.6.8/3.8.10 - the default 
Python version in Rocky Linux 8/ Ubuntu 20.4. So, for the required Python 
version, can we set it to `>= 3.6`?



##########
mcp-server/pyproject.toml:
##########
@@ -0,0 +1,51 @@
+[project]
+name = "cloudberry-mcp-server"
+version = "0.1.0"
+description = "MCP server for Apache Cloudberry database interaction"
+readme = "README.md"
+requires-python = ">=3.10"
+authors = [
+    {name = "HashML Team", email = "[email protected]"},

Review Comment:
   ```suggestion
       {name = "Apache Cloudberry", email = "[email protected]"},
   ```



##########
mcp-server/src/cbmcp/prompt.py:
##########
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# 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.
+
+"""Prompt templates for PostgreSQL database analysis."""
+
+ANALYZE_QUERY_PERFORMANCE_PROMPT = """Please help me analyze and optimize a 
PostgreSQL query.

Review Comment:
   ```suggestion
   ANALYZE_QUERY_PERFORMANCE_PROMPT = """Please help me analyze and optimize a 
Cloudberry query.
   ```



##########
mcp-server/pyproject.toml:
##########
@@ -0,0 +1,51 @@
+[project]
+name = "cloudberry-mcp-server"
+version = "0.1.0"
+description = "MCP server for Apache Cloudberry database interaction"
+readme = "README.md"
+requires-python = ">=3.10"
+authors = [
+    {name = "HashML Team", email = "[email protected]"},
+]
+maintainers = [
+    {name = "Yangshengwen", email = "[email protected]"},
+]
+license = {text = "MIT"}

Review Comment:
   ```suggestion
   license = {text = "Apache-2.0"}
   ```
   
   If we don't include any other files created by the third-party, we need to 
adopt the Apache License v2.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to