Connect to the MCP server with an access token
By default, MCP clients sign in to the remote MCP server with OAuth, so the assistant acts as your MotherDuck user. To connect as a service account, or from an agent that can't complete an OAuth sign-in, send a MotherDuck access token in the Authorization header instead:
Authorization: Bearer <your_motherduck_token>
The MCP server runs every tool call as the user who owns the token. A service account token gives the assistant that service account's databases, shares, and Duckling settings. A read scaling token works the same way and limits the assistant to read-only queries.
Use this when you want to:
- Give a shared agent, bot, or automation its own identity instead of a person's account.
- Run the MCP server from a headless environment, such as a CI job or a cloud agent, where no one can complete a browser sign-in.
- Enforce read-only access with a read scaling token. See Restricting to read-only access.
Prerequisites
- A MotherDuck access token. Create a personal access token, or a service account token.
- An MCP client that can send a custom header to a remote server. The tabs below cover the clients that support it.
Configure your client
Most configurations read the token from the MOTHERDUCK_TOKEN environment variable, so the token stays out of the config file. Set it in the shell that starts your client:
export MOTHERDUCK_TOKEN='<your_motherduck_token>'
Then select your client:
- Claude
- ChatGPT
- Cursor
- Claude Code
- Codex
- VS Code
- Gemini CLI
- Copilot Studio
- Others
On Claude web and Claude Desktop, add MotherDuck as a custom connector that sends the token as a request header.
Request header authentication is in beta for a limited set of Claude organizations. If you don't see Request headers in the Add custom connector dialog, use the Claude Desktop config below.
- Open the Add custom connector dialog:
- On Free, Pro, and Max plans, go to Customize → Connectors and click Add custom connector.
- On Team and Enterprise plans, an Owner goes to Organization settings → Connectors, clicks Add, and selects Custom.
- Enter
https://api.motherduck.com/mcpas the server URL. - Under Authentication, choose No sign-in.
- Under Request headers, select
authorizationas the header name and enterBearer <your_motherduck_token>as the value. Claude sends the value exactly as entered, so include theBearerprefix. - Click Add.
Claude doesn't let you edit request headers after you add the connector. To rotate the token, remove the connector and add it again.
Claude Desktop config
If your organization doesn't have request headers, connect Claude Desktop through mcp-remote, which bridges the remote server into a local server and adds the header. Go to Settings → Developer → Edit Config and add:
{
"mcpServers": {
"MotherDuck": {
"command": "npx",
"args": [
"mcp-remote",
"https://api.motherduck.com/mcp",
"--header",
"Authorization:${AUTH_HEADER}"
],
"env": {
"AUTH_HEADER": "Bearer <your_motherduck_token>"
}
}
}
}
Keep the header argument without spaces. Claude Desktop on Windows doesn't escape spaces inside args, so the space after Bearer goes in the env value. Restart Claude Desktop after you save the file. This method requires Node.js for npx.
Custom MCP servers with full MCP support are available on ChatGPT Business, Enterprise, and Edu plans, on the web. On Business, only admins and owners can add them. On Enterprise and Edu, admins can grant the Create plugins with MCPs permission to selected members.
- Go to ChatGPT Plugins, click +, and select Add custom MCP server.
- Enter
MotherDuckas the name. - Under Connection, select Server URL and enter
https://api.motherduck.com/mcp. - Under Authentication, select Access token / API key and enter your MotherDuck token.
- Review the risk warning, select I understand and want to continue, and select Create as a plugin.
Access token authentication isn't available on every plan. If Authentication only offers OAuth and No Auth, you can't connect ChatGPT with a token. To give ChatGPT users access through a service account anyway, run your own MCP server that signs users in with OAuth and calls MotherDuck with the service account token on the backend. See White-label the MotherDuck MCP server.
Add the server to ~/.cursor/mcp.json for all projects, or .cursor/mcp.json for one project:
{
"mcpServers": {
"MotherDuck": {
"url": "https://api.motherduck.com/mcp",
"headers": {
"Authorization": "Bearer ${env:MOTHERDUCK_TOKEN}"
}
}
}
}
Cursor reads MOTHERDUCK_TOKEN from the environment it starts in. If you launch Cursor from the Dock or Start menu, set the variable in your shell profile or system environment, then restart Cursor.
Run this command in your terminal:
claude mcp add --transport http --scope user MotherDuck \
https://api.motherduck.com/mcp \
--header 'Authorization: Bearer ${MOTHERDUCK_TOKEN}'
The single quotes keep your shell from expanding the variable, so Claude Code stores ${MOTHERDUCK_TOKEN} and reads the token from the environment each time it connects.
Run claude mcp get MotherDuck to check the connection. When an Authorization header is set, Claude Code doesn't fall back to OAuth, so a missing or invalid token shows as a failed connection.
Run this command in your terminal:
codex mcp add motherduck \
--url https://api.motherduck.com/mcp \
--bearer-token-env-var MOTHERDUCK_TOKEN
Or add the server to ~/.codex/config.toml directly:
[mcp_servers.motherduck]
url = "https://api.motherduck.com/mcp"
bearer_token_env_var = "MOTHERDUCK_TOKEN"
Codex reads the token from MOTHERDUCK_TOKEN and sends it as a Bearer token. The Codex CLI, IDE extension, and desktop app share this configuration.
Add this configuration to .vscode/mcp.json. VS Code prompts for the token when the server starts and stores it in its secret store:
{
"inputs": [
{
"type": "promptString",
"id": "motherduck-token",
"description": "MotherDuck access token",
"password": true
}
],
"servers": {
"motherduck": {
"type": "http",
"url": "https://api.motherduck.com/mcp",
"headers": {
"Authorization": "Bearer ${input:motherduck-token}"
}
}
}
}
Add this server to ~/.gemini/settings.json, or your project's .gemini/settings.json:
{
"mcpServers": {
"motherduck": {
"httpUrl": "https://api.motherduck.com/mcp",
"headers": {
"Authorization": "Bearer ${MOTHERDUCK_TOKEN}"
}
}
}
}
Run gemini mcp list and confirm that motherduck is connected.
Follow the Copilot Studio setup and choose API key authentication. Set Type to Header and Header name to Authorization. When you create the connection, enter the token with the Bearer prefix:
Bearer <your_motherduck_token>
All users of the agent share this token.
For clients that support remote HTTP servers with custom headers, use this configuration and check your client's documentation for how it reads environment variables:
{
"mcpServers": {
"MotherDuck": {
"url": "https://api.motherduck.com/mcp",
"type": "http",
"headers": {
"Authorization": "Bearer <your_motherduck_token>"
}
}
}
}
For clients that only support local (stdio) servers, bridge the connection with mcp-remote:
{
"mcpServers": {
"MotherDuck": {
"command": "npx",
"args": [
"mcp-remote",
"https://api.motherduck.com/mcp",
"--header",
"Authorization:${AUTH_HEADER}"
],
"env": {
"AUTH_HEADER": "Bearer <your_motherduck_token>"
}
}
}
}
Verify the connection
Start a new chat and ask "List all my databases on MotherDuck". The assistant should call a MotherDuck tool and return the databases of the token's owner. For a service account token, you see the service account's databases, not your own.
Troubleshooting
| Error | Cause and fix |
|---|---|
Authentication required. Please authenticate using OAuth or provide a Bearer token. | The client sent no token, or an empty one. Check that MOTHERDUCK_TOKEN is set in the environment that starts the client, then restart the client. |
Invalid token format: not a valid JWT | The header value isn't a MotherDuck token. Check that the variable expanded and that the value is Bearer followed by the full token. |
A message that starts with Invalid token: | MotherDuck rejected the token. Check that you copied the full token and that it hasn't been revoked. |