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 analysis using Alibaba Cloud DMS MCP Server, simplifying data query generation across diverse databases.

Instructions

Generate SELECT-type SQL queries from natural language input.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_idYesDMS databaseId
knowledgeNoAdditional context
questionYesNatural language question

Implementation Reference

  • Handler function 'nl2sql' for the 'generateSql' tool. Calls Alibaba Cloud DMS Enterprise API to generate SQL from natural language question.
    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.
    self.mcp.tool(name="generateSql", description="Generate SELECT-type SQL queries from natural language input.", annotations={"title": "自然语言转SQL (DMS)", "readOnlyHint": True})(nl2sql)
  • Pydantic model for the output schema of the 'generateSql' tool, containing the generated SQL.
    class SqlResult(MyBaseModel): sql: Optional[str] = Field(description="The generated SQL query")

Other Tools

Related Tools

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