Skip to content

Commit 086fa0c

Browse files
Copilotkeac
andcommitted
Add custom port support for --mcp parameter
- Change --mcp from boolean to string flag - Support formats: :8080, http://localhost:8080 - Falls back to config.yaml if not specified - Update all IsMCPServer references to MCPServer string check Co-authored-by: keac <[email protected]>
1 parent 1f8e2d0 commit 086fa0c

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.dll
55
*.so
66
*.dylib
7+
enscan
78

89
.idea
910
# Test binary, built with `go test -c`
@@ -12,6 +13,7 @@
1213
# Output of the go coverage tool, specifically when used with LiteIDE
1314
*.out
1415
config.yaml
16+
*.gob
1517
/res
1618
/out
1719
/Report

common/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ type ENOptions struct {
4646
IsNoMerge bool //聚合
4747
OutPutType string // 导出文件类型
4848
IsApiMode bool
49-
IsMCPServer bool
50-
IsPlugins bool // 是否作为后置插件查询
49+
MCPServer string // MCP模式运行地址,如 :8080 或 http://localhost:8080
50+
IsPlugins bool // 是否作为后置插件查询
5151
IsFast bool // 是否快速查询
5252
ENConfig *ENConfig
5353
BranchFilter string

common/flag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Flag(Info *ENOptions) {
4949
//其他设定
5050
flag.BoolVar(&Info.IsGroup, "is-group", false, "查询关键词为集团")
5151
flag.BoolVar(&Info.IsApiMode, "api", false, "API模式运行")
52-
flag.BoolVar(&Info.IsMCPServer, "mcp", false, "MCP模式运行")
52+
flag.StringVar(&Info.MCPServer, "mcp", "", "MCP模式运行,可指定监听地址,如 :8080 或 http://localhost:8080")
5353
flag.BoolVar(&Info.ISKeyPid, "is-pid", false, "批量查询文件是否为公司PID")
5454
flag.IntVar(&Info.DelayTime, "delay", 0, "每个请求延迟(S)-1为随机延迟1-5S")
5555
flag.StringVar(&Info.Proxy, "proxy", "", "设置代理")

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.IsMCPServer {
57+
if op.KeyWord == "" && op.CompanyID == "" && op.InputFile == "" && !op.IsApiMode && op.MCPServer == "" {
5858
flag.PrintDefaults()
5959
os.Exit(0)
6060
}

runner/mcpServer.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,20 @@ func McpServer(options *common.ENOptions) {
180180
),
181181
), getInfoByKeyword(enTask))
182182
enTask.StartENWorkers()
183-
sseServer := server.NewSSEServer(s, server.WithBaseURL(options.ENConfig.Api.Mcp))
184-
port, err := utils.ExtractPortString(options.ENConfig.Api.Mcp)
183+
184+
// 优先使用命令行参数,否则使用配置文件
185+
mcpAddr := options.MCPServer
186+
if mcpAddr == "" {
187+
mcpAddr = options.ENConfig.Api.Mcp
188+
}
189+
190+
// 如果只提供了端口(如 :8080),则补全为完整URL
191+
if len(mcpAddr) > 0 && mcpAddr[0] == ':' {
192+
mcpAddr = "http://localhost" + mcpAddr
193+
}
194+
195+
sseServer := server.NewSSEServer(s, server.WithBaseURL(mcpAddr))
196+
port, err := utils.ExtractPortString(mcpAddr)
185197
if err != nil {
186198
gologger.Error().Msgf("MCP服务启动失败!")
187199
gologger.Fatal().Msgf(err.Error())

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.IsMCPServer {
119+
} else if options.MCPServer != "" {
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.IsMCPServer {
333+
if !q.op.IsApiMode && q.op.MCPServer == "" {
334334
gologger.Error().Msgf("任务未完成退出,将自动保存过程文件!")
335335
_ = q.OutFileByEnInfo("未完成任务结果")
336336
}

0 commit comments

Comments
 (0)