# `Codex.AppServer.Mcp`
[🔗](https://github.com/nshkrdotcom/codex_sdk/blob/v0.18.0/lib/codex/app_server/mcp.ex#L1)

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.

# `connection`

```elixir
@type connection() :: pid()
```

# `list_server_statuses`

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

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

# `list_servers`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

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

Requests MCP servers to reload configuration and refresh cached tools.

# `resource_read`

```elixir
@spec resource_read(connection(), String.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, term()}
```

Reads an MCP resource within the context of a thread.

# `tool_call`

```elixir
@spec tool_call(connection(), String.t(), String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}
```

Calls a tool on a configured MCP server within the context of a thread.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
