can1357/oh-my-pi · error · Error

MCP server not connected: ${name}

Error message

MCP server not connected: ${name}

What it means

A lookup path in MCPManager (e.g. retrieving a connection to call a tool) throws "MCP server not connected: <name>" when no active connection exists for that server and no reconnection is in flight. If a pending reconnection promise exists, the call awaits it and returns its result; only when there is neither a live connection nor a pending reconnect does it throw.

Source

Thrown at packages/coding-agent/src/mcp/manager.ts:915

	getServerConfig(name: string): MCPServerConfig | undefined {
		return this.#connections.get(name)?.config ?? this.#serverConfigs.get(name);
	}

	/**
	 * Wait for a connection to complete (or fail).
	 */
	async waitForConnection(name: string): Promise<MCPServerConnection> {
		const connection = this.#connections.get(name);
		if (connection) return connection;
		const pending = this.#pendingConnections.get(name);
		if (pending) return pending;
		// If a reconnection is in flight, wait for it to complete
		const reconnecting = this.#pendingReconnections.get(name);
		if (reconnecting) {
			const result = await reconnecting;
			if (result) return result;
		}
		throw new Error(`MCP server not connected: ${name}`);
	}

	/**
	 * Resolve auth and shell-command substitutions in config before connecting.
	 * Pass `oauth: false` to skip OAuth credential injection (used by reauth's
	 * unauthenticated probe, which must observe the server's bare 401).
	 */
	async prepareConfig(config: MCPServerConfig, options?: { oauth?: boolean }): Promise<MCPServerConfig> {
		return this.#resolveAuthConfig(config, options);
	}

	/**
	 * Get all connected server names.
	 */
	getConnectedServers(): string[] {
		return Array.from(this.#connections.keys());
	}

View on GitHub (pinned to 9690622007)

Solutions

  1. Check /mcp status (or manager state) to see whether the server is connected; reconnect it first.
  2. Fix the underlying connect failure (bad command, missing package, auth) that prevented the connection.
  3. Verify the server name spelling matches the config entry exactly.
  4. Ensure connectServers() has completed before issuing tool calls at startup.
  5. If the server was disconnected intentionally, trigger an explicit reconnect rather than assuming auto-reconnect.
  6. Catch this error in tool-call paths and surface a 'server not running — run /mcp' hint to the user.

Example fix

// before
const result = await manager.callTool("github", "list_issues", args); // throws if not connected
// after
let conn;
try {
  conn = await manager.getConnection("github");
} catch {
  await manager.connectServers(["github"]); // reconnect, then retry
  conn = await manager.getConnection("github");
}
Defensive patterns

Strategy: try-catch

Validate before calling

import { readMCPConfigFile } from "@oh-my-pi/pi-coding-agent/mcp/config";
const cfg = await readMCPConfigFile(configPath);
if (!cfg.mcpServers?.[serverName]) throw new Error(`Server "${serverName}" is not in config`);

Type guard

function hasConnection(manager: MCPManager, name: string): boolean {
  // only meaningful if your manager build exposes status; otherwise gate on config
  return manager.isConnected?.(name) ?? false;
}

Try / catch

try {
  return await manager.callTool(serverName, tool, args);
} catch (e) {
  if (e instanceof Error && e.message === `MCP server not connected: ${serverName}`) {
    await manager.connectServers(); // reconnect then surface a user-facing hint
    throw new Error(`MCP server "${serverName}" is not running — reconnect attempted, please retry`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling a tool or requesting the connection for a server that was never connected, was disconnected via disconnectServer/disconnectAll, failed to connect earlier (bad command, crashed on start), or whose config was removed — with no reconnect currently in flight.

Common situations: Invoking an MCP tool while the server's stdio process failed to launch (missing npx, bad package); server was disabled or removed from config; a previous connect attempt errored (auth failure) and no retry is queued; calling tools before connectServers() finished; /mcp disconnect then immediate tool call.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/925f63c015be5a18. Report an issue: GitHub.