feat: add MCP config support to hrp run command with priority handling

This commit is contained in:
lilong.129
2025-05-28 23:11:52 +08:00
parent 4ea08b0198
commit 08a8b06578
3 changed files with 24 additions and 5 deletions
+5
View File
@@ -35,6 +35,7 @@ var (
saveTests bool saveTests bool
genHTMLReport bool genHTMLReport bool
caseTimeout float32 caseTimeout float32
runMCPConfigPath string // MCP config path for run command
) )
func init() { func init() {
@@ -46,6 +47,7 @@ func init() {
CmdRun.Flags().BoolVarP(&saveTests, "save-tests", "s", false, "save tests summary") CmdRun.Flags().BoolVarP(&saveTests, "save-tests", "s", false, "save tests summary")
CmdRun.Flags().BoolVarP(&genHTMLReport, "gen-html-report", "g", false, "generate html report") CmdRun.Flags().BoolVarP(&genHTMLReport, "gen-html-report", "g", false, "generate html report")
CmdRun.Flags().Float32Var(&caseTimeout, "case-timeout", 3600, "set testcase timeout (seconds)") CmdRun.Flags().Float32Var(&caseTimeout, "case-timeout", 3600, "set testcase timeout (seconds)")
CmdRun.Flags().StringVar(&runMCPConfigPath, "mcp-config", "", "path to the MCP config file")
} }
func makeHRPRunner() *hrp.HRPRunner { func makeHRPRunner() *hrp.HRPRunner {
@@ -71,5 +73,8 @@ func makeHRPRunner() *hrp.HRPRunner {
if proxyUrl != "" { if proxyUrl != "" {
runner.SetProxyUrl(proxyUrl) runner.SetProxyUrl(proxyUrl)
} }
if runMCPConfigPath != "" {
runner.SetMCPConfigPath(runMCPConfigPath)
}
return runner return runner
} }
+1 -1
View File
@@ -1 +1 @@
v5.0.0-beta-2505282259 v5.0.0-beta-2505282311
+18 -4
View File
@@ -52,6 +52,7 @@ func NewRunner(t *testing.T) *HRPRunner {
t: t, t: t,
failfast: true, // default to failfast failfast: true, // default to failfast
genHTMLReport: false, genHTMLReport: false,
mcpConfigPath: "",
httpClient: &http.Client{ httpClient: &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
@@ -84,6 +85,7 @@ type HRPRunner struct {
venv string venv string
saveTests bool saveTests bool
genHTMLReport bool genHTMLReport bool
mcpConfigPath string // MCP config file path
httpClient *http.Client httpClient *http.Client
http2Client *http.Client http2Client *http.Client
wsDialer *websocket.Dialer wsDialer *websocket.Dialer
@@ -193,6 +195,13 @@ func (r *HRPRunner) GenHTMLReport() *HRPRunner {
return r return r
} }
// SetMCPConfigPath configures the MCP config path.
func (r *HRPRunner) SetMCPConfigPath(mcpConfigPath string) *HRPRunner {
log.Info().Str("mcpConfigPath", mcpConfigPath).Msg("[init] SetMCPConfigPath")
r.mcpConfigPath = mcpConfigPath
return r
}
// Run starts to execute one or multiple testcases. // Run starts to execute one or multiple testcases.
func (r *HRPRunner) Run(testcases ...ITestCase) (err error) { func (r *HRPRunner) Run(testcases ...ITestCase) (err error) {
log.Info().Str("hrp_version", version.VERSION).Msg("start running") log.Info().Str("hrp_version", version.VERSION).Msg("start running")
@@ -309,14 +318,19 @@ func NewCaseRunner(testcase TestCase, hrpRunner *HRPRunner) (*CaseRunner, error)
} }
// init MCP servers // init MCP servers
if config.MCPConfigPath != "" { mcpConfigPath := hrpRunner.mcpConfigPath
mcpHost, err := mcphost.NewMCPHost(config.MCPConfigPath, false) if mcpConfigPath == "" {
mcpConfigPath = config.MCPConfigPath
}
if mcpConfigPath != "" {
mcpHost, err := mcphost.NewMCPHost(mcpConfigPath, false)
if err != nil { if err != nil {
log.Error().Err(err).Msg("init MCP hub failed") log.Error().Err(err).
Str("mcpConfigPath", mcpConfigPath).Msg("init MCP hub failed")
return nil, err return nil, err
} }
caseRunner.parser.MCPHost = mcpHost caseRunner.parser.MCPHost = mcpHost
log.Info().Str("mcpConfigPath", config.MCPConfigPath).Msg("mcp server loaded") log.Info().Str("mcpConfigPath", mcpConfigPath).Msg("mcp server loaded")
} }
// parse testcase config // parse testcase config