Skip to content

Commit 06aa627

Browse files
authored
Merge pull request #76 from Gerifield/feat/audit-logging-mcp-skills
feat: add audit logging to mcp-skills tool handlers
2 parents 1b1c2a1 + 7607f7a commit 06aa627

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

cmd/server-mcp-skills/tools.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io/fs"
7+
"log/slog"
78
"os"
89
"os/exec"
910
"path/filepath"
@@ -48,6 +49,7 @@ func ensureSafePath(baseDir, reqPath string) (string, error) {
4849
func handleListFiles(baseDir string) func(context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error) {
4950
return func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
5051
pathArg := req.GetString("path", ".")
52+
slog.InfoContext(ctx, "audit: list_files called", slog.String("path", pathArg))
5153

5254
safePath, err := ensureSafePath(baseDir, pathArg)
5355
if err != nil {
@@ -94,6 +96,7 @@ func handleReadFile(baseDir string) func(context.Context, mcp.CallToolRequest) (
9496
if pathArg == "" {
9597
return mcp.NewToolResultError("path parameter is required"), nil
9698
}
99+
slog.InfoContext(ctx, "audit: read_file called", slog.String("path", pathArg))
97100

98101
safePath, err := ensureSafePath(baseDir, pathArg)
99102
if err != nil {
@@ -118,6 +121,7 @@ func handleWriteFile(baseDir string) func(context.Context, mcp.CallToolRequest)
118121
}
119122

120123
contentArg := req.GetString("content", "")
124+
slog.InfoContext(ctx, "audit: write_file called", slog.String("path", pathArg), slog.Int("content_len", len(contentArg)))
121125

122126
safePath, err := ensureSafePath(baseDir, pathArg)
123127
if err != nil {
@@ -146,6 +150,7 @@ func handleExecuteCommand(baseDir string) func(context.Context, mcp.CallToolRequ
146150
if cmdArg == "" {
147151
return mcp.NewToolResultError("command parameter is required"), nil
148152
}
153+
slog.InfoContext(ctx, "audit: execute_command called", slog.String("command", cmdArg))
149154

150155
absBase, err := filepath.Abs(baseDir)
151156
if err != nil {

0 commit comments

Comments
 (0)