Codex.AppServer.Mcp (Codex SDK v0.7.2)

Copy Markdown View Source

MCP (Model Context Protocol) server management for app-server connections.

This module provides functions to interact with MCP servers configured in the Codex app-server, including listing server status and handling OAuth authentication flows.

Summary

Functions

Alias for list_servers/2. Returns MCP server status information.

Lists configured MCP servers with their tools, resources, and auth status.

Starts an OAuth login flow for a streamable HTTP MCP server.

Deletes stored OAuth tokens for a configured MCP server.

Loads stored OAuth tokens for a configured MCP server.

Requests MCP servers to reload configuration and refresh cached tools.

Types

connection()

@type connection() :: pid()

Functions

list_server_statuses(conn, opts \\ [])

@spec list_server_statuses(
  connection(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Alias for list_servers/2. Returns MCP server status information.

list_servers(conn, opts \\ [])

@spec list_servers(
  connection(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Lists configured MCP servers with their tools, resources, and auth status.

Supports cursor-based pagination via :cursor and :limit options.

Compatibility

This function tries the new mcpServerStatus/list method first. If the server returns a "method not found" (-32601) or "unknown variant" (-32600) error (older servers), it falls back to the legacy mcpServers/list method automatically.

oauth_login(conn, opts)

@spec oauth_login(
  connection(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Starts an OAuth login flow for a streamable HTTP MCP server.

OAuth credentials are stored using the configured MCP credentials store. Use oauth_tokens/3 to load them after login completes.

oauth_logout(conn, name, opts \\ [])

@spec oauth_logout(connection(), String.t(), keyword()) :: :ok | {:error, term()}

Deletes stored OAuth tokens for a configured MCP server.

Returns {:error, :server_not_found} if the server is not configured, or {:error, :missing_url} if the server is not a streamable HTTP server.

oauth_tokens(conn, name, opts \\ [])

@spec oauth_tokens(connection(), String.t(), keyword()) ::
  {:ok, Codex.MCP.OAuth.tokens() | nil} | {:error, term()}

Loads stored OAuth tokens for a configured MCP server.

Returns {:error, :server_not_found} if the server is not configured, or {:error, :missing_url} if the server is not a streamable HTTP server.

reload(conn)

@spec reload(connection()) :: {:ok, map()} | {:error, term()}

Requests MCP servers to reload configuration and refresh cached tools.