Skip to main content
Version: v7

Connect a chat app with MCP

Chibisafe exposes a remote MCP server at https://files.example.com/api/mcp. It supports Streamable HTTP and OAuth authorization code flow with S256 PKCE. Each user signs in to Chibisafe, reviews the requested scopes, and selects the access to grant. Write scopes are unchecked by default.

Deploy the server​

  1. Set PUBLIC_ORIGIN to the public HTTPS origin, such as https://files.example.com, in the Chibisafe deployment.
  2. Start the Chibisafe container. It applies the database migrations before starting the API, including the OAuth tables.
  3. Forward the public HTTPS origin to the application on port 24424. The frontend handles the MCP, OAuth, and discovery paths.
  4. Check https://files.example.com/.well-known/oauth-protected-resource/api/mcp and https://files.example.com/.well-known/oauth-authorization-server. Both return JSON. An unauthenticated request to /api/mcp returns HTTP 401 with a WWW-Authenticate discovery header.

HTTP loopback origins are supported in development. Hosted chat apps need a reachable HTTPS deployment.

Connect a client​

  1. In an MCP-capable chat app, add https://files.example.com/api/mcp as a remote Streamable HTTP server and select OAuth authentication.
  2. Use dynamic client registration with token_endpoint_auth_method: "none". Clients that need a preconfigured client ID can register one at /api/oauth/register using the example below. Client secrets, password grants, implicit grants, and client metadata document registration are not supported.
  3. Request the scopes needed for the task. In the same browser, use the API reference at /api/docs to send your credentials to POST /api/v1/auth/login before opening the authorization request.
  4. Review the client name and callback origin. The client name is supplied by its developer. Select any required write scopes, then choose Allow selected access.
  5. Refresh the client's tool list after deploying changes. Authenticated clients can discover the complete catalogue and each tool's required scopes. Calling a tool still requires explicit authorization for those scopes and the account's existing permissions.
curl https://files.example.com/api/oauth/register \
-H 'Content-Type: application/json' \
-d '{"client_name":"My chat app","redirect_uris":["https://chat.example.com/oauth/callback"],"token_endpoint_auth_method":"none"}'

Registration returns a public client_id. Use the exact registered redirect URI, code_challenge_method=S256, and resource=https://files.example.com/api/mcp in authorization requests. Include that same resource in code exchanges and refresh requests. Token and revocation endpoints accept URL-encoded forms. The server checks exact redirect URIs and permits HTTPS callbacks or HTTP loopback callbacks.

ChatGPT's OAuth integration requirements are described in the official OpenAI documentation. Client UI availability and organization policies vary. This implementation is tested with the official TypeScript MCP client; a hosted ChatGPT connection still needs verification against your deployment. Other chat apps must support the same OAuth discovery, registration, PKCE, and Streamable HTTP flow.

Browser MCP requests allow the public Files origin, https://chatgpt.com, and https://claude.ai. Set MCP_ALLOWED_ORIGINS to a comma-separated list of additional browser origins when needed. This adds origins for MCP bearer requests without allowing those sites to use Files session cookies. Clients that make server requests without an Origin header do not need this setting.

Choose scopes​

The server advertises its current tool catalogue to authenticated clients. Read, write, and upload scopes are independent. Request each scope needed for the task.

  • files:read and files:write: list, search, and inspect files; update sources, regenerate thumbnails, and delete files.
  • files:upload: upload files from temporary HTTPS download URLs. Requires the account's upload permission and available storage quota. Existing connections must authorize this scope before uploading.
  • folders:read and folders:write: inspect folders and their files, collaborators, and existing share links; create, edit, and delete folders, add or remove files, and manage sharing and collaborators.
  • tags:read and tags:write: inspect tags and their files; create, edit, and delete tags, and add or remove tags on your files.
  • users:read and users:write: inspect users and roles; ban or unban users and replace their role assignments.
  • roles:read and roles:write: inspect, create, edit, and delete roles.
  • invites:read and invites:write: inspect invitations; create invitations, receive their one-time codes, edit expiry, and revoke invitations.
  • moderation:read and moderation:write: inspect IP bans; manage bans, quarantine files, and restore files.
  • audit:read: inspect the audit log.

Scopes restrict operations in addition to existing account permissions. They never grant a role or bypass ownership, collaboration, quarantine, or administration checks. File scopes can include administration views when the account already has the corresponding management permissions. Reading folder shares exposes existing public links; creating invitations returns a code that can create an account.

The consent page displays the scopes the client requests. A read-only consent request therefore shows only read permissions. The tool catalogue remains discoverable after that approval, including upload and write tools, so clients can request additional scopes when needed. Insufficient-scope calls return an OAuth challenge with the required scopes and an error description before executing the operation. Refresh the custom MCP connection's metadata in ChatGPT after deploying tool changes, then start a new conversation and request the action. The host controls when it offers additional consent; Files never silently expands a grant.

Most tools accept named params, query, and body objects using the REST schemas. For example:

{ "name": "folders_create", "arguments": { "body": { "name": "Receipts" } } }

Search uses the read-only files_search tool even though the underlying REST endpoint uses POST. Query booleans such as quarantine use the strings "true" and "false", matching the REST contract.

Binary download payloads and ZIP exports, settings, password or account changes, user creation, content purges, API keys, passkeys, sessions, and impersonation are excluded. URL fetching is limited to the upload flow below; there is no arbitrary HTTP request tool. Adding an operation requires an explicit catalogue entry and scope review.

Display images in chat​

File details, listings, search results, folder/tag file listings, and folder/tag covers include absolute url and imageUrl fields built from PUBLIC_ORIGIN. url points to the original file; imageUrl contains the same URL for images and is null for other file types. Both fields are null for quarantined files.

The client can use imageUrl in an inline image preview. These are the same public media URLs used by Files, so fetching the bytes does not require OAuth headers. The chat app controls whether it renders remote images; returning a URL cannot force every client to display it. The public deployment must serve media at the configured origin.

Upload tool instructions require previews to use each result's exact imageUrl and file links to use its exact url. If a preview cannot be rendered, the client should show the returned file link. It must not substitute searched or generated images. Correct instructions and URLs do not guarantee that every chat app follows them; a correct file link with an unrelated preview indicates a client presentation issue.

Upload from chat​

files_upload accepts a top-level file reference, rather than the usual body envelope:

{
"name": "files_upload",
"arguments": {
"file": {
"download_url": "https://downloads.example.com/temporary-file-url",
"file_id": "host-file-reference",
"file_name": "photo.png",
"mime_type": "image/png"
}
}
}

The tool declares _meta["openai/fileParams"]: ["file"] and the OpenAI file-input schema. Compatible ChatGPT clients can supply an attachment reference with a temporary download URL. Other clients can construct the same object with their own file_id. Attachment support depends on the host client; local paths, sandbox paths, and base64 payloads are not accepted. Only download_url and file_id are required. Use the optional top-level filename to override a missing or unsuitable name; otherwise the server uses file_name or the URL's final path component. MIME type is detected from the bytes rather than trusted from the reference.

The server streams the download to temporary disk storage and calls the existing upload finalization pipeline. MCP requests contain the reference, so they do not need chunk management. The hard cap is 90 MiB (94,371,840 bytes), or the instance's uploadMaxSize if lower. The existing default instance upload limit is 1 GiB; this MCP cap does not change that setting. Downloads have a two-minute deadline. Configure a compatible tool timeout in clients when large transfers need longer than their default timeout.

Downloads must use HTTPS on port 443 and be accessible without extra cookies or Authorization headers. Embedded URL credentials, nonpublic DNS/IP destinations, redirects to internal addresses, and encoded responses are rejected. Each redirect is validated, and connections use the validated DNS address. Declared length and actual streamed bytes are checked. Temporary bytes are removed on success or failure. OAuth authorization is checked again after the download, before finalization.

The normal upload permission, quota, file-extension policy, deduplication, cache invalidation, and background processing apply. Signed download URLs are not automatically saved as file sources; supply optional source only for intended provenance. Successful results contain the stored UUID, identifier, filename, detected MIME type, size, url, and imageUrl. Retrying an identical file for the same account returns the existing file. Use folder/tag membership tools afterward to organize it; those operations require their separate write scopes.

Complete library tasks in chat​

After connecting with the required read and write scopes, the client can combine tools to complete these tasks:

  • Summarize the library: call statistics_get with {} or {"query":{"topLimit":5}}. It returns server-calculated totals, type breakdowns, UTC upload activity, file size extremes, duplicates, media orientation, source coverage, processing outcomes, and owned folder/tag usage. It requires files:read, folders:read, and tags:read. See Library statistics for fields and counting rules. The statistics cover the current personal inventory, including quarantine, without fetching every file record.
  • Share a folder: find it with folders_list, then call folders_create_share with its UUID and an options body. Use {} or {"expiresAt":null} for no expiry, or supply an ISO timestamp. The response includes a complete url at the configured public origin, which the client can return directly in chat. Share listing and expiry updates also return complete URLs.
  • Tag every image in a folder: use files_search with folderUuid and type: "image". Read every result page before changing memberships. Create or find the tag, then call tags_update_files with targetType: "tag", operation: "add", tag UUIDs in targetUuids, and the selected file UUIDs in fileUuids.
  • Place the latest ten uploads in a folder: call files_list with scope: "personal", sort: "newest", and limit: 10. Send those UUIDs to folders_update_files with targetType: "folder" and operation: "add".
  • Place a date range in a folder: use files_search with dateFrom and dateTo, collect all matching UUIDs, then add them using folders_update_files. Both dates are inclusive UTC calendar dates.
  • Place tagged images in a folder: search with tagUuids and type: "image", then add the returned UUIDs to the destination folder. Include folderUuid to restrict the selection to a source folder.
  • Remove tagged images from a folder: search with folderUuid, tagUuids, and type: "image", collect all pages, then call folders_update_files with operation: "remove".
  • Delete a folder: call folders_delete. This removes its memberships and public shares while preserving the files themselves.

Membership tools accept at most 200 file UUIDs and 200 target UUIDs per call. The client must split larger selections into batches. Collect all selection pages before mutations, especially when removing files from the same folder or tag used to select them, so the changing selection does not skip later results.

Files can belong to multiple folders. Adding a folder membership preserves existing memberships; removing one preserves the file in the library. To move files between folders, add them to the destination first, then remove only the successfully added files from the source.

Each membership result names successful file UUIDs and per-file failures. Partial or failed batches set MCP isError: true and include those details in both text and structured output. The client must report partial completion accurately. ALREADY_ATTACHED and NOT_ATTACHED indicate memberships that were already in the requested state. Existing ownership and collaboration checks still apply: for example, tagging another user's image in a shared folder returns FILE_FORBIDDEN.

folders_update_files requires folders:write; tags_update_files requires tags:write. The server also checks the request's targetType when an OAuth client calls the underlying membership endpoint directly, so one scope cannot be used to change the other type of collection. Refresh the chat app's tool list after updating the server, and reconnect if additional scopes are required.

Revoke access​

Open /api/oauth/connections and choose Revoke access for the connection. Revocation immediately blocks existing access tokens and refreshes. A client can also revoke its token at /api/oauth/revoke with its client_id.

Connections belong to the login session used during consent. Signing out of that session, revoking it, deleting the account, or banning the account stops access. A connection expires no later than that session's expiry at approval, even if the browser later renews the session. Normal session-token rotation preserves the session ID. Reconnect to extend authorization.

Access tokens last at most 15 minutes. Authorization codes and consent forms expire after five minutes. Refresh rotates the refresh token and can narrow its scopes. Reusing a consumed code with valid bindings or a consumed refresh token revokes the entire connection. Clients must serialize refreshes and reconnect after losing a refresh response. Raw codes, consent nonces, and tokens are never stored in the database. Hourly cleanup removes expired grants and credentials while retaining spent refresh tokens until their connection expires.

See API keys for direct REST integrations and sharing before giving a client access to create public links.