Skip to content

Separate tray app and core. Add rest API, Web UI.#73

Merged
Dumbris merged 142 commits intomainfrom
next
Oct 8, 2025
Merged

Separate tray app and core. Add rest API, Web UI.#73
Dumbris merged 142 commits intomainfrom
next

Conversation

@Dumbris
Copy link
Contributor

@Dumbris Dumbris commented Oct 8, 2025

No description provided.

Dumbris and others added 30 commits September 12, 2025 20:37
- Create docs/releasing.md with hotfix/x.y.z workflow
- Add PR template with hotfix backport reminders
- Document GitHub environments setup for production/staging
- Establish next branch for development aggregation

This implements the P0 branching model to keep main hotfixable
while aggregating refactor work in next branch.
This document outlines the complete refactoring strategy from core+tray split
through v1 REST API, embedded Web UI, hardened OAuth/storage, and robust
tests/observability while preserving hotfix/release workflow.
- Update release.yml for stable releases from main with production environment
- Add prerelease.yml for next branch with staging environment
- Prerelease workflow excludes latest assets to prevent auto-updates
- Environment separation for production vs staging secrets
- Both workflows include codesigning and notarization
- Only stable releases update Homebrew tap

Implements P1 from refactoring plan for proper release management.
- Add MCPPROXY_ALLOW_PRERELEASE_UPDATES environment flag (default: false)
- Modify getLatestRelease to respect prerelease flag
- Add getLatestReleaseIncludingPrereleases for canary behavior
- Update GitHubRelease struct to include Prerelease field
- Comprehensive unit tests for asset selection logic
- Update AUTOUPDATE.md with prerelease/canary mode documentation

Safety features:
- Prerelease workflow excludes latest assets (prevents auto-update)
- Default behavior only updates to stable releases
- Opt-in flag required for prerelease updates
- All existing functionality preserved

Implements P2 from refactoring plan for updater safety.
- Create new cmd/mcpproxy-tray binary for macOS system tray
- Add HTTP API endpoints in internal/api/handlers.go for inter-process communication
- Implement SSE (Server-Sent Events) for real-time status updates
- Create HTTPServerClient adapter implementing ServerInterface via HTTP calls
- Remove tray integration from core mcpproxy binary
- Delete tray_gui.go and tray_stub.go build-tagged files

This enables:
- CGO-free core binary for better cross-platform compatibility
- Independent tray binary that communicates via HTTP API
- Preserved functionality while eliminating build complexity
- Clean separation of concerns between core and UI

Core binary now builds with CGO_ENABLED=0 for full static linking.
Tray binary uses CGO for native macOS UI integration.
- Add chi router with comprehensive REST API endpoints
- Implement /api/v1/servers for server management
- Add /api/v1/servers/{id}/{action} for server control (enable/disable/restart/login)
- Create /api/v1/servers/{id}/tools for listing server tools
- Implement /api/v1/servers/{id}/logs for server log access (placeholder)
- Add /api/v1/index/search for tool search with BM25 scoring
- Create /events SSE endpoint for real-time status updates
- Maintain backward compatibility with existing /api endpoints

Features:
- CORS support for browser access
- Consistent JSON response format with success/error handling
- Real-time status streaming via Server-Sent Events
- Tool search with input schema parsing
- Server state management (enable/disable/quarantine)
- Comprehensive server statistics and connection status

This provides a modern REST API foundation for web UI and improved tray integration.
- Create API client for /api/v1 endpoints with SSE support
- Add adapter pattern to bridge API client with ServerInterface
- Update tray to communicate via HTTP API instead of direct imports
- Add 'Open Web Control Panel' menu item
- Remove direct core package dependencies from tray
- Achieve clean separation: tray ↔ HTTP API ↔ core server
- Maintain real-time updates and full server management functionality
- Implement modern web control panel for MCPProxy
- Add Vue 3 with Composition API and TypeScript
- Include DaisyUI + TailwindCSS for responsive UI design
- Create reusable components: ServerCard, NavBar, ToastContainer
- Build core views: Dashboard, Servers, Tools, Search, Settings
- Add Pinia stores for state management
- Implement real-time updates via Server-Sent Events
- Setup Vitest testing framework with component tests
- Add ESLint configuration and GitHub Actions CI
- Create production build system with Go embed integration
- Support development mode with live reload
- Add comprehensive documentation and setup guide
- Add base path '/ui/' to vite.config.ts for correct asset references
- Fix path handling in web/handler.go to properly serve embedded files
- Resolves 404 errors for JavaScript and CSS assets when accessing via /ui/
- Add comprehensive interface layer for all major components
- Create ApplicationContext for clean dependency injection
- Implement 489 contract tests to lock method signatures
- Add adapter pattern for bridging concrete implementations
- Update DESIGN.md with P7 Interface Architecture documentation
- Apply code formatting fixes from linter

Core interfaces added:
• UpstreamManager: MCP server connections and tool routing
• IndexManager: BM25 search indexing and tool discovery
• StorageManager: Unified storage operations (BBolt + stats)
• OAuthTokenManager: OAuth token lifecycle and persistence
• DockerIsolationManager: Docker isolation for stdio servers
• LogManager: Per-server logging and management
• CacheManager: Response caching with TTL management

This stabilizes the architecture against AI-assisted modifications
while enabling comprehensive unit testing with mock implementations.
- Implement reliable E2E tests using @modelcontextprotocol/server-everything
- Add API E2E test script with 14 comprehensive test cases
- Add binary E2E tests and MCP protocol tests
- Create test utilities for binary execution and HTTP clients
- Add master test runner script for complete validation

- Fix deadlock in concurrent API requests by removing redundant GetUpstreamStats() call
- Fix lock ordering in GetStatus() to prevent mutex deadlock
- Update CLAUDE.md with test requirements and deadlock investigation guide
- Update DESIGN.md with refactoring completion status

Tests now pass reliably: 14/14 ✅
- Fix dashboard status display to show correct server state
- Add complete Tools page with search, filtering, and pagination
- Implement BM25-powered Search page with relevance scoring
- Enhance ServerDetail page with tools, logs, and config tabs
- Add visual feedback and loading states throughout UI
- Fix TypeScript compilation issues with method names
- Resolve linter warnings for unused parameters

All E2E tests passing, core functionality validated.
Implements single writer goroutine pattern to resolve HTTP request timeouts
on server enable/disable/restart endpoints that were caused by BoltDB
transaction conflicts and lock ordering deadlocks.

Key changes:
- Add internal/storage/async_ops.go with queue-based AsyncManager
- Update storage manager to use async operations for server state changes
- Optimize runtime SaveConfiguration to reduce lock holding time
- Make config save/reload operations asynchronous to prevent blocking

Resolves TestBinaryAPIEndpoints timeouts and Phase 4 refactoring issues.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Merges REFACTORING.md and REFACTORING_CODEX.md into a single source of truth
that clearly shows:

✅ COMPLETED: Phases 0, 1, 3, 4 (runtime extraction, event bus, API cleanup)
🚧 IN PROGRESS: Phase 2 (contracts), Phase 6 (web UI + tests)
📋 TODO: Phases 5, 7-13 (observability, security, packaging)

Key accomplishments marked:
- Runtime architecture extracted and operational
- BoltDB deadlock issues resolved with async storage
- Event bus system working with SSE
- Web UI embedded and functional
- TestBinaryAPIEndpoints now passes consistently

Next priorities identified:
1. Complete typed contracts (Phase 2)
2. Add observability endpoints (Phase 5)
3. Implement secure OAuth storage (P8)

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

Co-Authored-By: Claude <noreply@anthropic.com>
…ting

Phase 2 - Typed DTOs:
✅ Created internal/contracts package with typed data structures
✅ Replaced map[string]interface{} with proper contracts throughout HTTP API
✅ Added conversion functions between generic and typed data
✅ All endpoints now return strongly-typed responses

Phase 6 - Contract Tests & TypeScript Generation:
✅ Generated TypeScript types for frontend from Go contracts
✅ Added comprehensive contract tests with golden file validation
✅ Implemented automated type generation via cmd/generate-types
✅ Created test coverage for all API endpoints

Key files:
- internal/contracts/types.go - Core data structures
- internal/contracts/converters.go - Type conversion utilities
- cmd/generate-types/main.go - TypeScript type generator
- internal/httpapi/contracts_test.go - Golden file contract tests
- internal/httpapi/testdata/golden/ - API response reference files

Benefits:
- Type safety across Go ↔ TypeScript boundary
- Automated contract validation prevents API regressions
- Clear data structure documentation for frontend development
- Maintainable API evolution with breaking change detection
Add comprehensive observability package with:
- Health and readiness endpoints (/healthz, /readyz)
- Prometheus metrics collection (/metrics)
- OpenTelemetry distributed tracing support
- Component health checkers for database, index, upstream servers
- HTTP middleware for metrics and tracing
- Observability manager to coordinate all features

Features:
- Kubernetes-compatible health/readiness probes
- HTTP request metrics and tool call tracking
- Optional Jaeger tracing with configurable sampling
- Database, index, and upstream connectivity health checks
- Graceful degradation when observability is disabled

Updated HTTP API server to integrate observability manager
and mount new endpoints. Added dependencies for Prometheus
and OpenTelemetry libraries.

Tests passing for observability integration.
PHASE COMPLETIONS:
✅ Phase 0: Prep & Guard Rails
✅ Phase 1: Runtime Skeleton
✅ Phase 2: Shared Contracts Package
✅ Phase 3: Event Bus & Config Sync
✅ Phase 4: Legacy API Removal
✅ Phase 5: Observability Module
✅ Phase 6: Web UI & Contract Tests
✅ Phase 7: Follow-up Hardening

NEW FEATURES:
- Feature flags system for modular functionality
- TypeScript type generation from Go contracts
- Comprehensive architecture documentation
- Feature flag validation and dependency checking
- Manual testing guide with all scenarios

FILES ADDED:
- internal/config/features.go - Feature flag system
- ARCHITECTURE.md - Complete module boundary documentation
- MANUAL_TESTING.md - Comprehensive testing instructions
- web/frontend/src/types/contracts.ts - Generated TypeScript types

All core phases complete! MCPProxy now has:
- Modular architecture with clear boundaries
- Type-safe contracts throughout
- Comprehensive observability stack
- Feature-flag controlled functionality
- Full test coverage with golden files
- Complete documentation for testing and architecture

Ready for production use with all refactoring objectives met.
Resolved two critical bugs causing the UI to show incorrect "Stopped" status:

1. **StatusSnapshot running state inconsistency**:
   - Modified runtime.StatusSnapshot() to accept serverRunning parameter
   - Ensures authoritative server running state is used instead of runtime copy
   - Updated server.GetStatus() and enqueueStatusSnapshot() calls
   - Fixed test cases to pass correct running state

2. **Phase transition during background initialization**:
   - Modified runtime background initialization to preserve "Running" phase
   - Added condition to prevent phase change from "Running" to "Connecting"
   - Server now maintains "Running" status while upstream connections happen

**Impact**: SSE endpoint now correctly sends:
- "running": true (was false)
- "phase": "Running" (was "Connecting")

**Files modified**:
- internal/runtime/runtime.go: StatusSnapshot signature and logic
- internal/server/server.go: GetStatus and enqueueStatusSnapshot calls
- internal/runtime/lifecycle.go: Background initialization logic
- internal/runtime/runtime_test.go: Test parameter updates

**Testing**: All unit tests pass, SSE endpoint verified with curl
- Add context cancellation to OAuth event monitor to stop infinite loop during shutdown
- Reduce stderr and process monitoring timeouts from 2s to 500ms during disconnect
- Add proper shutdown context to upstream manager DisconnectAll method
- OAuth event monitor now responds to context cancellation and stops cleanly
- Background processes no longer hang during graceful shutdown

Resolves manual testing issue where Ctrl+C would hang indefinitely due to:
1. OAuth event monitor running infinite loop without cancellation
2. Long timeouts during stderr monitoring cleanup
3. Missing shutdown coordination between components
- Add 1 second timeout to stopBackgroundMonitoring WaitGroup.Wait()
- Prevents indefinite hanging during shutdown when background health check is stuck
- Allows complete shutdown sequence to proceed properly
- HTTP server now shuts down cleanly and process exits completely

This resolves the issue where Ctrl+C would stop upstream connections but
never reach HTTP server shutdown, leaving the process running and accepting
new connections without returning control to terminal.
- Prevents caching files from being tracked in version control
- Ensures a cleaner repository and avoids unnecessary clutter
Remove global 60-second timeout middleware that was causing SSE
connections to terminate prematurely. Apply timeout selectively
to API routes only, keeping SSE endpoint unrestricted.

Add 30-second heartbeat mechanism to SSE handler to maintain
connection stability and prevent proxy/load balancer timeouts.

This resolves periodic reconnect messages in the web UI.
- Fix frontend status reading to check top-level running field first
- Fix HTTP server shutdown by running ListenAndServe in goroutine with context
- Add force quit mechanism on second Ctrl+C signal within 10 seconds
- Improve graceful shutdown handling with proper timeout
- Add debug logging for SSE status updates to help diagnose issues

Resolves critical UI status display showing 'Stopped 0/0 servers' when running
Resolves Ctrl+C not freeing shell due to HTTP server blocking shutdown
- Add troubleshooting entries for the fixed UI status and shutdown issues
- Improve Servers.vue empty state message formatting
- Enhance Settings.vue with comprehensive settings management UI
- Add documentation for force quit mechanism and status display fixes
Updated NavBar component to use the SVG logo from assets directory
instead of the text-based placeholder for better branding.
Implement comprehensive secrets management system for secure storage
of API keys, tokens, and other sensitive configuration values using
the operating system's native keyring (Keychain/Secret Service/WinCred).

Core Features:
- SecretRef syntax: ${env:NAME}, ${keyring:alias} for config files
- Multi-provider architecture (Environment, OS Keyring)
- Secret resolution with automatic expansion in configurations
- Automatic detection and analysis of potential secrets for migration

CLI Commands:
- mcpproxy secrets set/get/del/list - Full secrets lifecycle management
- mcpproxy secrets migrate - Analyze and migrate plaintext secrets

REST API:
- GET /api/v1/secrets/refs - List secret references (values masked)
- POST /api/v1/secrets/migrate - Migration analysis (dry-run only)

Web UI:
- New Secrets page (/secrets) for managing stored secrets
- Display unresolved references and migration candidates
- Integration with system keyring via CLI workflows

Security:
- No plaintext secrets in config files or logs
- All secret values masked in API responses and UI
- OS keyring integration for cross-platform security
- Automatic secret detection with confidence scoring

Dependencies:
- Added zalando/go-keyring for cross-platform keyring support

Tests:
- Comprehensive unit tests for all secret resolution components
- Mock providers for testing secret operations
- Parser and resolver functionality validation

This implementation fulfills P8-SEC requirements for secure secret
storage and provides a foundation for eliminating plaintext secrets
from MCPProxy configurations.
Dumbris added 28 commits October 3, 2025 21:04
- Added API endpoints for listing registries and searching registry servers.
- Introduced new types for registry and repository server in the API contract.
- Updated frontend to support registry selection and server search with UI enhancements.
- Implemented loading states and error handling for registry operations.
- Added E2E tests for new API endpoints to ensure functionality.
- Added detailed debug logging in various methods to improve traceability and error diagnosis.
- Introduced synchronization using WaitGroup in LoadConfiguredServers to prevent deadlocks during tool discovery.
- Modified ApplyConfig to ensure locks are released before emitting events to avoid potential deadlocks.
- Improved error handling and logging in AddServerConfig to ensure old clients are disconnected safely.
- Enhanced logging in DiscoverTools and CallTool methods to provide better insights into client states and actions.
build: Enhance cleanup process in run-all-tests script
build: Modify run-e2e-tests script to skip specific tests and improve coverage handling
fix: Add timeout to curl commands in test-api-e2e script for better reliability
…rations and modify e2e-config for enabled state
@Dumbris Dumbris merged commit 2efdf34 into main Oct 8, 2025
7 of 20 checks passed
@Dumbris Dumbris deleted the next branch October 27, 2025 08:10
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