mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-25 17:44:02 +08:00
feat: add MCP config support to hrp run command with priority handling
This commit is contained in:
@@ -35,6 +35,7 @@ var (
|
||||
saveTests bool
|
||||
genHTMLReport bool
|
||||
caseTimeout float32
|
||||
runMCPConfigPath string // MCP config path for run command
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -46,6 +47,7 @@ func init() {
|
||||
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().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 {
|
||||
@@ -71,5 +73,8 @@ func makeHRPRunner() *hrp.HRPRunner {
|
||||
if proxyUrl != "" {
|
||||
runner.SetProxyUrl(proxyUrl)
|
||||
}
|
||||
if runMCPConfigPath != "" {
|
||||
runner.SetMCPConfigPath(runMCPConfigPath)
|
||||
}
|
||||
return runner
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
v5.0.0-beta-2505282259
|
||||
v5.0.0-beta-2505282311
|
||||
|
||||
22
runner.go
22
runner.go
@@ -52,6 +52,7 @@ func NewRunner(t *testing.T) *HRPRunner {
|
||||
t: t,
|
||||
failfast: true, // default to failfast
|
||||
genHTMLReport: false,
|
||||
mcpConfigPath: "",
|
||||
httpClient: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
@@ -84,6 +85,7 @@ type HRPRunner struct {
|
||||
venv string
|
||||
saveTests bool
|
||||
genHTMLReport bool
|
||||
mcpConfigPath string // MCP config file path
|
||||
httpClient *http.Client
|
||||
http2Client *http.Client
|
||||
wsDialer *websocket.Dialer
|
||||
@@ -193,6 +195,13 @@ func (r *HRPRunner) GenHTMLReport() *HRPRunner {
|
||||
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.
|
||||
func (r *HRPRunner) Run(testcases ...ITestCase) (err error) {
|
||||
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
|
||||
if config.MCPConfigPath != "" {
|
||||
mcpHost, err := mcphost.NewMCPHost(config.MCPConfigPath, false)
|
||||
mcpConfigPath := hrpRunner.mcpConfigPath
|
||||
if mcpConfigPath == "" {
|
||||
mcpConfigPath = config.MCPConfigPath
|
||||
}
|
||||
if mcpConfigPath != "" {
|
||||
mcpHost, err := mcphost.NewMCPHost(mcpConfigPath, false)
|
||||
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
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user