> ## 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.

# File System

> Persist MCP sessions to a local JSON file with the file system storage backend, ideal for local development and single-instance deployments without Redis.

**Perfect for local development with persistent sessions across restarts.**

File storage persists sessions to a JSON file on disk. Ideal for:

* Local development
* Single-instance deployments
* Testing with persistent state
* Environments without Redis

## Configuration

```bash theme={null}
# Explicit selection (optional)
MCP_TS_STORAGE_TYPE=file

# File path for session storage (required)
MCP_TS_STORAGE_FILE=./sessions.json
```

## Features

* **Persistent** across application restarts
* **No external dependencies**
* **Human-readable** JSON format
* **Automatic** directory creation

## Usage

### Option 1: Automatic Detection (Recommended)

When `MCP_TS_STORAGE_FILE` is present in your environment, the global `sessions` proxy automatically uses the File System backend.

```typescript theme={null}
import { sessions } from '@mcp-ts/sdk/server';

// This will use File System automatically if env vars are set
const sessionList = await sessions.list('user-123');
console.log('Stored sessions:', sessionList);
```

### Option 2: Manual Instantiation

If you want to manage the File System backend yourself:

```typescript theme={null}
import { FileStorageBackend } from '@mcp-ts/sdk/server';

const fileBackend = new FileStorageBackend({ path: './sessions.json' });
await fileBackend.init();

const sessionList = await fileBackend.list('user-123');
```

### File Format

```json theme={null}
[
  {
    "sessionId": "abc123",
    "userId": "user-123",
    "serverId": "server-1",
    "serverName": "My MCP Server",
    "serverUrl": "https://mcp.example.com",
    "callbackUrl": "https://app.com/callback",
    "transportType": "sse",
    "active": true,
    "createdAt": 1706234567890
  }
]
```

## Troubleshooting

### File Storage Not Persisting

```bash theme={null}
# Check file permissions
ls -la ./sessions.json

# Verify path is writable
touch ./sessions.json

# Check environment variable
echo $MCP_TS_STORAGE_FILE
```
