diff --git a/cmd/litestream/mcp.go b/cmd/litestream/mcp.go index fb5f8bdeb..86149558e 100644 --- a/cmd/litestream/mcp.go +++ b/cmd/litestream/mcp.go @@ -243,16 +243,11 @@ func RestoreTool(configPath string) (mcp.Tool, server.ToolHandlerFunc) { func VersionTool() (mcp.Tool, server.ToolHandlerFunc) { tool := mcp.NewTool("litestream_version", - mcp.WithDescription("Print the Litestream binary version."), + mcp.WithDescription("Print the running Litestream daemon version."), ) return tool, func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { - cmd := exec.CommandContext(ctx, "litestream", "version") - output, err := cmd.CombinedOutput() - if err != nil { - return mcp.NewToolResultError(strings.TrimSpace(string(output)) + ": " + err.Error()), nil - } - return mcp.NewToolResultText(string(output)), nil + return mcp.NewToolResultText(Version + "\n"), nil } } diff --git a/cmd/litestream/mcp_test.go b/cmd/litestream/mcp_test.go new file mode 100644 index 000000000..36b7d9eea --- /dev/null +++ b/cmd/litestream/mcp_test.go @@ -0,0 +1,33 @@ +package main + +import ( + "testing" + + "github.com/mark3labs/mcp-go/mcp" +) + +func TestVersionTool(t *testing.T) { + prevVersion := Version + t.Cleanup(func() { Version = prevVersion }) + Version = resolveVersion("v0.5.14-running", nil) + t.Setenv("PATH", t.TempDir()) + + _, handler := VersionTool() + result, err := handler(t.Context(), mcp.CallToolRequest{}) + if err != nil { + t.Fatal(err) + } + if result.IsError { + t.Fatalf("unexpected tool error: %#v", result.Content) + } + if got, want := len(result.Content), 1; got != want { + t.Fatalf("content length=%d, want %d", got, want) + } + content, ok := result.Content[0].(mcp.TextContent) + if !ok { + t.Fatalf("content type=%T, want mcp.TextContent", result.Content[0]) + } + if got, want := content.Text, Version+"\n"; got != want { + t.Fatalf("content=%q, want %q", got, want) + } +}