Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 9, 2025

Summary

Implements lightweight response structure for MCP server that reduces JSON payload size while preserving all essential security data.

Changes

  • Created lightweight mcpAnalysisResponse struct with only essential fields:
    • Security findings and rule definitions
    • Repository metadata: purl, repository, scm_type, git_ref, commit_sha, last_commit
  • Removed embedded PackageInsights to eliminate heavy fields like github_actions_workflows, package_dependencies, and repository statistics
  • Updated all MCP handlers (analyze_repo, analyze_local, analyze_org, analyze_stale_branches) to use lightweight response
  • Added comprehensive test suite with 4 test cases to verify response structure and prevent regressions

Results

  • ✅ Lightweight response: ~182 bytes for empty findings (vs kilobytes with full PackageInsights)
  • ✅ All essential security findings and repository metadata preserved
  • ✅ Enhanced SCM context with purl and scm_type fields for better repository identification
  • ✅ All tests passing with no regressions

Review Feedback Addressed

  • Added purl field for fully qualified package identifier
  • Added scm_type field to identify SCM platform (github/gitlab)
  • Renamed ref to git_ref for clarity
  • Fixed all gofmt formatting issues

Fixes #359

Copilot AI changed the title [WIP] Update MCP server to return lightweight JSON Reduce MCP server JSON response size by 74% to minimize LLM token consumption Oct 9, 2025
Copilot finished work on behalf of fproulx-boostsecurity October 9, 2025 17:37
@fproulx-boostsecurity fproulx-boostsecurity marked this pull request as ready for review October 9, 2025 19:35
@fproulx-boostsecurity fproulx-boostsecurity requested a review from a team as a code owner October 9, 2025 19:35
@fproulx-boostsecurity

This comment was marked as outdated.

This comment was marked as outdated.

Copilot finished work on behalf of fproulx-boostsecurity October 9, 2025 19:42
Copilot AI changed the title Reduce MCP server JSON response size by 74% to minimize LLM token consumption Reduce MCP server JSON response size to minimize LLM token consumption with enhanced SCM context Oct 9, 2025
Copilot finished work on behalf of fproulx-boostsecurity October 9, 2025 20:00
@fproulx-boostsecurity
Copy link
Contributor

@copilot rebase

Copy link
Contributor Author

Copilot AI commented Oct 24, 2025

@copilot rebase

Rebased onto latest main branch. Branch is now up to date with main and includes the --allowed-rules filtering support from PR #358. All tests pass after rebase (commit 3916e93).

Copilot finished work on behalf of fproulx-boostsecurity October 24, 2025 15:47
Implement lightweight response structure for MCP server that reduces
JSON payload size while preserving all essential security data and
adding enhanced SCM context for better repository identification.

Changes:
- Create mcpAnalysisResponse struct with only essential fields:
  findings, rules, purl, repository, scm_type, git_ref, commit_sha, last_commit
- Remove embedded PackageInsights to eliminate heavy fields like
  github_actions_workflows, package_dependencies, and repo statistics
- Update all MCP handlers (analyze_repo, analyze_local, analyze_org,
  analyze_stale_branches) to use lightweight response
- Add comprehensive test suite to verify response structure and size
- Add SCM context fields (purl, scm_type) per reviewer feedback
- Rename 'ref' to 'git_ref' for clarity

Results:
- Lightweight response: ~182 bytes for empty findings vs kilobytes before
- All essential security findings and repository metadata preserved
- Better SCM identification with purl and scm_type fields
- All tests passing with no regressions

Fixes #359
@fproulx-boostsecurity fproulx-boostsecurity force-pushed the copilot/reduce-lightweight-json-output branch from 3916e93 to b711017 Compare October 24, 2025 16:42
@fproulx-boostsecurity fproulx-boostsecurity changed the title Reduce MCP server JSON response size to minimize LLM token consumption with enhanced SCM context Reduce MCP server JSON response size to minimize LLM token consumption Oct 24, 2025
Copy link
Contributor

@fproulx-boostsecurity fproulx-boostsecurity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have successfully tested with local build against Claude Code

@fproulx-boostsecurity
Copy link
Contributor

Fixes #359

Copy link
Collaborator

@Talgarr Talgarr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of bytes is not the best metrics to estimate AI usage. We should have token estimator and compare the number of tokens. Using XML or other format then JSON might show a much lower token usage even at the cost of raw byte size.


// The lightweight response should be significantly smaller than a full PackageInsights response
// which would include many more fields like workflows, dependencies, repo stats, etc.
assert.Less(t, len(lightweightData), 1000, "Lightweight response should be under 1KB for empty findings")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This number seems really arbitrary... We should probably compare the two results.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Talgarr I agree, but the goal here is more to do the clean up, validate it's still working and that's enough. we know it will drastically drop tokens in practice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fproulx-boostsecurity that test is pretty useless honestly

}

// TestMCPResponseStructure verifies the new mcpAnalysisResponse structure
func TestMCPResponseStructure(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not very uselful and a copy of the previous one essentially

@fproulx-boostsecurity fproulx-boostsecurity merged commit 3b535b6 into main Oct 28, 2025
11 checks passed
@fproulx-boostsecurity fproulx-boostsecurity deleted the copilot/reduce-lightweight-json-output branch October 28, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP server should return a more lightweight JSON to reduce LLM tokens consumption

4 participants