Skip to content

Conversation

@patrickcping
Copy link
Collaborator

Description

Adds automated enforcement mechanisms and comprehensive documentation to prevent future MCP protocol compliance violations. This housekeeping PR complements PR #35 by ensuring contributors don't accidentally introduce fmt.Printf calls in MCP server code.

Changes

New Files

  • .golangci.yml: golangci-lint configuration with forbidigo linter to block fmt.Printf/println in MCP server code
  • .github/copilot-instructions.md: Comprehensive development guide (250+ lines) covering:
    • MCP protocol logging requirements
    • Where fmt.Printf IS and ISN'T allowed
    • Correct usage patterns and examples
    • FAQs and troubleshooting
  • docs/mcp-specification-compliance.md: Detailed MCP compliance documentation

Modified Files

  • Makefile: Added mcp-spec-check and validate-all targets for validation
  • CONTRIBUTING.md: Added MCP Specification Compliance section
  • contributing/pr-checklist.md: Added MCP compliance verification steps

Enforcement Strategy

The forbidigo linter automatically exempts appropriate locations:

  • cmd/ directory - CLI commands can use fmt.Printf
  • ✅ Test files (*_test.go)
  • internal/errs/ - Error formatting
  • internal/logger/ - Logger implementation

And blocks fmt.Printf in MCP server code:

  • internal/server
  • internal/tools
  • internal/sdk
  • internal/auth/client, internal/auth/login, internal/auth/logout

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Chore (maintenance, tooling, enforcement)

Testing

Makefile Targets Validation

make mcp-spec-check    # Verifies no fmt.Printf in MCP server code
make validate-all      # Runs all validation checks

Lint Check

make lint              # Now includes forbidigo linter check

Checklist

  • Code follows MCP specification
  • Documentation is comprehensive and clear
  • Lint configuration properly exempts CLI code
  • Enforcement mechanisms tested
  • PR template is filled out completely

Related PRs

Additional Context

This is part 2 of a 2-part change:

The lint checks will catch violations during development and in CI, providing clear guidance to contributors about where fmt.Printf is and isn't allowed.

Fixes MCP protocol compliance violations in authentication wrapper code where fmt.Printf was causing protocol communication issues.

Changes:
- Replaced all fmt.Printf calls in internal/auth/client/wrapper.go with structured logging using log.Info
- Fixed cmd/session/session.go to use correct fmt.Printf for CLI output (CLI commands are exempt from MCP logging restrictions)
- Removed format strings, newlines, and trailing punctuation from log messages to follow MCP structured logging patterns

This ensures the MCP server's authentication flows properly use structured logging as required by the MCP specification, preventing interference with protocol communication on stdout/stderr.
- Add golangci-lint forbidigo linter to prevent fmt.Printf in MCP server code
- Add comprehensive MCP compliance documentation
- Update contributing guides with MCP specification requirements
- Add Makefile targets for MCP spec validation
- Exemptions properly configured for CLI commands and test files

This housekeeping change prevents future MCP protocol violations by providing
automated checks and clear documentation for contributors.
@patrickcping patrickcping marked this pull request as draft December 12, 2025 12:24
Base automatically changed from fix/auth-wrapper-logging-mcp-protocol/pc/20251212 to main December 12, 2025 15:34
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