Skip to content

Raudbjorn/MDMAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TTRPG Assistant MCP Server

A comprehensive Model Context Protocol (MCP) server designed to assist with Tabletop Role-Playing Games (TTRPGs). This project provides a complete assistant ecosystem for Dungeon Masters and Game Runners, featuring AI-powered content search, campaign management, and real-time collaboration tools.

๐ŸŽฏ Project Overview

The TTRPG Assistant is a modern, production-ready application that combines:

  • MCP Server: FastMCP-based protocol server for AI assistant integration
  • Web Application: Responsive SvelteKit frontend for browser use
  • Desktop Application: Cross-platform Tauri + Rust desktop app with native features
  • Real-time Collaboration: WebSocket-based multi-user gaming sessions

โœจ Key Features

Core Functionality

  • ๐Ÿ“– PDF Processing: Extracts and indexes content from TTRPG rulebooks and source materials
  • ๐Ÿ” Hybrid Search: Combines semantic (vector) and keyword search for accurate, contextual results
  • ๐ŸŽฒ Campaign Management: Complete campaign data storage and retrieval system
  • โš”๏ธ Session Tracking: Initiative tracking, monster health, condition management
  • ๐ŸŽญ Personality System: Adapts AI responses to match different game system tones
  • ๐Ÿ‘ฅ Character Generation: Create NPCs and characters with appropriate stats and backstories
  • ๐Ÿง  Adaptive Learning: Improves PDF processing accuracy through machine learning

Technical Features

  • ๐ŸŒ Multi-Platform: Web application + cross-platform desktop app (Windows, macOS, Linux)
  • ๐Ÿค– AI Provider Integration: Support for Anthropic Claude, OpenAI GPT, Google Gemini, and Ollama
  • ๐Ÿ”’ Enterprise Security: OAuth2, JWT tokens, AES-256-GCM encryption, sandboxed execution
  • โšก Real-time Collaboration: WebSocket-based multi-user sessions with conflict resolution
  • ๐Ÿ“ฑ Responsive Design: Mobile-first UI that works on all devices
  • ๐Ÿ”„ Offline Support: Service Worker-based offline capabilities

๐Ÿ—๏ธ Architecture

Technology Stack

Backend

  • Language: Python 3.11+
  • MCP Framework: FastMCP with stdio/WebSocket communication
  • Web Framework: FastAPI for bridge services and HTTP endpoints
  • Database: ChromaDB (vector database) + SQLite (structured data)
  • Search: Hybrid vector embeddings + BM25 keyword search
  • AI Integration: Multi-provider support with automatic failover

Frontend (Web)

  • Framework: SvelteKit 2.6+ with SSR and static generation
  • Language: TypeScript with strict type checking
  • Styling: TailwindCSS with responsive design
  • State Management: Svelte 5 runes and stores
  • Real-time: WebSocket client with automatic reconnection

Desktop Application

  • Framework: Tauri 2.1 (Rust) with SvelteKit frontend
  • Size: 12-18MB (96% smaller than Electron)
  • Communication: JSON-RPC 2.0 over stdio (no network required)
  • Features: System tray, native dialogs, auto-updater, file associations
  • Performance: <1ms IPC latency vs 5-10ms for WebSocket

DevOps & Quality

  • Code Quality: Black, isort, flake8, mypy (Python) + ESLint, Prettier (TypeScript)
  • Testing: Pytest, Vitest, Playwright for comprehensive coverage
  • Build System: Unified build script with auto-detected package managers
  • Deployment: Docker, systemd service, automated packaging

๐Ÿš€ Quick Start

Unified Build System

The project includes a comprehensive build script that automatically detects and uses your preferred package managers:

# Clone and setup
git clone https://github.com/Raudbjorn/MDMAI.git
cd MDMAI

# Install all dependencies (auto-detects uv, poetry, pnpm, yarn, npm)
./build.sh setup

# Build all components
./build.sh build

# Start development servers
./build.sh dev-backend    # Python MCP server
./build.sh dev-webapp     # SvelteKit web app  
./build.sh dev-desktop    # Tauri desktop app

Manual Setup (Alternative)

If you prefer manual setup or want more control:

Python Backend

# Recommended: Use uv for fastest setup
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv && uv pip install -e ".[dev,test,docs]"

# Alternative: Use poetry
poetry install --with dev,test,docs

# Alternative: Use pip with venv
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev,test,docs]"

Web Frontend

cd frontend
npm install  # or yarn/pnpm
npm run dev

Desktop Application

cd desktop/frontend
npm install
npm run tauri:dev

๐Ÿ’ป Development Commands

The unified build script provides comprehensive development commands:

Setup & Dependencies

./build.sh setup          # Install all dependencies

Building

./build.sh build          # Build all components
./build.sh backend         # Build Python backend only
./build.sh webapp          # Build web app only  
./build.sh desktop         # Build desktop app (dev)
./build.sh desktop-release # Build desktop app (release)

Development Servers

./build.sh dev-backend     # Start MCP server (stdio mode)
./build.sh dev-webapp      # Start web app (http://localhost:5173)
./build.sh dev-desktop     # Start desktop app with hot reload

Quality Assurance

./build.sh test           # Run all tests
./build.sh lint           # Lint all code
./build.sh format         # Format all code

Utilities

./build.sh clean          # Clean all build artifacts
./build.sh help           # Show detailed help

๐Ÿงช Testing

Running Tests

# All tests
./build.sh test

# Python tests only
source .venv/bin/activate  # or poetry shell
pytest -v

# Frontend tests
cd frontend && npm test

# Type checking
./build.sh lint

Test Coverage

  • Python: Unit, integration, and performance tests with pytest
  • Frontend: Component tests with Vitest, E2E tests with Playwright
  • Desktop: Rust unit tests + TypeScript validation
  • Target: 80% overall coverage, 95% for critical paths

๐Ÿ“ฆ Project Structure

MDMAI/
โ”œโ”€โ”€ src/                          # Python MCP server source
โ”‚   โ”œโ”€โ”€ main.py                   # MCP server entry point
โ”‚   โ”œโ”€โ”€ tools/                    # MCP tool implementations
โ”‚   โ”œโ”€โ”€ search/                   # Hybrid search engine
โ”‚   โ”œโ”€โ”€ campaign/                 # Campaign management
โ”‚   โ””โ”€โ”€ bridge/                   # WebSocket bridge server
โ”œโ”€โ”€ frontend/                     # SvelteKit web application
โ”‚   โ”œโ”€โ”€ src/lib/                  # Shared components and utilities
โ”‚   โ”œโ”€โ”€ src/routes/               # SvelteKit routes
โ”‚   โ””โ”€โ”€ src/app.html              # HTML template
โ”œโ”€โ”€ desktop/                      # Desktop application
โ”‚   โ”œโ”€โ”€ frontend/                 # SvelteKit frontend (desktop)
โ”‚   โ”‚   โ”œโ”€โ”€ src-tauri/            # Rust/Tauri backend
โ”‚   โ”‚   โ””โ”€โ”€ src/                  # TypeScript/Svelte frontend
โ”‚   โ””โ”€โ”€ backend/                  # Python MCP wrapper
โ”œโ”€โ”€ tests/                        # Python tests
โ”œโ”€โ”€ docs/                         # Documentation
โ”œโ”€โ”€ deploy/                       # Deployment scripts and configs  
โ”œโ”€โ”€ scripts/                      # Build and utility scripts
โ”œโ”€โ”€ build.sh                     # Unified build script
โ”œโ”€โ”€ Makefile                     # Traditional make targets
โ””โ”€โ”€ pyproject.toml               # Python project configuration

๐ŸŒŸ Current Status & Implementation Progress

โœ… Completed (Phase 23: Desktop Application)

  • Core Architecture: Multi-platform build system with Tauri + SvelteKit
  • Desktop Framework: Full Tauri 2.1 integration with native features
  • Communication Layer: JSON-RPC 2.0 over stdio for zero-latency IPC
  • Process Management: Robust Python subprocess lifecycle management
  • Data Management: Enterprise-grade SQLite + ChromaDB with AES-256-GCM encryption
  • File Operations: Streaming file processing with integrity verification
  • Native Features: System tray, drag-drop, native dialogs, auto-updater
  • Error Handling: Comprehensive error-as-values patterns throughout
  • Type Safety: Full TypeScript + Rust type safety with zero compilation errors
  • Code Quality: Refactored codebase with 14% line reduction, eliminated dead code

๐Ÿšง In Progress

  • Core MCP Server: FastMCP implementation with tool definitions
  • PDF Processing: Advanced extraction pipeline with table preservation
  • Search Engine: Hybrid vector + keyword search with ChromaDB
  • Campaign Management: Backend data models and API endpoints

๐Ÿ“‹ Upcoming

  • Web Frontend: Complete SvelteKit application with real-time features
  • MCP Tools: 30+ specialized tools for TTRPG assistance
  • AI Integration: Multi-provider support with Ollama local models
  • Deployment: Production packaging and systemd service integration

๐ŸŽฎ MCP Tools

The server provides 30+ specialized MCP tools optimized for TTRPG gameplay:

Core Search & Content

  • search_rules - Hybrid semantic + keyword search across rulebooks
  • get_monster - Monster stat blocks with party scaling suggestions
  • add_source - Add PDF rulebooks to the knowledge base
  • list_sources - Manage indexed source materials

Campaign Management

  • create_campaign - Initialize new campaigns with metadata
  • manage_timeline - Track in-game time and events
  • track_resources - Party inventory and resource management
  • manage_quests - Quest objectives and progress tracking

Session Tools

  • roll_dice - Advanced dice rolling with modifiers and advantage
  • manage_initiative - Combat initiative with conditions and delays
  • track_damage - HP tracking with resistances and temporary effects
  • take_notes - AI-categorized session notes with entity linking

Generation Tools

  • generate_character - Complete character creation with backstories
  • generate_npc - NPCs with relationships and motivations
  • generate_location - Detailed locations with maps and encounters
  • generate_plot_hook - Context-aware story seeds and adventures

Real-time Collaboration

  • broadcast_to_players - Selective information sharing
  • sync_game_state - Automatic state synchronization
  • request_player_action - Interactive prompts and decision points

๐Ÿ”ง Configuration

Environment Setup

Copy .env.example to .env and configure:

# MCP Server Configuration
MCP_STDIO_MODE=true                    # Use stdio for MCP (recommended)
MCP_LOG_LEVEL=INFO                     # Logging level

# AI Provider Settings (choose one or more)
ANTHROPIC_API_KEY=your_key_here        # Claude integration
OPENAI_API_KEY=your_key_here           # OpenAI integration  
GOOGLE_API_KEY=your_key_here           # Gemini integration

# Database Configuration
DATABASE_PATH=./data/ttrpg.db          # SQLite database location
VECTOR_DB_PATH=./data/chroma           # ChromaDB vector storage

# Security Settings
SECRET_KEY=your_secret_key             # JWT signing key
ENCRYPTION_KEY=your_encryption_key     # Data encryption key

Package Manager Detection

The build system automatically detects and uses available package managers:

  • Python: uv (fastest) โ†’ poetry โ†’ pip
  • Node.js: pnpm โ†’ yarn โ†’ npm
  • Rust: cargo (required for desktop builds)

๐Ÿš€ Deployment

Docker Deployment

# Build Docker image
./build.sh clean && docker build -t ttrpg-assistant .

# Run with Docker Compose
docker-compose up -d

System Service (Linux)

# Install as systemd service
make deploy-install

# Configure service
make deploy-configure

# Start service
systemctl start ttrpg-assistant

Desktop Application Distribution

# Build release packages
./build.sh desktop-release

# Packages created in: desktop/frontend/src-tauri/target/release/bundle/
# - Windows: .msi installer
# - macOS: .dmg disk image  
# - Linux: .AppImage + .deb package

๐Ÿค Contributing

Development Setup

  1. Fork and clone the repository
  2. Install dependencies: ./build.sh setup
  3. Run tests: ./build.sh test
  4. Start development: ./build.sh dev-desktop or ./build.sh dev-webapp

Code Quality

  • Python: Follow PEP 8, use type hints, maintain 90%+ test coverage
  • TypeScript: Strict mode enabled, use error-as-values patterns
  • Rust: Follow Rust best practices, use cargo clippy
  • Commits: Use conventional commits with clear descriptions

Pull Request Process

  1. Create feature branch: git checkout -b feature/your-feature
  2. Run quality checks: ./build.sh lint && ./build.sh test
  3. Update documentation if needed
  4. Submit PR with clear description and test results

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • FastMCP: Modern MCP framework for Python
  • SvelteKit: Outstanding frontend framework
  • Tauri: Revolutionary desktop application framework
  • ChromaDB: Excellent vector database for embeddings
  • Claude: AI assistance in development and documentation

๐Ÿ“ž Support & Community


Happy Gaming! ๐ŸŽฒ

Built with โค๏ธ for the TTRPG community

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7