JSON DB MCP Server

JSON DB MCP Server

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.

Category
访问服务器

README

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) or pip
  • Git (optional, for version control)

Project Layout

.
├─ main.py
├─ db.json                # created on first write
└─ README.md

Installation

Using uv (recommended)

uv venv
uv pip install fastapi uvicorn fastmcp

Using pip

python -m venv .venv
source .venv/bin/activate
pip install fastapi uvicorn fastmcp

Running

Development (auto-reload)

uv run main.py
# or
uv run python main.py
# Server: http://localhost:8000

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:

{
  "id": "uuid-string",
  "...": "fields you provide"
}

Create

curl -X POST http://localhost:8000/db/users \
  -H "Content-Type: application/json" \
  -d '{"name":"Omar","role":"admin"}'

List

curl http://localhost:8000/db/users

Get by ID

curl http://localhost:8000/db/users/<ITEM_ID>

Update

curl -X PUT http://localhost:8000/db/users/<ITEM_ID> \
  -H "Content-Type: application/json" \
  -d '{"role":"owner"}'

Delete

curl -X DELETE http://localhost:8000/db/users/<ITEM_ID>

MCP Server (HTTP transport, recommended)

This server mounts FastMCP’s HTTP transport at /mcp/.

VS Code — GitHub Copilot (Chat)

  1. Open Copilot ChatTools (or Add MCP).
  2. Transport: HTTP
  3. URL: http://localhost:8000/mcp/ (include the trailing slash)
  4. 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 with collection="users" and payload={"name":"Omar"}.

Gemini CLI

Add the server via CLI (writes settings for you):

# Project-scoped (./.gemini/settings.json)
gemini mcp add --transport http jsondb http://localhost:8000/mcp/

# Or user-scoped (~/.gemini/settings.json)
gemini mcp add --scope user --transport http jsondb http://localhost:8000/mcp/

List tools:

gemini mcp list

Call a tool:

gemini mcp call jsondb db.add_item \
  --args collection=users \
  --args payload='{"name":"Omar"}'

MCP over SSE (optional)

If you prefer SSE, change the mount in main.py:

# replace the HTTP mount:
# mcp_http_app = mcp.http_app(path="/")
# app.mount("/mcp", mcp_http_app)

mcp_sse_app = mcp.sse_app()
app.mount("/mcp", mcp_sse_app)  # SSE lives under /mcp/sse/
  • SSE endpoint: http://localhost:8000/mcp/sse/ (note trailing slash)
  • Copilot: Transport = SSE, URL = http://localhost:8000/mcp/sse/
  • Gemini CLI:
    gemini mcp add --scope user --transport sse jsondb http://localhost:8000/mcp/sse/
    

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:

@app.get("/")
def health():
    return {"ok": True, "rest": "/db/{collection}", "mcp": "/mcp/"}

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:

from fastapi import Request
from fastapi.responses import JSONResponse
import os

API_KEY = os.getenv("API_KEY", "")

@app.middleware("http")
async def api_key_guard(request: Request, call_next):
    if API_KEY and request.headers.get("x-api-key") != API_KEY:
        return JSONResponse(status_code=401, content={"detail": "Unauthorized"})
    return await call_next(request)
  • 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:

    app.router.redirect_slashes = False
    
  • 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:

    unset GIT_ASKPASS SSH_ASKPASS VSCODE_GIT_ASKPASS_NODE VSCODE_GIT_ASKPASS_MAIN
    

License

Copyright© - Omar SOLIMAN

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选