mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-29 03:21:29 +08:00
refactor: move mcp to pkg/mcphost
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/internal/mcp"
|
||||
"github.com/httprunner/httprunner/v5/pkg/mcphost"
|
||||
"github.com/httprunner/httprunner/v5/uixt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -22,23 +22,23 @@ func NewRouter() *Router {
|
||||
|
||||
type Router struct {
|
||||
*gin.Engine
|
||||
mcpHub *mcp.MCPHub
|
||||
mcpHost *mcphost.MCPHost
|
||||
}
|
||||
|
||||
func (r *Router) InitMCPHub(configPath string) error {
|
||||
mcpHub, err := mcp.NewMCPHub(configPath)
|
||||
func (r *Router) InitMCPHost(configPath string) error {
|
||||
mcpHost, err := mcphost.NewMCPHost(configPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("init MCP hub failed")
|
||||
log.Error().Err(err).Msg("init MCP host failed")
|
||||
return err
|
||||
}
|
||||
|
||||
err = mcpHub.InitServers(context.Background())
|
||||
err = mcpHost.InitServers(context.Background())
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("init MCP servers failed")
|
||||
return err
|
||||
}
|
||||
|
||||
r.mcpHub = mcpHub
|
||||
r.mcpHost = mcpHost
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ type ToolRequest struct {
|
||||
}
|
||||
|
||||
func (r *Router) invokeToolHandler(c *gin.Context) {
|
||||
if r.mcpHub == nil {
|
||||
RenderError(c, errors.New("mcp hub not initialized"))
|
||||
if r.mcpHost == nil {
|
||||
RenderError(c, errors.New("mcp host not initialized"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func (r *Router) invokeToolHandler(c *gin.Context) {
|
||||
req.Args["platform"] = c.Param("platform")
|
||||
req.Args["serial"] = c.Param("serial")
|
||||
|
||||
result, err := r.mcpHub.InvokeTool(c.Request.Context(),
|
||||
result, err := r.mcpHost.InvokeTool(c.Request.Context(),
|
||||
req.ServerName, req.ToolName, req.Args)
|
||||
if err != nil {
|
||||
RenderError(c, err)
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestTapHandler(t *testing.T) {
|
||||
|
||||
func TestInvokeToolHandler(t *testing.T) {
|
||||
router := NewRouter()
|
||||
router.InitMCPHub("../internal/mcp/testdata/test.mcp.json")
|
||||
router.InitMCPHost("../internal/mcp/testdata/test.mcp.json")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user