> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mcp-use.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MCPConnection

> Protocol-neutral API for one MCP server connection

```ts theme={null}
import { MCPClient, type MCPConnection } from "@mcp-use/client";

const connection = await client.connect("demo");
```

One API for legacy sessionful (v1) and modern sessionless (v2) servers. Create connections via `MCPClient.connect()` — do not construct directly unless using low-level connectors.

`MCPSession` is a deprecated alias for `MCPConnection`.

## Metadata

```ts theme={null}
connection.info.protocolEra   // "legacy" | "modern"
connection.info.protocolVersion
connection.info.server          // { name, version, title, ... }
connection.info.capabilities
connection.info.instructions
connection.info.extensions
connection.authorization             // optional mixed-auth state
connection.info.authorization        // same state in the metadata snapshot
await connection.discoverAuthorization() // populate optional mixed-auth state
connection.supports("sampling") // capability check
```

## Lifecycle

| Method | Description |
| - | - |
| `connect()` | Start transport |
| `initialize()` | Run MCP init handshake |
| `discoverAuthorization()` | Discover optional mixed-auth metadata without forcing login |
| `authenticate()` | Start optional OAuth for a connected mixed-auth server |
| `disconnect()` | Close transport |

## Tools

| Method | Description |
| - | - |
| `listTools(options?)` | Fetch tool list |
| `callTool(name, args?, options?)` | Invoke a tool |

## Resources

| Method | Description |
| - | - |
| `listResources(cursor?, options?)` | Paginated list |
| `listAllResources(options?)` | All resources |
| `listResourceTemplates(options?)` | Template list |
| `readResource(uri, options?)` | Read by URI |
| `subscribeToResource(uri, options?)` | Subscribe to updates |
| `unsubscribeFromResource(uri, options?)` | Unsubscribe |

## Prompts

| Method | Description |
| - | - |
| `listPrompts()` | List prompts |
| `getPrompt(name, args)` | Fetch prompt with arguments |

## Completions

| Method | Description |
| - | - |
| `complete(params)` | Autocomplete prompt/resource arguments |

## Roots & notifications

| Method | Description |
| - | - |
| `setRoots(roots)` | Update roots (sends notification) |
| `getRoots()` | Current roots |
| `on("notification", handler)` | Listen for server notifications |

## Low-level

| Method | Description |
| - | - |
| `request(method, params?, options?)` | Raw MCP request |

## Types

```ts theme={null}
interface MCPConnectionInfo {
  protocolEra: "legacy" | "modern";
  protocolVersion: string;
  server: MCPServerInfo;
  capabilities: Record<string, unknown>;
  instructions?: string;
  extensions: Record<string, unknown>;
  authorization?: MCPAuthorizationInfo;
}

interface MCPAuthorizationInfo {
  mode: "mixed";
  authenticated: boolean;
  resource?: string;
  scopesSupported?: string[];
}

interface Root {
  uri: string;   // file://...
  name?: string;
}

type NotificationHandler = (notification: Notification) => void | Promise<void>;
```

Re-exported: `CallToolResult`, `Notification`, `Root`, `Tool`

## Related

* [`MCPClient`](https://docs.mcp-use.com/v1/typescript/api-reference/client/mcp-client)
* [Tools guide](https://docs.mcp-use.com/v1/typescript/client/tools.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.