perf:分离cli和rpc,加入mcp模块

This commit is contained in:
tongque 2025-04-28 19:22:08 +08:00
parent 0dc4a6c360
commit 0f0da9fd0a
13 changed files with 47 additions and 18 deletions

View File

@ -152,8 +152,7 @@ func Flag(Info *HostInfo) {
// ═════════════════════════════════════════════════
flag.StringVar(&Shellcode, "sc", "", GetText("flag_shellcode"))
flag.StringVar(&Language, "lang", "zh", GetText("flag_language"))
flag.StringVar(&ApiAddr, "api", "", GetText("flag_api"))
flag.StringVar(&SecretKey, "secret", "", GetText("flag_api_key"))
// 解析命令行参数
parseCommandLineArgs()

29
Remote/remote.go Normal file
View File

@ -0,0 +1,29 @@
package main
import (
"flag"
"github.com/shadow1ng/fscan/Common"
"github.com/shadow1ng/fscan/Remote/server"
)
func main() {
// 初始化日志系统
Common.InitLogger()
var apiURL string
var secret string
var transport string
var Info Common.HostInfo
flag.StringVar(&apiURL, "api", "", "RPC调用地址")
flag.StringVar(&secret, "secret", "", "RPC调用使用的秘钥")
flag.StringVar(&transport, "transport", "stdio", "MCP传输协议stdio 或 sse")
Common.Flag(&Info)
if apiURL != "" {
Common.ApiAddr = apiURL
server.StartApiServer(apiURL, secret)
} else {
server.StartMcpServer(transport)
}
}

9
Remote/server/mcp.go Normal file
View File

@ -0,0 +1,9 @@
package server
import "fmt"
func StartMcpServer(transport string) error {
fmt.Println("Starting MCP server...")
fmt.Println("Transport protocol:", transport)
return nil
}

View File

@ -1,4 +1,4 @@
package rpc
package server
import (
"context"
@ -8,8 +8,8 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/shadow1ng/fscan/Common"
pb "github.com/shadow1ng/fscan/RPC/lib"
"github.com/shadow1ng/fscan/RPC/service"
pb "github.com/shadow1ng/fscan/Remote/lib"
"github.com/shadow1ng/fscan/Remote/service"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
@ -17,18 +17,15 @@ import (
var internalSecretKey string
// 启动 gRPC + HTTP Gateway 服务(仅当设置了 API 地址时)
func StartApiServer() error {
if Common.ApiAddr == "" {
return nil
}
if Common.SecretKey != "" {
internalSecretKey = Common.SecretKey
func StartApiServer(apiURL, sercetkey string) error {
if sercetkey != "" {
internalSecretKey = sercetkey
} else {
internalSecretKey = time.Now().Format("20060102150405")
}
grpcAddr := "127.0.0.1:50051"
httpAddr := validateHTTPAddr(Common.ApiAddr, ":8088")
httpAddr := validateHTTPAddr(apiURL, ":8088")
go runGRPCServer(grpcAddr)

View File

@ -9,7 +9,7 @@ import (
"github.com/shadow1ng/fscan/Common"
"github.com/shadow1ng/fscan/Core"
pb "github.com/shadow1ng/fscan/RPC/lib"
pb "github.com/shadow1ng/fscan/Remote/lib"
structpb "google.golang.org/protobuf/types/known/structpb"
)

View File

@ -6,7 +6,6 @@ import (
"github.com/shadow1ng/fscan/Common"
"github.com/shadow1ng/fscan/Core"
rpc "github.com/shadow1ng/fscan/RPC"
)
func main() {
@ -15,10 +14,6 @@ func main() {
var Info Common.HostInfo
Common.Flag(&Info)
// 启动 gRPC + HTTP Gateway 服务
if err := rpc.StartApiServer(); err != nil {
os.Exit(1)
}
// 解析 CLI 参数
if err := Common.Parse(&Info); err != nil {
os.Exit(1)