Skip to content

Commit d07b636

Browse files
authored
fix: fix the reliance on resources (#31)
1 parent ae858e8 commit d07b636

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

pkg/tools/scan/aqua.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package scan
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"os"
7-
"strings"
88

99
"path/filepath"
1010

@@ -16,6 +16,9 @@ import (
1616

1717
func (t *ScanTools) scanWithAquaPlatform(ctx context.Context, args []string, creds creds.AquaCreds) (*mcp.CallToolResult, error) {
1818

19+
// add quiet to reduce the noise
20+
args = append(args, "--quiet")
21+
1922
logger := log.WithPrefix("aqua")
2023
logger.Debug("Scanning with args", log.Any("args", args))
2124
logger.Info("Using Aqua platform for scanning")
@@ -66,14 +69,15 @@ func (t *ScanTools) scanWithAquaPlatform(ctx context.Context, args []string, cre
6669

6770
logger.Debug("Environment", log.Any("ENV", os.Environ()))
6871

69-
tempFile := filepath.Join(os.TempDir(), "trivy-mcp-scan.results.json")
72+
filename := "trivy-mcp-scan.results.json"
73+
resultsFilePath := filepath.Join(os.TempDir(), filename)
7074
defer func() {
71-
if err := os.Remove(tempFile); err != nil {
75+
if err := os.Remove(resultsFilePath); err != nil {
7276
logger.Error("Failed to remove temp file", log.Err(err))
7377
}
7478
}()
7579

76-
if err := os.Setenv("AQUA_ASSURANCE_EXPORT", tempFile); err != nil {
80+
if err := os.Setenv("AQUA_ASSURANCE_EXPORT", resultsFilePath); err != nil {
7781
logger.Error("Failed to set Aqua assurance export in environment variables", log.Err(err))
7882
return nil, err
7983
}
@@ -83,11 +87,15 @@ func (t *ScanTools) scanWithAquaPlatform(ctx context.Context, args []string, cre
8387
return nil, err
8488
}
8589

86-
sb := strings.Builder{}
87-
sb.WriteString("Aqua scan results:\n")
88-
sb.WriteString("====================================\n")
89-
sb.WriteString("Scan completed successfully\n")
90-
91-
return mcp.NewToolResultText(sb.String()), nil
90+
return mcp.NewToolResultResource(
91+
fmt.Sprintf(`The results can be found in the file "%s", which is found at "%s" \n
92+
Summarise the contents of the file and report it back to the user in a nicely formatted way.\n
93+
It is important that the output MUST include the ID and the severity of the issues to inform the user of the issues.
94+
`, filename, resultsFilePath),
95+
mcp.TextResourceContents{
96+
URI: resultsFilePath,
97+
MIMEType: "application/json",
98+
},
99+
), nil
92100

93101
}

pkg/tools/scan/scan.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,14 @@ func (t *ScanTools) ScanWithTrivyHandler(ctx context.Context, request mcp.CallTo
160160
return result, nil
161161
}
162162

163-
defer func() {
164-
if err := os.Remove(resultsFilePath); err != nil {
165-
logger.Error("Failed to remove results file", log.Err(err))
166-
}
167-
}()
168-
169-
content, err := os.ReadFile(resultsFilePath)
170-
if err != nil {
171-
logger.Error("Failed to read scan results file", log.Err(err))
172-
return nil, errors.New("failed to read scan results file")
173-
}
174-
175163
return mcp.NewToolResultResource(
176-
"The embedded resource is a human readable JSON format and found at the filepath that can be further processed.",
164+
fmt.Sprintf(`The results can be found in the file "%s", which is found at "%s" \n
165+
Summarise the contents of the file and report it back to the user in a nicely formatted way.\n
166+
It is important that the output MUST include the ID and the severity of the issues to inform the user of the issues.
167+
`, filename, resultsFilePath),
177168
mcp.TextResourceContents{
178-
URI: resultsFilePath,
179-
Text: string(content),
169+
URI: resultsFilePath,
170+
MIMEType: "application/json",
180171
},
181172
), nil
182173
}

plugin.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: mcp
22
repository: github.com/aquasecurity/trivy-mcp
33
maintainer: aquasecurity
4-
version: 0.0.6
4+
version: 0.0.7
55
summary: Starts an MCP server that knows how to work with Trivy
66
description: |-
77
A Trivy plugin that starts an MCP server that knows how to work with Trivy.
@@ -10,25 +10,25 @@ platforms:
1010
- selector:
1111
os: linux
1212
arch: amd64
13-
uri: https://github.com/aquasecurity/trivy-mcp/releases/download/v0.0.6/trivy-mcp-linux-amd64.tar.gz
13+
uri: https://github.com/aquasecurity/trivy-mcp/releases/download/v0.0.7/trivy-mcp-linux-amd64.tar.gz
1414
bin: ./trivy-mcp
1515
- selector:
1616
os: linux
1717
arch: arm64
18-
uri: https://github.com/aquasecurity/trivy-mcp/releases/download/v0.0.6/trivy-mcp-linux-arm64.tar.gz
18+
uri: https://github.com/aquasecurity/trivy-mcp/releases/download/v0.0.7/trivy-mcp-linux-arm64.tar.gz
1919
bin: ./trivy-mcp
2020
- selector:
2121
os: darwin
2222
arch: amd64
23-
uri: https://github.com/aquasecurity/trivy-mcp/releases/download/v0.0.6/trivy-mcp-darwin-amd64.tar.gz
23+
uri: https://github.com/aquasecurity/trivy-mcp/releases/download/v0.0.7/trivy-mcp-darwin-amd64.tar.gz
2424
bin: ./trivy-mcp
2525
- selector:
2626
os: darwin
2727
arch: arm64
28-
uri: https://github.com/aquasecurity/trivy-mcp/releases/download/v0.0.6/trivy-mcp-darwin-arm64.tar.gz
28+
uri: https://github.com/aquasecurity/trivy-mcp/releases/download/v0.0.7/trivy-mcp-darwin-arm64.tar.gz
2929
bin: ./trivy-mcp
3030
- selector:
3131
os: windows
3232
arch: amd64
33-
uri: https://github.com/aquasecurity/trivy-mcp/releases/download/v0.0.6/trivy-mcp-windows-amd64.tar.gz
33+
uri: https://github.com/aquasecurity/trivy-mcp/releases/download/v0.0.7/trivy-mcp-windows-amd64.tar.gz
3434
bin: ./trivy-mcp

0 commit comments

Comments
 (0)