xiyan_mcp_server
by: XGenerationLab
A Model Context Protocol (MCP) server that enables natural language queries to databases
๐Overview
Purpose: The XiYan MCP Server facilitates interaction with databases through natural language queries, powered by advanced text-to-SQL capabilities.
Overview: The XiYan MCP Server implements a Model Context Protocol (MCP) that enables users to seamlessly perform database queries using natural language. Leveraging the XiYan-SQL framework, it showcases state-of-the-art performance in text-to-SQL applications and provides flexible integration options, including local and remote modes.
Key Features:
-
Natural Language Data Retrieval: Users can query databases using natural language, which the system converts to SQL queries, simplifying the interaction with complex data systems.
-
Support for Multiple Database Systems: The server supports popular database dialects, specifically MySQL and PostgreSQL, offering flexibility in deployment.
-
Local Mode for Enhanced Security: A pure local mode option is available, allowing users to operate without an API key, thereby enhancing security and privacy.
-
Integration with Advanced LLMs: It supports both general Large Language Models (LLMs) and specialized state-of-the-art models, enabling diverse applications based on user needs.
XiYan MCP Server
A Model Context Protocol (MCP) server that enables natural language queries to databases
powered by XiYan-SQL, SOTA of text-to-sql on open benchmarks
๐ป XiYan-mcp-server |
๐ XiYan-SQL |
๐ Arxiv |
๐ PapersWithCode |
๐ป HuggingFace |
๐ค ModelScope |
๐ ๆ่จGBI
[English] | ไธญๆ
Follow me on Weibo
Table of Contents
- Features
- Preview
- Architecture
- Best Practice
- Tools Preview
- Installation
- Installing from pip
- Installing from Smithery.ai
- Configuration
- LLM Configuration
- General LLMs
- Text-to-SQL SOTA model
- Local Model
- Database Configuration
- MySQL
- PostgreSQL
- LLM Configuration
- Launch
- Claude Desktop
- Cline
- Goose
- Cursor
- Witsy
- It Does Not Work
- Citation
Features
- ๐ Fetch data by natural language through XiYanSQL
- ๐ค Support general LLMs (GPT, qwenmax), Text-to-SQL SOTA model
- ๐ป Support pure local mode (high security!)
- ๐ Support MySQL and PostgreSQL
- ๐ฑ๏ธ List available tables as resources
- ๐ง Read table contents
Preview
Architecture
There are two integration modes for this server:
- Remote mode (default): Requires an API key to access the xiyanSQL-qwencoder-32B model from a service provider (see Configuration).
- Local mode: More secure, does not require an API key.
Best Practice and Reports
- "Build a local data assistant using MCP + Modelscope API-Inference without writing a single line of code"
- "Xiyan MCP on Modelscope"
Evaluation on MCPBench
XiYan MCP server outperforms MySQL MCP and PostgreSQL MCP servers by 2-22 percentage points on MCPBench. Detailed results: MCPBench, report Evaluation Report on MCP Servers.
Tools Preview
get_data
: Natural language interface to query databases. Converts natural language to SQL using a built-in model and returns query results.{dialect}://{table_name}
: Retrieves sample data from a specified table for model reference.{dialect}://
: Lists current database names.
Installation
Installing from pip
Requires Python 3.11+.
Install with pip:
pip install xiyan-mcp-server
Run the server:
python -m xiyan_mcp_server
To use, create a YAML config file and then run:
env YML=path/to/yml python -m xiyan_mcp_server
Installing from Smithery.ai
Visit @XGenerationLab/xiyan_mcp_server (not fully tested).
Configuration
Use a YAML config file to configure the server. Example 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: ""
LLM Configuration
Version | General LLMs (GPT, qwenmax) | SOTA model by Modelscope | SOTA model by Dashscope | Local LLMs |
---|---|---|---|---|
Description | basic, easy to use | best performance, stable, recommended | best performance, for trial | slow, high-security |
Name | official model name (e.g. gpt-3.5-turbo) | XGenerationLab/XiYanSQL-QwenCoder-32B-2412 | xiyansql-qwencoder-32b | xiyansql-qwencoder-3b |
Key | API key from provider (OpenAI, Alibaba) | API key of Modelscope | API key via email | "" |
URL | provider endpoint (e.g. OpenAI API URL) | https://api-inference.modelscope.cn/v1/ | https://xiyan-stream.biz.aliyun.com/service/api/xiyan-sql | http://localhost:5090 |
General LLMs
Example config for GPT-3.5:
model:
name: "gpt-3.5-turbo"
key: "YOUR KEY"
url: "https://api.openai.com/v1"
database:
For Alibaba Qwen-max:
model:
name: "qwen-max"
key: "YOUR KEY"
url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
database:
Text-to-SQL SOTA model
Recommended: XiYanSQL-qwencoder-32B (GitHub), SOTA on Bird benchmark.
Two usage options: Modelscope or Alibaba Cloud DashScope.
(1) Modelscope version
Get API key from Modelscope (API docs):
model:
name: "XGenerationLab/XiYanSQL-QwenCoder-32B-2412"
key: ""
url: "https://api-inference.modelscope.cn/v1/"
(2) Dashscope version
Set environment variables with a key requested by email to godot.lzl@alibaba-inc.com:
name: "YOUR NAME"
email: "YOUR EMAIL"
organization: "Your organization"
Example config:
model:
name: "xiyansql-qwencoder-32b"
key: "KEY"
url: "https://xiyan-stream.biz.aliyun.com/service/api/xiyan-sql"
database:
Note: This service is for trial only. Contact for production use. You can also deploy the model yourself.
Local Model
Slow (~12 seconds per query). For a stable and fast service, use Modelscope version.
Requirements:
- PC/Mac with at least 16GB RAM
- 6GB disk space
Steps:
- Install dependencies:
pip install flask modelscope torch==2.2.2 accelerate>=0.26.0 numpy=2.2.3
- (Optional) Download model manually:
modelscope download --model XGenerationLab/XiYanSQL-QwenCoder-3B-2502
- Run local server:
python local_xiyan_server.py
Server runs at http://localhost:5090/.
- Sample config:
model:
name: "xiyansql-qwencoder-3b"
key: "KEY"
url: "http://127.0.0.1:5090"
Database Configuration
Connection info: host
, port
, user
, password
, database
.
Supports MySQL and PostgreSQL.
MySQL
database:
host: "localhost"
port: 3306
user: "root"
password: ""
database: ""
PostgreSQL
Install driver:
pip install psycopg2
Config example:
database:
dialect: "postgresql"
host: "localhost"
port: 5432
user: ""
password: ""
database: ""
Launch
Claude Desktop
Add to Claude Desktop config:
{
"mcpServers": {
"xiyan-mcp-server": {
"command": "python",
"args": ["-m", "xiyan_mcp_server"],
"env": {"YML": "PATH/TO/YML"}
}
}
}
Cline
Same config as Claude Desktop.
Goose
Run with:
env YML=path/to/yml python -m xiyan_mcp_server
Cursor
Use same command as Goose.
Witsy
Command:
python -m xiyan_mcp_server
Add environment variable key YML
with value as the path to your yml file.
It Does Not Work!
Contact:
Ding Group้้็พค
Follow on Weibo
Citation
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}
}