The XiYan MCP Server is a Model Context Protocol (MCP) server designed to enable natural language queries to databases. Powered by XiYan-SQL, it provides state-of-the-art text-to-SQL capabilities, making it easier to interact with databases using plain language.
The server supports two integration modes:
1. Remote Mode: Requires an API key to access the XiYanSQL-QwenCoder-32B model from a service provider.
2. Local Mode: More secure, does not require an API key.
Learn how to build a local data assistant using MCP + Modelscope API-Inference without writing a single line of code: Best Practice Guide
Python 3.11+ is required. Install the server via pip:
pip install xiyan-mcp-server
Run the server:
python -m xiyan_mcp_server
After configuring the YAML file, run the server with:
env YML=path/to/yml python -m xiyan_mcp_server
For installation via Smithery.ai, visit: @XGenerationLab/xiyan_mcp_server
A YAML configuration file is required. Below is a sample config_demo.yml
:
model:
name: "XGenerationLab/XiYanSQL-QwenCoder-32B-2412"
key: ""
url: "https://api-inference.modelscope.cn/v1/"
database:
host: "localhost"
port: 3306
user: "root"
password: ""
database: ""
Supported models include general LLMs, Text-to-SQL SOTA models, and local LLMs.
Example configuration for GPT-3.5:
model:
name: "gpt-3.5-turbo"
key: "YOUR_KEY"
url: "https://api.openai.com/v1"
For XiYanSQL-QwenCoder-32B, use:
model:
name: "XGenerationLab/XiYanSQL-QwenCoder-32B-2412"
key: "YOUR_KEY"
url: "https://api-inference.modelscope.cn/v1/"
To run the server in local mode:
pip install flask modelscope torch==2.2.2 accelerate>=0.26.0 numpy=2.2.3
modelscope download --model XGenerationLab/XiYanSQL-QwenCoder-3B-2502
python local_xiyan_server.py
model:
name: "xiyansql-qwencoder-3b"
key: "KEY"
url: "http://127.0.0.1:5090"
Supported databases include MySQL and PostgreSQL.
Example configuration:
database:
host: "localhost"
port: 3306
user: "root"
password: ""
database: ""
Example configuration:
database:
dialect: "postgresql"
host: "localhost"
port: 5432
user: ""
password: ""
database: ""
Add the following to your Claude Desktop config file:
{
"mcpServers": {
"xiyan-mcp-server": {
"command": "python",
"args": ["-m", "xiyan_mcp_server"],
"env": {
"YML": "PATH/TO/YML"
}
}
}
}
Prepare the config similar to Claude Desktop.
Add the following command in the config:
env YML=path/to/yml python -m xiyan_mcp_server
Use the same command as Goose.
Add the following in the command:
python -m xiyan_mcp_server
Set the environment variable YML
to the path of your YAML file.
For support, contact us via Ding Group or Weibo.
If you find our work helpful, please cite:
@article{xiyansql,
title={A Preview of XiYan-SQL: A Multi-Generator Ensemble Framework for Text-to-SQL},
author={Yingqi Gao and Yifu Liu and Xiaoxia Li and Xiaorong Shi and Yin Zhu and Yiming Wang and Shiqi Li and Wei Li and Yuntao Hong and Zhiling Luo and Jinyang Gao and Liyu Mou and Yu Li},
year={2024},
journal={arXiv preprint arXiv:2411.08599},
url={https://arxiv.org/abs/2411.08599},
primaryClass={cs.AI}
}
The XiYan MCP Server is a powerful tool for enabling natural language queries to databases, making database interactions more intuitive and efficient.