JSON DB MCP Server (FastAPI + FastMCP)
A minimal Model Context Protocol (MCP) server that also exposes a small REST API.
Data is stored in a single JSON file (db.json
) as collections of items with auto-generated UUIDs.
- MCP Tools:
db.add_item
,db.get_item
,db.list_items
,db.update_item
,db.delete_item
- REST Endpoints:
POST/GET/PUT/DELETE /db/{collection}[/{id}]
- Transports: HTTP (recommended) and SSE (optional)
- Stack: Python, FastAPI, Uvicorn, FastMCP
Features
- Simple JSON-file database with atomic writes
- Thread-safe in a single-process server using a lock
- Shared core logic for both MCP tools and REST
- Works with VS Code Copilot (Chat) and Gemini CLI as an MCP server
Requirements
- Python 3.10+
uv
(recommended) orpip
- Git (optional, for version control)
Project Layout
Installation
Using uv
(recommended)
Using pip
Running
Development (auto-reload)
Default MCP transport: HTTP at
/mcp/
(recommended).
If you prefer SSE, see MCP over SSE (optional) below.
REST API
All endpoints operate on a collection (created on first write) with items of shape:
Create
List
Get by ID
Update
Delete
MCP Server (HTTP transport, recommended)
This server mounts FastMCP’s HTTP transport at /mcp/
.
VS Code — GitHub Copilot (Chat)
- Open Copilot Chat → Tools (or Add MCP).
- Transport:
HTTP
- URL:
http://localhost:8000/mcp/
(include the trailing slash) - Enable the server. You should see tools:
db.add_item
,db.get_item
,db.list_items
,db.update_item
,db.delete_item
Using tools in chat:
Select a tool from the list or ask:
Use
db.add_item
withcollection="users"
andpayload={"name":"Omar"}
.
Gemini CLI
Add the server via CLI (writes settings for you):
List tools:
Call a tool:
MCP over SSE (optional)
If you prefer SSE, change the mount in main.py
:
- SSE endpoint:
http://localhost:8000/mcp/sse/
(note trailing slash) - Copilot: Transport =
SSE
, URL =http://localhost:8000/mcp/sse/
- Gemini CLI:
Many HTTP clients require a trailing slash for SSE endpoints; use
/mcp/sse/
.
Health Check (optional)
Add this to main.py
(after app = FastAPI(...)
) if you want a friendly root:
Persistence & Backups
- Data file:
db.json
(created on first write). - Writes are atomic: a
db.json.tmp
is written then replaced. - For safety, consider periodic snapshots (e.g.,
cp db.json db.json.bak
in a cron job).
Authentication (optional)
For local development MCP/REST are open.
If you need auth, simplest is an API key header via FastAPI middleware and headers in your MCP client configuration. Example:
- Copilot/Gemini: configure an
x-api-key
header in the MCP server settings.
Troubleshooting
- 404 on
/
Expected. Use REST under/db/...
and MCP at/mcp/
(HTTP) or/mcp/sse/
(SSE). - 307 redirect from
/mcp
→/mcp/
Some SSE clients don’t follow redirects. Use the trailing slash or disable redirect slashes: - SSE returns 404
Make sure you’re hitting/mcp/sse/
(not/mcp/
). - Concurrency
Run as a single process for file-backed DB. Multi-process/worker deployments need a real DB or OS-level file locks. - Git push errors (VS Code AskPass socket)
Unset helper vars or use GitHub CLI / SSH keys:
License
Copyright© - Omar SOLIMAN
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables users to manage data in a simple JSON file database through MCP tools and REST API. Supports creating, reading, updating, and deleting items organized in collections with auto-generated UUIDs.
Related MCP Servers
- AsecurityAlicenseAqualityProvides a standardized interface for interacting with Quickbase's JSON RESTful API through Claude and other MCP clients, supporting operations like querying records, managing table relationships, and handling file attachments.Last updated -122TypeScriptMIT License
- -securityFlicense-qualityAllows interaction with MongoDB collections and documents through standardized MCP requests, supporting operations like listing collections, reading documents with filtering, and executing structured queries.Last updated -JavaScript
- -securityFlicense-qualityA robust server-side application that implements Model Context Protocol (MCP) for file operations, providing authentication and modular REST APIs for managing files, users, and posts.Last updated -TypeScript
- -securityAlicense-qualityA modular server that enables management of MongoDB databases, collections, documents, indexes, and bulk operations through the Model Context Protocol (MCP) interface.Last updated -TypeScriptMIT License