Skip to content

feat: enhance mcp#15

Merged
sehwan505 merged 10 commits intomainfrom
feature/enhance-mcp
Nov 12, 2025
Merged

feat: enhance mcp#15
sehwan505 merged 10 commits intomainfrom
feature/enhance-mcp

Conversation

@sehwan505
Copy link
Copy Markdown
Contributor

@sehwan505 sehwan505 commented Nov 12, 2025

MCP 서버 개선

@sehwan505 sehwan505 requested a review from Copilot November 12, 2025 08:11
@sehwan505 sehwan505 changed the title Feat: enhance mcp feat: enhance mcp Nov 12, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the MCP (Model Context Protocol) server implementation with significant architectural improvements:

  • Migrates from numeric no field to string id field for policy rules, enabling more flexible rule identifiers
  • Integrates the official modelcontextprotocol/go-sdk for spec-compliant MCP communication
  • Adds comprehensive test coverage for MCP convention queries with filtering by category and language

Key Changes

  • Rule identification system upgraded from sequential numbers to flexible string IDs (e.g., "SEC-001", "STYLE-001")
  • MCP server now uses official SDK with proper stdio transport and tool registration
  • Enhanced LLM validator to handle non-git-diff formatted code snippets
  • Automatic policy conversion when user-policy.json is updated

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/schema/types.go Replaced No field with ID field in UserRule struct, removing numeric constraint
internal/policy/manager.go Updated validation logic to check for duplicate IDs instead of rule numbers
internal/server/static/policy-editor.js Refactored DOM handling from data-rule-no to data-rule-id attributes with new ID generation
internal/policy/templates/*.json Converted all template rules from numeric no to string id fields
internal/mcp/server.go Major refactor: integrated go-sdk, added dual policy support, improved MCP response formatting
internal/mcp/server_test.go Added comprehensive test suite for query_conventions functionality
internal/validator/llm_validator.go Enhanced to handle non-git-diff code snippets by treating entire content as added lines
internal/converter/converter.go Changed default engine from "custom" to "llm-validator", reformatted struct fields
internal/cmd/mcp.go Simplified by moving conversion logic to mcp package, removed duplicate code
internal/cmd/dashboard.go Added "dash" alias for dashboard command
internal/adapter/prettier/executor_test.go Changed test to skip instead of fail when Prettier unavailable
go.mod Added modelcontextprotocol/go-sdk v1.1.0 and related dependencies
go.sum Updated checksums for new dependencies
tests/e2e/full_workflow_test.go Updated test to use new PolicyRule structure with id and enhanced fields

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +254 to +257
CodePolicy *schema.CodePolicy // Internal policy
LinterConfigs map[string]*linters.LinterConfig // Linter-specific configs
Results map[string]*linters.ConversionResult // Detailed results per linter
Warnings []string // Overall warnings
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

[nitpick] The field alignment changes appear to be purely cosmetic formatting adjustments. While this improves visual consistency, it creates unnecessary noise in the diff. Consider using a tool like gofmt or goimports to automatically handle alignment across the entire codebase consistently, rather than manual alignment in individual PRs.

Suggested change
CodePolicy *schema.CodePolicy // Internal policy
LinterConfigs map[string]*linters.LinterConfig // Linter-specific configs
Results map[string]*linters.ConversionResult // Detailed results per linter
Warnings []string // Overall warnings
CodePolicy *schema.CodePolicy // Internal policy
LinterConfigs map[string]*linters.LinterConfig // Linter-specific configs
Results map[string]*linters.ConversionResult // Detailed results per linter
Warnings []string // Overall warnings

Copilot uses AI. Check for mistakes.

// Check if conversion is needed
if s.userPolicy != nil {
needsConversion := s.needsConversion(codePolicyPath)
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

The needsConversion method is called with codePolicyPath as a parameter (line 154), but the method implementation doesn't use this parameter at all. The parameter should either be removed from the call, or if it's intended to check file modification times, it should be used in the implementation to compare timestamps between user-policy.json and code-policy.json.

Copilot uses AI. Check for mistakes.
Comment on lines +462 to +466
const maxId = appState.policy.rules.reduce((max, rule) => {
const ruleId = parseInt(rule.id, 10);
return isNaN(ruleId) ? max : Math.max(max, ruleId);
}, 0);
const newId = String(maxId + 1);
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

The ID generation logic has a potential collision issue when rules contain a mix of numeric and non-numeric IDs (e.g., "SEC-001", "STYLE-1", "5"). The parseInt on line 463 will return NaN for non-numeric IDs like "SEC-001", which are then excluded from the max calculation. This could result in duplicate IDs if existing rules have IDs like "SEC-001" and the new rule gets ID "1" when there's already a rule with ID "1".

Consider using a more robust ID generation strategy, such as:

  • Using UUIDs
  • Using a timestamp-based ID
  • Prefixing numeric IDs with a consistent pattern (e.g., "RULE-1", "RULE-2")
  • Scanning for all existing IDs and generating a truly unique one

Copilot uses AI. Check for mistakes.
if !s.isRuleRelevant(rule, req) {
continue
severity := rule.Severity
if severity == "" && s.userPolicy.Defaults.Severity != "" {
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

Potential null pointer dereference: s.userPolicy.Defaults.Severity is accessed without checking if s.userPolicy.Defaults is nil. If Defaults is nil, this will cause a panic. Add a nil check before accessing Defaults.Severity:

if severity == "" && s.userPolicy.Defaults != nil && s.userPolicy.Defaults.Severity != "" {
    severity = s.userPolicy.Defaults.Severity
}
Suggested change
if severity == "" && s.userPolicy.Defaults.Severity != "" {
if severity == "" && s.userPolicy.Defaults != nil && s.userPolicy.Defaults.Severity != "" {

Copilot uses AI. Check for mistakes.
@sehwan505 sehwan505 merged commit eed1bdc into main Nov 12, 2025
2 checks passed
@sehwan505 sehwan505 deleted the feature/enhance-mcp branch December 10, 2025 04:12
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.

2 participants