# stmcp **Repository Path**: shentongdata/stmcp ## Basic Information - **Project Name**: stmcp - **Description**: 与神通数据库安全交互的MCP Server,支持执行SQL语句,支持数据字典查询,支持神通MPP分布式数据库和神通集中式数据库产品。 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-09 - **Last Updated**: 2026-01-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MCP + Shentong Database (Oscar or MPP) AI Agent解决方案 随着AI从静态推理向动态交互演进,智能体(Agent)逐渐成为焦点。Agent不仅能够调用LLM进行推理,还能访问数据库、调用API、执行任务。然而,当前LLM和Agent之间缺乏标准化交互协议, 每个新数据源都需要自定义实现,使得真正互联的系统难以扩展。MCP(Model Context Protocol, 模型上下文协议)解决了这一挑战,MCP是为LLM和Agent系统设计的标准化交互框架,使LLM可以与外部数据库、API和工具进行高效交互。 ## 快速搭建 Shentong Database (Oscar or MPP) + MCP 的 AI Agent 应用 ### 环境准备 安装和配置环境 #### 1. 安装 python 和 uv 手动安装好 python3 环境, 然后使用 pip 命令安装 uv,并验证是否加载成功,最后确定可执行程序 uv 的路径,有需要配置到环境变量(WINODWS 设置PATH)中。 ``` pip install uv ## 验证安装 uv pip show uv PS C:\Users\st> pip show uv Name: uv Version: 0.9.2 Summary: An extremely fast Python package and project manager, written in Rust. Home-page: https://pypi.org/project/uv/ Author: Author-email: "Astral Software Inc." License: Location: C:\Users\st\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages Requires: Required-by: ``` 通过 `pip show uv` 获取到 `uv` 的安装目录(Location),在该目录上级目录下存在一个 `Scripts` 目录(如本机目录 `C:\Users\st\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\Scripts`), 该目录下存放了python安装的可执行程序(`uv`),可将该目录路径配置到系统环境变量中,确保命令 `uv` 直接可用。 因为后面配置神通 MCP 服务会使用到该命令,当然也可以跳过环境变量设置而使用绝对路径。 #### 2. 下载 `mcp-stdb` MCP服务 python 源码, 切换到该源码根目录下, 准备配置 uv 虚拟环境 ``` PS D:\Codes> cd .\mcp-stdb\ PS D:\Codes\mcp-stdb> tree /F 文件夹 PATH 列表 卷序列号为 01BA-5638 D:. │ pyproject.toml │ pytest.ini │ README.md │ ├─src │ server.py │ __init__.py │ └─test conftest.py requirements.txt test_server.py ``` #### 3. 配置 uv 虚拟环境 - 查询环境安装 python 可执行的路径(以windows系统为例) ``` PS D:\Codes\mcp-stdb> Get-Command python CommandType Name Version Source ----------- ---- ------- ------ Application python.exe 0.0.0.0 C:\Users\st\AppData\Local\Microsoft\WindowsApps\python.exe ``` - 指定 uv 虚拟环境使用的python版本相关的路径(以windows系统为例) ``` PS D:\Codes\mcp-stdb> uv venv --python C:\Users\st\AppData\Local\Microsoft\WindowsApps\python.exe Using CPython 3.13.9 interpreter at: C:\Users\st\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\python.exe Creating virtual environment at: .venv Activate with: .venv\Scripts\activate ``` - 激活 uv 虚拟环境(以windows系统为例) 激活方式取决于你的操作系统和 shell: Linux / macOS(bash/zsh): ```Bash source .venv/bin/activate ``` Windows(PowerShell): ```Powershell PS D:\Codes\mcp-stdb> .\.venv\Scripts\Activate.ps1 (mcp-stdb) PS D:\Codes\mcp-stdb> ``` 如果遇到执行策略错误,可以临时允许脚本运行: ```Powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser ``` - 安装 `mcp-stdb` 依赖的 `mcp` 等依赖组件 ``` (mcp-stdb) PS D:\Codes\mcp-stdb> uv pip install . Resolved 35 packages in 7.83s Built mcp-stdb @ file:///D:/Codes/mcp-stdb Prepared 3 packages in 55.82s ░░░░░░░░░░░░░░░░░░░░ [0/35] Installing wheels... warning: Failed to hardlink files; falling back to full copy. This may lead to degraded performance. If the cache and target directories are on different filesystems, hardlinking may not be supported. If this is intentional, set `export UV_LINK_MODE=copy` or use `--link-mode=copy` to suppress this warning. Installed 35 packages in 1.59s + annotated-types==0.7.0 + anyio==4.11.0 + attrs==25.4.0 + certifi==2025.10.5 + click==8.3.0 + colorama==0.4.6 + h11==0.16.0 + httpcore==1.0.9 + httpx==0.28.1 + httpx-sse==0.4.3 + idna==3.11 + jsonschema==4.25.1 + jsonschema-specifications==2025.9.1 + markdown-it-py==4.0.0 + mcp==1.18.0 + mcp-stdb==0.1.0 (from file:///D:/Codes/mcp-stdb) + mdurl==0.1.2 + pydantic==2.12.3 + pydantic-core==2.41.4 + pydantic-settings==2.11.0 + pygments==2.19.2 + python-dotenv==1.1.1 + python-multipart==0.0.20 + pywin32==311 + referencing==0.37.0 + rich==14.2.0 + rpds-py==0.27.1 + shellingham==1.5.4 + sniffio==1.3.1 + sse-starlette==3.0.2 + starlette==0.48.0 + typer==0.19.2 + typing-extensions==4.15.0 + typing-inspection==0.4.2 + uvicorn==0.38.0 (mcp-stdb) PS D:\Codes\mcp-stdb> ``` - 离线安装 STPython 依赖驱动包,名为 stpython-xxx.whl, 如 `stpython-2.0.30a0-cp313-cp313-win_amd64.whl`。 ``` (mcp-stdb) PS D:\Codes\mcp-stdb> uv pip install .\stpython-2.0.30a0-cp313-cp313-win_amd64.whl Resolved 1 package in 27ms Prepared 1 package in 35ms ░░░░░░░░░░░░░░░░░░░░ [0/1] Installing wheels... warning: Failed to hardlink files; falling back to full copy. This may lead to degraded performance. If the cache and target directories are on different filesystems, hardlinking may not be supported. If this is intentional, set `export UV_LINK_MODE=copy` or use `--link-mode=copy` to suppress this warning. Installed 1 package in 40ms + stpython==2.0.30a0 (from file:///D:/Codes/mcp-stdb/stpython-2.0.30a0-cp313-cp313-win_amd64.whl) ``` > 注意:依赖 STPython 驱动依赖 ACI 驱动,详细配置请参阅神通数据库开发手册。 - 验证 STPython 依赖驱动包是否成功加载 ``` (mcp-stdb) PS D:\Codes\mcp-stdb> uv pip list Package Version ------------------------- --------- annotated-types 0.7.0 anyio 4.11.0 attrs 25.4.0 certifi 2025.10.5 click 8.3.0 colorama 0.4.6 h11 0.16.0 httpcore 1.0.9 httpx 0.28.1 httpx-sse 0.4.3 idna 3.11 jsonschema 4.25.1 jsonschema-specifications 2025.9.1 markdown-it-py 4.0.0 mcp 1.18.0 mcp-stdb 0.1.0 mdurl 0.1.2 pydantic 2.12.3 pydantic-core 2.41.4 pydantic-settings 2.11.0 pygments 2.19.2 python-dotenv 1.1.1 python-multipart 0.0.20 pywin32 311 referencing 0.37.0 rich 14.2.0 rpds-py 0.27.1 shellingham 1.5.4 sniffio 1.3.1 sse-starlette 3.0.2 starlette 0.48.0 stpython 2.0.30a0 typer 0.19.2 typing-extensions 4.15.0 typing-inspection 0.4.2 uvicorn 0.38.0 (mcp-stdb) PS D:\Codes\mcp-stdb> ``` ### 启动和检测神通数据库状态。 请参考神通数据库开发手册,确保数据库服务已经启动并且使用 isql 工具尝试连接数据库服务。 ``` PS C:\Users\st> isql -h localhost Welcome to ShenTong Isql 2.0.79 interactive terminal, Client Default Encoding is GBK. Password for default user: Connect to: 神通数据库7.0 for Windows(x86 64bit) (65535 connections license) Using New Protocol. Database Encoding is GBK. Logon Database At Time : 2025-10-20 11:25:26 Type: 'copyright' for distribution terms 'help' or '\h' for help with SQL commands ';' for end with commands '!' to run system commands '@' to run sql script 'exit' for quit SQL=> select version(); VERSION ------------------------------------------------------------------- 神通数据库7.0 for Windows(x86 64bit) (65535 connections license) (1 row) SQL=> ``` ### 下载和安装 MCP 客户端, 如 Trae CN、Claude Desktop 等。 下图为 Trae CN 安装界面
### 为 MCP 客户端配置 MCP 服务 以本机环境为例进行 trae cn IDE客户端配置介绍 下图为 trae cn IDE客户端界面,点击右上角设置按钮,配置 MCP 自定义服务。
--- 下图为 trae cn IDE客户端设置界面,点击右上角 MCP 选项按钮,选择手动添加方式,进行配置 MCP 自定义服务下一步。
--- 下图为 trae cn IDE客户端手动添加配置 MCP 服务方式界面,在配置编辑框添加您的 MCP 服务, 点击下方确定按钮确定创建。
--- 配置内容如下, 配置 mcp 服务的名称,例如下列配置内容中配置了一个以 `oscar-mcp`名称命名的 mcp 服务, 您也可以自定义该名称。 其中包含了 `command` 指定 `uv` 可执行命令, `args` 指定 `mcp-stdb` 的源文件源码 `src` 目录,以及 `run server.py` 指定运行python文件, `env` 指定相关环境变量,指定连接神通数据库的连接相关信息。 环境变量包含 - `STDB_DSN` : 指定连接神通数据库的域名(IP)、端口、数据库名称、参数信息等。 - `STDB_USER` : 指定连接神通数据库的用户名(要求用户拥有查询相关系统表的权限,如 sysdba 角色用户)。 - `STDB_PASSWORD` : 指定连接神通数据库的用户密码。 - `STDB_ENCODING` : 指定连接神通数据库的客户端字符集编码。 ``` { "mcpServers": { "oscar-mcp": { "command": "uv", "args": [ "--directory", "D:\\Codes\\mcp-stdb\\src", "run", "server.py" ], "env": { "STDB_DSN": "localhost:2003/osrdb", "STDB_USER": "sysdba", "STDB_PASSWORD": "Szoscar@55" } } } } ``` --- 下图为 trae cn IDE客户端手动添加配置 MCP 服务创建完成的界面, 名称右侧出现连接成功标识(绿色小勾图标),表示 MCP 服务配置连接成功。
--- trae cn IDE客户端要求必须先为 MCP 服务创建一个自定义智能体,才能使用 MCP 功能。 下图展示 trae cn IDE客户端创建一个自定义智能体操作界面,点击智能体选项,选择创建自定义智能体按钮,进行配置页面。
--- 下图展示 trae cn IDE客户端创建自定义智能体操作页面, 填写自定义智能体的名称,提示词,并选择智能体使用的 MCP 服务,点击创建按钮。
--- 下图展示 trae cn IDE客户端创建自定义智能体后,进入的智能界面。
--- ### 客户端进行 MCP 服务的智能问答 例如下图中,我们请求查询数据库中存在的所有表,trae cn IDE客户端成功显示出神通数据库中所有的结果。
--- 使用 MCP 的 `\?` 查询MCP服务支持的所有 meta-commands 命令
--- 使用 MCP 的 `\l` meta-commands 命令
--- 使用 MCP 服务执行一条普通SQL语句