knosh add-mcp¶
Add an MCP server entry to knosh.json.
Synopsis¶
knosh add-mcp <name> --url <url> [options]
knosh add-mcp <name> --commandLine <command-line> [options]
knosh add-mcp <name> [options] -- <argv>...
Description¶
add-mcp writes a new entry under the mcp key in a Knosh config file. It supports both server types — a "local" server, run as a child process, and a "remote" server, connected over MCP Streamable HTTP — but never asks which type to write: the type is inferred from which input you supplied.
--urlmakes the server remote.- Trailing argv after
--, or--commandLine, makes the server local. Supply exactly one of the two.
There is no --type flag; supplying the wrong combination of options for the inferred type is a usage error, checked before any file is touched.
If the target config file does not already exist, add-mcp creates it. Adding a name that already exists is an error unless --force is given, in which case the existing entry is replaced wholesale.
add-mcp only writes configuration. It does not spawn the local server or connect to the remote URL to confirm it works — use mcp-info for that.
Options¶
--url <url>- The remote server's MCP endpoint. Its presence is what makes the server remote.
--commandLine <command-line>/--command-line <command-line>- The local server's command as a single string, tokenized POSIX-style when the server starts. Mutually exclusive with trailing argv.
- (trailing
-- <argv>...) - The local server's command as separate argv tokens, given after
--. Mutually exclusive with--commandLine.--is required only when the argv itself contains a dash-leading token (e.g.-y); otherwise it is optional but always accepted. --env KEY=VALUE- Sets an environment variable for a local server. Repeatable. Requires a local server — supplying
--envalongside--urlis a usage error. The value may itself contain=; only the first=is treated as the separator. --header NAME=VALUE- Sets an HTTP header for a remote server. Repeatable. Requires
--url— supplying--headerfor a local server is a usage error. Same=-splitting rule as--env. --timeoutSeconds <n>/--timeout-seconds <n>- Sets the server's
timeoutfield, in seconds. Must be a positive integer. Applies to both server types. --required- Sets
required: true— a startup failure for this server aborts the run instead of being skipped with a warning. --disabled- Writes the server with
enabled: false. --global-
Targets
~/.config/knosh/knosh.jsoninstead of.knosh.jsonin the current directory, mirroringinit --global.A local
mcpentry merges with the global one per server handle — seemcp— so runningadd-mcpwithout--globaladds a project-specific server alongside any global ones, rather than displacing them. --force- Replaces an existing entry with the same name instead of failing.
Output¶
On success, add-mcp names the file it modified and echoes the JSON of the entry it wrote — just the new entry, not the whole file:
Added MCP server 'ksrc' in /Users/you/project/.knosh.json
"ksrc": {
"type": "local",
"command": ["npx", "-y", "ksrc-mcp"]
}
When --force replaced an existing entry, the first line reads Replaced MCP server '<name>' in <path> instead of Added, so an overwrite is never reported in words that read like a fresh add.
Examples¶
Add a local server using trailing argv:
Add the same server using --commandLine:
Add a remote server with a timeout and mark it required:
Add a remote server with a header, keeping the token out of knosh.json via the {env:NAME} indirection — see header value resolution:
knosh add-mcp docs --url https://mcp.example.com/v1 --header 'Authorization=Bearer {env:DOCS_TOKEN}'
Add a local server to the global config with an environment variable:
Replace an existing entry: