feat: invoke tool in hrp server

This commit is contained in:
lilong.129
2025-04-01 21:55:58 +08:00
parent 0c80e3d872
commit 86d0555074
5 changed files with 109 additions and 4 deletions

34
server/tool.go Normal file
View File

@@ -0,0 +1,34 @@
package server
import (
"errors"
"github.com/gin-gonic/gin"
)
type ToolRequest struct {
ServerName string `json:"server_name"`
ToolName string `json:"tool_name"`
Args map[string]interface{} `json:"args"`
}
func (r *Router) invokeToolHandler(c *gin.Context) {
if r.mcpHub == nil {
RenderError(c, errors.New("mcp hub not initialized"))
return
}
var req ToolRequest
if err := c.ShouldBindJSON(&req); err != nil {
RenderError(c, err)
return
}
result, err := r.mcpHub.InvokeTool(c.Request.Context(),
req.ServerName, req.ToolName, req.Args)
if err != nil {
RenderError(c, err)
return
}
RenderSuccess(c, result)
}