Overview
MCPJam Inspector is a sophisticated multi-platform application that runs in three distinct modes: Web Application, Electron Desktop App, and Docker Container. This architecture guide explains how the system adapts to each deployment mode while maintaining a unified codebase.Web App
Standalone web application with separate client and server
Desktop App
Electron application with embedded Hono server
Container
Dockerized deployment for cloud hosting
High-Level Architecture
The application consists of distinct layers that work together across all deployment modes:Deployment Modes
Mode Detection Flow
The application automatically detects its runtime environment and configures itself accordingly:Web Development Mode
Web Development Mode
When:
NODE_ENV=development
(no Electron)Characteristics:- Backend: Hono server on
localhost:3000
- Frontend: Vite dev server on
localhost:8080
- CORS enabled for cross-origin requests
- Hot module replacement (HMR)
- API-only server (no static file serving)
server/app.ts:135-142
- Development mode routingclient/vite.config.ts
- Vite configuration
Web Production Mode
Web Production Mode
When:
NODE_ENV=production
(no Electron)Characteristics:- Backend: Hono server on
0.0.0.0:3001
- Frontend: Served from
dist/client
- SPA fallback to
index.html
- Optimized production bundles
- No CORS (same-origin)
server/app.ts:119-126
- Production static servingserver/index.ts
- Standalone server entry point
Electron Development Mode
Electron Development Mode
When:
ELECTRON_APP=true
and IS_PACKAGED=false
Characteristics:- Embedded Hono server on
localhost:3000
- Frontend: Vite dev server redirects
- Resources from
app.getAppPath()
- DevTools enabled
- Auto-reload on changes
src/main.ts:62-92
- Server startupsrc/main.ts:112
- Vite dev server URL loading
Electron Production Mode
Electron Production Mode
When:
ELECTRON_APP=true
and IS_PACKAGED=true
Characteristics:- Embedded Hono server on
127.0.0.1:3000
- Frontend: Bundled in
resources/client
- Resources from
process.resourcesPath
- Code signing enabled
- Single .app/.exe bundle
src/main.ts:68-73
- Environment setupserver/app.ts:119-124
- Packaged static serving
Server Architecture
Hono Application Factory
The server uses a factory pattern to create the Hono app, allowing it to be reused across different contexts: Key Implementation:server/app.ts:20-146
The factory function createHonoApp()
is called from:
server/index.ts
- Standalone web serversrc/main.ts:75
- Electron embedded server
Request Lifecycle
Every HTTP request flows through multiple layers:API Routes Structure
- MCP Routes
- File Locations
Electron Integration
Process Architecture
Electron uses a multi-process architecture for security and stability:Security Note: The renderer process has no direct access to Node.js APIs.
All privileged operations must go through the preload script and IPC.
Startup Sequence
Here’s what happens when you launch the Electron app:Environment Setup
src/main.ts:66-73
sets critical environment variables that tell the server it’s running in ElectronServer Start
src/main.ts:62-92
starts the embedded Hono server on an available portWindow Creation
src/main.ts:94-133
creates the main BrowserWindow with security settingsIPC Setup
src/ipc/listeners-register.ts
registers all IPC event handlersOAuth Deep Linking
The Electron app handles OAuth callbacks through a custom protocol handler:OAuth Architecture
Learn about the complete OAuth flow including deep linking, state management,
and security
src/main.ts:31-33
- Protocol registrationsrc/main.ts:273-313
- Deep link handlerclient/src/hooks/useElectronOAuth.ts
- React OAuth hook
MCP Client Management
MCPClientManager Architecture
TheMCPClientManager
is the heart of MCP server integration:
STDIO Transport
Spawns child processes for local MCP servers
SSE Transport
EventSource connections for remote servers
HTTP Transport
Fetch-based requests with streaming support
Client Lifecycle
For detailed MCP client implementation, see MCP Client Manager
Architecture
State Management
Frontend State Architecture
The application uses a hybrid state management approach:TanStack Query (Server State)
TanStack Query (Server State)
Purpose: Manage server-side data with caching and auto-refetchUsed for:
- MCP server lists
- Tool/resource/prompt data
- Eval results
- Real-time data synchronization
- Automatic background refetching
- Optimistic updates
- Request deduplication
- Stale-while-revalidate
Zustand (Client State)
Zustand (Client State)
Purpose: Manage client-side UI stateUsed for:
- User preferences (theme, layout)
- UI state (modals, sidebars)
- Form state
- Temporary local data
- Simple API
- No boilerplate
- TypeScript support
- Middleware (persist, devtools)
Context API (Scoped State)
Context API (Scoped State)
Purpose: Provide scoped state to component treesUsed for:
- Authentication (WorkOS AuthKit)
- Theme provider
- Feature flags
- React-native
- Component composition
- Clean separation of concerns
Real-time Communication
SSE Event Bus
Real-time RPC logging uses Server-Sent Events for live updates: Flow:- MCPClientManager calls a tool
- RPC logger callback fires
- Publishes to rpcLogBus
- Bus emits to all SSE connections
- Frontend EventSource receives event
- React components update UI
server/services/rpc-log-bus.ts
- Event bus implementationserver/app.ts:67-79
- RPC logger setupclient/src/hooks/useRPCLogs.ts
- Frontend subscription
Environment Configuration
The application adapts to its environment through a series of configuration steps:Required Environment Variables
Variable | Purpose | Set By | Required |
---|---|---|---|
CONVEX_HTTP_URL | Convex backend URL | User/CI | ✅ Yes |
ELECTRON_APP | Indicates Electron runtime | Main process | Auto |
IS_PACKAGED | Indicates packaged app | Main process | Auto |
ELECTRON_RESOURCES_PATH | Resources directory | Main process | Auto |
NODE_ENV | Runtime environment | Build/User | Auto |
PORT | Server port | User | Optional (default: 3001) |
DEBUG_MCP_SELECTION | Enable debug logs | User | Optional |
Build & Deployment
Build Process Flow
- Web Deployment
- Electron Deployment
- Docker Deployment
Production Build:Artifacts:
dist/client/
- Frontend static filesdist/server/
- Backend Node.js files
Performance Considerations
Caching Strategy
Key Optimizations:- Query cache reduces API calls by 80%+
- Stale-while-revalidate provides instant UI updates
- Background refetching keeps data fresh
- Mutation invalidation ensures consistency
Connection Pooling
The MCPClientManager maintains a pool of connections to avoid repeated handshakes:Security Architecture
The application handles sensitive data including API keys, OAuth tokens, and
MCP server access. Security is a top priority.
Security Layers
Electron Security
Electron Security
Context Isolation: Renderer has no direct Node.js accessSecure Preload:
src/preload.ts
exposes only safe APIsNo Remote Module: Disabled for securityProtocol Registration: Custom mcpjam://
protocol for OAuthAuthentication
Authentication
WorkOS AuthKit: Enterprise-grade OAuth 2.0Token Storage: Secure localStorage with expirationPKCE Flow: Proof Key for Code Exchange in ElectronConvex Integration: Server-side token validation
Input Validation
Input Validation
Zod Schemas: Runtime type validationSanitization: All user inputs cleanedRate Limiting: Prevent abuseError Handling: No sensitive data in error messages
Monitoring & Observability
Telemetry Pipeline
Error Tracking:- Sentry integration in both main and renderer processes
- Automatic error reporting in production
- Source maps for stack traces
- User context and breadcrumbs
- React Query DevTools for cache inspection
- Browser DevTools for profiling
- Network tab for API timing
- Electron process manager for memory
Next Steps
MCP Client Manager
Deep dive into MCP protocol implementation
OAuth Architecture
Learn about authentication and OAuth flow
Playground Architecture
Understand the LLM playground system
Evals Architecture
Explore the evaluation framework
Now you understand the complete system architecture! Ready to contribute?
Check out the Contributing Guide.