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

View File

@@ -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