返回市场
细烟_mcp服务器

细烟_mcp服务器

作者:XGenerationLab218 星标更新:2025-09-26

项目介绍

技术文档摘要

<h1 align="center">析言 MCP 服务器</h1> <p align="center"> <a href="https://github.com/XGenerationLab/XiYan-SQL"><img alt="MCP Playwright" src="https://gips2.baidu.com/it/u=1543276661,3417375918&fm=3081&app=3081&f=PNG?w=264&h=62" height="60"/></a> </p> <p align="center"> <b>一个模型上下文协议(MCP)服务器,支持通过自然语言查询数据库</b><br/> <sub>由 <a href="https://github.com/XGenerationLab/XiYan-SQL" >析言-SQL</a> 提供支持,开源基准测试中的文本到SQL最佳模型</sub> </p> <p align="center"> 💻 <a href="https://github.com/XGenerationLab/xiyan_mcp_server" >析言-mcp-server</a> | 🌐 <a href="https://github.com/XGenerationLab/XiYan-SQL" >析言-SQL</a> | 📖 <a href="https://arxiv.org/abs/2507.04701"> Arxiv</a> | 🏆 <a href="https://github.com/XGenerationLab/XiYanSQL-QwenCoder" >析言SQL 模型</a> | 📄 <a href="https://paperswithcode.com/paper/xiyan-sql-a-multi-generator-ensemble" >PapersWithCode</a> 🤗 <a href="https://huggingface.co/collections/XGenerationLab/xiyansql-models-67c9844307b49f87436808fc">HuggingFace</a> | 🤖 <a href="https://modelscope.cn/collections/XiYanSQL-Models-4483337b614241" >ModelScope</a> | 🌕 <a href="https://bailian.console.aliyun.com/xiyan">析言GBI</a> <br /> <img src="https://badge.mcpx.dev/?type=server%20%27MCP%20Server%27" alt="MCP Server" /> <a href="https://arxiv.org/abs/2411.08599"><img src="imgs/Paper-Arxiv-orange.svg" ></a> <a href="https://opensource.org/licenses/Apache-2.0"> <img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License: Apache 2.0" /> </a> <a href="https://pepy.tech/projects/xiyan-mcp-server"><img src="https://static.pepy.tech/badge/xiyan-mcp-server" alt="PyPI 下载量"></a>

信任评分 <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>

</p>

目录

功能

  • 🌐 通过 析言SQL 使用自然语言获取数据
  • 🤖 支持通用LLM(GPT, qwenmax),文本到SQL最佳模型
  • 💻 支持纯本地模式(高安全性!)
  • 📝 支持MySQL和PostgreSQL。
  • 🖱️ 列出可用表作为资源
  • 🔧 读取表内容

预览

架构

在项目中集成此服务器有两种方式,如下所示: 左侧是远程模式,默认模式。需要API密钥来访问服务提供商的析言SQL-qwencoder-32B模型(参见配置)。 另一种模式是本地模式,更安全。不需要API密钥。

architecture.png

最佳实践和报告

"使用MCP + Modelscope API-Inference构建本地数据助手,无需编写任何代码"

"析言MCP在Modelscope上的应用"

在MCPBench上的评估

下图展示了析言MCP服务器在MCPBench基准测试中的性能表现。析言MCP服务器相比MySQL MCP服务器和PostgreSQL MCP服务器表现出色,领先2-22个百分点。详细的实验结果可以在MCPBench和报告"对MCP服务器的评估报告"中找到。

exp_mcpbench.png

工具预览

  • 工具 get_data 提供了一个自然语言接口来从数据库检索数据。该服务器会将输入的自然语言转换成SQL,并调用数据库返回查询结果。

  • 资源 {dialect}://{table_name} 允许在指定特定表名时从数据库获取部分样本数据以供模型参考。

  • 资源 {dialect}:// 将列出当前数据库的名称

安装

从pip安装

需要Python 3.11+。 你可以通过pip安装服务器,它会安装最新版本:

pip install xiyan-mcp-server

如果你想从源码安装开发版本,可以从github源码安装:

pip install git+https://github.com/XGenerationLab/xiyan_mcp_server.git

从Smithery.ai安装

参见@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: ""

MCP配置

你可以设置传输协议为 stdiosse

STDIO

对于stdio协议,可以设置如下:

mcp:
  transport: "stdio"

SSE

对于sse协议,可以设置mcp配置如下:

mcp:
  transport: "sse"
  port: 8000
  log_level: "INFO"

默认端口是 8000。如果需要,可以更改端口。 默认日志级别是 ERROR。我们建议将日志级别设置为 INFO 以获得更多信息。

其他配置如 debughostsse_pathmessage_path 也可以自定义,但通常不需要修改它们。

LLM配置

name 是要使用的模型名称,key 是模型的API密钥,url 是模型的API URL。我们支持以下模型。

版本通用LLM(GPT, qwenmax)Modelscope的最佳模型Dashscope的最佳模型本地LLM
描述基础,易于使用性能最佳,稳定,推荐性能最佳,用于试用较慢,高安全性
名称正式模型名称(例如gpt-3.5-turbo, qwen-max)XGenerationLab/XiYanSQL-QwenCoder-32B-2412xiyansql-qwencoder-32bxiyansql-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-sqlhttp://localhost:5090

通用LLM

如果你想使用通用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最佳模型

我们推荐使用析言SQL-qwencoder-32B(https://github.com/XGenerationLab/XiYanSQL-QwenCoder),这是文本到SQL的最佳模型,请参阅[Bird基准](https://bird-bench.github.io/)。 有两种使用该模型的方式。你可以选择其中一种。 (1) Modelscope,(2) 阿里云DashScope。

(1) Modelscope版本

你需要从Modelscope申请一个API-inference的keyhttps://www.modelscope.cn/docs/model-service/API-Inference/intro 然后你可以使用以下配置:

model:
  name: "XGenerationLab/XiYanSQL-QwenCoder-32B-2412"
  key: ""
  url: "https://api-inference.modelscope.cn/v1/"

阅读我们的模型描述以了解更多信息。

(2) Dashscope版本

我们在阿里云DashScope上部署了该模型,因此你需要设置以下环境变量: 发送你的电子邮件给我以获取key。(godot.lzl@alibaba-inc.com) 在邮件中,请附上以下信息:

name: "YOUR NAME",
email: "YOUR EMAIL",
organization: "your college or Company or Organization"

我们将根据您的电子邮件发送key。然后您可以在yml文件中填写keykey将在1个月或200次查询或其他法律限制后过期。

model:
  name: "xiyansql-qwencoder-32b"
  key: "KEY"
  url: "https://xiyan-stream.biz.aliyun.com/service/api/xiyan-sql"

注意:此模型服务仅用于试用,如果您需要在生产环境中使用,请联系我们。

(3) 本地版本

或者,你也可以在自己的服务器上部署模型XiYanSQL-qwencoder-32B。 详见本地模型

数据库配置

hostportuserpassworddatabase 是数据库的连接信息。

你可以使用本地或任何远程数据库。目前我们支持MySQL和PostgreSQL(更多方言即将推出)。

MySQL

database:
  host: "localhost"
  port: 3306
  user: "root"
  password: ""
  database: ""

PostgreSQL

步骤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

在你的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传输协议。

Cline

准备配置类似于Claude Desktop

Goose

如果你使用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

Cursor

使用类似的命令如下。

对于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"
    }
  }
}

Witsy

在命令中添加以下内容:

/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>

其他相关链接

MseeP.ai 安全评估徽章

引用

如果您发现我们的工作有所帮助,请随意引用我们。

@article{XiYanSQL,
      title={析言-SQL: 一种新颖的多生成器框架用于文本到SQL}, 
      author={刘一夫, 朱胤, 高颖奇, 罗智玲