API reference
Every function and type exported by the add-mcp package.
All exports come from the package root:
import {
upsertServer,
removeServer,
listInstalledServers,
detectProjectAgents,
detectGlobalAgents,
getAgentTypes,
agents,
} from "add-mcp";
upsertServer
Adds or replaces an MCP server in an agent’s config file. Creates the config file (and parent directories) when missing. Reinstalling an existing name replaces the entire entry rather than merging fields; pass the complete desired configuration. Unrelated servers and config sections are preserved (2.0.0 changelog).
function upsertServer(
agentType: AgentInput,
serverName: string,
serverConfig: McpServerConfig,
options?: InstallOptions,
): InstallResult;
| Parameter | Type | Description |
|---|---|---|
agentType |
AgentInput |
Agent identifier, e.g. "cursor", "claude-code". Validated at runtime. |
serverName |
string |
Key the server is stored under in the agent config. |
serverConfig |
McpServerConfig |
Canonical server definition (see below). |
options |
InstallOptions |
{ local?: boolean; cwd?: string } — project-level install and its working directory. |
Returns InstallResult. Never throws — errors are reported via result.error.
upsertServer and removeServer default to global scope. For project scope, pass local: true; cwd alone does not change scope. Global-only agents reject local: true rather than falling back to global. These functions accept canonical agent identifiers, not CLI aliases (SDK validation, path resolution).
removeServer
Removes a server entry from an agent’s config file. Succeeds (with removed: false) when the config or entry doesn’t exist.
function removeServer(
agentType: AgentInput,
serverName: string,
options?: InstallOptions,
): RemoveServerResult;
Returns { success: boolean; path: string; removed: boolean; error?: string }.
listInstalledServers
Gathers installed servers across detected (or explicitly specified) agents. Defaults to project scope; pass global: true for global configs (reader source).
function listInstalledServers(options: {
global?: boolean;
agents?: AgentType[];
cwd?: string;
}): Promise<AgentServers[]>;
When agents is provided, those agents are included even if not detected (with detected: false). A detected agent whose config cannot be read is still returned, with servers: [] and error set to the failure message.
detectProjectAgents
Detects agents with project-level config files in a directory (synchronous).
function detectProjectAgents(cwd?: string): AgentType[];
detectGlobalAgents
Detects globally-installed agents by their global config paths (asynchronous).
function detectGlobalAgents(): Promise<AgentType[]>;
getAgentTypes
Returns all supported agent identifiers.
function getAgentTypes(): AgentType[];
agents
The full agent capability map — Record<AgentType, AgentConfig> with each agent’s display name, config paths, file format, supported transports, and supported optional fields.
Types
McpServerConfig
The canonical server definition. add-mcp maps it into each client’s native schema and strips capability-gated fields the target agent doesn’t support.
interface McpServerConfig {
// Remote servers
type?: "http" | "sse";
url?: string;
headers?: Record<string, string>;
// Local stdio servers
command?: string;
args?: string[];
env?: Record<string, string>;
// Capability-gated optional fields
timeout?: number; // milliseconds; Claude Code, Factory Droid, Gemini CLI, Grok Build, Hermes Agent, Kilo Code, Kimi Code, Kiro CLI, Pi
oauthScopes?: string[]; // Cursor, Gemini CLI, Mastra Code
autoApproveTools?: string[]; // Codex, Claude Code; [] = all tools
bearerTokenEnv?: string; // fx writes bearer_token_env
}
Capability lists and mappings come from the 2.6.1 agent transforms and canonical types. Unlike the remote-only CLI --timeout flag, SDK stdio configs can also carry a timeout for Factory Droid, Hermes, Kilo Code, Kimi Code, and Pi. Kimi Code drops timeouts outside the integer range 1..2147483647.
InstallOptions
interface InstallOptions {
/** Install to local (project-level) config instead of global */
local?: boolean;
/** Current working directory for local installs */
cwd?: string;
}
InstallResult
interface InstallResult {
success: boolean;
path: string;
error?: string;
/** Optional fields dropped because the agent doesn't support them */
droppedFields?: OptionalField[];
/** Additional files written beyond the main config */
extraPaths?: string[];
}
AgentType
type AgentType =
| "antigravity"
| "cline"
| "cline-cli"
| "claude-code"
| "claude-desktop"
| "codex"
| "cursor"
| "factory-droid"
| "fx"
| "gemini-cli"
| "goose"
| "github-copilot-cli"
| "grok-build"
| "hermes"
| "junie"
| "kilo-code"
| "kimi-code"
| "kiro-cli"
| "mastracode"
| "mcporter"
| "opencode"
| "pi"
| "vscode"
| "windsurf"
| "zed";
AgentInput is AgentType | (string & {}) — it keeps autocomplete on the known literals while accepting arbitrary strings that are validated at runtime.
AgentServers / InstalledServer
Returned by listInstalledServers:
interface AgentServers {
agentType: AgentType;
displayName: string;
detected: boolean;
scope: "local" | "global";
configPath: string;
servers: InstalledServer[];
/** Set when this agent's config could not be read */
error?: string;
}
interface InstalledServer {
serverName: string;
config: Record<string, unknown>;
/** URL for remote servers, package/command string for stdio servers */
identity: string;
agentType: AgentType;
scope: "local" | "global";
configPath: string;
/** Key in the config file this server was read from. `""` means the file root (a Copilot CLI bare name map). */
configKey: string;
}