Skip to main content
Glama
aliyun

Alibaba Cloud DMS MCP Server

Official
by aliyun

generateSql

Convert natural language questions into SELECT SQL queries for database querying using Alibaba Cloud DMS MCP Server.

Instructions

Generate SELECT-type SQL queries from natural language input.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_idYesDMS databaseId
questionYesNatural language question
knowledgeNoOptional: additional context
modelNoOptional: if a specific model is desired, it can be specified here

Implementation Reference

  • The handler function `nl2sql` that implements the core logic of the `generateSql` tool by calling the Alibaba Cloud DMS Enterprise API `generate_sql_from_nl` to convert natural language to SQL.
    async def nl2sql( database_id: str = Field(description="DMS databaseId"), question: str = Field(description="Natural language question"), knowledge: Optional[str] = Field(default=None, description="Optional: additional context"), model: Optional[str] = Field(default=None, description="Optional: if a specific model is desired, it can be specified here") ) -> SqlResult: client = create_client() req = dms_enterprise_20181101_models.GenerateSqlFromNLRequest(db_id=database_id, question=question) if knowledge: req.knowledge = knowledge if mcp.state.real_login_uid: req.real_login_user_uid = mcp.state.real_login_uid if model: req.model = model try: resp = client.generate_sql_from_nl(req) if not resp or not resp.body: return SqlResult(sql=None) data = resp.body.to_map() sql_content = data.get('Data', {}).get('Sql') if data else None return SqlResult(sql=sql_content) except Exception as e: logger.error(f"Error in nl2sql_explicit_db: {e}") raise
  • Registration of the `generateSql` tool, binding the `nl2sql` handler function to the MCP tool named `generateSql`.
    self.mcp.tool(name="generateSql", description="Generate SELECT-type SQL queries from natural language input.", annotations={"title": "自然语言转SQL (DMS)", "readOnlyHint": True})(nl2sql)
  • Pydantic model defining the output schema for the `generateSql` tool, containing the generated SQL string.
    class SqlResult(MyBaseModel): sql: Optional[str] = Field(description="The generated SQL query")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aliyun/alibabacloud-dms-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server