opc-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ # Python
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+
9
+ # Virtual environment
10
+ .venv/
11
+
12
+ # Testing
13
+ .pytest_cache/
14
+ .coverage
15
+ htmlcov/
16
+
17
+ # IDE
18
+ .vscode/
19
+ .idea/
20
+
21
+ # Project specific
22
+ config.yaml
23
+
24
+ # Claude config
25
+ .claude/
26
+ .trae/
27
+
@@ -0,0 +1,13 @@
1
+ {
2
+ "mcpServers": {
3
+ "opc-mcp-stdio": {
4
+ "command": "uvx",
5
+ "args": [
6
+ "--from", "D:/code/python/opc-mcp",
7
+ "opc-mcp",
8
+ "--config", "D:/code/python/opc-mcp/config.yaml",
9
+ "--mode", "stdio"
10
+ ]
11
+ }
12
+ }
13
+ }
opc_mcp-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 zhouxinhai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
opc_mcp-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,260 @@
1
+ Metadata-Version: 2.4
2
+ Name: opc-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server for order center database access
5
+ Project-URL: Homepage, https://github.com/zhouxinhai/opc-mcp
6
+ Project-URL: Repository, https://github.com/zhouxinhai/opc-mcp
7
+ Project-URL: Issues, https://github.com/zhouxinhai/opc-mcp/issues
8
+ Author-email: zhouxinhai <your.email@example.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: database,mcp,mysql,oracle,order-center
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Database
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: mcp[cli]>=1.0.0
22
+ Requires-Dist: mysql-connector-python>=9.7.0
23
+ Requires-Dist: pydantic>=2.0
24
+ Requires-Dist: pyyaml>=6.0
25
+ Requires-Dist: sqlparse>=0.5.0
26
+ Description-Content-Type: text/markdown
27
+
28
+ # OPC-MCP
29
+
30
+ 订单中心数据库 MCP 服务,通过 MCP 协议暴露数据库查询能力,供 AI 助手动态查询和排查订单问题。
31
+
32
+ ## 功能
33
+
34
+ - **配置驱动工具** — 在 `config.yaml` 中定义 SQL 模板,自动生成 MCP 工具
35
+ - **`run_query`** — 动态执行任意 SELECT 查询,支持命名参数、LIKE 自动检测、分页
36
+ - **`query_table_desc`** — 查询表结构信息(列名、数据类型、注释),表名大小写不敏感
37
+ - **多连接池** — 支持多个数据库(opc、smc 等),连接池名称大小写不敏感
38
+ - **安全防护** — 仅允许 SELECT 语句,拒绝多语句注入,参数化查询
39
+
40
+ ## 安装
41
+
42
+ ```bash
43
+ pip install -e .
44
+ ```
45
+
46
+ ## 配置
47
+
48
+ 编辑 `config.yaml`:
49
+
50
+ ```yaml
51
+ server:
52
+ host: "0.0.0.0"
53
+ port: 8000
54
+
55
+ pools:
56
+ opc:
57
+ host: 10.0.0.1
58
+ port: 1521
59
+ user: readonly
60
+ password: xxx
61
+ database: opc_db
62
+ pool_size: 5
63
+ smc:
64
+ host: 10.0.0.2
65
+ port: 1521
66
+ user: readonly
67
+ password: xxx
68
+ database: smc_db
69
+ pool_size: 3
70
+
71
+ tools:
72
+ query_sub_order:
73
+ description: "查询子订单信息"
74
+ pool: opc
75
+ sql: "SELECT * FROM or_sub_order WHERE 1=1 AND order_id = :order_id AND status = :status"
76
+ params:
77
+ order_id:
78
+ type: str
79
+ description: "订单号"
80
+ status:
81
+ type: str
82
+ description: "订单状态"
83
+ limit:
84
+ default: 50
85
+ max: 100
86
+ offset:
87
+ default: 0
88
+ ```
89
+
90
+ ## 启动
91
+
92
+ ```bash
93
+ # Streamable HTTP 模式(默认)
94
+ uv run opc-mcp --config config.yaml
95
+
96
+ # SSE 模式
97
+ uv run opc-mcp --config config.yaml --mode sse
98
+
99
+ # stdio 模式(本地进程通信)
100
+ uv run opc-mcp --config config.yaml --mode stdio
101
+
102
+ # 指定日志级别
103
+ uv run opc-mcp --config config.yaml --log-level DEBUG
104
+ ```
105
+
106
+ ### 连接地址
107
+
108
+ | 模式 | 连接方式 |
109
+ |------|----------|
110
+ | Streamable HTTP(默认) | `http://localhost:8000/mcp` |
111
+ | SSE | `http://localhost:8000/sse` |
112
+ | stdio | 通过 stdin/stdout 通信 |
113
+
114
+ ### MCP 客户端配置
115
+
116
+ Streamable HTTP 模式:
117
+
118
+ ```json
119
+ {
120
+ "mcpServers": {
121
+ "opc-mcp": {
122
+ "url": "http://localhost:8000/mcp"
123
+ }
124
+ }
125
+ }
126
+ ```
127
+
128
+ SSE 模式:
129
+
130
+ ```json
131
+ {
132
+ "mcpServers": {
133
+ "opc-mcp": {
134
+ "url": "http://localhost:8000/sse"
135
+ }
136
+ }
137
+ }
138
+ ```
139
+
140
+ stdio 模式(通过 `cwd` 指定项目目录):
141
+
142
+ - uv启动方式
143
+
144
+ ```json
145
+ {
146
+ "mcpServers": {
147
+ "opc-mcp-stdio": {
148
+ "command": "uv",
149
+ "args": [
150
+ "run",
151
+ "opc-mcp",
152
+ "--config",
153
+ "config.yaml",
154
+ "--mode",
155
+ "stdio"
156
+ ],
157
+ "cwd": "D:/code/python/opc-mcp"
158
+ }
159
+ }
160
+ }
161
+ ```
162
+
163
+ - uvx启动方式
164
+
165
+ ```json
166
+ {
167
+ "mcpServers": {
168
+ "opc-mcp-stdio": {
169
+ "command": "uvx",
170
+ "args": [
171
+ "--from", "D:/code/python/opc-mcp",
172
+ "opc-mcp",
173
+ "--config", "D:/code/python/opc-mcp/config.yaml",
174
+ "--mode", "stdio"
175
+ ]
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+
182
+
183
+ ## MCP 工具
184
+
185
+ ### run_query
186
+
187
+ 动态执行 SELECT 查询,支持命名参数和分页。
188
+
189
+ **参数:**
190
+
191
+ | 参数 | 类型 | 必填 | 说明 |
192
+ |------|------|------|------|
193
+ | sql | string | 是 | SELECT SQL,使用 `:param_name` 占位符 |
194
+ | params | object | 否 | 命名参数,key 大小写不敏感 |
195
+ | pool | string | 否 | 连接池名称,默认 `opc` |
196
+ | limit | integer | 否 | 返回行数限制,默认 50,最大 200 |
197
+ | offset | integer | 否 | 分页偏移量,默认 0 |
198
+
199
+ **示例:**
200
+
201
+ ```json
202
+ {
203
+ "sql": "SELECT * FROM or_dict_def WHERE dict_type = :dict_type AND dict_class = :dict_class",
204
+ "params": {"dict_type": 18, "dict_class": 1},
205
+ "pool": "opc"
206
+ }
207
+ ```
208
+
209
+ 支持 JOIN、GROUP BY、子查询、UNION、聚合等复杂查询。LIKE 条件自动检测并包裹 `%`。
210
+
211
+ ### query_table_desc
212
+
213
+ 查询表的列结构信息。
214
+
215
+ **参数:**
216
+
217
+ | 参数 | 类型 | 必填 | 说明 |
218
+ |------|------|------|------|
219
+ | table_name | string | 是 | 表名,大小写不敏感 |
220
+ | pool | string | 是 | 连接池名称 |
221
+
222
+ **示例:**
223
+
224
+ ```json
225
+ {
226
+ "table_name": "or_dict_def",
227
+ "pool": "opc"
228
+ }
229
+ ```
230
+
231
+ **返回:**
232
+
233
+ ```json
234
+ {
235
+ "table_name": "OR_DICT_DEF",
236
+ "count": 5,
237
+ "columns": [
238
+ {"table_name": "OR_DICT_DEF", "column_name": "DICT_TYPE", "data_type": "NUMBER", "comments": "字典类型"},
239
+ {"table_name": "OR_DICT_DEF", "column_name": "DICT_NAME", "data_type": "VARCHAR2", "comments": "字典名称"}
240
+ ]
241
+ }
242
+ ```
243
+
244
+ ## 测试
245
+
246
+ ```bash
247
+ pytest tests/ -v
248
+ ```
249
+
250
+ ## 项目结构
251
+
252
+ ```
253
+ src/opc_mcp/
254
+ main.py # 入口,服务创建与启动
255
+ config.py # 配置模型(AppConfig, ToolConfig, PoolConfig)
256
+ pool_manager.py # 连接池管理
257
+ handlers.py # 工具执行逻辑
258
+ register.py # MCP 工具注册
259
+ tools.py # SQL 校验、参数绑定等工具函数
260
+ ```
@@ -0,0 +1,233 @@
1
+ # OPC-MCP
2
+
3
+ 订单中心数据库 MCP 服务,通过 MCP 协议暴露数据库查询能力,供 AI 助手动态查询和排查订单问题。
4
+
5
+ ## 功能
6
+
7
+ - **配置驱动工具** — 在 `config.yaml` 中定义 SQL 模板,自动生成 MCP 工具
8
+ - **`run_query`** — 动态执行任意 SELECT 查询,支持命名参数、LIKE 自动检测、分页
9
+ - **`query_table_desc`** — 查询表结构信息(列名、数据类型、注释),表名大小写不敏感
10
+ - **多连接池** — 支持多个数据库(opc、smc 等),连接池名称大小写不敏感
11
+ - **安全防护** — 仅允许 SELECT 语句,拒绝多语句注入,参数化查询
12
+
13
+ ## 安装
14
+
15
+ ```bash
16
+ pip install -e .
17
+ ```
18
+
19
+ ## 配置
20
+
21
+ 编辑 `config.yaml`:
22
+
23
+ ```yaml
24
+ server:
25
+ host: "0.0.0.0"
26
+ port: 8000
27
+
28
+ pools:
29
+ opc:
30
+ host: 10.0.0.1
31
+ port: 1521
32
+ user: readonly
33
+ password: xxx
34
+ database: opc_db
35
+ pool_size: 5
36
+ smc:
37
+ host: 10.0.0.2
38
+ port: 1521
39
+ user: readonly
40
+ password: xxx
41
+ database: smc_db
42
+ pool_size: 3
43
+
44
+ tools:
45
+ query_sub_order:
46
+ description: "查询子订单信息"
47
+ pool: opc
48
+ sql: "SELECT * FROM or_sub_order WHERE 1=1 AND order_id = :order_id AND status = :status"
49
+ params:
50
+ order_id:
51
+ type: str
52
+ description: "订单号"
53
+ status:
54
+ type: str
55
+ description: "订单状态"
56
+ limit:
57
+ default: 50
58
+ max: 100
59
+ offset:
60
+ default: 0
61
+ ```
62
+
63
+ ## 启动
64
+
65
+ ```bash
66
+ # Streamable HTTP 模式(默认)
67
+ uv run opc-mcp --config config.yaml
68
+
69
+ # SSE 模式
70
+ uv run opc-mcp --config config.yaml --mode sse
71
+
72
+ # stdio 模式(本地进程通信)
73
+ uv run opc-mcp --config config.yaml --mode stdio
74
+
75
+ # 指定日志级别
76
+ uv run opc-mcp --config config.yaml --log-level DEBUG
77
+ ```
78
+
79
+ ### 连接地址
80
+
81
+ | 模式 | 连接方式 |
82
+ |------|----------|
83
+ | Streamable HTTP(默认) | `http://localhost:8000/mcp` |
84
+ | SSE | `http://localhost:8000/sse` |
85
+ | stdio | 通过 stdin/stdout 通信 |
86
+
87
+ ### MCP 客户端配置
88
+
89
+ Streamable HTTP 模式:
90
+
91
+ ```json
92
+ {
93
+ "mcpServers": {
94
+ "opc-mcp": {
95
+ "url": "http://localhost:8000/mcp"
96
+ }
97
+ }
98
+ }
99
+ ```
100
+
101
+ SSE 模式:
102
+
103
+ ```json
104
+ {
105
+ "mcpServers": {
106
+ "opc-mcp": {
107
+ "url": "http://localhost:8000/sse"
108
+ }
109
+ }
110
+ }
111
+ ```
112
+
113
+ stdio 模式(通过 `cwd` 指定项目目录):
114
+
115
+ - uv启动方式
116
+
117
+ ```json
118
+ {
119
+ "mcpServers": {
120
+ "opc-mcp-stdio": {
121
+ "command": "uv",
122
+ "args": [
123
+ "run",
124
+ "opc-mcp",
125
+ "--config",
126
+ "config.yaml",
127
+ "--mode",
128
+ "stdio"
129
+ ],
130
+ "cwd": "D:/code/python/opc-mcp"
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ - uvx启动方式
137
+
138
+ ```json
139
+ {
140
+ "mcpServers": {
141
+ "opc-mcp-stdio": {
142
+ "command": "uvx",
143
+ "args": [
144
+ "--from", "D:/code/python/opc-mcp",
145
+ "opc-mcp",
146
+ "--config", "D:/code/python/opc-mcp/config.yaml",
147
+ "--mode", "stdio"
148
+ ]
149
+ }
150
+ }
151
+ }
152
+ ```
153
+
154
+
155
+
156
+ ## MCP 工具
157
+
158
+ ### run_query
159
+
160
+ 动态执行 SELECT 查询,支持命名参数和分页。
161
+
162
+ **参数:**
163
+
164
+ | 参数 | 类型 | 必填 | 说明 |
165
+ |------|------|------|------|
166
+ | sql | string | 是 | SELECT SQL,使用 `:param_name` 占位符 |
167
+ | params | object | 否 | 命名参数,key 大小写不敏感 |
168
+ | pool | string | 否 | 连接池名称,默认 `opc` |
169
+ | limit | integer | 否 | 返回行数限制,默认 50,最大 200 |
170
+ | offset | integer | 否 | 分页偏移量,默认 0 |
171
+
172
+ **示例:**
173
+
174
+ ```json
175
+ {
176
+ "sql": "SELECT * FROM or_dict_def WHERE dict_type = :dict_type AND dict_class = :dict_class",
177
+ "params": {"dict_type": 18, "dict_class": 1},
178
+ "pool": "opc"
179
+ }
180
+ ```
181
+
182
+ 支持 JOIN、GROUP BY、子查询、UNION、聚合等复杂查询。LIKE 条件自动检测并包裹 `%`。
183
+
184
+ ### query_table_desc
185
+
186
+ 查询表的列结构信息。
187
+
188
+ **参数:**
189
+
190
+ | 参数 | 类型 | 必填 | 说明 |
191
+ |------|------|------|------|
192
+ | table_name | string | 是 | 表名,大小写不敏感 |
193
+ | pool | string | 是 | 连接池名称 |
194
+
195
+ **示例:**
196
+
197
+ ```json
198
+ {
199
+ "table_name": "or_dict_def",
200
+ "pool": "opc"
201
+ }
202
+ ```
203
+
204
+ **返回:**
205
+
206
+ ```json
207
+ {
208
+ "table_name": "OR_DICT_DEF",
209
+ "count": 5,
210
+ "columns": [
211
+ {"table_name": "OR_DICT_DEF", "column_name": "DICT_TYPE", "data_type": "NUMBER", "comments": "字典类型"},
212
+ {"table_name": "OR_DICT_DEF", "column_name": "DICT_NAME", "data_type": "VARCHAR2", "comments": "字典名称"}
213
+ ]
214
+ }
215
+ ```
216
+
217
+ ## 测试
218
+
219
+ ```bash
220
+ pytest tests/ -v
221
+ ```
222
+
223
+ ## 项目结构
224
+
225
+ ```
226
+ src/opc_mcp/
227
+ main.py # 入口,服务创建与启动
228
+ config.py # 配置模型(AppConfig, ToolConfig, PoolConfig)
229
+ pool_manager.py # 连接池管理
230
+ handlers.py # 工具执行逻辑
231
+ register.py # MCP 工具注册
232
+ tools.py # SQL 校验、参数绑定等工具函数
233
+ ```