How I Built an AI Dungeon Master (And Why Writers Should Care)

What happens when you teach Claude to roll dice and remember your NPCs?
You know what I have been doing last couple of months? I've been playing Dungeons & Dragons with an AI. Not just any AI, but one I build to be a proper dungeon master. One that can roll dice, look up rules in actual rulebooks, remember every NPC it has ever created, and track my campaign journals across multiple adventures. As someone who went from never playing DnD to playing it daily in couple of weeks, I couldn't be happier.
What surprised me the most was that it wasn't even that difficult. I built the required tools in couple of days during my lunch breaks.
If you are a writer who is not into TTRPGs and might think this is just about gaming, let me stop you right there. What I've built, what I'm about to show you, is really a creative writing laboratory. It's a tool for generating storylines, testing narrative branches, and exploring characters in ways that traditional writing can't match. It just happens to use dice and dragons as the medium. In theory, you could really fine-tune it to work with any genre.
The Problem: Solo Play Is Difficult (And Repetitive)
I love tabletop RPGs. The captivating storytelling, the unexpected twists, the way a single dice roll can change everything. But here's the thing: I'm not that social as a person and I don't have a group available. Work, kids, and life causes a lot of schedule conflicts. Sometimes you just want to explore a story idea right now, not next Thursday at 7 PM.
Solo RPG play has existed for decades, with systems designed specifically for it. You use oracle tables, random generators, and your imagination to simulate a game master. Roll some dice, consult a table, interpret the results through your narrative lens. It works, but it's clunky. You're constantly flipping between rulebooks, oracle tables, and your journal. The flow breaks constantly, and ultimately nothing that unexpected happens because you are the one telling the story and the one playing it.
What if there was a better way? What if an AI could handle all the mechanical parts while you focused on the story?
Enter Claude and MCP
I've been using Claude for writing help for couple of months now. Brainstorming plot ideas, developing characters, getting unstuck when my novel hits a wall. Claude is good at creative work. It understands narrative structure, character motivation, thematic resonance. It can riff with you, challenge your assumptions, suggest alternatives.
But Claude has limitations. It can't remember things that well between conversations. It can't roll dice or look up rules accurately. It can't save your characters or track your campaign across sessions. It's a brilliant improviser with no memory and no tools.
That changed when Anthropic introduced the Model Context Protocol (MCP). MCP lets you give Claude tools, actual programmatic functions it can call. Want Claude to search the web? There's an MCP tool for that. Want it to access your Google Drive? MCP tool. Want it to roll a d20 and look up the fireball spell in the Player's Handbook? Yep, you can make that one too.
And that's where this blog post comes in.
Building ChatDM: A Toolbox for AI-Powered TTRPGs
I'm a software developer by day, fantasy writer by night. I know Java, I know Spring Boot, and I really know how to overthink a hobby project. So I built ChatDM, an MCP server that gives Claude everything it needs to run tabletop RPG sessions.
The architecture is straightforward: Spring Boot application, exposed as an MCP server, providing 90+ tools that Claude can call during our conversations. When Claude needs to roll for initiative, it's actually calling a tool. When I ask it to search the D&D rulebook for grappling rules, it's running a full-text search against indexed PDFs. When it invents an NPC, it's saving a structured file to disk.
What ChatDM Can Do
The server breaks down into four main categories:
Oracle Tools handle randomness and inspiration. Claude can roll any dice (d4 through d100), draw tarot or playing cards, answer yes/no questions with probability weighting, and generate random narrative elements. Oracle tools are for generating an NPC with personality, or when you need to know what the weather is like. These tools are basically for running the games basic mechanics.
It it important to understand that these aren't just for gameplay. As a writer, I use these constantly. When I'm stuck on what a side character should be like, I can generate a random personality and occupation, then build from there. Another example is when I need a scene setting. I can just generate location type, weather, atmosphere, and time of day all at once. The randomness breaks you out of your patterns.
However, you should also realise that these are only tools for you as a writer! You should not just copy paste AI generated text into you book and call it a day.
I also implemented a PDF Rulebook Search which is where things get to the next level. I indexed the entire Player's Handbook, Dungeon Master's Guide, Monster Manual, and several supplements using SQLite's FTS5 full-text search engine. When Claude needs to look up a rule, it searches across thousands of pages in milliseconds and returns relevant excerpts with page numbers.
This means Claude can actually cite the rulebook when making rulings. "According to page 240 of the Player's Handbook, fireball requires a Dexterity saving throw." It's not hallucinating rules anymore. It's reading them.
I've done this for four game systems: D&D 5e (2024 edition), The One Ring 2nd Edition, Brambletrek, and My Little Pony RPG. Yes, really. That's 23 indexed rulebooks and adventures, all searchable in real-time. As a beginner this has been super helpful. I don't know the rules and I don't want to Google everytime I don't understand something. Now I can just ask Claude and it explains the rules to me.
Next important part of ChagDM is the Journal System which solves the memory problem. With it Claude can save characters with full stat blocks, create adventure logs with timestamped events, track NPCs with personality details and story roles, and catalog locations you've discovered. Everything is organized by campaign, so your different stories don't bleed into each other.
This is huge for long-form storytelling. Imagine writing a novel where you could ask your AI assistant, "What did Captain Thorne say about the rebellion in chapter three?" and it could pull up exact notes. That's what this does for RPG campaigns.
The last important bit is the Game-Specific Prompts which are detailed instruction sets for different game systems. Want to create a D&D character? There's a structured prompt that walks Claude through species selection, class features, ability scores, and equipment. Want to run combat? There's a combat prompt with initiative tracking, action economy, and tactical guidance.
I've written 34 of these prompts across the four game systems, covering everything from character creation to spell mechanics to how to run social encounters. They're essentially mini-tutorials that Claude can reference on-demand. If you want to really go meta, you can ask Claude to browser through guidebooks and suggest missing prompts.
How It Actually Works: A Session Walkthrough
So what is a typical session like, you might ask? Well, let me show you exactly that.
Me: "I want to start a new D&D adventure. My character is Leyri, a Wood Elf Druid, level 2. I'm exploring the town of Pinehaven."
Claude immediately springs into action. It loads the D&D gameplay prompts, asks me to confirm some character details, then starts building the scene. But here's where it gets interesting.
Claude: "You arrive in Pinehaven as the sun dips below the treeline. Let me set the scene..." [calls scene_setup tool] "The town square has a tense atmosphere, late afternoon light, with storm clouds gathering. As you enter, you notice a crowd gathering near the town well. Do you approach?"
The atmosphere wasn't planned. Claude generated it randomly, then incorporated it into the narrative. That's emergent storytelling.
Me: "I approach the crowd and ask what's happening."
Claude: [calls generate_npc tool] "An older woman with calloused hands, a weaver by trade, turns to you nervously. 'It's the Peterson farm,' she says. 'Livestock killed, strange tracks everywhere. Third farm this month.' She introduces herself as Mara."
Claude just created an NPC on the fly, gave her a profession, a personality trait, and wove her into the plot. Then, without me asking, it saved her to the NPC catalog under my campaign name. The next time Mara appears, Claude can load her details and portray her consistently.
Me: "I offer to investigate. What do I know about the tracks?"
Claude: [calls roll_dice d20] "Rolling Survival check... You rolled a 14, plus your Wisdom modifier of +3, that's 17 total. You examine the tracks and recognize them as dire wolf prints, but there's something unnatural about them. They're too deliberate, almost like they were directed by intelligence."
Real dice roll. Real mechanics. And because Claude has access to the Monster Manual, it knows what dire wolves are capable of.
The session continues like this. Combat encounters with proper initiative and action economy. Investigation scenes with skill checks. Moral choices with consequences. And every major event gets logged to my adventure journal automatically.
Why Writers Should Care About This
You might be thinking, "That's cool for gaming, but I'm a writer, not a gamer." Fair. But consider what this system actually does:
It's a plot generator that responds to choices. Traditional outlining is static. You plan chapter five, but then chapter three goes in an unexpected direction and suddenly chapter five doesn't work. With this system, the story responds to what happens. Every choice creates new branches, new complications, new NPCs with their own agendas.
I've used this to workshop entire plot threads for my novel. I'll set up a scenario similar to what I'm writing, play through it with Claude, and see what emerges. Sometimes the random complications are better than what I planned. Sometimes an NPC I generated on the fly becomes a crucial character.
It forces you to think in scenes, not summaries. When you're playing through a story, you can't just write "They fought the bandits and won." You have to describe the environment, the tactics, the moment-to-moment action. You have to make it real. That's excellent practice for descriptive writing.
It creates genuine surprise. You know that moment in writing where you surprise yourself? Where a character does something unexpected and suddenly the story goes somewhere new? This system creates those moments constantly. The dice add unpredictability. The random generators inject elements you'd never choose consciously. The AI interprets results in ways you didn't expect.
It maintains continuity automatically. How many times have you forgotten a minor character's name? Or contradicted something you established three chapters ago? The journal system prevents that. Every NPC, every location, every event is recorded and retrievable.
The thing that is one of the most interesting posibilities with these kinds of systems is that when you have written you manuscript (or parts of it), you can give it to the MCP server as a "guidebook" and actually step into the world you have created. You can walk around the town you just described and talk to you characters. And that open some incredible doors to you as a writer.
The Technical Side (For the Curious)
If you're technical enough to run a Spring Boot application, you can use this. The server is a standard Java application, built with Maven, using Spring AI's MCP support. I'm running Java 25, Spring Boot 3.5.6, and a handful of dependencies. My not so polished version can be found here.
The PDF indexing happens at compile time. A Maven plugin extracts text from all the rulebooks and builds an SQLite database with FTS5 indexes. That database gets packaged into the application, so searches are fast (around 100ms for most queries). The journal system, on the other hand, is deliberately simple: plain text files in a .chatdm directory in your home folder. Characters, NPCs, locations, all stored as readable markdown files. You can edit them by hand if you want. No over complication with databases, just files.
When I open Claude, it connects to the MCP server and discovers all 90+ tools automatically. From its perspective, it just gained a huge toolkit. From your perspective, you just start chatting and Claude handles the tool calls seemlessly.
The code behind the tools is quite simple because it's the prompts that are the secret sauce of this pasta dish. I think I actually spent most of the development time writing them, pulling from actual rulebooks, playtesting with Claude, refining the instructions. They teach Claude not just the rules, but the feel of each game system. How to describe combat cinematically in D&D versus tactically in The One Ring. How to handle the wholesome tone of My Little Pony versus the dark fantasy of traditional D&D.
What I've Learned
Randomness is underrated in creative work. As writers, we tend to trust our conscious minds too much. We pick the obvious character trait, the expected plot twist, the safe scene setting. Random generators force you out of those ruts. They suggest combinations you'd never consciously choose, and sometimes those combinations are brilliant.
AI is best as a collaborative partner, not a replacement. Claude doesn't write my stories. It responds to my choices, offers options, asks clarifying questions, and handles the mechanical aspects. But the creative decisions, the emotional core, the thematic resonance? That's still me. The AI amplifies my creativity; it doesn't replace it. I am the writer, it is my companion I can brainstorm with.
Systems thinking improves storytelling. Building this tool forced me to think systematically about narrative structure. What makes a good NPC? What elements do you need for a complete scene? How do you track causality across a long story? These questions make you a better writer, whether you're using AI or not.
The future of writing tools is interactive. We're moving beyond passive tools like grammar checkers and thesauruses. The next generation of writing tools will be conversational. They'll ask questions, offer suggestions, and help you think through problems. ChatDM is just the beginning.
The Bottom Line
I started building ChatDM because I wanted to play D&D on my lunch breaks. What I ended up with is a creative writing laboratory that happens to use dice and dungeons as its interface.
The dice rolls don't matter because they're "realistic." They matter because they inject controlled chaos into the creative process. The NPC generator doesn't matter because it saves time. It matters because it suggests characters I wouldn't have thought of. The journal system doesn't matter because it's convenient. It matters because it lets the AI maintain continuity across long, complex narratives.
This is what writing tools will look like within five years. Interactive, conversational, integrated with AI that actually understands story structure. The technical barriers are dropping rapidly. Soon, you won't need to be a Java developer to build something like this.
But for now, I'll keep playing D&D with Claude during my lunch breaks. And when I sit down to work on my novel, I'll have a dozen new plot ideas, three interesting NPCs, and a much clearer sense of how that tricky action sequence should flow.
Sometimes the best way to write a story is to play it first.
What creative tools have changed your writing process? I'd love to hear about the systems and approaches that work for you on Instagram.