<a href="https://smithery.ai/server/@XGenerationLab/xiyan_mcp_server"><img alt="Smithery 安装量" src="https://smithery.ai/badge/@XGenerationLab/xiyan_mcp_server" height="20"/></a>
<a href="https://github.com/XGenerationLab/xiyan_mcp_server" target="_blank">
<img src="https://img.shields.io/github/stars/XGenerationLab/xiyan_mcp_server?style=social" alt="GitHub 星数" />
</a>
<br />
<a href="https://github.com/XGenerationLab/xiyan_mcp_server" >英文</a> | <a href="https://github.com/XGenerationLab/xiyan_mcp_server/blob/main/README_zh.md"> 中文 </a> | <a href="https://github.com/XGenerationLab/xiyan_mcp_server/blob/main/README_ja.md"> 日语 </a><br />
<a href="https://github.com/XGenerationLab/xiyan_mcp_server/blob/main/imgs/dinggroup_out.png">钉钉群</a>|
<a href="https://weibo.com/u/2540915670" target="_blank">微博关注我</a>
在项目中集成此服务器有两种方式,如下所示: 左侧是远程模式,默认模式。需要API密钥来访问服务提供商的析言SQL-qwencoder-32B模型(参见配置)。 另一种模式是本地模式,更安全。不需要API密钥。

"使用MCP + Modelscope API-Inference构建本地数据助手,无需编写任何代码"
下图展示了析言MCP服务器在MCPBench基准测试中的性能表现。析言MCP服务器相比MySQL MCP服务器和PostgreSQL MCP服务器表现出色,领先2-22个百分点。详细的实验结果可以在MCPBench和报告"对MCP服务器的评估报告"中找到。

工具 get_data 提供了一个自然语言接口来从数据库检索数据。该服务器会将输入的自然语言转换成SQL,并调用数据库返回查询结果。
资源 {dialect}://{table_name} 允许在指定特定表名时从数据库获取部分样本数据以供模型参考。
资源 {dialect}:// 将列出当前数据库的名称
需要Python 3.11+。 你可以通过pip安装服务器,它会安装最新版本:
pip install xiyan-mcp-server
如果你想从源码安装开发版本,可以从github源码安装:
pip install git+https://github.com/XGenerationLab/xiyan_mcp_server.git
参见@XGenerationLab/xiyan_mcp_server
尚未完全测试。
你需要一个YAML配置文件来配置服务器。 提供了一个默认配置文件config_demo.yml,看起来像这样:
mcp:
transport: "stdio"
model:
name: "XGenerationLab/XiYanSQL-QwenCoder-32B-2412"
key: ""
url: "https://api-inference.modelscope.cn/v1/"
database:
host: "localhost"
port: 3306
user: "root"
password: ""
database: ""
你可以设置传输协议为 stdio 或 sse。
对于stdio协议,可以设置如下:
mcp:
transport: "stdio"
对于sse协议,可以设置mcp配置如下:
mcp:
transport: "sse"
port: 8000
log_level: "INFO"
默认端口是 8000。如果需要,可以更改端口。
默认日志级别是 ERROR。我们建议将日志级别设置为 INFO 以获得更多信息。
其他配置如 debug、host、sse_path、message_path 也可以自定义,但通常不需要修改它们。
name 是要使用的模型名称,key 是模型的API密钥,url 是模型的API URL。我们支持以下模型。
| 版本 | 通用LLM(GPT, qwenmax) | Modelscope的最佳模型 | Dashscope的最佳模型 | 本地LLM |
|---|---|---|---|---|
| 描述 | 基础,易于使用 | 性能最佳,稳定,推荐 | 性能最佳,用于试用 | 较慢,高安全性 |
| 名称 | 正式模型名称(例如gpt-3.5-turbo, qwen-max) | XGenerationLab/XiYanSQL-QwenCoder-32B-2412 | xiyansql-qwencoder-32b | xiyansql-qwencoder-3b |
| 密钥 | 服务提供商的API密钥(例如OpenAI, 阿里云) | Modelscope的API密钥 | 通过邮件获取的API密钥 | "" |
| URL | 服务提供商的端点(例如"https://api.openai.com/v1") | https://api-inference.modelscope.cn/v1/ | https://xiyan-stream.biz.aliyun.com/service/api/xiyan-sql | http://localhost:5090 |
如果你想使用通用LLM,例如gpt3.5,可以直接配置如下:
model:
name: "gpt-3.5-turbo"
key: "YOUR KEY "
url: "https://api.openai.com/v1"
database:
如果你想使用来自阿里云的Qwen,例如Qwen-max,可以使用以下配置:
model:
name: "qwen-max"
key: "YOUR KEY "
url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
database:
我们推荐使用析言SQL-qwencoder-32B(https://github.com/XGenerationLab/XiYanSQL-QwenCoder),这是文本到SQL的最佳模型,请参阅[Bird基准](https://bird-bench.github.io/)。 有两种使用该模型的方式。你可以选择其中一种。 (1) Modelscope,(2) 阿里云DashScope。
你需要从Modelscope申请一个API-inference的key,https://www.modelscope.cn/docs/model-service/API-Inference/intro
然后你可以使用以下配置:
model:
name: "XGenerationLab/XiYanSQL-QwenCoder-32B-2412"
key: ""
url: "https://api-inference.modelscope.cn/v1/"
阅读我们的模型描述以了解更多信息。
我们在阿里云DashScope上部署了该模型,因此你需要设置以下环境变量:
发送你的电子邮件给我以获取key。(godot.lzl@alibaba-inc.com)
在邮件中,请附上以下信息:
name: "YOUR NAME",
email: "YOUR EMAIL",
organization: "your college or Company or Organization"
我们将根据您的电子邮件发送key。然后您可以在yml文件中填写key。
key将在1个月或200次查询或其他法律限制后过期。
model:
name: "xiyansql-qwencoder-32b"
key: "KEY"
url: "https://xiyan-stream.biz.aliyun.com/service/api/xiyan-sql"
注意:此模型服务仅用于试用,如果您需要在生产环境中使用,请联系我们。
或者,你也可以在自己的服务器上部署模型XiYanSQL-qwencoder-32B。 详见本地模型。
host、port、user、password、database 是数据库的连接信息。
你可以使用本地或任何远程数据库。目前我们支持MySQL和PostgreSQL(更多方言即将推出)。
database:
host: "localhost"
port: 3306
user: "root"
password: ""
database: ""
步骤1:安装Python包
pip install psycopg2
步骤2:准备config.yml如下:
database:
dialect: "postgresql"
host: "localhost"
port: 5432
user: ""
password: ""
database: ""
请注意,对于PostgreSQL,dialect应为postgresql。
如果你想使用sse启动服务器,你需要在终端运行以下命令:
YML=path/to/yml python -m xiyan_mcp_server
然后你应该能在浏览器中看到http://localhost:8000/sse的信息。(默认情况下,如果您的MCP服务器运行在其他主机/端口上,请相应更改)
否则,如果你使用的是stdio传输协议,通常会在特定的MCP应用程序中声明MCP服务器命令,而不是在终端中启动它。
然而,如果需要,你仍然可以使用这个命令进行调试。
在你的Claude Desktop配置文件中添加以下内容,参见<a href="https://github.com/XGenerationLab/xiyan_mcp_server/blob/main/imgs/claude_desktop.jpg">Claude Desktop配置示例</a>
{
"mcpServers": {
"xiyan-mcp-server": {
"command": "/xxx/python",
"args": [
"-m",
"xiyan_mcp_server"
],
"env": {
"YML": "PATH/TO/YML"
}
}
}
}
请注意,这里的Python命令需要完整的Python可执行文件路径(/xxx/python);否则,Python解释器将无法找到。你可以使用命令which python确定这个路径。其他应用程序也是如此。
Claude Desktop目前不支持SSE传输协议。
准备配置类似于Claude Desktop
如果你使用stdio,在配置中添加以下命令,参见<a href="https://github.com/XGenerationLab/xiyan_mcp_server/blob/main/imgs/goose.jpg">Goose配置示例</a>
env YML=path/to/yml /xxx/python -m xiyan_mcp_server
否则,如果你使用sse,将类型改为SSE并设置端点为http://127.0.0.1:8000/sse
使用类似的命令如下。
对于stdio:
{
"mcpServers": {
"xiyan-mcp-server": {
"command": "/xxx/python",
"args": [
"-m",
"xiyan_mcp_server"
],
"env": {
"YML": "path/to/yml"
}
}
}
}
对于sse:
{
"mcpServers": {
"xiyan-mcp_server_1": {
"url": "http://localhost:8000/sse"
}
}
}
在命令中添加以下内容:
/xxx/python -m xiyan_mcp_server
添加一个环境变量:键是YML,值是你yml文件的路径。 参见<a href="https://github.com/XGenerationLab/xiyan_mcp_server/blob/main/imgs/witsy.jpg">Witsy配置示例</a>
如果您对我们研究或产品感兴趣,请随时联系我们。
刘一夫,zhencang.lyf@alibaba-inc.com
<a href="https://github.com/XGenerationLab/XiYan-SQL/blob/main/xiyansql_dingding.png">钉钉群</a>
如果您发现我们的工作有所帮助,请随意引用我们。
@article{XiYanSQL,
title={析言-SQL: 一种新颖的多生成器框架用于文本到SQL},
author={刘一夫, 朱胤, 高颖奇, 罗智玲