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

# Types & Errors

> Reference for core mcp-ts TypeScript types and error classes, including McpConnectionState, McpConnectionEvent, ToolInfo, and shared error subclasses.

### Connection Types

```typescript theme={null}
import type {
  McpConnectionState,
  McpConnectionEvent,
} from '@mcp-ts/client/shared';

type McpConnectionState =
  | 'DISCONNECTED'
  | 'CONNECTING'
  | 'AUTHENTICATING'
  | 'AUTHENTICATED'
  | 'DISCOVERING'
  | 'CONNECTED'
  | 'VALIDATING'
  | 'RECONNECTING'
  | 'FAILED';

type McpConnectionEvent =
  | { type: 'state_changed'; sessionId: string; state: McpConnectionState; /* ... */ }
  | { type: 'capabilities_discovered'; sessionId: string; serverId: string; tools: ToolInfo[]; allTools: ToolInfo[]; prompts: Prompt[]; resources: Resource[]; resourceTemplates: ResourceTemplate[]; timestamp: number; }
  | { type: 'auth_required'; sessionId: string; authUrl: string; /* ... */ }
  | { type: 'error'; sessionId: string; error: string; /* ... */ }
  | { type: 'disconnected'; sessionId: string; reason?: string; /* ... */ }
  | { type: 'progress'; sessionId: string; message: string; /* ... */ };
```

### Tool Types

```typescript theme={null}
import type { ToolInfo } from '@mcp-ts/client/shared';

interface ToolInfo {
  name: string;
  description?: string;
  inputSchema: {
    type: 'object';
    properties?: Record<string, any>;
    required?: string[];
  };
}
```

### Session Types

```typescript theme={null}
interface Session {
  sessionId: string;
  userId: string;
  serverId?: string;
  serverName?: string;
  serverUrl: string;
  callbackUrl: string;
  serverOptions?: {
    client?: StoredMcpSdkClientOptions;
    transport?: { type?: 'sse' | 'streamable-http'; protocolVersion?: string };
    discoverResult?: DiscoverResult;
  } | null;
  status: 'pending' | 'active';
  createdAt: number;
  updatedAt?: number;
  expiresAt?: number | null;
  headers?: Record<string, string>;
  authUrl?: string | null;
  toolPolicy?: ToolPolicy;
  clientInformation?: OAuthClientInformationMixed | null;
  tokens?: OAuthTokens | null;
  codeVerifier?: string | null;
  clientId?: string | null;
  oauthState?: OAuthState | null;
}
```

Durable session storage keeps v2 metadata under `serverOptions`. `SessionInfo`, `GetSessionResult`, and `FinishAuthResult` can still expose live protocol metadata when a client has connected.

### Tool Policy Types

```typescript theme={null}
import { createToolId, isToolAllowed, filterToolsByPolicy } from '@mcp-ts/client/server';

interface ToolPolicy {
  mode: 'all' | 'allowlist' | 'denylist';
  toolIds: string[];
  updatedAt: number;
}
```

**Utility functions:**

| Function                                                   | Description                                                            |
| ---------------------------------------------------------- | ---------------------------------------------------------------------- |
| `createToolId(serverId, toolName)`                         | Creates composite `{serverId}::{toolName}` ID                          |
| `normalizeToolPolicy(input, now?)`                         | Normalizes raw input into `ToolPolicy \| undefined`                    |
| `normalizeToolPolicyForUpdate(input, now?)`                | Like above but falls back to `{ mode: 'all', toolIds: [], updatedAt }` |
| `isToolAllowed(policy, toolName, serverId?)`               | Checks if a tool is permitted under the policy                         |
| `assertToolAllowed(policy, toolName, serverId?)`           | Throws if tool is not allowed                                          |
| `filterToolsByPolicy(tools, policy, serverId?)`            | Filters tool array to only allowed tools                               |
| `validateToolPolicyAgainstTools(policy, tools, serverId?)` | Validates all tool IDs correspond to actual tools                      |

````

## Error Handling

### UnauthorizedError

Thrown when OAuth authorization is required.

```typescript
import { UnauthorizedError } from '@mcp-ts/client/server';

try {
  await client.connect();
} catch (error) {
  if (error instanceof UnauthorizedError) {
    console.log('Redirect to:', error.authUrl);
  }
}
````
