iflow-mcp_yezere-codeql_n1ght_mcp_server 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,6 @@
1
+ [2026-02-06] [INFO] 步骤1:获取项目完成 - Fork和克隆成功
2
+ [2026-02-06] [INFO] 步骤2:阅读代码开始 - 分析项目类型和配置
3
+ [2026-02-06] [INFO] 步骤2:阅读代码完成 - Python MCP服务端项目,使用FastMCP,支持stdio协议
4
+ [2026-02-06] [INFO] 步骤3:本地测试开始 - 安装依赖并构建项目
5
+ [2026-02-06] [INFO] 步骤3:本地测试完成 - 成功构建并测试,发现5个工具
6
+ [2026-02-06] [INFO] 步骤4:创建并推送iflow分支完成 - 分支已推送到远程仓库
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: iflow-mcp_yezere-codeql_n1ght_mcp_server
3
+ Version: 0.1.0
4
+ Summary: MCP server for CodeQL N1ght tool integration
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: mcp>=1.1.0
7
+ Description-Content-Type: text/markdown
8
+
9
+ # CodeQL N1ght MCP Server
10
+
11
+ A Model Context Protocol (MCP) server for integrating CodeQL N1ght tool with AI assistants.
12
+
13
+ ## Overview
14
+
15
+ This MCP server provides a standardized interface for AI assistants to interact with the CodeQL N1ght tool, enabling automated code analysis workflows including environment setup, database creation, and security scanning.
16
+
17
+ ## Features
18
+
19
+ - **Environment Installation**: One-click setup of JDK, Ant, and CodeQL dependencies
20
+ - **Database Creation**: Create CodeQL databases from JAR/WAR/ZIP files with configurable decompilers
21
+ - **Security Scanning**: Execute security scans with customizable query packs
22
+ - **Parallel Processing**: Support for goroutines and multi-threading
23
+ - **Flexible Configuration**: Customizable paths, timeouts, and caching options
24
+
25
+ ## Available Tools
26
+
27
+ ### `version`
28
+ Get version or help information from the CodeQL N1ght executable.
29
+
30
+ ### `install_environment`
31
+ Install required dependencies (JDK, Ant, CodeQL) with optional custom URLs.
32
+
33
+ ### `create_database`
34
+ Create a CodeQL database from target files (JAR/WAR/ZIP) with options for:
35
+ - Decompiler selection (procyon/fernflower)
36
+ - Dependency handling (none/all)
37
+ - Parallel processing
38
+ - Cache management
39
+
40
+ ### `scan_database`
41
+ Execute security scans on CodeQL databases with configurable:
42
+ - Database and query pack paths
43
+ - Parallel processing options
44
+ - Cache control
45
+
46
+ ### `run_codeql_n1ght`
47
+ Generic interface for direct command execution with custom arguments.
48
+
49
+ ## Installation
50
+
51
+ 1. Install dependencies:
52
+ ```bash
53
+ pip install -r requirements.txt
54
+ ```
55
+
56
+ 2. Ensure the CodeQL N1ght executable is available at the configured path (default: `J:\mcp\codeql-n1ght.exe`)
57
+
58
+ ## Usage
59
+
60
+ Run the MCP server in STDIO mode:
61
+
62
+ ```bash
63
+ python codeql_n1ght_mcp_server.py
64
+ ```
65
+
66
+ ## Configuration
67
+
68
+ - **Default Executable Path**: `J:\mcp\codeql-n1ght.exe`
69
+ - **Path Compatibility**: Supports both Windows (`J:\path`) and Unix-style (`/j:/path`) path formats
70
+ - **Timeouts**: Configurable per operation (default: 10 minutes for general operations, 20 hours for database/scan operations)
71
+
72
+ ## Response Format
73
+
74
+ All tools return a standardized response format:
75
+ ```json
76
+ {
77
+ "returncode": 0,
78
+ "stdout": "command output",
79
+ "stderr": "error output",
80
+ "timeout": false
81
+ }
82
+ ```
83
+
84
+ ## Error Handling
85
+
86
+ - **Executable Not Found**: Returns error if CodeQL N1ght executable is missing
87
+ - **Invalid Parameters**: Validates decompiler and dependency options
88
+ - **Timeout Management**: Configurable timeouts with process termination
89
+ - **Path Resolution**: Automatic path normalization and validation
90
+
91
+ ## License
92
+
93
+ This project is open source and available under the MIT License.
@@ -0,0 +1,85 @@
1
+ # CodeQL N1ght MCP Server
2
+
3
+ A Model Context Protocol (MCP) server for integrating CodeQL N1ght tool with AI assistants.
4
+
5
+ ## Overview
6
+
7
+ This MCP server provides a standardized interface for AI assistants to interact with the CodeQL N1ght tool, enabling automated code analysis workflows including environment setup, database creation, and security scanning.
8
+
9
+ ## Features
10
+
11
+ - **Environment Installation**: One-click setup of JDK, Ant, and CodeQL dependencies
12
+ - **Database Creation**: Create CodeQL databases from JAR/WAR/ZIP files with configurable decompilers
13
+ - **Security Scanning**: Execute security scans with customizable query packs
14
+ - **Parallel Processing**: Support for goroutines and multi-threading
15
+ - **Flexible Configuration**: Customizable paths, timeouts, and caching options
16
+
17
+ ## Available Tools
18
+
19
+ ### `version`
20
+ Get version or help information from the CodeQL N1ght executable.
21
+
22
+ ### `install_environment`
23
+ Install required dependencies (JDK, Ant, CodeQL) with optional custom URLs.
24
+
25
+ ### `create_database`
26
+ Create a CodeQL database from target files (JAR/WAR/ZIP) with options for:
27
+ - Decompiler selection (procyon/fernflower)
28
+ - Dependency handling (none/all)
29
+ - Parallel processing
30
+ - Cache management
31
+
32
+ ### `scan_database`
33
+ Execute security scans on CodeQL databases with configurable:
34
+ - Database and query pack paths
35
+ - Parallel processing options
36
+ - Cache control
37
+
38
+ ### `run_codeql_n1ght`
39
+ Generic interface for direct command execution with custom arguments.
40
+
41
+ ## Installation
42
+
43
+ 1. Install dependencies:
44
+ ```bash
45
+ pip install -r requirements.txt
46
+ ```
47
+
48
+ 2. Ensure the CodeQL N1ght executable is available at the configured path (default: `J:\mcp\codeql-n1ght.exe`)
49
+
50
+ ## Usage
51
+
52
+ Run the MCP server in STDIO mode:
53
+
54
+ ```bash
55
+ python codeql_n1ght_mcp_server.py
56
+ ```
57
+
58
+ ## Configuration
59
+
60
+ - **Default Executable Path**: `J:\mcp\codeql-n1ght.exe`
61
+ - **Path Compatibility**: Supports both Windows (`J:\path`) and Unix-style (`/j:/path`) path formats
62
+ - **Timeouts**: Configurable per operation (default: 10 minutes for general operations, 20 hours for database/scan operations)
63
+
64
+ ## Response Format
65
+
66
+ All tools return a standardized response format:
67
+ ```json
68
+ {
69
+ "returncode": 0,
70
+ "stdout": "command output",
71
+ "stderr": "error output",
72
+ "timeout": false
73
+ }
74
+ ```
75
+
76
+ ## Error Handling
77
+
78
+ - **Executable Not Found**: Returns error if CodeQL N1ght executable is missing
79
+ - **Invalid Parameters**: Validates decompiler and dependency options
80
+ - **Timeout Management**: Configurable timeouts with process termination
81
+ - **Path Resolution**: Automatic path normalization and validation
82
+
83
+ ## License
84
+
85
+ This project is open source and available under the MIT License.
@@ -0,0 +1,267 @@
1
+ import asyncio
2
+ import logging
3
+ import os
4
+ from typing import List, Optional, Dict, Any
5
+
6
+ from mcp.server import FastMCP
7
+
8
+ # 注意:STDIO 模式下不要向 stdout 打印任何非协议内容,使用 logging(写入 stderr)记录日志
9
+ logging.basicConfig(level=logging.INFO)
10
+
11
+ APP_NAME = "codeql_n1ght_mcp"
12
+ # 默认可执行文件路径(兼容传入 "/j:/mcp/codeql-n1ght.exe" 的写法)
13
+ EXE_PATH = r"J:\\mcp\\codeql-n1ght.exe"
14
+
15
+ app = FastMCP(APP_NAME)
16
+
17
+
18
+ def _resolve_exe_path(custom_path: Optional[str]) -> str:
19
+ """返回可执行文件的绝对路径,优先使用传入路径。兼容类似 "/j:/mcp/codeql-n1ght.exe" 的写法。"""
20
+ path = (custom_path or EXE_PATH).strip()
21
+ if path.startswith("/") and len(path) > 2 and path[2] == ":":
22
+ path = path[1:]
23
+ return os.path.abspath(path)
24
+
25
+
26
+ async def _run_subprocess(cmd: List[str], cwd: Optional[str], timeout: Optional[float]) -> Dict[str, Any]:
27
+ """以异步方式运行子进程,捕获 stdout/stderr,返回 {returncode, stdout, stderr, timeout}."""
28
+ logging.info("Running command: %s", " ".join(cmd))
29
+ if cwd:
30
+ logging.info("Working directory: %s", cwd)
31
+
32
+ proc = await asyncio.create_subprocess_exec(
33
+ *cmd,
34
+ cwd=cwd,
35
+ stdout=asyncio.subprocess.PIPE,
36
+ stderr=asyncio.subprocess.PIPE,
37
+ )
38
+
39
+ try:
40
+ stdout_b, stderr_b = await asyncio.wait_for(proc.communicate(), timeout=timeout)
41
+ timed_out = False
42
+ except asyncio.TimeoutError:
43
+ try:
44
+ proc.kill()
45
+ except ProcessLookupError:
46
+ pass
47
+ return {
48
+ "returncode": None,
49
+ "stdout": "",
50
+ "stderr": f"Process timeout after {timeout} seconds",
51
+ "timeout": True,
52
+ }
53
+
54
+ stdout = stdout_b.decode(errors="replace") if stdout_b else ""
55
+ stderr = stderr_b.decode(errors="replace") if stderr_b else ""
56
+
57
+ return {
58
+ "returncode": proc.returncode,
59
+ "stdout": stdout,
60
+ "stderr": stderr,
61
+ "timeout": timed_out,
62
+ }
63
+
64
+
65
+ @app.tool()
66
+ async def run_codeql_n1ght(
67
+ args: Optional[List[str]] = None,
68
+ exe_path: Optional[str] = None,
69
+ cwd: Optional[str] = None,
70
+ timeout_seconds: Optional[float] = 600.0,
71
+ ) -> Dict[str, Any]:
72
+ """
73
+ 通用执行接口:直接传入参数数组,运行 codeql-n1ght.exe。
74
+
75
+ - args 例如:["-install"]、["-database", "your.jar", "-decompiler", "fernflower"] 等。
76
+ - exe_path 可选,覆盖默认可执行路径。
77
+ - cwd 可选,子进程工作目录。
78
+ - timeout_seconds 超时(秒)。
79
+ """
80
+ resolved_path = _resolve_exe_path(exe_path)
81
+ if not os.path.exists(resolved_path):
82
+ return {
83
+ "returncode": None,
84
+ "stdout": "",
85
+ "stderr": f"Executable not found: {resolved_path}",
86
+ "timeout": False,
87
+ }
88
+
89
+ args = args or []
90
+ cmd = [resolved_path, *args]
91
+ return await _run_subprocess(cmd, cwd=cwd, timeout=timeout_seconds)
92
+
93
+
94
+ @app.tool()
95
+ async def version(
96
+ exe_path: Optional[str] = None,
97
+ timeout_seconds: Optional[float] = 60.0,
98
+ ) -> Dict[str, Any]:
99
+ """获取可执行文件版本或帮助信息:先尝试 --version,失败回退 --help。"""
100
+ resolved_path = _resolve_exe_path(exe_path)
101
+ if not os.path.exists(resolved_path):
102
+ return {
103
+ "returncode": None,
104
+ "stdout": "",
105
+ "stderr": f"Executable not found: {resolved_path}",
106
+ "timeout": False,
107
+ }
108
+
109
+ # 先尝试 --version
110
+ res = await _run_subprocess([resolved_path, "--version"], cwd=None, timeout=timeout_seconds)
111
+ if res.get("returncode") == 0 and res.get("stdout"):
112
+ return res
113
+
114
+ # 回退 --help
115
+ return await _run_subprocess([resolved_path, "--help"], cwd=None, timeout=timeout_seconds)
116
+
117
+
118
+ @app.tool()
119
+ async def install_environment(
120
+ jdk_url: Optional[str] = None,
121
+ ant_url: Optional[str] = None,
122
+ codeql_url: Optional[str] = None,
123
+ exe_path: Optional[str] = None,
124
+ cwd: Optional[str] = None,
125
+ timeout_seconds: Optional[float] = 3600.0,
126
+ ) -> Dict[str, Any]:
127
+ """
128
+ 一键安装环境:等价于命令行
129
+ ./codeql_n1ght -install [-jdk <url>] [-ant <url>] [-codeql <url>]
130
+ """
131
+ resolved_path = _resolve_exe_path(exe_path)
132
+ if not os.path.exists(resolved_path):
133
+ return {
134
+ "returncode": None,
135
+ "stdout": "",
136
+ "stderr": f"Executable not found: {resolved_path}",
137
+ "timeout": False,
138
+ }
139
+
140
+ args: List[str] = ["-install"]
141
+ if jdk_url:
142
+ args += ["-jdk", jdk_url]
143
+ if ant_url:
144
+ args += ["-ant", ant_url]
145
+ if codeql_url:
146
+ args += ["-codeql", codeql_url]
147
+
148
+ return await _run_subprocess([resolved_path, *args], cwd=cwd, timeout=timeout_seconds)
149
+
150
+
151
+ @app.tool()
152
+ async def create_database(
153
+ target: str,
154
+ decompiler: Optional[str] = None, # procyon | fernflower
155
+ extra_src_dir: Optional[str] = None, # -dir
156
+ deps: Optional[str] = None, # none | all | None(进入交互TUI)
157
+ goroutine: bool = False, # -goroutine
158
+ max_goroutines: Optional[int] = None, # -max-goroutines N
159
+ threads: Optional[int] = None, # -threads N
160
+ clean_cache: bool = False, # -clean-cache
161
+ exe_path: Optional[str] = None,
162
+ cwd: Optional[str] = None,
163
+ timeout_seconds: Optional[float] = 72000.0,
164
+ ) -> Dict[str, Any]:
165
+ """
166
+ 创建 CodeQL 数据库:等价命令
167
+ ./codeql_n1ght -database <JAR|WAR|ZIP> [-decompiler procyon|fernflower] [-dir <path>] [-deps none|all]
168
+ [-goroutine] [-max-goroutines N] [-threads N] [-clean-cache]
169
+ """
170
+ resolved_path = _resolve_exe_path(exe_path)
171
+ if not os.path.exists(resolved_path):
172
+ return {
173
+ "returncode": None,
174
+ "stdout": "",
175
+ "stderr": f"Executable not found: {resolved_path}",
176
+ "timeout": False,
177
+ }
178
+
179
+ args: List[str] = ["-database", target]
180
+
181
+ if decompiler:
182
+ dec = decompiler.lower().strip()
183
+ if dec not in {"procyon", "fernflower"}:
184
+ return {
185
+ "returncode": None,
186
+ "stdout": "",
187
+ "stderr": f"Invalid decompiler: {decompiler}. Expected 'procyon' or 'fernflower'",
188
+ "timeout": False,
189
+ }
190
+ args += ["-decompiler", dec]
191
+
192
+ if extra_src_dir:
193
+ args += ["-dir", extra_src_dir]
194
+
195
+ if deps:
196
+ d = deps.lower().strip()
197
+ if d not in {"none", "all"}:
198
+ return {
199
+ "returncode": None,
200
+ "stdout": "",
201
+ "stderr": f"Invalid deps: {deps}. Expected 'none' or 'all' or leave empty to use interactive TUI",
202
+ "timeout": False,
203
+ }
204
+ args += ["-deps", d]
205
+
206
+ # 新增:并行与缓存控制参数
207
+ if goroutine:
208
+ args += ["-goroutine"]
209
+ if isinstance(max_goroutines, int):
210
+ args += ["-max-goroutines", str(max_goroutines)]
211
+ if isinstance(threads, int):
212
+ args += ["-threads", str(threads)]
213
+ if clean_cache:
214
+ args += ["-clean-cache"]
215
+
216
+ return await _run_subprocess([resolved_path, *args], cwd=cwd, timeout=timeout_seconds)
217
+
218
+
219
+ @app.tool()
220
+ async def scan_database(
221
+ db: Optional[str] = None,
222
+ ql: Optional[str] = None,
223
+ goroutine: bool = False,
224
+ max_goroutines: Optional[int] = None,
225
+ threads: Optional[int] = None,
226
+ clean_cache: bool = False,
227
+ exe_path: Optional[str] = None,
228
+ cwd: Optional[str] = None,
229
+ timeout_seconds: Optional[float] = 720000.0,
230
+ ) -> Dict[str, Any]:
231
+ """
232
+ 执行安全扫描:等价命令
233
+ ./codeql_n1ght -scan [-db <path>] [-ql <path>] [-goroutine] [-max-goroutines N] [-threads N] [-clean-cache]
234
+ """
235
+ resolved_path = _resolve_exe_path(exe_path)
236
+ if not os.path.exists(resolved_path):
237
+ return {
238
+ "returncode": None,
239
+ "stdout": "",
240
+ "stderr": f"Executable not found: {resolved_path}",
241
+ "timeout": False,
242
+ }
243
+
244
+ args: List[str] = ["-scan"]
245
+ if db:
246
+ args += ["-db", db]
247
+ if ql:
248
+ args += ["-ql", ql]
249
+ if goroutine:
250
+ args += ["-goroutine"]
251
+ if isinstance(max_goroutines, int):
252
+ args += ["-max-goroutines", str(max_goroutines)]
253
+ if isinstance(threads, int):
254
+ args += ["-threads", str(threads)]
255
+ if clean_cache:
256
+ args += ["-clean-cache"]
257
+
258
+ return await _run_subprocess([resolved_path, *args], cwd=cwd, timeout=timeout_seconds)
259
+
260
+
261
+ def main():
262
+ # 以 STDIO 方式启动 MCP 服务
263
+ print("MCP server started in STDIO mode")
264
+ app.run(transport="stdio")
265
+
266
+ if __name__ == "__main__":
267
+ main()
@@ -0,0 +1 @@
1
+ iflow-mcp_yezere-codeql_n1ght_mcp_server
@@ -0,0 +1,19 @@
1
+ [project]
2
+ name = "iflow-mcp_yezere-codeql_n1ght_mcp_server"
3
+ version = "0.1.0"
4
+ description = "MCP server for CodeQL N1ght tool integration"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ dependencies = [
8
+ "mcp>=1.1.0",
9
+ ]
10
+
11
+ [project.scripts]
12
+ codeql-n1ght-mcp = "codeql_n1ght_mcp_server:main"
13
+
14
+ [build-system]
15
+ requires = ["hatchling"]
16
+ build-backend = "hatchling.build"
17
+
18
+ [tool.hatch.build.targets.wheel]
19
+ packages = ["."]