Skip to content

Feat/mcp registration#17

Merged
baeyc0510 merged 7 commits intomainfrom
feat/mcp-registration
Nov 12, 2025
Merged

Feat/mcp registration#17
baeyc0510 merged 7 commits intomainfrom
feat/mcp-registration

Conversation

@baeyc0510
Copy link
Copy Markdown
Contributor

Summary
This PR enhances the sym init command with automated MCP server registration
and OpenAI API key configuration, improving the developer onboarding
experience.

What Changed

  1. MCP Server Registration (internal/cmd/mcp_register.go)
    ✨ Added automatic MCP server registration for Claude Code, Cursor, and VS
    Code
    🔧 Supports multiple application configurations:
    Claude Code: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
    Cursor: ~/.cursor/mcp.json
    VS Code: ~/Library/Application Support/Code/User/settings.json
    📦 Configures Symphony MCP server with npx @dev-symphony/sym@latest mcp
    🛡️ Creates backup files before modifying existing configurations
    🎯 New flags: --register-mcp (register MCP only), --skip-mcp (skip MCP
    registration)
  2. OpenAI API Key Management (internal/cmd/api_key.go)
    🔑 Interactive API key configuration with standard input
    📁 Stores API keys securely in .sym/.env with 0600 permissions
    🔍 Validates API key format (must start with 'sk-', minimum length check)
    🧹 Cleans input to remove control characters and whitespace for reliable
    validation
    📋 Full paste support with bufio.Reader (no duplicate output issues)
    🚫 Automatically adds .sym/.env to .gitignore
    🎯 New flags: --setup-api-key (setup API key only), --skip-api-key (skip
    API key setup)
    🔄 Priority: System environment variable → .sym/.env file
  3. Enhanced Init Command (internal/cmd/init.go)
    🎉 Integrated MCP registration prompt after roles/policy initialization
    🎉 Integrated API key configuration prompt if not already configured
    🎛️ Added new command-line flags for flexible workflows
  4. Code Quality Improvements
    ✅ Fixed all golangci-lint errcheck violations
    ✅ Added proper error handling for file operations (Close(), WriteFile())
    ✅ Removed redundant newlines in fmt.Println statements
    ✅ Improved paste handling to prevent duplicate output
    Usage Examples
    Standard initialization with all features
    sym init

Creates roles.json, user-policy.json

Prompts for MCP registration

Prompts for API key configuration if needed

Register MCP server only

sym init --register-mcp

Interactive prompt to choose: Claude Code, Cursor, or VS Code

Setup API key only

sym init --setup-api-key

Prompts for OpenAI API key with paste support

Skip prompts

sym init --skip-mcp --skip-api-key

Only creates roles.json and user-policy.json

Technical Details

API Key Input Handling

  • Replaced promptui masked input with bufio.Reader for better paste
    compatibility
  • Added cleanAPIKey() function to filter out control characters (keeps ASCII
    33-126)
  • Resolves issues with:
    • Duplicate label output during paste
    • Hidden whitespace/newlines in pasted keys
    • Validation false positives

Error Handling

  • All file.Close() calls now properly check errors: _ = file.Close()
  • os.WriteFile() operations include error handling with user feedback
  • Backup file creation failures are logged with warnings

Test Plan

  • Local testing completed
  • go vet ./... passes
  • golangci-lint run passes with no errcheck violations
  • Unit tests pass
  • Paste operations work correctly (no duplicate output)
  • API key validation works with pasted keys
  • CI tests pending

Breaking Changes

None. All new features are opt-in via flags.

Dependencies

  • Added: github.com/manifoldco/promptui for interactive prompts
  • Added: github.com/pkg/browser for opening URLs
  • Updated: golang.org/x/sys v0.15.0 → v0.38.0

Files Changed

  • internal/cmd/init.go - Integrated MCP and API key setup
  • internal/cmd/mcp_register.go - New file for MCP registration
  • internal/cmd/api_key.go - New file for API key management
  • internal/cmd/convert.go, validate.go, mcp.go - API key integration
  • .gitignore - Added .sym/.env
  • go.mod, go.sum - Dependency updates

baeyc0510 and others added 7 commits November 12, 2025 15:47
Add interactive MCP server registration during project initialization
with support for multiple platforms and configuration types.

Features:
- Interactive prompt with arrow key navigation (promptui)
- Support for 4 platforms:
  * Claude Desktop (global config)
  * Claude Code (project .mcp.json)
  * Cursor (project .cursor/mcp.json)
  * VS Code/Cline (project .vscode/mcp.json)
- Platform-specific JSON formats (VS Code uses different structure)
- New flags: --register-mcp (registration only), --skip-mcp (skip prompt)
- Automatic backup creation before modification
- Project-specific configs enable team collaboration via version control

Changes:
- Add promptui dependency for interactive selection
- Create internal/cmd/mcp_register.go with registration logic
- Update internal/cmd/init.go with MCP registration flow
- Support both global and project-specific MCP configurations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add interactive API key configuration during project initialization
with support for both environment variables and .sym/.env file.

Features:
- Interactive prompt only when API key not found
- Priority: system env var > .sym/.env file
- Masked input for API key entry
- Basic validation (sk- prefix, length check)
- Automatic .gitignore update for .sym/.env
- File permissions set to 0600 for security

New flags:
- --setup-api-key: Setup API key only (skip roles/policy init)
- --skip-api-key: Skip API key configuration prompt

Changes:
- Create internal/cmd/api_key.go with key management logic
- Add promptAPIKeyIfNeeded() to init.go workflow
- Update convert, validate, mcp commands to use getAPIKey()
- Support loading API key from .sym/.env file

Benefits:
- No need to set environment variables manually
- Project-specific API keys (team collaboration)
- Secure file storage with restrictive permissions
- Backward compatible with existing env var setup
- Can be configured later with 'sym init --setup-api-key'
Remove '\n' from fmt.Println calls to fix go vet errors.
fmt.Println automatically adds a newline, so explicit '\n' is redundant.
…ance

- Add error checking for file.Close() calls in api_key.go
- Add error checking for os.WriteFile() calls in mcp_register.go
- Display warning messages when backup file creation fails
- Fixes all errcheck linter violations in CI
- Replace promptui masked input with bufio.Reader for better paste support
- Add cleanAPIKey function to remove control characters and whitespace
- Fix duplicate label output when pasting API keys
- Keep only printable ASCII characters (33-126) in API key input
- Update .gitignore to include .sym/.env
…at/mcp-registration

# Conflicts:
#	go.mod
#	go.sum
#	internal/cmd/mcp.go
- Remove duplicate autoConvertPolicy function (moved to internal/mcp/server.go)
- Clean up unused imports (context, encoding/json, converter, llm, schema)
- Fix golangci-lint unused function warning
@baeyc0510 baeyc0510 merged commit 28ae1f4 into main Nov 12, 2025
2 checks passed
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.

1 participant