mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
feat: print MCP Server logs
This commit is contained in:
+16
-1
@@ -1,8 +1,10 @@
|
||||
package mcp
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -92,7 +94,7 @@ func (h *MCPHub) connectToServer(ctx context.Context, serverName string, config
|
||||
delete(h.connections, serverName)
|
||||
}
|
||||
|
||||
var mcpClient client.MCPClient
|
||||
var mcpClient *client.Client
|
||||
var err error
|
||||
|
||||
// create client
|
||||
@@ -113,6 +115,16 @@ func (h *MCPHub) connectToServer(ctx context.Context, serverName string, config
|
||||
return fmt.Errorf("failed to create client: %w", err)
|
||||
}
|
||||
|
||||
// print MCP Server logs
|
||||
stderr := client.GetStderr(mcpClient)
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(stderr)
|
||||
for scanner.Scan() {
|
||||
fmt.Fprintf(os.Stderr, "MCP Server %s: %s\n",
|
||||
serverName, scanner.Text())
|
||||
}
|
||||
}()
|
||||
|
||||
// prepare client init request
|
||||
initRequest := mcp.InitializeRequest{}
|
||||
initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
|
||||
@@ -196,6 +208,9 @@ func (h *MCPHub) GetTool(ctx context.Context, serverName, toolName string) (*mcp
|
||||
func (h *MCPHub) InvokeTool(ctx context.Context,
|
||||
serverName, toolName string, arguments map[string]interface{},
|
||||
) (*mcp.CallToolResult, error) {
|
||||
log.Info().Str("tool", toolName).Interface("args", arguments).
|
||||
Str("server", serverName).Msg("invoke tool")
|
||||
|
||||
conn, err := h.GetClient(serverName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err,
|
||||
|
||||
Reference in New Issue
Block a user