A Go MCP server for D&D campaign state management, dice rolling, and session memory. - Serves a Model Context Protocol (MCP) toolset over stdio or streamable HTTP. - Stores campaign data in per-campaign SQLite databases. - Tracks characters, plot events/hooks, world flags, roll history, checkpoints, and session summaries. - Generates session briefs and markdown recaps for fast DM context restorati
Add this skill
npx mdskills install andr1an/llmdmWell-architected D&D campaign manager with comprehensive tooling and robust persistence
1# llmdm23A Go MCP server for D&D campaign state management, dice rolling, and session memory.45## What It Does67- Serves a Model Context Protocol (MCP) toolset over `stdio` or streamable HTTP.8- Stores campaign data in per-campaign SQLite databases.9- Tracks characters, plot events/hooks, world flags, roll history, checkpoints, and session summaries.10- Generates session briefs and markdown recaps for fast DM context restoration.11- Compresses end-of-session logs using Anthropic when available, with deterministic local fallback.1213## Tech Stack1415- Go `1.25.6`16- MCP framework: `github.com/mark3labs/mcp-go`17- Database: SQLite (`modernc.org/sqlite`)18- Config loading: `.env` via `github.com/joho/godotenv`1920## Repository Layout2122```text23cmd/server/main.go # MCP server bootstrap, transport, tool registration/handlers24config/config.go # Environment config parsing and defaults25internal/db/ # SQLite open/migrations and embedded schema26internal/dice/ # Dice parser/roller and log models27internal/memory/ # Data access layer for campaign entities28internal/session/ # Brief rendering, recap rendering, event compression29internal/dm/ # DM system prompt generation30internal/types/ # Shared domain structs31```3233## Requirements3435- Go `>= 1.25`36- Optional: Anthropic API key for AI session compression3738## Configuration3940Environment variables (see `.env.example`):4142| Variable | Default | Description |43|---|---|---|44| `ANTHROPIC_API_KEY` | _(empty)_ | Optional key for Anthropic summarization in `end_session` |45| `DB_PATH` | `./data/campaigns` | Base directory for campaign database files |46| `LOG_LEVEL` | `info` | `debug`, `info`, `warn`, `error` |47| `MCP_TRANSPORT` | `stdio` | `stdio`, `http`, or `streamable-http` |48| `HTTP_ADDR` | `127.0.0.1:8080` | Bind address for HTTP mode (loopback by default) |49| `MCP_HTTP_ENDPOINT` | `/mcp` | MCP endpoint path in HTTP mode |50| `READ_TIMEOUT` | `15s` | HTTP read timeout (also used for read header timeout) |51| `WRITE_TIMEOUT` | `60s` | HTTP write timeout |52| `IDLE_TIMEOUT` | `60s` | HTTP idle timeout |5354### Example `.env`5556```bash57cp .env.example .env58```5960## Build, Test, Run6162```bash63make build64make test65make run66```6768Additional targets:6970- `make lint` (requires `golangci-lint`)71- `make build-linux` (cross-compile to `bin/dnd-mcp-linux`)72- `make clean`7374### Direct Run7576```bash77go run ./cmd/server serve78```7980Binary usage:8182```bash83./bin/dnd-mcp serve84```8586## Transport Modes8788### 1) `stdio` (default)8990Use when launching the server as a local MCP subprocess from an MCP client.9192```bash93MCP_TRANSPORT=stdio ./bin/dnd-mcp serve94```9596### 2) Streamable HTTP9798```bash99MCP_TRANSPORT=http HTTP_ADDR=127.0.0.1:8080 MCP_HTTP_ENDPOINT=/mcp ./bin/dnd-mcp serve100```101102Security note: HTTP transport does not provide built-in authentication. Keep `HTTP_ADDR` bound to loopback (for example, `127.0.0.1:8080`) unless you place it behind a trusted authn/authz proxy.103104Health endpoint:105106```bash107curl http://127.0.0.1:8080/health108```109110MCP endpoint:111112- `http://127.0.0.1:8080/mcp`113114## MCP Client Examples115116This repo includes `.mcp.json` for a local HTTP MCP server:117118```json119{120 "mcpServers": {121 "dnd-campaign": {122 "type": "http",123 "url": "http://127.0.0.1:8080/mcp"124 }125 }126}127```128129### Claude (`stdio` transport)130131Use this when configuring Claude to launch the MCP server as a local subprocess:132133```json134{135 "mcpServers": {136 "dnd-campaign": {137 "command": "/absolute/path/to/bin/dnd-mcp",138 "args": ["serve"],139 "env": {140 "MCP_TRANSPORT": "stdio"141 }142 }143 }144}145```146147## Available MCP Tools148149### Dice150151- `roll`152- `roll_contested`153- `roll_saving_throw`154- `get_roll_history`155156### Campaign Memory157158- `create_campaign`159- `save_character`160- `update_character`161- `get_character`162- `list_characters`163- `save_plot_event`164- `list_open_hooks`165- `resolve_hook`166- `set_world_flag`167- `get_world_flags`168169### Session Management170171- `start_session`172- `end_session`173- `checkpoint`174- `get_session_brief`175- `list_sessions`176- `get_npc_relationships`177- `export_session_recap`178179## Persistence Model180181Each campaign is persisted in its own SQLite file:182183- `<DB_PATH>/<campaign_id>.db`184185Core tables (auto-migrated on access):186187- `campaigns`188- `characters`189- `plot_events`190- `plot_hooks`191- `world_flags`192- `roll_log`193- `sessions`194- `checkpoints`195196Schema source: `internal/db/schema.sql`.197198## End-Session Compression Behavior199200`end_session` always returns a summary:201202- If `ANTHROPIC_API_KEY` is set and the API call succeeds, summary is model-generated.203- If key is missing or API fails, server falls back to deterministic truncation + `OPEN HOOKS` scaffold.204205This keeps workflows resilient in offline or degraded network/API conditions.206207## Development Notes208209- SQLite pragmas are enabled on open: foreign keys, WAL, and busy timeout.210- Logging is structured JSON via `log/slog`.211- Migrations are embedded and run automatically when opening campaign DBs.212- Test suite uses race detector by default via `make test`.213214## Troubleshooting215216- `invalid MCP_TRANSPORT ...`: set to one of `stdio`, `http`, `streamable-http`.217- `Failed to load config`: verify env values and `.env` formatting.218- Empty/short summary in `end_session`: confirm `raw_events` is non-empty.219- HTTP connection issues: verify `HTTP_ADDR`, `MCP_HTTP_ENDPOINT`, and that client URL matches exactly.220
Full transparency — inspect the skill content before installing.