Cortex Code CLI Model Context Protocol (MCP) support¶
Cortex Code CLI implements the Model Context Protocol (MCP), an open standard that connects AI agents to external tools and data sources such as GitHub, Jira, internal APIs, and databases. Once you add an MCP server to Cortex Code, its tools become available to the agent automatically — no code changes are required.
This topic covers how to add and manage MCP servers, the full configuration schema, credential handling, and administrator controls.
Transport types¶
Cortex Code supports three MCP transport types. Choose the transport that matches your server:
Type |
Use case |
How Cortex Code connects |
|---|---|---|
|
Local tools, CLI wrappers, language-specific MCP servers |
Spawns a subprocess and communicates over |
|
Web services, hosted APIs |
Streamable HTTP requests |
|
Real-time streaming services |
Server-Sent Events over HTTPS |
Managing MCP servers¶
You can manage MCP servers from the command line using cortex mcp, or interactively from a Cortex Code session using the /mcp slash command.
Command reference¶
Command |
Description |
|---|---|
|
Register a new MCP server. See Adding a server for flags. |
|
List all configured servers with transport, URL or command, and masked credential keys. |
|
Show detailed configuration for a single server, including OAuth fields. |
|
Remove a server from configuration and delete its stored credentials. |
|
Connect to all configured servers and report connected and failed counts. Waits up to 300 seconds for servers to load. |
Interactive management¶
Run /mcp in a Cortex Code CLI session to open an interactive MCP status viewer. The viewer shows:
Each server’s name, transport type, and connection state (
connecting,connected,reconnecting,failed,not_started)The number of tools exposed by each connected server
The last error reported by any failed server
Toggle buttons to enable or disable individual servers without editing configuration files
Adding a server¶
Use cortex mcp add to register a new MCP server from the command line:
Flags:
Flag |
Description |
|---|---|
|
Transport type: |
|
Set an environment variable for the subprocess ( |
|
Set an HTTP header ( |
|
Connection timeout in milliseconds. |
Common examples:
Action |
Command |
|---|---|
Add a stdio server |
|
Add an HTTP server |
|
Add with environment variable |
|
Add with header |
|
Sensitive values passed via -e or -H are migrated into the OS keychain on first connection (see Credential storage).
Configuration file¶
MCP servers are configured in:
The top-level key is mcpServers. Each entry is keyed by server name:
Server fields¶
Field |
Type |
Description |
|---|---|---|
|
string |
Required. One of |
|
string |
The executable to launch for |
|
array of strings |
Arguments passed to |
|
string |
Working directory for the |
|
string |
The endpoint URL for |
|
object |
Environment variables for the |
|
object |
HTTP headers for |
|
number |
Tool call timeout in milliseconds. Defaults to 60,000 (60 seconds). Can also be overridden globally via the |
|
object |
OAuth 2.0 configuration for |
Environment variable expansion¶
Cortex Code expands environment variables in every field of mcp.json before connecting. Three syntaxes are supported:
Syntax |
Behavior |
|---|---|
|
Replaced with the value of |
|
Replaced with |
|
Short form of |
Important
Use environment variables for credentials. Do not hardcode tokens or secrets in mcp.json. Export sensitive values from your shell profile (~/.bashrc, ~/.zshrc) so they are not checked into source control.
Configuration precedence¶
Cortex Code merges MCP servers from multiple sources in the following order (later sources win when names collide, with the exception of plugins):
Administrator-enforced servers from the managed settings enforcement file.
Connection profile servers declared in your active Snowflake connection.
User servers from
~/.snowflake/cortex/mcp.json(only if your administrator allows user MCP servers).Plugin servers declared by installed plugins (skipped when user MCP servers are disabled by the administrator). Plugin servers never overwrite an existing server that was configured at a higher level.
Administrator URL allowlist. After merging, any server whose
urlis not permitted by managed settings is silently removed.
See managed settings for details on enforcement policies.
Tool names and permissions¶
MCP tools are namespaced by server name so that two servers can expose tools of the same name without conflict. The composed tool name has the form:
For example, a tool named search exposed by the server github is visible to the agent as mcp__github__search.
Tool names are limited to 64 characters and must contain only alphanumeric characters, underscores, and hyphens.
Permissions¶
MCP tools participate in the standard Cortex Code permission system. Default permission decisions can be configured in:
You can match individual tools by their full composed name, or match all tools from a server with a wildcard pattern:
At runtime, permissions are also requested on first use and can be remembered for the session.
Credential storage¶
When a server is added or configured with env, headers, or OAuth, Cortex Code migrates sensitive values out of mcp.json and into the OS keychain on first connection. The mcp.json file is rewritten with those fields removed.
Credentials are stored under the keychain entry
mcp_oauth_<server-name>as a unified blob containing tokens, OAuth client registration, headers, and environment variables.cortex mcp listandcortex mcp getdisplay key names but never display secret values.cortex mcp removeremoves both the configuration entry and the keychain entry.
If the OS keychain is unavailable (for example, in a headless container), credential storage degrades gracefully and no secrets are written to disk.
OAuth authentication¶
For HTTP MCP servers that require OAuth 2.0, add an oauth block to the server configuration:
On first connection, Cortex Code opens your system browser for authentication. The resulting access and refresh tokens are stored in the OS keychain and are refreshed automatically before expiry.
Field |
Description |
|---|---|
|
The OAuth client ID registered with the authorization server. If omitted, Cortex Code attempts Dynamic Client Registration. |
|
Human-readable client name shown during dynamic registration. |
|
Local port used for the OAuth redirect URI. Defaults to |
|
Space-separated list of OAuth scopes to request. |
|
URL of the authorization server. If omitted, Cortex Code discovers it from the MCP server’s metadata. |
Note
To reset OAuth credentials for a server, run cortex mcp remove <server> and re-add the server. You can then run cortex mcp start to reconnect all configured servers and trigger a fresh OAuth flow.
Disabling servers¶
You can temporarily disable an MCP server without removing it from configuration. From the /mcp viewer, select the server and toggle it off. The disabled state is persisted to:
Disabled servers are not connected at session start, their tools are not exposed to the agent, and they are not auto-reconnected. Re-enable them at any time from /mcp.
Using MCP tools¶
Once configured, MCP tools are available in every Cortex Code CLI session automatically. Invoke them through natural language:
Tool results are capped at 50 KB. If a tool returns more data, the output is truncated and Cortex Code appends a notice to the truncation point.
Sample configurations¶
Git server (stdio)¶
HTTP API with OAuth¶
SSE server with headers¶
Sourcegraph integration (stdio with env)¶
Plugin-declared MCP servers¶
Plugins can ship MCP servers with their distribution by declaring them in plugin.json. These servers are loaded automatically when the plugin is active:
Plugin MCP servers have lower priority than user or profile servers — a plugin cannot overwrite a server that you configured directly. See the Cortex Code CLI plugins documentation for details.
Administrator controls¶
Administrators can restrict MCP usage through managed settings:
Disable user MCP servers. When
areUserMcpServersAllowedis set tofalse, Cortex Code ignores~/.snowflake/cortex/mcp.jsonentirely and only servers provided by the administrator or the Snowflake connection profile are loaded. Plugin-declared MCP servers are also skipped in this mode.URL allowlist. Administrators can restrict the set of allowed MCP endpoint URLs. Servers whose URL is not permitted are silently removed after configuration is merged.
Enforced servers. Administrators can ship a base
mcp.jsonthat is always applied. Users cannot remove or modify enforced servers.
See managed settings for the full enforcement schema.
MCP troubleshooting¶
Server not connecting¶
Run
/mcpand check the server’s status and last error.Run
cortex mcp startfrom the terminal and watch for error output.Check
~/.snowflake/cortex/logs/for MCP client and manager logs.Confirm that any required environment variables are set in your shell (
echo $VAR).
Tools not appearing¶
Run
cortex mcp listto confirm the server is configured.Make sure tool names are alphanumeric, underscore, or hyphen and shorter than 64 characters; MCP servers exposing invalid tool names are rejected.
Confirm the server is not disabled in
~/.snowflake/cortex/mcp-disabled.json.
OAuth issues¶
Clear cached credentials with
cortex mcp remove <server>and re-add the server to trigger a fresh flow.Confirm that port
8585(or your configuredredirect_port) is available.If your authorization server supports Dynamic Client Registration, omit
client_idand let Cortex Code register on your behalf.
Environment variables not expanding¶
Prefer
${VAR}with braces over bare$VARto avoid ambiguity.Verify the variable is exported in your shell (
echo $VAR).Remember that Cortex Code expands variables from the process environment when the CLI was launched, not from an editor’s embedded shell.
Output truncated¶
Tool results are capped at 50 KB. For large datasets, have the MCP server return a summary, a reference, or a pointer to a file that Cortex Code can read in a follow-up step.
MCP best practices¶
Use descriptive server names. Server names appear in the tool namespace, so pick names that make tool calls self-describing (for example,
mcp__github__searchis clearer thanmcp__gh1__search).Secure credentials. Use environment variables or OAuth; never hardcode tokens in
mcp.json.Set appropriate timeouts. The default tool timeout is 60 seconds. Increase it for long-running tools, or decrease it to fail fast on unresponsive servers.
Test connectivity first. Run
cortex mcp startafter adding or updating a server to confirm it connects and exposes the tools you expect before relying on it from an agent session.Scope permissions narrowly. Use the
allowanddenylists inpermissions.jsonto pre-approve safe read-only tools and explicitly deny destructive ones.