Get the FREE Ultimate OpenClaw Setup Guide →

mcp-mongodb-novel

A Model Context Protocol (MCP) server that provides an interface between LLMs and MongoDB databases, optimized for small context windows (3k tokens). Specially for novel.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio sfbb-mcp-mongodb-novel-server docker run -i sfbb/mcp-mongodb-novel-server \
  --env PORT="3000" \
  --env MONGODB_URI="mongodb://localhost:27017" \
  --env DATABASE_NAME="your_database"

How to use

This MCP server exposes a high-performance interface between language models and a MongoDB-backed knowledge store focused on novels, chapters, characters, and a Q&A knowledge base. It operates as a dual-server system: an MCP SSE (Server-Sent Events) endpoint for efficient, low-overhead communication with LLMs, and a RESTful CRUD API to manage the MongoDB collections. The MCP interface supports JSON-RPC 2.0 style commands (via the /message endpoint) to query and update domain data, while the SSE channel streams contextually relevant information to the client. Start by launching the server, then connect your LLM client to the SSE endpoint for conversational retrieval or to the /message endpoint for structured, RPC-style requests. A typical workflow involves querying characters, novels, or chapters, or updating chapter summaries, and optionally populating the database via the included scrapers.

How to install

Prerequisites:

  • Docker installed and running
  • Access to a MongoDB instance (local or remote)
  • (Optional) Environment configuration for your MongoDB URI and database name

Installation steps:

  1. Pull the server image (or build your own if you maintain a custom image): docker pull sfbb/mcp-mongodb-novel-server

  2. Create a configuration file or set environment variables to point to MongoDB:

    • MONGODB_URI=mongodb://localhost:27017
    • DATABASE_NAME=your_database
    • PORT=3000
  3. Run the server using Docker (as provided in the mcp_config): docker run -i -e MONGODB_URI="mongodb://localhost:27017" -e DATABASE_NAME="your_database" -e PORT="3000" sfbb/mcp-mongodb-novel-server

  4. Verify endpoints are reachable:

Notes:

  • If you are deploying behind a port map, adjust LOCAL_PORT in your docker run command (e.g., -p 3000:3000 -p 3001:3001).
  • The server expects a running MongoDB instance accessible via the MONGODB_URI.
  • If you modify the environment, ensure the container has access to the updated variables on startup.

Additional notes

Environment variables:

  • MONGODB_URI: Connection string to MongoDB (default: mongodb://localhost:27017)
  • DATABASE_NAME: Target database for the MCP server
  • PORT: Base port for the MCP SSE server (CRUD API typically at PORT+1)

Common issues and tips:

  • Ensure MongoDB is reachable from inside the container (network/networking issues can block access).
  • If using a remote MongoDB, ensure proper authentication and network whitelisting are in place.
  • For best performance with small context windows, tune MongoDB indexes on the data models (novels, chapters, characters, qa) and consider adjusting the container's CPU/memory limits.
  • Use the REST API to populate or update data, and use the MCP POST /message endpoint for LLM-driven queries via JSON-RPC 2.0 payloads.
  • When using the SSE endpoint, establish a persistent connection from the LLM client to stream responses efficiently.

Related MCP Servers

Sponsor this space

Reach thousands of developers