Help Center/ Data Warehouse Service/ Best Practices/ Data for AI Converged Analysis/ Creating a Data Analysis Agent Using DWS MCP Server
Updated on 2026-09-28 GMT+08:00

Creating a Data Analysis Agent Using DWS MCP Server

During enterprise data analysis and operations decision-making, business personnel often need to extract data from data warehouses and generate analysis reports. In traditional mode, business personnel need to submit data requests to developers, who will write SQL statements to query data and return the results to the business personnel. This process usually takes a few days, and frequent communication and iteration further slow down decision-making.

With large language models (LLMs) becoming mature, there is a way for business personnel to directly interact with databases for data query and analysis using natural languages without writing SQL statements.

DWS MCP Server is a solution designed to meet this requirement. It uses the Model Context Protocol (MCP) and provides standard tool interfaces for LLMs to use functions such as metadata query and SQL statement execution. This enables LLMs to automatically understand the database structure, generate SQL statements, execute queries, and interpret and visualize query results.

Through this practice, you can quickly set up a data analysis agent based on DWS, MCP, and LLM to enable one-click data services, including natural language Q&A, automatic SQL statement generation, query execution, and analysis report generation.

Basic Concepts

The following core concepts help you better understand the operations in this practice.

  • Model Context Protocol (MCP) is an open standard proposed by Anthropic in November 2024. It standardizes how LLMs communicate with external systems (such as databases and APIs). MCP provides a standardized interface that allows LLMs to dynamically understand tool functions and perform operations, reducing integration costs. Just as USB provides a unified standardized interface for peripherals, MCP provides a unified standardized interface for AI applications to connect to different systems.
  • MCP Server is a server program that implements MCP. It provides the capabilities of a specific system (such as a database) to MCP-compliant clients in the form of tools and resources. In this document, DWS MCP Server is a server that provides DWS database capabilities to LLMs.
  • MCP Client is a client application that supports MCP. It communicates with the MCP Server and forwards tool invocation requests to LLMs. Common MCP Clients include Cline (a VS Code plugin) and Claude Desktop.
  • Agent is an automation system built on LLMs. It can autonomously plan task steps, invoke external tools, and complete complex workflows based on natural language instructions input by users. The intelligent data analysis agent to be created in this document can automatically query databases and generate analysis reports.
  • uv is a high-performance Python package manager and runner written in Rust. It can quickly install and run Python projects. In this practice, it is used to start the DWS MCP Server. You can install it using pip install uv.
  • Psycopg2 is the most popular PostgreSQL database adapter in Python. DWS is based on the PostgreSQL kernel, so Psycopg2 is used as the driver for connecting the DWS MCP Server and the database.

Function

Currently, the DWS MCP Server supports basic functions such as metadata query, statement execution, and monitoring information query. These functions are available to MCP-compliant clients in the form of tools and resources defined in the MCP. For details about the tools and resources, see Table 1 and Table 2.

Table 1 Database management tools

Name

Description

list_databases

Lists all databases.

get_activity

Obtains the latest query activity from the pgxc_stat_activity view.

execute_query

Executes a SQL query.

list_schemas

List all schemas in the current database.

list_tables

Lists all tables in a specified schema.

list_views

Lists all views in a specified schema.

get_table_info

Obtains the definition of a table or view.

get_comment

Obtains the comments of a schema or table.

Table 2 Available resources

Resource URI

Function

gaussdb:///{schema}/tables

Lists all tables in a specified schema.

gaussdb:///{schema}/views

Lists all views in a specified schema.

gaussdb:///{schema}/{table}/attributes

Lists all columns in a specified table or view.

system:///{system_path}

System information (for example, /version)

Prerequisites

  • A DWS cluster has been created and is available. For details about how to create a cluster, see Creating a DWS Storage-Compute Decoupled Cluster.
  • You have obtained the connection information (host IP address, port number, database name, username, and password) of the DWS cluster. For details, see Obtaining the Connection Address of a DWS Cluster.
  • The client can communicate with the DWS cluster. If the cluster is accessed over an internal network, ensure that the client and the cluster are in the same VPC. If the cluster needs to be accessed over a public network, an EIP needs to be bound to the cluster first.
  • The Python version is 3.10 or later. You can run the python --version or python3 --version command to obtain the current version.
  • The uv version is 0.6.7 or later. You can run the uv --version command to obtain the current version. If uv is not installed, run the pip install uv command to install it.
  • You have installed VS Code and the Cline plugin. If you use another MCP client (such as Claude Desktop), ensure that the client supports stdio transport over MCP.

Step 1: Set Up an Agent and Configure the Server

The following steps use Cline as the client to demonstrate how to configure and use the DWS MCP Server. You can also select another client that supports MCP (such as Claude Desktop) as required. The configuration method is similar.

  1. Download the DWS MCP Server source code from GitHub to the local environment.

    1. Start VS Code and press Ctrl + ` (backquote, the key below Esc in the upper left corner of the keyboard) to open the terminal panel. You can also open it by choosing Terminal > New Terminal from the menu bar.
    2. Run the following command in the terminal to download or update uv:
      If uv has been installed, skip this step.
      pip install uv
    3. Run the following command in the terminal to clone the source code repository:
      git clone https://github.com/HuaweiCloudDeveloper/mcp-server.git

      Note that the source code is downloaded to the huaweicloud_dws_mcp_inner directory by default. Set the directory when configuring Cline later. For example, if you run the clone command in the /home/user/ directory, the source code is downloaded to the /home/user/mcp-server/huaweicloud_dws_mcp_inner directory.

  2. Configure an LLM access credential for Cline so that it can call LLMs for natural language inference and tool calling.

    1. Click the gear icon (settings button) in the upper right corner of the Cline dialog box to access the Cline settings page.
    2. In the API Configuration area on the settings page, set the following information as needed:
      • API Provider: Select the LLM provider you use (such as OpenAI or Anthropic).
      • OpenAI Compatible API Key: Enter the corresponding API key.
    3. Your settings will be automatically saved.

  3. Configure the MCP Server. Register the DWS MCP Server with the Cline client so that it can discover and call the DWS database tool.

    1. Click the MCP icon in the upper right corner of the Cline dialog box to access the MCP configuration page.
    2. Click the Installed tab and click Configure MCP Servers in the lower part. A JSON configuration file is opened.
    3. Enter the following DWS MCP Server configuration in the configuration file. For details about the parameters, see Table 3.
      {
        "mcpServers": {
          "DWS": {
            "disabled": false,
            "timeout": 60,
            "type": "stdio",
            "command": "uv",
            "args": [
              "--directory",
              "/path/to/huaweicloud_dws_mcp_inner",
              "run",
              "server.py"
            ],
            "env": {
              "DB_HOST": "192.168.0.1",
              "DB_PORT": "8000",
              "DB_NAME": "gaussdb",
              "DB_USER": "dbadmin",
              "DB_PWD": "password"
            }
          }
        }
      }

      Table 3 Cline parameters

      Parameter

      Description

      Example

      /path/to/huaweicloud_dws_mcp_inner

      Directory where the MCP Server source code is located

      Replace it with the path of the huaweicloud_dws_mcp_inner directory.

      host_ip

      IP address of the DWS cluster

      192.168.0.1

      port_no

      Port number of the DWS cluster

      8000

      database

      Name of the DWS database

      gaussdb

      username

      Username of the DWS database

      dbadmin

      password

      Password of the DWS database user

      -

  4. If UV is unavailable due to network issues, you can use Python to start the server. The procedure is as follows:

    1. Install dws-mcp-server using pip in the source code directory.
      pip install .
    2. Replace the values of the MCP Server parameters configured on Cline with the following values: Note: Replace /path/to/huaweicloud_dws_mcp_inner/src/server.py with the full path of server.py in the DWS MCP Server source code.
      {
        "mcpServers": {
          "DWS": {
            "disabled": false,
            "timeout": 60,
            "type": "stdio",
            "command": "python",
            "args": [
              "/path/to/huaweicloud_dws_mcp_inner/src/server.py",
            ],
            "env": {
              "DB_HOST": "host_ip",
              "DB_PORT": "port_no",
              "DB_NAME": "database",
              "DB_USER": "username",
              "DB_PWD": "password"
            }
          }
        }
      }

      Save the configuration and check whether the DWS MCP Server is successfully loaded on the Cline MCP page. If it is loaded and the corresponding tools and resources are displayed, the configuration is successful.

  5. To enable the DWS MCP Server to connect to a cluster through Psycopg2, allow traffic through the DWS security group.

    1. Log in to the DWS console. In the navigation pane, choose Cluster > Cluster List. Click the cluster name to view the cluster details.
    2. Click the security group name.
      Figure 1 DWS security group
    3. Click the Inbound Rules tab and check whether traffic from all IP addresses to port 8000 is allowed. If there is no such a rule, add one.

Step 2: Use Natural Language to Execute a SQL Query and Generate a Report

After configuring the client and cluster, you can start using the data analysis agent. The following steps use Cline as the client and the TPC-DS dataset as an example.

Scenario: Analyze the sales data from 1998 to 2002 based on the tables in TPC-DS, gain insights, provide suggestions, and deliver a data analysis report.

DWS MCP Server provides an accurate data source for LLMs. With the inference and analytics capabilities of models, you can obtain data without manually writing SQL query statements. You can use natural language to execute a query with a few clicks and use an LLM to preliminarily analyze and gain insights into the data.

  1. In the Cline dialog box, enter the prompt for the data analysis task you want to run. The following is an example:

    "Analyze the sales trend from 1998 to 2002 based on the TPC-DS data in the database, including the changes in annual sales revenue, rankings of best-selling categories, and seasonal fluctuations. Provide suggestions based on the analysis result."

  2. After the task is sent, Cline calls a model and initiates a series of requests to call tools or resources.

    Most of the requests do not require intervention. You only need to observe the request bodies and choose to approve the requests. (You can enable automatic approval as required.)
    • Parse the task and generate an execution plan. The model understands your intent and breaks down the analysis task into sub-steps.

    • Call tools to obtain metadata. The model automatically calls tools such as list_tables and get_table_info (see Table 1) to learn about the tables and table structures in the database.

    • Generate a SQL statement and execute a query. Based on the metadata information, the model infers and generates a query SQL statement and calls the execute_query tool to obtain specific data.

    • Generate an analysis report. The model organizes the query result into a structured analysis report, which contains data forms and analysis.

    • Output a summary. The model provides key business insights and suggestions.

Summary

By setting up a DWS MCP Server, enterprises and data analysis teams can seamlessly integrate natural language conversations with the DWS data warehouse to enable end-to-end data services such as one-click query, automated report generation, and dynamic analysis. After the configuration in this practice is complete, the LLM directly identifies MCP tool interfaces (such as list_databases and execute_query) and calls these interfaces within security constraints to generate and execute a SQL statement. Metadata query (schemas, tables, and views) is seamlessly connected to service query results. Then, the model can immediately analyze business data to gain insights and generate visual charts and reports. This solution not only significantly lowers the barrier to SQL development and reduces O&M costs, but also accelerates the response to data iteration, providing a highly reliable and scalable technical platform for data-driven decision-making.