🔊 Add logger to mcp

issue #64
This commit is contained in:
OpenWaygate committed 2025-08-18 00:46:57 +08:00
1 parent 367140ebb8
commit df7d5f4135
51 files changed
+727 -49

No files matched your search

+14 -1
View File
@@ -3,12 +3,14 @@ package channel
import (
"bytes"
"context"
"io"
"log/slog"
"github.com/eat-pray-ai/yutu/cmd"
"github.com/eat-pray-ai/yutu/pkg/channel"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/mark3labs/mcp-go/mcp"
"github.com/spf13/cobra"
"io"
)
const (
@@ -161,11 +163,22 @@ func listHandler(
output, _ = args["output"].(string)
jpath, _ = args["jsonpath"].(string)
slog.InfoContext(ctx, "channel list started")
var writer bytes.Buffer
err := list(&writer)
if err != nil {
slog.ErrorContext(
ctx, "channel list failed",
"error", err,
"args", args,
)
return mcp.NewToolResultError(err.Error()), err
}
slog.InfoContext(
ctx, "channel list completed successfully",
"resultSize", writer.Len(),
)
return mcp.NewToolResultText(writer.String()), nil
}
+14 -1
View File
@@ -3,11 +3,13 @@ package channel
import (
"bytes"
"context"
"io"
"log/slog"
"github.com/eat-pray-ai/yutu/cmd"
"github.com/eat-pray-ai/yutu/pkg/channel"
"github.com/mark3labs/mcp-go/mcp"
"github.com/spf13/cobra"
"io"
)
const (
@@ -113,11 +115,22 @@ func updateHandler(
output, _ = args["output"].(string)
jpath, _ = args["jsonpath"].(string)
slog.InfoContext(ctx, "channel update started")
var writer bytes.Buffer
err := update(&writer)
if err != nil {
slog.ErrorContext(
ctx, "channel update failed",
"error", err,
"args", args,
)
return mcp.NewToolResultError(err.Error()), err
}
slog.InfoContext(
ctx, "channel update completed successfully",
"resultSize", writer.Len(),
)
return mcp.NewToolResultText(writer.String()), nil
}