Desktop App Background Workers
Issue
The Desktop app was not auto-installing MCP servers detected in agents because the background workers were not being started.
Root Cause
Web App (src/McpManager.Web/Program.cs):
- Uses ASP.NET Core's built-in hosted service infrastructure
- Background workers are registered with
AddHostedService<T>() - ASP.NET Core automatically starts and manages their lifecycle
Desktop App (src/McpManager.Desktop/Program.cs):
- Uses Photino.Blazor instead of ASP.NET Core
- Photino does not have
IHostedServicesupport - Background workers were registered but never started
The Fix
Updated src/McpManager.Desktop/Program.cs to manually start background workers:
// Register background workers as singletons
appBuilder.Services.AddSingleton<RegistryRefreshWorker>();
appBuilder.Services.AddSingleton<AgentServerSyncWorker>();
appBuilder.Services.AddSingleton<DownloadStatsWorker>();
appBuilder.Services.AddSingleton<ConfigurationWatcherWorker>();
// Start them manually after app is built
var cancellationTokenSource = new CancellationTokenSource();
StartBackgroundWorkers(app.Services, cancellationTokenSource.Token);
Background Workers
1. AgentServerSyncWorker (Most Important for Your Issue)
- Purpose: Auto-installs servers detected in agent configurations
- Interval: Every 5 minutes, plus initial sync after 5 seconds
- What it does:
- Detects installed agents (Claude Desktop, Claude Code, GitHub Copilot, etc.)
- Reads their configuration files to find configured MCP servers
- Searches registries for matching servers
- Auto-installs any servers not already in MCP Manager
- Creates agent-server relationships
2. RegistryRefreshWorker
- Purpose: Refreshes cached registry data
- Interval: Every 60 minutes
- What it does:
- Fetches latest server lists from all registries
- Updates the database cache
- Ensures browse/search results are up-to-date
3. DownloadStatsWorker
- Purpose: Updates package download statistics
- Interval: Every 120 minutes
- What it does:
- Fetches download counts from npm, PyPI, etc.
- Updates popularity metrics for servers
4. ConfigurationWatcherWorker
- Purpose: Monitors agent config files for external changes
- What it does:
- Watches
~/.claude.jsonand other agent config files - Raises events when files change
- Enables real-time UI updates when configs are edited externally
- Watches
Lifecycle Management
Web App: Handled by ASP.NET Core
- Workers start automatically with the application
- Workers stop gracefully on shutdown
Desktop App: Manual management (post-fix)
- Workers are started manually after app builds
- Cancellation token is canceled on ProcessExit
- Workers stop gracefully on application exit
Expected Behavior (Post-Fix)
When you start the Desktop app:
- After 5 seconds,
AgentServerSyncWorkerruns its initial sync - It detects your
~/.claude.jsonfile and finds the "github" server - It searches registries for a matching server definition
- If found in a registry, it installs the full server metadata
- If not found, it creates a minimal entry marked as "auto-discovered"
- It creates the agent-server relationship in the database
- The server appears in your installed servers list
- Every 5 minutes, it checks again for new servers
Verification
To verify the fix is working:
Build and run the Desktop app:
dotnet build src/McpManager.Desktop dotnet run --project src/McpManager.DesktopCheck logs (console output):
- You should see: "Agent Server Sync Worker starting"
- After 5 seconds: "Syncing servers from X detected agent(s)"
- Look for: "Auto-installed server 'github' from agent claudecode"
Check the UI:
- Navigate to "Installed Servers"
- You should see any servers from your
~/.claude.jsonfile - They should be linked to the "Claude Code" agent
Troubleshooting
If servers still aren't auto-installing:
Check if Claude Code is detected:
- Go to the "Agents" page
- Verify "Claude Code" shows as detected
- Check that it shows the correct config path
Check logs for errors:
- Look for "Agent sync worker error" messages
- Check for "Failed to sync agent servers" errors
Verify config file exists:
- Ensure
~/.claude.jsonexists - Verify it has valid JSON
- Check the
mcpServerssection has entries
- Ensure
Manual sync:
- The sync runs every 5 minutes
- Restart the app to trigger an immediate sync
- Or wait 5 seconds + 5 minutes for the next automatic sync