The Model Context Protocol (MCP) establishes a communication channel between large language models (LLMs) and external tools. This topic describes how to configure the Data Management (DMS) MCP to securely access databases hosted in DMS using a multicloud-compatible MCP Server.
Background information
Traditional database MCP implementations have the following limitations:
-
Limited compatibility with heterogeneous databases: Traditional implementations support connections to and operations on only databases of the same type, which makes unified cross-platform management impossible.
-
No account and permission management: They lack a centralized capability to manage credentials independently and rely on manual maintenance, which introduces security risks.
-
Limited SQL operations: They support only basic, standard SQL statements that are entered manually and cannot parse complex or non-standard syntax.
-
No built-in NL2SQL support: They do not support natural language to SQL (NL2SQL) queries and require integration with an external LLM to use this feature.
DMS MCP addresses these issues by providing LLMs with unified data ingestion and access capabilities through standardized interfaces that resolve compatibility and security challenges. Additionally, DMS MCP unlocks new features, such as retrieving schema information, generating Data Access Object (DAO) code, performing structural analysis, and using automatic SQL routing to accurately retrieve data for upper-layer applications.
Core features of DMS MCP
-
Secure access
-
Secure credential hosting: DMS securely manages database usernames and passwords. This eliminates the need for manual handling and prevents sensitive information leaks.
-
Private network access: You can access databases over a private network without exposing public endpoints. This ensures data security and privacy.
-
Fine-grained access control: You can enforce precise permissions at the instance, database, table, column, and row levels to prevent unauthorized operations and protect data.
-
Detection and blocking of high-risk SQL statements: Built-in security rules identify and block potentially dangerous SQL statements in real time to mitigate security risks.
-
SQL auditing and traceability: All SQL operations are logged for full traceability and compliance auditing to meet regulatory requirements.
-
-
Intelligent querying
-
Built-in NL2SQL algorithm: This feature converts natural language questions into SQL queries by intelligently matching relevant tables and understanding their business context. The query is then executed to return results quickly.
-
Customizable knowledge base: This feature includes built-in metadata and a query knowledge base. You can customize business knowledge and query patterns to build an intelligent querying capability that is tailored to your specific scenarios.
-
-
Support for multiple data sources
-
Unified management of diverse data sources: DMS MCP supports more than 40 mainstream databases and data warehouses, which enables unified access to multiple data types.
-
Centralized multi-environment management: You can manage data sources across development, testing, and production environments from a single interface. This improves operations and maintenance (O&M) efficiency.
-
Seamlessly integrates with mainstream cloud platforms, such as Alibaba Cloud and AWS, and self-managed databases and data warehouses to effectively reduce maintenance costs.
-
Workflow diagram
The following diagram shows the data access workflow when a client sends a request.
Scenarios
Scenario 1: Generate DAO (Data Access Object) code with AI IDEs like Tongyi Lingma
The following compares traditional development workflows with intelligent development using DMS MCP.
-
Traditional workflow: You manually run table-creation SQL statements using a database tool, write DAO code in an integrated development environment (IDE), build data using a database tool, and then preview the data.
-
Intelligent development workflow: You design tables in an AI IDE, allow DMS MCP to automatically execute table-creation SQL statements, auto-generate DAO code in the IDE, use MCP to intelligently build data, and then preview the results.
Scenario 2: Use DMS NL2SQL to get data statistics directly
Marketing analysts can use DMS NL2SQL to retrieve statistical results using natural language, which makes it easier to analyze data trends.
For a demonstration video, see DMS MCP usage example.
Pricing
DMS MCP is currently in public preview and is available at no cost.
If you need more information about this solution, fill out the form to provide your contact details or join the DingTalk group (ID: 129600002740) to contact DMS technical support.
Preparations
Before you can use DMS MCP to access databases hosted in DMS, you must register your database instances in DMS and enable security hosting for each instance. You can use one of the following methods to register instances:
Method 1: Register Alibaba Cloud database instances using the DMS MCP tool
-
This method supports only Alibaba Cloud database instances.
-
Instances registered using this tool automatically have security hosting enabled by default.
The DMS MCP Server provides an addInstance tool to help you quickly register instances in DMS. In your MCP-integrated agent, which is a conversational AI application, you can instruct the LLM to register an instance by providing its details, such as the instance ID, database username, password, and region. The LLM then automatically invokes the appropriate tool.
Method 2: Register Alibaba Cloud, other-cloud, or self-managed database instances via the DMS console
This method supports Alibaba Cloud database instances, database instances on other clouds, and self-managed database instances. The following steps use an Alibaba Cloud ApsaraDB RDS for MySQL database as an example.
Log in to DMS 5.0.
On the left side of the console homepage, in the Database Instances section, click the Add Instance
icon.NoteYou can also enter Instances in the search box on the homepage, click Instances in the search results, and then click New.
-
On the Add Instance page, enter the instance information.
Category
Configuration item
Description
Data source
-
Default is Alibaba Cloud - MySQL. You can change the database type.
Basic information
Database type
Select the database instance type.
NoteAfter selecting a database type, DMS automatically refreshes the configuration items on the Basic Information page.
Instance region
Select the region where the database instance resides.
Other primary accounts
NoteThis field appears only if you select Cross Alibaba Cloud Account Instance.
Enter the ARN of the RAM role under the Alibaba Cloud account (root account) that owns the instance. For required permissions, see Authorization operations.
In the RAM console, go to Identity Management > Roles, click the target role name to open its details page, and copy the value from the ARN field under Basic Information.
Registration method
Select how to register the database instance. Options are Instance ID or Connection string.
Instance ID or Connection string
Enter the Instance ID or Connection string.
NoteA connection string consists of a private endpoint and port. For RDS MySQL, the format is rm-XXXXXXX.mysql.rds.aliyuncs.com:3306.
Access method
Enabling security hosting prevents direct exposure of credentials and enables fine-grained permission control.
-
Security Hosting - Auto (recommended): DMS automatically enables security hosting and creates a database username and password for DMS access.
Note-
This option appears only when registering RDS instances.
-
You can view the auto-created account in the RDS console. Do not modify or delete it, as this may affect DMS functionality.
-
Except for RDS PostgreSQL instances, auto-created accounts on other RDS instances cannot create databases or database accounts.
-
-
Security Hosting - Manual: DMS automatically enables security hosting, but you must manually enter an existing database username and password.
-
Security Hosting - KMS: DMS automatically enables security hosting, but you must manually select an RDS credential created in KMS for database access.
NoteThis option appears only when registering RDS instances.
Value-added feature package
Select feature packages as needed.
-
Security Collaboration or Stable Change (choose one).
NoteIf you do not select the paid Security Collaboration or Stable Change feature packages, the instance defaults to Flexible Management (free).
-
Sensitive Data Protection (paid).
Security rules
This field appears only if you select Security Collaboration.
You can choose system-default or custom security rules for fine-grained database control.
Classification and grading template
This field appears only when Sensitive Data Protection is enabled. For details, see Classification and grading template.
Advanced information
-
You can keep the default values for parameters in this section. For details, see Register ApsaraDB instances.
-
After configuring the parameters, click Test Connection in the lower-left corner.
NoteIf the connection test fails, check the instance information based on the error message.
-
After the Connection successful message appears, click Submit.
The database instance is successfully registered in DMS.
For more information about the registration procedures, see Register ApsaraDB instances and Register other-cloud or self-managed database instances.
Usage modes
DMS MCP Server supports two usage modes.
|
Mode |
Applicable scenario |
|
Mode 1: Multi-instance mode |
Use this mode to manage and access multiple database instances across different environments. Register all instances in DMS and manage them through DMS MCP Server. |
|
Mode 2: Single-database mode |
Use this mode when accessing a single database. Configure the CONNECTION_STRING parameter in the server to specify the target database. When the service starts, DMS MCP Server accesses the specified database directly. Format: In the DMS console, find the database in the list on the left, double-click its name, and use the SQL window to quickly obtain the After opening the SQL window, view the value in the connection info bar at the top, for example: |
Quick start
Option 1: Run using a PyPI package
-
Obtain an AccessKey or a Security Token Service (STS) token that has the AliyunDMSFullAccess permissions for Data Management (DMS).
For more information about how to add permissions, see Authorization management.
-
Add the following configuration to your MCP client's configuration file.
-
Multi-instance mode
{ "mcpServers": { "dms-mcp-server": { "command": "uvx", "args": [ "alibabacloud-dms-mcp-server@latest" ], "env": { "ALIBABA_CLOUD_ACCESS_KEY_ID": "access_id", "ALIBABA_CLOUD_ACCESS_KEY_SECRET": "access_key", "ALIBABA_CLOUD_SECURITY_TOKEN": "sts_security_token optional, required when using STS Token" } } } } -
Single-database mode
{ "mcpServers": { "dms-mcp-server": { "command": "uvx", "args": [ "alibabacloud-dms-mcp-server@latest" ], "env": { "ALIBABA_CLOUD_ACCESS_KEY_ID": "access_id", "ALIBABA_CLOUD_ACCESS_KEY_SECRET": "access_key", "ALIBABA_CLOUD_SECURITY_TOKEN": "optional sts_security_token, required when using STS Token", "CONNECTION_STRING": "dbName@host:port" } } } }
-
Option 2: Use the MCP service hosted in DMS
Log in to DMS 5.0.
-
Activate the MCP service.
-
In the lower-right corner, move the mouse pointer over the MCP icon
and click Activate Now in the dialog box that appears.The DMS MCP dialog box displays four core features: Credential Security (built-in credential hosting), Secure Execution (private network access and fine-grained permissions), Unified Compatibility (support for more than 40 mainstream data sources), and Intelligent Querying (built-in NL2SQL). The dialog box also provides quick links to product documentation and demonstration videos.
-
Select the activation scope for the MCP service.
-
All databases: All database instances that you registered by following the steps in the Prerequisites section.
-
Specific database: One of the database instances that you registered by following the steps in the Prerequisites section.
NoteIf you select Specific database, you must also select a target database.
-
-
Click Confirm Activation.
-
-
After the service is activated, view the MCP configuration information.
NoteMove the mouse pointer over the MCP icon
in the lower-right corner to view the MCP configuration in the dialog box that appears. -
Integrate the DMS MCP service into your AI agent and start using it.
Note-
When you use the DMS MCP service, you must set the Bearer Token in the Authorization header based on the value of the Authorization field in the MCP configuration example described in Step 3.
-
To change the database scope of the MCP Server, you can first cancel the MCP Server. To do this, move the mouse pointer over the MCP icon
, click Cancel Service, and then click Confirm Cancellation in the dialog box that appears. After the service is canceled, you can activate the MCP Server again.
-
Option 3: Use DMS MCP service hosted on other platforms
You can use the DMS MCP service on Alibaba Cloud Model Studio, ModelScope, and Function AI.
Tools supported by DMS MCP
|
Tool name |
Description |
Supported mode |
|
|
Registers an instance in DMS. If the instance already exists, returns its information. |
Multi-instance mode |
|
|
Searches for a list of instances in DMS. |
Multi-instance mode |
|
|
Gets detailed instance information by host and port. |
Multi-instance mode |
|
|
Searches for databases by schemaName. |
Multi-instance mode |
|
|
Gets detailed information for a specific database. |
Multi-instance mode |
|
|
Searches for tables in a specified database. |
Multi-instance mode & single-database mode |
|
|
Gets detailed information for a specific database table. |
Multi-instance mode & single-database mode |
|
|
Executes an SQL script and returns the result. |
Multi-instance mode & single-database mode |
|
|
Creates a data change ticket to submit DDL/DML operation requests. |
Multi-instance mode & single-database mode |
|
|
Queries ticket details, including status, approval workflow, and execution logs. |
Multi-instance mode & single-database mode |
|
|
Submits a ticket to the approval workflow for review before execution. |
Multi-instance mode & single-database mode |
|
|
Converts natural language questions into executable SQL statements. |
Multi-instance mode |
|
|
Queries databases using natural language (NL2SQL + SQL execution). |
Single-database mode |
|
|
Automatically fixes SQL statements with syntax or logic errors. |
Multi-instance mode & single-database mode |
|
|
Provides explanations and suggestions for SQL syntax issues. |
Multi-instance mode & single-database mode |
|
|
Analyzes and optimizes SQL statements to improve execution efficiency. |
Multi-instance mode & single-database mode |