Skip to content

Commit 7142238

Browse files
0.1.4 version
1 parent 523de16 commit 7142238

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

Diff for: README.md

+25-5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
- [Text-to-SQL SOTA model](#text-to-sql-sota-model)
4545
- [Local Model](#local-model)
4646
- [Database Configuration](#database-configuration)
47+
- [MySQL](#mysql)
48+
- [PostgreSQL](#postgresql)
4749
- [Launch](#launch)
4850
- [Claude Desktop](#claude-desktop)
4951
- [Cline](#cline)
@@ -57,14 +59,15 @@
5759
- 🌐 Fetch data by natural language through [XiYanSQL](https://github.com/XGenerationLab/XiYan-SQL)
5860
- 🤖 Support general LLMs (GPT,qwenmax), Text-to-SQL SOTA model
5961
- 💻 Support pure local mode (high security!)
60-
- 🖱️ List available MySQL tables as resources
62+
- 📝 Support MySQL and PostgreSQL.
63+
- 🖱️ List available tables as resources
6164
- 🔧 Read table contents
6265

6366
## Tool Preview
6467
- The tool ``get_data`` provides a natural language interface for retrieving data from a database. This server will convert the input natural language into SQL using a built-in model and call the database to return the query results.
6568

66-
- The ``mysql://{table_name}`` resource allows obtaining a portion of sample data from the database for model reference when a specific table_name is specified.
67-
- The ``mysql://`` resource will list the names of the current databases
69+
- The ``{dialect}://{table_name}`` resource allows obtaining a portion of sample data from the database for model reference when a specific table_name is specified.
70+
- The ``{dialect}://`` resource will list the names of the current databases
6871

6972
## Installation
7073
### Installing from pip
@@ -224,10 +227,11 @@ model:
224227
Til now the local mode is ready.
225228
226229
### Database Configuration
227-
``host``, ``port``, ``user``, ``password``, ``database`` are the connection information of the MySQL database.
230+
``host``, ``port``, ``user``, ``password``, ``database`` are the connection information of the database.
228231
229-
You can use local or any remote databases. Now we support MySQL (more dialects soon).
232+
You can use local or any remote databases. Now we support MySQL and PostgreSQL(more dialects soon).
230233
234+
#### MySQL
231235
232236
```yaml
233237
database:
@@ -237,7 +241,23 @@ database:
237241
password: ""
238242
database: ""
239243
```
244+
#### PostgreSQL
245+
step1: Install python packages
246+
```bash
247+
pip install psycopg2
248+
```
249+
step2: prepare the config.yml like this:
250+
```yaml
251+
database:
252+
dialect: "postgresql"
253+
host: "localhost"
254+
port: 5432
255+
user: ""
256+
password: ""
257+
database: ""
258+
```
240259
260+
Note that ``dialect`` should be ``postgresql`` for postgresql.
241261
## Launch
242262
### Claude desktop
243263
Add this in your claude desktop config file, ref <a href="https://github.com/XGenerationLab/xiyan_mcp_server/blob/main/imgs/claude_desktop.jpg">claude desktop config example</a>

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "xiyan_mcp_server"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
description = "A Model Context Protocol (MCP) server that utilizes XiyanSQL with databases. This server enables AI assistants to list tables, read data, and execute natural language queries"
55
readme = "README.md"
66
requires-python = ">=3.11"

Diff for: src/xiyan_mcp_server/server.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def get_yml_config():
3838

3939

4040
def get_xiyan_config(db_config):
41-
xiyan_db_config = DBConfig(dialect='mysql',db_name=db_config['database'], user_name=db_config['user'], db_pwd=db_config['password'], db_host=db_config['host'], port=db_config['port'])
41+
dialect = db_config.get('dialect','mysql')
42+
xiyan_db_config = DBConfig(dialect=dialect,db_name=db_config['database'], user_name=db_config['user'], db_pwd=db_config['password'], db_host=db_config['host'], port=db_config['port'])
4243
return xiyan_db_config
4344

4445

@@ -47,17 +48,17 @@ def get_xiyan_config(db_config):
4748
model_config = global_config['model']
4849
global_db_config = global_config['database']
4950
global_xiyan_db_config = get_xiyan_config(global_db_config)
51+
dialect = global_db_config.get('dialect','mysql')
52+
#print("dialect is !!!!"+dialect)
5053

51-
52-
53-
@mcp.resource('mysql://'+global_db_config['database'])
54+
@mcp.resource(dialect+'://'+global_db_config['database'])
5455
async def read_resource() -> str:
5556

5657
db_engine = init_db_conn(global_xiyan_db_config)
5758
db_source = HITLSQLDatabase(db_engine)
5859
return db_source.mschema.to_mschema()
5960

60-
@mcp.resource("mysql://{table_name}")
61+
@mcp.resource(dialect+"://{table_name}")
6162
async def read_resource(table_name) -> str:
6263
"""Read table contents."""
6364
config = global_db_config

Diff for: src/xiyan_mcp_server/utils/db_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __post_init__(self):
1717
self.db_path = self.db_path or 'book_1.sqlite'
1818
elif self.dialect in ['mysql', 'postgresql']:
1919
self.db_name = self.db_name or 'default_db'
20-
self.user_name = self.user_name or 'default_user'
20+
self.user_name = quote_plus(self.user_name) or 'default_user'
2121
self.db_pwd = quote_plus(self.db_pwd) or 'default_password'
2222
self.db_host = self.db_host or 'localhost'
2323
self.port = self.port or (3306 if self.dialect == 'mysql' else 5432)

0 commit comments

Comments
 (0)