Skip to content

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.

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.

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

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

The GraphQL API used by the control panel is also available to automate tasks.

Pass the token as an HTTP header with every request:

Authorization: Bearer <YOUR TOKEN>
Content-Type: application/json

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 id and name of all SSH keys in the account: { sshList {id, name}}
  • Get name and 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.

Using cURL:

Terminal window
curl \
-X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <YOUR TOKEN>" \
-d '{"query": "{ sshList {id, name}}" }' \
https://api.borgbase.com/graphql

Using 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 os
from borgbase_api_client.client import GraphQLClient
from 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)

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.

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/mcp

The server uses the Streamable HTTP transport and authenticates with the same Authorization: Bearer <YOUR TOKEN> header as the GraphQL API.

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.

Replace <YOUR TOKEN> with the token from Account > API.

Terminal window
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.