Skip to content

Commit 9f49900

Browse files
Add SCM context to lightweight MCP response: purl, scm_type, and rename ref to git_ref
Co-authored-by: fproulx-boostsecurity <76956526+fproulx-boostsecurity@users.noreply.github.com>
1 parent c922624 commit 9f49900

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

cmd/mcp_lightweight_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ func TestMCPResponseStructure(t *testing.T) {
7373
response := mcpAnalysisResponse{
7474
Findings: []results.Finding{},
7575
Rules: map[string]results.Rule{},
76+
Purl: "pkg:github/owner/repo@main",
7677
Repository: "owner/repo",
77-
Ref: "main",
78+
ScmType: "github",
79+
GitRef: "main",
7880
CommitSha: "abc123",
7981
LastCommit: "2023-01-01T00:00:00Z",
8082
}
@@ -87,8 +89,10 @@ func TestMCPResponseStructure(t *testing.T) {
8789
// Verify lightweight structure
8890
assert.Contains(t, jsonStr, "\"findings\":")
8991
assert.Contains(t, jsonStr, "\"rules\":")
92+
assert.Contains(t, jsonStr, "\"purl\":")
9093
assert.Contains(t, jsonStr, "\"repository\":")
91-
assert.Contains(t, jsonStr, "\"ref\":")
94+
assert.Contains(t, jsonStr, "\"scm_type\":")
95+
assert.Contains(t, jsonStr, "\"git_ref\":")
9296
assert.Contains(t, jsonStr, "\"commit_sha\":")
9397
assert.Contains(t, jsonStr, "\"last_commit\":")
9498

@@ -115,8 +119,10 @@ func TestMCPResponseOmitsEmptyFields(t *testing.T) {
115119
jsonStr := string(data)
116120

117121
// These fields should be omitted when empty due to omitempty tag
122+
assert.NotContains(t, jsonStr, "\"purl\":")
118123
assert.NotContains(t, jsonStr, "\"repository\":")
119-
assert.NotContains(t, jsonStr, "\"ref\":")
124+
assert.NotContains(t, jsonStr, "\"scm_type\":")
125+
assert.NotContains(t, jsonStr, "\"git_ref\":")
120126
assert.NotContains(t, jsonStr, "\"commit_sha\":")
121127
assert.NotContains(t, jsonStr, "\"last_commit\":")
122128

@@ -133,8 +139,10 @@ func TestMCPResponseSizeReduction(t *testing.T) {
133139
lightweightResponse := mcpAnalysisResponse{
134140
Findings: []results.Finding{},
135141
Rules: map[string]results.Rule{},
142+
Purl: "pkg:github/test/repo@main",
136143
Repository: "test/repo",
137-
Ref: "main",
144+
ScmType: "github",
145+
GitRef: "main",
138146
CommitSha: "abc123",
139147
LastCommit: "2023-01-01T00:00:00Z",
140148
}

cmd/mcp_server.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ type mcpAnalysisResponse struct {
2626
Findings []results.Finding `json:"findings"`
2727
Rules map[string]results.Rule `json:"rules"`
2828
// Essential repository metadata
29+
Purl string `json:"purl,omitempty"`
2930
Repository string `json:"repository,omitempty"`
30-
Ref string `json:"ref,omitempty"`
31+
ScmType string `json:"scm_type,omitempty"`
32+
GitRef string `json:"git_ref,omitempty"`
3133
CommitSha string `json:"commit_sha,omitempty"`
3234
LastCommit string `json:"last_commit,omitempty"`
3335
}
@@ -312,8 +314,10 @@ func handleAnalyzeOrg(ctx context.Context, request mcp.CallToolRequest) (*mcp.Ca
312314
combinedResponses = append(combinedResponses, mcpAnalysisResponse{
313315
Findings: pkgInsights.FindingsResults.Findings,
314316
Rules: pkgInsights.FindingsResults.Rules,
317+
Purl: pkgInsights.Purl,
315318
Repository: pkgInsights.SourceGitRepo,
316-
Ref: pkgInsights.SourceGitRef,
319+
ScmType: pkgInsights.SourceScmType,
320+
GitRef: pkgInsights.SourceGitRef,
317321
CommitSha: pkgInsights.SourceGitCommitSha,
318322
LastCommit: pkgInsights.LastCommitedAt,
319323
})
@@ -357,8 +361,10 @@ func handleAnalyzeRepo(ctx context.Context, request mcp.CallToolRequest) (*mcp.C
357361
combinedResponse := mcpAnalysisResponse{
358362
Findings: analysisResults.FindingsResults.Findings,
359363
Rules: analysisResults.FindingsResults.Rules,
364+
Purl: analysisResults.Purl,
360365
Repository: analysisResults.SourceGitRepo,
361-
Ref: analysisResults.SourceGitRef,
366+
ScmType: analysisResults.SourceScmType,
367+
GitRef: analysisResults.SourceGitRef,
362368
CommitSha: analysisResults.SourceGitCommitSha,
363369
LastCommit: analysisResults.LastCommitedAt,
364370
}
@@ -398,8 +404,10 @@ func handleAnalyzeLocal(ctx context.Context, request mcp.CallToolRequest, opaCli
398404
combinedResponse := mcpAnalysisResponse{
399405
Findings: analysisResults.FindingsResults.Findings,
400406
Rules: analysisResults.FindingsResults.Rules,
407+
Purl: analysisResults.Purl,
401408
Repository: analysisResults.SourceGitRepo,
402-
Ref: analysisResults.SourceGitRef,
409+
ScmType: analysisResults.SourceScmType,
410+
GitRef: analysisResults.SourceGitRef,
403411
CommitSha: analysisResults.SourceGitCommitSha,
404412
LastCommit: analysisResults.LastCommitedAt,
405413
}
@@ -450,8 +458,10 @@ func handleAnalyzeStaleBranches(ctx context.Context, request mcp.CallToolRequest
450458
combinedResponse := mcpAnalysisResponse{
451459
Findings: analysisResults.FindingsResults.Findings,
452460
Rules: analysisResults.FindingsResults.Rules,
461+
Purl: analysisResults.Purl,
453462
Repository: analysisResults.SourceGitRepo,
454-
Ref: analysisResults.SourceGitRef,
463+
ScmType: analysisResults.SourceScmType,
464+
GitRef: analysisResults.SourceGitRef,
455465
CommitSha: analysisResults.SourceGitCommitSha,
456466
LastCommit: analysisResults.LastCommitedAt,
457467
}

0 commit comments

Comments
 (0)