RouterMCP
RouterMCP CLI

Advanced Features

Daemon mode, proxy command, sessions, and other advanced CLI features.

Advanced Features

This guide covers advanced RouterMCP CLI features including daemon mode, the proxy command, and session management.

Daemon Mode

Daemon mode allows multiple MCP clients to share a single gateway instance, reducing resource usage and maintaining session state.

How It Works

  1. Run routermcp connect to connect to a daemon
  2. If no daemon is running, one starts automatically in the background
  3. The daemon runs an HTTP server on port 5151 (default)
  4. The connect command proxies stdio to/from the daemon
  5. The daemon shuts down after 10 seconds of idle

Usage

routermcp connect                    # Connect (auto-starts daemon)
routermcp connect --project /path    # Specific project directory
routermcp connect -v                 # Verbose logging

Manual Daemon Mode

Run the gateway explicitly as a daemon:

routermcp serve --daemon-mode --http 5151
routermcp serve --daemon-mode -v

Daemon Files

Daemon state is stored in ~/.routermcp/projects/<project-id>/:

FileDescription
daemon.pidProcess ID of running daemon
daemon.portHTTP port the daemon uses

Proxy Command

Proxy a stdio-based MCP server over HTTP without the full gateway configuration. Useful for exposing a single MCP server.

Basic Usage

# SSE proxy (default)
routermcp proxy --stdio "npx -y @modelcontextprotocol/server-filesystem ."

# Streamable HTTP (stateless)
routermcp proxy --stdio "node server.js" --outputTransport streamableHttp

# Streamable HTTP (stateful)
routermcp proxy --stdio "python mcp_server.py" --outputTransport streamableHttp --stateful

Proxy Options

OptionDefaultDescription
--stdio <command>(required)Command to spawn MCP server
--outputTransportsseOutput: sse or streamableHttp
-p, --port8000HTTP server port
--basePath""Base path prefix
--ssePath/sseSSE endpoint path
--messagePath/messageMessage endpoint (SSE mode)
--streamableHttpPath/mcpStreamable HTTP endpoint
--statefulfalseEnable stateful sessions
--sessionTimeout60000Session timeout (ms)
--healthEndpoint/healthHealth check path
--cors / --no-corstrueEnable/disable CORS
--maxRestarts3Max restart attempts

Transport Modes

SSE (Server-Sent Events)

  • Legacy but widely supported
  • Single child process shared across connections
  • Endpoints: GET /sse (connect), POST /message (send)

Streamable HTTP (Stateless)

  • Each request spawns a new child process
  • Best for simple, short-lived operations
  • Endpoint: POST /mcp

Streamable HTTP (Stateful)

  • Sessions persist with dedicated process per session
  • Supports server-initiated notifications
  • Endpoints: POST /mcp, GET /mcp (SSE), DELETE /mcp

Session Management

When running in HTTP mode, RouterMCP manages sessions for connected clients.

Session Behavior

  • Each connected client gets an isolated session
  • Sessions maintain state across requests
  • Sessions timeout after inactivity (default: 5 minutes)
  • Each session has its own upstream server connections

Configuration

{
  "session": {
    "timeout": 300,      // Seconds (default: 300)
    "max_sessions": 25   // Maximum concurrent (default: 25)
  }
}

Error Handling

Name Collisions

If multiple servers expose tools with the same name, the gateway fails to start with a collision error.

Resolution:

  • Use filtering to expose only unique names
  • Rename tools at the upstream server level
  • Disable conflicting servers

Graceful Degradation

If an upstream server fails to connect:

  • Gateway continues with available servers
  • Failed servers are logged with error details
  • Their tools/resources/prompts are not exposed
  • Restart gateway after fixing the configuration

CLI Reference

Global Options

OptionDescription
-v, --verboseEnable verbose logging
-h, --helpShow help message

Serve Options

OptionDescription
-c, --config <path>Config file path
--stdioUse stdio transport (default)
--http <port>Use HTTP on specified port
--daemon-modeRun as background daemon
--socket <path>Unix socket path (daemon, non-Windows)

Connect Options

OptionDescription
-c, --config <path>Config file path
--project <path>Project directory for daemon

Features Summary

FeatureDescription
MCP GatewayProxy multiple upstream servers
Code ModeJavaScript execution in WebAssembly sandbox
Session MultiplexingIsolated sessions for HTTP clients
Daemon ModeBackground process with auto-startup
Stdio-to-HTTP ProxyConvert stdio servers to HTTP
Tool FilteringAllow/deny with exact names or globs
Resource FilteringSame filtering for resources
Prompt FilteringSame filtering for prompts
Multiple TransportsStdio and HTTP for both directions
Graceful DegradationContinue if some servers fail
Auto-RestartRestart child processes on failure
Interactive ConfigCLI wizard for configuration
Tunnel SupportCloudflare and ngrok integration
Environment Variables${VAR} substitution in config

On this page