Provides container management operations including starting, stopping, and monitoring Docker containers, as well as automated image pruning and maintenance tasks.
Enables realm statistics monitoring, session management, user administration, event log analysis, and automated client secret rotation through the Keycloak Admin API.
Offers access and error log analysis, configuration validation and testing, service reload capabilities, and upstream health checks for NGINX web servers.
Supports monitoring and management of Node.js processes running under PM2 process manager.
Provides comprehensive database management including connection monitoring, replication status, table bloat detection, slow query analysis, automated VACUUM and reindexing, and backup/restore operations.
Enables memory statistics monitoring, keyspace analysis, slow log inspection, client list management, and automated BGSAVE operations for Redis instances.
Delivers system-level operations including service management, package updates, system metrics monitoring (disk, memory, CPU, network), and journal log analysis for Ubuntu servers.
SERVER-MCP
On-Server Model Context Protocol Agent for PostgreSQL, Redis, Keycloak, and NGINX management on Ubuntu infrastructure.
Overview
SERVER-MCP is a specialized MCP server that runs directly on Ubuntu infrastructure servers (unlike IT-MCP which runs on desktop/laptop and SSH's to remote servers). It provides real-time database monitoring, service health management, and automated maintenance for production environments.
Architecture
Key Differences from IT-MCP
Aspect | IT-MCP | SERVER-MCP |
Deployment | Desktop/laptop (macOS/Windows/Linux) | Ubuntu server (server.acdev.host) |
Execution | SSH/WinRM to remote servers | Local commands via sudo |
Database | SQLite primary + PostgreSQL sync (optional) | PostgreSQL primary + SQLite cache |
Focus | Cross-platform diagnostics, remote admin | Database management, service health, backups |
MCP Client | Claude Desktop, CLI tools | Headless (API-driven by IT-MCP or cron) |
Capabilities |
,
,
,
|
,
,
,
|
Features
Database Management
PostgreSQL: Real-time connection stats, replication monitoring, table bloat detection, slow query analysis, automated VACUUM, reindexing, backup/restore
Redis: Memory stats, keyspace analysis, slow log, client list, BGSAVE automation
Service Management
Keycloak: Realm stats, session monitoring, user management, event logs, client secret rotation
NGINX: Access log analysis, error log parsing, config testing, upstream health checks
System: Service restarts, package updates, Docker container management, PM2 process monitoring
Automated Maintenance
Nightly database backups (PostgreSQL + Redis)
Weekly Docker image pruning
Monthly Keycloak secret rotation
Security updates (with approval workflow)
Auto-restart failed services
Integration
Agent Registration: Auto-registers with IT-MCP central registry on startup
Command Queue: Polls PostgreSQL command queue for remote jobs
Heartbeat: Sends heartbeat to Redis every 30 seconds
JWT Authentication: Keycloak client credentials flow
Installation
Prerequisites
Ubuntu Server 24.04 LTS (or compatible)
Node.js 18.18+ installed
PostgreSQL 16+ running locally
Redis 7+ running locally
Keycloak running (Docker or standalone)
NGINX installed
Sudo access for the service user
Setup
Clone and install dependencies:
cd /opt sudo git clone <repository-url> server-mcp cd server-mcp sudo npm installConfigure environment:
sudo cp .env.example .env sudo nano .env # Fill in PostgreSQL, Redis, Keycloak credentialsBuild TypeScript:
sudo npm run buildCreate service user:
sudo useradd -r -s /bin/false mcp-agent sudo chown -R mcp-agent:mcp-agent /opt/server-mcpConfigure sudo access (edit
/etc/sudoers.d/server-mcp):mcp-agent ALL=(ALL) NOPASSWD: /usr/bin/systemctl mcp-agent ALL=(ALL) NOPASSWD: /usr/bin/docker mcp-agent ALL=(ALL) NOPASSWD: /usr/bin/pg_dump mcp-agent ALL=(ALL) NOPASSWD: /usr/bin/pg_dumpall mcp-agent ALL=(ALL) NOPASSWD: /usr/sbin/nginx -tInstall systemd service:
sudo cp systemd/server-mcp.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable server-mcp sudo systemctl start server-mcpVerify installation:
sudo systemctl status server-mcp sudo journalctl -u server-mcp -f
Configuration
Environment Variables
See .env.example for full configuration options. Key variables:
PostgreSQL:
POSTGRES_HOST,POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DATABASEPostgreSQL Sync:
POSTGRES_CONNECTION_STRING(optional - for structured thought sync)Redis:
REDIS_HOST,REDIS_PORT,REDIS_PASSWORDKeycloak Admin:
KEYCLOAK_BASE_URL,KEYCLOAK_CLIENT_ID,KEYCLOAK_CLIENT_SECRET,KEYCLOAK_REALMLocal Storage:
SERVER_MCP_SQLITE_PATH,SERVER_MCP_QUEUE_PATHStructured Thinking:
SERVER_MCP_STAGE_CONFIG(optional path to JSON stage framework definition),SERVER_MCP_SQLITE_PATHAgent Integration:
IT_MCP_REGISTRY_URL(optional),IT_MCP_SERVER_ID(optional)Security:
SERVER_MCP_ALLOW_SUDO(default: true)Logging:
SERVER_MCP_LOG_LEVEL(default: debug)
Backup Configuration
Automated backups are enabled by default:
MCP Tools
SERVER-MCP exposes 7 MCP tools (all execute locally, no SSH):
Tool | Description | Operations |
| Database health checks | PostgreSQL/Redis/Keycloak/NGINX/firewall/system diagnostics (6 suites) |
| PostgreSQL operations | Connections, replication, bloat, slow queries, vacuum, reindex, backup |
| Redis operations | Memory stats, keyspace, slow log, client list, BGSAVE |
| Keycloak admin | Realm stats, sessions, users, events, secret rotation |
| NGINX monitoring | Access log analysis, error log parsing, config testing, reload |
| System health | Overview, processes, disk I/O, network, journal errors, service status |
| Structured reasoning management | Capture/revise/retrieve thoughts, generate summaries, inspect framework, trigger sync |
Usage
As Distributed Agent
SERVER-MCP automatically registers with the IT-MCP agent registry on startup. IT-MCP can then dispatch commands:
Direct Invocation (Development)
For testing, you can invoke tools directly via stdio:
Monitoring
View logs in real-time:
Structured Thinking Interface
The structured-thinking tool turns SERVER-MCP into the source of truth for guided reasoning:
Capture or revise thoughts with rich metadata (stage, quality score, tags, branches).
Retrieve filtered timelines (by stage, branch, importance, tags, or full-text fragment) and generate branch-aware summaries.
Inspect or override the reasoning framework by supplying a JSON config via
SERVER_MCP_STAGE_CONFIG.Run diagnostics to detect stale or missing stages, and trigger PostgreSQL syncs when
POSTGRES_CONNECTION_STRINGis configured.Feedback heuristics surface stage dwell time, rolling quality drops, repetitive content, and unhealthy branches to nudge the agent when progress stalls.
Development
Build Commands
Service Architecture
SERVER-MCP follows IT-MCP's service layer pattern:
Error Handling
All services use CommandRunner for safe command execution:
Security
Sudo Configuration
SERVER-MCP requires sudo access for specific operations:
Service management:
systemctlContainer operations:
dockerDatabase backups:
pg_dump,pg_dumpallNGINX config testing:
nginx -t
NEVER grant NOPASSWD: ALL - only specific commands listed in /etc/sudoers.d/server-mcp.
Secret Management
Production: Use systemd credentials (not .env):
JWT Authentication
SERVER-MCP authenticates to the agent registry using Keycloak client credentials:
Service starts → authenticates to Keycloak
Receives JWT access token
Includes
Authorization: Bearer <token>in all registry API callsAuto-refreshes token before expiration
Monitoring & Operations
Health Checks
SERVER-MCP exposes a health check (future enhancement):
Backup Verification
Check backup status:
Service Restart
If SERVER-MCP crashes, systemd automatically restarts it:
Troubleshooting
Common Issues
Issue: "Permission denied" when running commands
Solution: Check sudo configuration in /etc/sudoers.d/server-mcp
Issue: "Cannot connect to PostgreSQL"
Solution: Verify PostgreSQL is running and credentials in .env are correct:
Issue: "Keycloak authentication failed"
Solution: Verify Keycloak client exists and credentials are correct:
Issue: "Backup directory not writable"
Solution: Check ownership and permissions:
Roadmap
Phase 1: Foundation ✅
Project structure
Core utilities (CommandRunner, logger)
Package dependencies
SQLite cache service (SQLitePlannerService)
Structured thinking service
Phase 2: Core Services ✅
ServerAdminService (from UbuntuAdminService)
DatabaseDiagnosticsService (simplified, no SSH)
PostgresManagerService (pg client)
RedisManagerService (ioredis client)
KeycloakManagerService (Admin API)
NginxMonitoringService
SystemMetricsService
Phase 3: MCP Tools ✅
Tool registration with Zod schemas (6 tools)
Error handling middleware
Dual content format (text + structuredContent)
Phase 4: Integration ✅
AutoDiscoveryService integration (agent registration)
KeycloakAuthService (JWT authentication)
CommandQueueService (SQLite job queue)
DatabaseSyncService (PostgreSQL ↔ SQLite sync)
Graceful startup/shutdown with cleanup
Phase 5: Deployment ✅
Systemd service file with security hardening
PM2 ecosystem configuration
Security hardening guide (docs/SECURITY.md)
Deployment guide (docs/DEPLOYMENT.md)
Automated setup script (scripts/setup.sh)
Automated deployment script (scripts/deploy.sh)
Environment configuration (.env.example)
Production deployment on server.acdev.host (ready to deploy)
Phase 6: Advanced Features
Automated maintenance scheduler
Backup automation
Health check endpoint
Metrics export (Prometheus)
Contributing
SERVER-MCP follows IT-MCP's coding standards:
TypeScript Strict Mode: All code must pass
tsc --strictService Layer: All operations in service classes, not tool handlers
Error Handling: Use
CommandExecutionErrorwith full contextNo Floating Promises: Resolve or explicitly
voidall promisesReadonly by Default: All interface properties
readonlyunless mutation required
License
MIT
Related Projects
IT-MCP: Parent project - cross-platform diagnostic tool with distributed coordination
Agent Registry: Central coordination service (private repository)
Questions? Open an issue or contact the maintainers.
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
On-server agent for managing PostgreSQL, Redis, Keycloak, and NGINX on Ubuntu infrastructure with real-time monitoring, automated maintenance, and distributed command execution.