Skip to content

Commit 60ae379

Browse files
Copilotkeac
andcommitted
Support --mcp flag without value to use config default
- Implement custom mcpFlag type with IsBoolFlag() support - Allow --mcp (uses config.yaml default) or --mcp=:8080 (custom port) - Add MCPServerSet field to track if flag was explicitly set - Update all MCP server checks to use MCPServerSet flag Co-authored-by: keac <[email protected]>
1 parent 1463b5d commit 60ae379

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

common/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type ENOptions struct {
4747
OutPutType string // 导出文件类型
4848
IsApiMode bool
4949
MCPServer string // MCP模式运行地址,如 :8080 或 http://localhost:8080
50+
MCPServerSet bool // MCP flag是否被设置
5051
IsPlugins bool // 是否作为后置插件查询
5152
IsFast bool // 是否快速查询
5253
ENConfig *ENConfig

common/flag.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@ import (
55
"github.com/wgpsec/ENScan/common/gologger"
66
)
77

8+
// mcpFlag is a custom flag type that supports optional values
9+
// When used as --mcp (without value), it will be set to "true"
10+
// When used as --mcp=:8080 or --mcp=http://..., it will be set to that value
11+
type mcpFlag struct {
12+
value string
13+
changed bool
14+
}
15+
16+
func (m *mcpFlag) String() string {
17+
return m.value
18+
}
19+
20+
func (m *mcpFlag) Set(s string) error {
21+
// When IsBoolFlag returns true and flag is used without value,
22+
// Go sets it to "true". We treat "true" as "use config default"
23+
if s == "true" {
24+
m.value = "" // Empty means use config default
25+
} else {
26+
m.value = s
27+
}
28+
m.changed = true
29+
return nil
30+
}
31+
32+
func (m *mcpFlag) IsBoolFlag() bool {
33+
return true
34+
}
35+
36+
func (m *mcpFlag) Get() (string, bool) {
37+
return m.value, m.changed
38+
}
39+
840
const banner = `
941
1042
███████╗███╗ ██╗███████╗ ██████╗ █████╗ ███╗ ██╗
@@ -49,12 +81,19 @@ func Flag(Info *ENOptions) {
4981
//其他设定
5082
flag.BoolVar(&Info.IsGroup, "is-group", false, "查询关键词为集团")
5183
flag.BoolVar(&Info.IsApiMode, "api", false, "API模式运行")
52-
flag.StringVar(&Info.MCPServer, "mcp", "", "MCP模式运行,可指定监听地址,如 :8080 或 http://localhost:8080")
84+
85+
// MCP flag with optional value support
86+
mcpFlagVar := &mcpFlag{}
87+
flag.Var(mcpFlagVar, "mcp", "MCP模式运行,可指定监听地址,如 :8080 或 http://localhost:8080,不指定则使用配置文件默认值")
88+
5389
flag.BoolVar(&Info.ISKeyPid, "is-pid", false, "批量查询文件是否为公司PID")
5490
flag.IntVar(&Info.DelayTime, "delay", 0, "每个请求延迟(S)-1为随机延迟1-5S")
5591
flag.StringVar(&Info.Proxy, "proxy", "", "设置代理")
5692
flag.IntVar(&Info.TimeOut, "timeout", 1, "每个请求默认1(分钟)超时")
5793
flag.BoolVar(&Info.IsNoMerge, "no-merge", false, "开启后查询文件将单独导出")
5894
flag.BoolVar(&Info.Version, "v", false, "版本信息")
5995
flag.Parse()
96+
97+
// Extract MCP flag value after parsing
98+
Info.MCPServer, Info.MCPServerSet = mcpFlagVar.Get()
6099
}

common/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (op *ENOptions) Parse() {
5454
gologger.Fatal().Msgf("配置文件当前[V%.1f] 程序需要[V%.1f] 不匹配,请备份配置文件重新运行-v\n", conf.Version, cfgYV)
5555
}
5656

57-
if op.KeyWord == "" && op.CompanyID == "" && op.InputFile == "" && !op.IsApiMode && op.MCPServer == "" {
57+
if op.KeyWord == "" && op.CompanyID == "" && op.InputFile == "" && !op.IsApiMode && !op.MCPServerSet {
5858
flag.PrintDefaults()
5959
os.Exit(0)
6060
}

runner/runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func RunEnumeration(options *common.ENOptions) {
116116

117117
} else if options.IsApiMode {
118118
api(options)
119-
} else if options.MCPServer != "" {
119+
} else if options.MCPServerSet {
120120
McpServer(options)
121121
} else {
122122
esjob := NewENTaskQueue(1, options)
@@ -330,7 +330,7 @@ func (q *ESJob) StartENWorkers() {
330330
gologger.Error().Msgf("保存缓存失败: %v", err)
331331
}
332332
case <-quitSig:
333-
if !q.op.IsApiMode && q.op.MCPServer == "" {
333+
if !q.op.IsApiMode && !q.op.MCPServerSet {
334334
gologger.Error().Msgf("任务未完成退出,将自动保存过程文件!")
335335
_ = q.OutFileByEnInfo("未完成任务结果")
336336
}

0 commit comments

Comments
 (0)