@@ -2,6 +2,7 @@ package tools
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67
78 mcpgo "github.com/mark3labs/mcp-go/mcp"
@@ -67,7 +68,17 @@ func (t *packageInsightsTool) executeGetPackageVulnerabilities(ctx context.Conte
6768
6869 vulns , err := t .driver .GetPackageVersionVulnerabilities (ctx , parsedPurl .PackageVersion ())
6970 if err != nil {
70- return nil , fmt .Errorf ("failed to get package vulnerabilities: %w" , err )
71+ if errors .Is (err , mcp .ErrPackageVersionInsightNotFound ) {
72+ return toolResultFromLlmError (
73+ fmt .Sprintf ("no package insights found for package: %s" , purl ),
74+ llmErrorCodePackageInsightNotFound ,
75+ )
76+ }
77+
78+ return toolResultFromLlmError (
79+ fmt .Sprintf ("failed to get package vulnerabilities: %v" , err ),
80+ llmErrorCodeUpstreamError ,
81+ )
7182 }
7283
7384 logger .Debugf ("Found %d vulnerabilities for package: %s" , len (vulns ), purl )
@@ -97,7 +108,17 @@ func (t *packageInsightsTool) executeGetPackagePopularity(ctx context.Context,
97108
98109 popularity , err := t .driver .GetPackageVersionPopularity (ctx , parsedPurl .PackageVersion ())
99110 if err != nil {
100- return nil , fmt .Errorf ("failed to get package popularity: %w" , err )
111+ if errors .Is (err , mcp .ErrPackageVersionInsightNotFound ) {
112+ return toolResultFromLlmError (
113+ fmt .Sprintf ("no package insights found for package: %s" , purl ),
114+ llmErrorCodePackageInsightNotFound ,
115+ )
116+ }
117+
118+ return toolResultFromLlmError (
119+ fmt .Sprintf ("failed to get package popularity: %v" , err ),
120+ llmErrorCodeUpstreamError ,
121+ )
101122 }
102123
103124 logger .Debugf ("Found %d popularity for package: %s" , len (popularity ), purl )
@@ -127,11 +148,24 @@ func (t *packageInsightsTool) executeGetPackageLicenseInfo(ctx context.Context,
127148
128149 licenseInfo , err := t .driver .GetPackageVersionLicenseInfo (ctx , parsedPurl .PackageVersion ())
129150 if err != nil {
130- return nil , fmt .Errorf ("failed to get package license info: %w" , err )
151+ if errors .Is (err , mcp .ErrPackageVersionInsightNotFound ) {
152+ return toolResultFromLlmError (
153+ fmt .Sprintf ("no package insights found for package: %s" , purl ),
154+ llmErrorCodePackageInsightNotFound ,
155+ )
156+ }
157+
158+ return toolResultFromLlmError (
159+ fmt .Sprintf ("failed to get package license info: %v" , err ),
160+ llmErrorCodeUpstreamError ,
161+ )
131162 }
132163
133164 if licenseInfo == nil {
134- return nil , fmt .Errorf ("no license info returned for package: %s" , purl )
165+ return toolResultFromLlmError (
166+ fmt .Sprintf ("no license info returned for package: %s" , purl ),
167+ llmErrorCodePackageInsightNotFound ,
168+ )
135169 }
136170
137171 logger .Debugf ("Found %d license info for package: %s" , len (licenseInfo .Licenses ), purl )
0 commit comments