# xiyan_mcp_server

> MCP Server

XiYan MCP Server is a Model Context Protocol server enabling natural language queries to databases, powered by XiYan-SQL, a state-of-the-art text-to-SQL system on open benchmarks. It offers various resources, including

## Overview

- **Category:** AI
- **Language:** Python
- **Stars:** 241
- **Forks:** 4
- **Owner:** XGenerationLab
- **GitHub:** https://github.com/XGenerationLab/xiyan_mcp_server
- **Created:** 2025-03-13T07:39:00+00:00
- **Updated:** 2025-03-28T15:03:04+00:00
- **Source:** https://model-context-protocol.com/servers/natural-language-database-query-server

## Setup

## Setup

**Installing from pip:**

1.  Python 3.11+ is required.
2.  Install the server through pip: `pip install xiyan-mcp-server`
3.  Run the server: `python -m xiyan_mcp_server`
4.  Complete the config to get a yml file.
5.  Run the server with the yml config: `env YML=path/to/yml python -m xiyan_mcp_server`

**Installing from Smithery.ai:**

1.  See [@XGenerationLab/xiyan_mcp_server](https://smithery.ai/server/@XGenerationLab/xiyan_mcp_server) (Not fully tested).

**Configuration:**

1.  Create a YAML config file (config_demo.yml).
2.  Configure LLM settings (name, key, url) based on the chosen model (General LLMs, Text-to-SQL SOTA model, or Local Model).
3.  Configure Database settings (host, port, user, password, database) for MySQL or PostgreSQL.

**Local Model Setup:**

1.  PC/Mac with at least 16GB RAM and 6GB disk space.
2.  Install additional Python packages: `pip install flask modelscope torch==2.2.2 accelerate>=0.26.0 numpy=2.2.3`
3.  (Optional) Manually download the model: `modelscope download --model XGenerationLab/XiYanSQL-QwenCoder-3B-2502`
4.  Download and run the local server script: `python local_xiyan_server.py`
5.  Configure config.yml to point to the local server.

**PostgreSQL Setup:**

1.  Install Python packages: `pip install psycopg2`
2.  Prepare the config.yml with dialect set to `postgresql`.

**Launch:**

1.  Configure Claude Desktop, Cline, Goose, Cursor, or Witsy with the appropriate command and environment variables (YML path).

## Tools

## Available Tools

1.  Fetch data by natural language through [XiYanSQL](https://github.com/XGenerationLab/XiYan-SQL).
2.  Support general LLMs (GPT,qwenmax), Text-to-SQL SOTA model.
3.  Support pure local mode (high security!).
4.  Support MySQL and PostgreSQL.
5.  List available tables as resources.
6.  Read table contents.
7.  ``get_data`` tool provides a natural language interface for retrieving data from a database.
8.  The ``{dialect}://{table_name}`` resource allows obtaining sample data from the database.
9.  The ``{dialect}://`` resource will list the names of the current databases.
