# Connect an AI to Dunjn

> Plug Claude, ChatGPT, Cursor or any MCP client into your campaigns: endpoint, OAuth, API keys, permissions, first conversation, security.

Source: https://dunjn.io/en/docs/connect-an-ai/

Dunjn exposes each campaign to the AI of your choice through an MCP server (Model Context Protocol). The AI reads your wiki, sessions and notes, creates or edits entities, prepares encounters. It does the writing, on its own subscription with its provider: Dunjn bills nothing for the AI.

## Essentials

- Endpoint: `https://app.dunjn.io/api/mcp/v1` (MCP Streamable HTTP, JSON-RPC requests over POST).
- Authentication: OAuth 2.1 with PKCE (recommended), or a personal API key in an `Authorization: Bearer` header.
- Permissions: `dunjn:read` (read), `dunjn:write` (write), `dunjn:rag` (semantic search, optional and off by default).
- Discovery: `https://app.dunjn.io/.well-known/oauth-authorization-server` and `https://app.dunjn.io/.well-known/oauth-protected-resource`.
- Tools: all prefixed with `dunjn_`. Exact list in [MCP tools and prompts](/en/docs/mcp-tools-and-prompts/).

## Method 1: OAuth connection (recommended)

For clients that support remote MCP servers: Claude (claude.ai, Claude Desktop, Claude Code), ChatGPT, Cursor and others.

1. In your client, add a remote MCP connector or server and paste the endpoint URL.
2. The client sends you to a Dunjn consent page. Sign in and authorize access.
3. The application appears under "Connected applications" in your Dunjn profile. You can revoke access at any time from that page.

No key to copy, no client ID to request: dynamic client registration is supported.

Example with Claude Code:

```sh
claude mcp add --transport http dunjn https://app.dunjn.io/api/mcp/v1
```

Then type `/mcp` in Claude Code to start the authentication.

## Method 2: personal API key

For clients that do not support OAuth but accept an HTTP header, and for your own scripts.

1. In Dunjn: Profile, then API keys, then Generate a key. It starts with `dunjn_pak_`. You can make it read-only and restrict it to specific campaigns.
2. Send it as an `Authorization: Bearer dunjn_pak_…` header to the endpoint.

Example configuration for Cursor, in `.cursor/mcp.json`:

```json
{
  "mcpServers": {
    "dunjn": {
      "url": "https://app.dunjn.io/api/mcp/v1",
      "headers": { "Authorization": "Bearer dunjn_pak_xxx" }
    }
  }
}
```

### Clients that only launch local servers

For a client that can only start local MCP servers (a configuration file that expects a command, not a URL), the [`dunjn-mcp`](https://www.npmjs.com/package/dunjn-mcp) bridge relays standard input to the HTTPS endpoint with your key. Node.js 18 or later is required.

```json
{
  "mcpServers": {
    "dunjn": {
      "command": "npx",
      "args": ["-y", "dunjn-mcp@latest"],
      "env": { "DUNJN_API_TOKEN": "dunjn_pak_xxx" }
    }
  }
}
```

Source code: [github.com/Liendaar/dunjn-mcp](https://github.com/Liendaar/dunjn-mcp).

An API key is a password: do not share it, and revoke it from the API keys page if it leaks.

## First conversation

Once connected, ask your AI to list your campaigns (tool `dunjn_list_campaigns`), then to pick the one to work on (`dunjn_set_active_campaign`). Then talk to it like a co-GM: "Create the tavern keeper in Padhrone and link him to the inn." It calls Dunjn's tools, and the result shows up in your wiki.

Six ready-made prompts, named after the Council of Mages, give the assistant a role:

- `dunjn_salmanazar`: general-purpose GM assistant that drives Dunjn.
- `dunjn_melchizedek`: entity creation (NPCs, monsters, places).
- `dunjn_balthazar`: writing session notes and lore.
- `dunjn_nabuchodonosor`: designing complete encounters.
- `dunjn_jeroboam`: full session preparation.
- `dunjn_rehoboam`: formatting existing notes.

## What the AI can do

- Read: campaigns, entities, sessions, world notes, roll tables, images.
- Write: create and edit entities, relations, sessions, encounters, notes (section by section), tags, roll tables; upload images.
- Nothing is generated on Dunjn's side: your client's model does the writing. Dunjn consumes no AI credits and bills none.

## Security and privacy

- Every access is tied to your account: a key or a connected application sees only your campaigns, and only the ones you open to it.
- Revoke at any time from your profile (API keys and connected applications).
- The AI reads your campaigns with your account at its provider. What happens to that data is governed by the provider's terms.
- Dunjn trains no model on your content.
