API & MCP
API tokens let scripts and AI assistants work with your BorgBase account without your password or second factor. The same token works with two interfaces:
- The GraphQL API, which also powers the BorgBase control panel. Use it from scripts and integrations to look up repository statistics, add SSH keys or create repositories.
- The MCP server, which lets AI assistants such as Claude Code list and set up repositories for you.
Both only manage repositories and SSH keys. Account, token and billing settings require a logged-in session in the control panel.
Creating an Access Token
Section titled “Creating an Access Token”Create a token in your BorgBase control panel under Account > API. Give it a name that identifies where it is used, choose a permission level and optionally set an expiration date for short-lived tokens. The token is shown only once, so copy it to a safe place before closing the dialog.
Permission Levels
Section titled “Permission Levels”- Read Only: Can query repositories and SSH keys, including events and usage. Cannot change anything.
- Create Only: Can list and create repositories and SSH keys, and view repository details. Cannot edit or delete existing ones. Allowed GraphQL operations:
repo,repoList,sshList,repoAdd,sshAdd. This is the recommended level for setting up new backups, including with an AI assistant. - Full Access: Can query, add, edit, delete and compact repositories and SSH keys. Use with care.
No permission level grants access to account, token or billing settings.
Keeping Tokens Safe
Section titled “Keeping Tokens Safe”- Create a separate token for each script, machine or assistant, so you can revoke it on its own.
- Choose the lowest permission level that works and set an expiration date where possible.
- Treat tokens like passwords and remove them under Account > API when they are no longer needed.
- All tokens are revoked when you reset your password.
GraphQL API
Section titled “GraphQL API”The GraphQL API used by the control panel is also available to automate tasks.
Authentication
Section titled “Authentication”Pass the token as an HTTP header with every request:
Authorization: Bearer <YOUR TOKEN>Content-Type: application/jsonLooking Up GraphQL Operations
Section titled “Looking Up GraphQL Operations”The full documentation with all available operations and variables can be accessed via the GraphiQL interface at https://api.borgbase.com/graphql.
Interfacing with GraphQL is relatively easy and can be done with any tool or library that can do JSON POST requests. To get you started, we provide the following Python client as an example. It simply wraps the Python requests package and provides sample GraphQL queries.
Some GraphQL sample queries:
- List the
idandnameof all SSH keys in the account:{ sshList {id, name}} - Get
nameand disk usage for all repositories:{ repoList {id, name, currentUsage} } - Delete an SSH key:
mutation { sshDelete(id: 1786) {ok}}
For an introduction to GraphQL, see How to GraphQL.
Examples
Section titled “Examples”Using cURL:
curl \ -X POST \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer <YOUR TOKEN>" \ -d '{"query": "{ sshList {id, name}}" }' \ https://api.borgbase.com/graphqlUsing Python requests:
import requests
TOKEN = '<YOUR TOKEN>'
headers = {"Authorization": "Bearer " + TOKEN}query = "{ sshList {id, name}}"
response = requests.post( 'https://api.borgbase.com/graphql', json={'query': query}, headers=headers,)
print(response.json())A more complex example that adds a new SSH key and backup repository:
import osfrom borgbase_api_client.client import GraphQLClientfrom borgbase_api_client.mutations import *
TOKEN = os.environ.get("TOKEN")client = GraphQLClient(TOKEN)
new_key_vars = { 'name': 'Key for VM-004', 'keyData': 'ecdsa-sha2-nistp384 AAAAE2Vj......aLqRJw+dl/E+2BJ xxx@yyy'}res = client.execute(SSH_ADD, new_key_vars)new_key_id = res['data']['sshAdd']['keyAdded']['id']
new_repo_vars = { 'name': 'VM-004-test', 'quotaEnabled': False, 'appendOnlyKeys': [new_key_id], 'region': 'us'}res = client.execute(REPO_ADD, new_repo_vars)new_repo_path = res['data']['repoAdd']['repoAdded']['repoPath']print('Added new repo with path:', new_repo_path)Integrations
Section titled “Integrations”The following libraries and tools interface with our API. Some are maintained externally:
- Ansible plugin by Andy Hawkins. Allows adding SSH keys and repositories from an Ansible playbook.
- GLPI plugin developed by TICgal to send backups to BorgBase.
MCP Server
Section titled “MCP Server”Our Model Context Protocol (MCP) server lets AI assistants list your repositories and SSH keys and set up new backups. It is available at:
https://api.borgbase.com/mcpThe server uses the Streamable HTTP transport and authenticates with the same Authorization: Bearer <YOUR TOKEN> header as the GraphQL API.
Available Tools
Section titled “Available Tools”The tools an assistant sees depend on the token’s permission level:
| Tool | Minimum permission | Description |
|---|---|---|
list_repos |
Read Only | List repositories, optionally filtered by name. |
get_repo |
Read Only | Show the details of one repository. |
list_ssh_keys |
Read Only | List SSH keys in the account. |
get_setup_guide |
Read Only | Return the instructions of a setup guide such as borg-setup. |
create_repo |
Create Only | Create a new repository. |
add_ssh_key |
Create Only | Add a public SSH key. |
edit_repo |
Full Access | Change repository settings. |
rename_ssh_key |
Full Access | Rename an SSH key. |
There are no tools to delete or compact repositories or SSH keys. A Create Only token is enough to set up new backups and can’t modify existing ones.
Connecting a Client
Section titled “Connecting a Client”Replace <YOUR TOKEN> with the token from Account > API.
claude mcp add --transport http --scope user borgbase https://api.borgbase.com/mcp --header "Authorization: Bearer <YOUR TOKEN>"Run claude mcp list to check the connection.
Codex reads the token from an environment variable, so it doesn’t end up in ~/.codex/config.toml:
codex mcp add borgbase --url https://api.borgbase.com/mcp --bearer-token-env-var BORGBASE_TOKENSet BORGBASE_TOKEN in the environment Codex runs in, for example in your shell profile:
export BORGBASE_TOKEN='<YOUR TOKEN>'Run codex mcp list to check the connection. See the Codex MCP docs for details.
opencode mcp add borgbase --global --url https://api.borgbase.com/mcp --header 'Authorization=Bearer <YOUR TOKEN>'Run opencode mcp list to check the connection. To keep the token out of the config file, use Bearer {env:BORGBASE_TOKEN} as the header value instead. See the OpenCode MCP docs for details.
agy mcp add --header "Authorization: Bearer <YOUR TOKEN>" borgbase https://api.borgbase.com/mcpFlags must come before the server name. Run agy mcp list to check the connection. The server is stored in ~/.gemini/config/mcp_config.json and is also available in the Antigravity app and IDE. See the Antigravity MCP docs for details.
Most MCP clients accept a JSON config like this one:
{ "mcpServers": { "borgbase": { "type": "http", "url": "https://api.borgbase.com/mcp", "headers": { "Authorization": "Bearer <YOUR TOKEN>" } } }}Key names and the location of the config file vary between clients. See your client’s documentation for details.