# Filelayer MCP server

> Manages user file permissions, sharing with expiry, and audit trails for SaaS applications using your own Postgres database.

- Repository: https://github.com/filelayer/filelayer
- Page: https://hostedmcp.org/servers/filelayer/core
- Transport: stdio
- Stars: 0
- License: Apache-2.0
- Latest version: 0.35.4

## Install

### Claude Code

```sh
claude mcp add --env 'DATABASE_URL=<YOUR_DATABASE_URL>' --env 'FILELAYER_AS=<FILELAYER_AS>' --env 'FILELAYER_ORG=<FILELAYER_ORG>' --env 'S3_ACCESS_KEY_ID=<YOUR_S3_ACCESS_KEY_ID>' --env 'S3_SECRET_ACCESS_KEY=<YOUR_S3_SECRET_ACCESS_KEY>' core -- npx -y @filelayer/core
```

### Cursor (`~/.cursor/mcp.json`)

```json
{
  "mcpServers": {
    "core": {
      "command": "npx",
      "args": [
        "-y",
        "@filelayer/core"
      ],
      "env": {
        "DATABASE_URL": "<YOUR_DATABASE_URL>",
        "FILELAYER_AS": "<FILELAYER_AS>",
        "FILELAYER_ORG": "<FILELAYER_ORG>",
        "S3_ACCESS_KEY_ID": "<YOUR_S3_ACCESS_KEY_ID>",
        "S3_SECRET_ACCESS_KEY": "<YOUR_S3_SECRET_ACCESS_KEY>"
      }
    }
  }
}
```

### VS Code (`.vscode/mcp.json`)

```json
{
  "servers": {
    "core": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@filelayer/core"
      ],
      "env": {
        "DATABASE_URL": "<YOUR_DATABASE_URL>",
        "FILELAYER_AS": "<FILELAYER_AS>",
        "FILELAYER_ORG": "<FILELAYER_ORG>",
        "S3_ACCESS_KEY_ID": "<YOUR_S3_ACCESS_KEY_ID>",
        "S3_SECRET_ACCESS_KEY": "<YOUR_S3_SECRET_ACCESS_KEY>"
      }
    }
  }
}
```

### VS Code CLI

```sh
code --add-mcp '{"name":"core","type":"stdio","command":"npx","args":["-y","@filelayer/core"],"env":{"DATABASE_URL":"<YOUR_DATABASE_URL>","FILELAYER_AS":"<FILELAYER_AS>","FILELAYER_ORG":"<FILELAYER_ORG>","S3_ACCESS_KEY_ID":"<YOUR_S3_ACCESS_KEY_ID>","S3_SECRET_ACCESS_KEY":"<YOUR_S3_SECRET_ACCESS_KEY>"}}'
```

### Claude Desktop (`claude_desktop_config.json`)

```json
{
  "mcpServers": {
    "core": {
      "command": "npx",
      "args": [
        "-y",
        "@filelayer/core"
      ],
      "env": {
        "DATABASE_URL": "<YOUR_DATABASE_URL>",
        "FILELAYER_AS": "<FILELAYER_AS>",
        "FILELAYER_ORG": "<FILELAYER_ORG>",
        "S3_ACCESS_KEY_ID": "<YOUR_S3_ACCESS_KEY_ID>",
        "S3_SECRET_ACCESS_KEY": "<YOUR_S3_SECRET_ACCESS_KEY>"
      }
    }
  }
}
```

### Codex

```sh
codex mcp add core --env 'DATABASE_URL=<YOUR_DATABASE_URL>' --env 'FILELAYER_AS=<FILELAYER_AS>' --env 'FILELAYER_ORG=<FILELAYER_ORG>' --env 'S3_ACCESS_KEY_ID=<YOUR_S3_ACCESS_KEY_ID>' --env 'S3_SECRET_ACCESS_KEY=<YOUR_S3_SECRET_ACCESS_KEY>' -- npx -y @filelayer/core
```

### Codex config.toml (`~/.codex/config.toml`)

```toml
[mcp_servers.core]
command = "npx"
args = ["-y", "@filelayer/core"]

[mcp_servers.core.env]
DATABASE_URL = "<YOUR_DATABASE_URL>"
FILELAYER_AS = "<FILELAYER_AS>"
FILELAYER_ORG = "<FILELAYER_ORG>"
S3_ACCESS_KEY_ID = "<YOUR_S3_ACCESS_KEY_ID>"
S3_SECRET_ACCESS_KEY = "<YOUR_S3_SECRET_ACCESS_KEY>"
```

### Gemini CLI

```sh
gemini mcp add -s user -e 'DATABASE_URL=<YOUR_DATABASE_URL>' -e 'FILELAYER_AS=<FILELAYER_AS>' -e 'FILELAYER_ORG=<FILELAYER_ORG>' -e 'S3_ACCESS_KEY_ID=<YOUR_S3_ACCESS_KEY_ID>' -e 'S3_SECRET_ACCESS_KEY=<YOUR_S3_SECRET_ACCESS_KEY>' core npx -- -y @filelayer/core
```

### Gemini settings.json (`~/.gemini/settings.json`)

```json
{
  "mcpServers": {
    "core": {
      "command": "npx",
      "args": [
        "-y",
        "@filelayer/core"
      ],
      "env": {
        "DATABASE_URL": "<YOUR_DATABASE_URL>",
        "FILELAYER_AS": "<FILELAYER_AS>",
        "FILELAYER_ORG": "<FILELAYER_ORG>",
        "S3_ACCESS_KEY_ID": "<YOUR_S3_ACCESS_KEY_ID>",
        "S3_SECRET_ACCESS_KEY": "<YOUR_S3_SECRET_ACCESS_KEY>"
      }
    }
  }
}
```

## Environment variables

| Name | Required | Secret | Description |
|---|---|---|---|
| `DATABASE_URL` | yes | yes | Your own PostgreSQL, where this library keeps file ownership, grants and the audit chain. Apply node_modules/@filelayer/core/schema.sql once before starting. |
| `FILELAYER_AS` | yes | no | The ONE subject this server speaks for, in your own id space. Fixed for the life of the process: no tool reads it as an argument and no tool can change it, which is the only reason exposing these tools to an agent is safe. Write it yourself or have your provisioning write it, never derive it from a conversation. Serving several people means starting several servers. |
| `FILELAYER_ORG` | yes | no | The organisation this server is scoped to, in your own id space. |
| `S3_ACCESS_KEY_ID` | no | yes | Access key id for the bucket. |
| `S3_SECRET_ACCESS_KEY` | no | yes | Secret access key for the bucket. |
| `FILELAYER_BASE_URL` | no | no | The base of the share URLs this instance mints. Without it, share links come back without a URL. |
| `FILELAYER_DATA_DIR` | no | no | A local directory for the bytes. Needs no bucket and no IAM user. Set this OR the S3_* block: with neither, the server refuses to start rather than falling back to memory, which would work in a demo and lose the first real file. |
| `FILELAYER_MCP_AGENT_LABEL` | no | no | How this agent names itself in the audit trail, recorded on every event these tools produce. It is what lets the chain separate "the partner opened this document" from "the partner's assistant opened this document". |
| `FILELAYER_MCP_ALLOW_DESTRUCTIVE` | no | no | Set to exactly `true` to register delete_file. Off by default because deleting is not recoverable and an agent that misreads a sentence deletes the wrong thing silently. |
| `FILELAYER_MCP_EXPOSE_AUDIT` | no | no | Set to exactly `true` to register file_audit. Off by default because the trail is an organisation's whole history and a tool that returns it copies every file name, actor and denial into the model's context. Reading it is itself audited since 0.27.0, which was the previous reason; the default did not move. |
| `FILELAYER_MCP_RETURN_BYTES` | no | no | Set to exactly `true` to register read_file. Off by default because a document returned by a tool is a document copied into a model's context; file_info plus a share link is usually what was actually needed. |
| `S3_BUCKET` | no | no | The bucket. It must be private: this library decides who may be GIVEN a URL and has no say in who the object store will answer. `npx -p @filelayer/core filelayer doctor` reports whether yours serves unauthenticated reads. |
| `S3_ENDPOINT` | no | no | An S3-compatible endpoint, for example https://<account>.r2.cloudflarestorage.com. Setting it makes S3_BUCKET, S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY required. |
| `S3_REGION` | no | no | Region, or `auto` for Cloudflare R2. |

## FAQ

### How does Filelayer handle audit logs?

Every access decision, including denials, is recorded in a hash-chained audit trail written within the same transaction as the decision.
