neo4j-mcp-gateway

neo4j-mcp-gateway

A single local MCP gateway for Neo4j that exposes both proxied generic Neo4j tools (schema, Cypher, GDS) and custom YAML-defined use-case tools behind one stdio endpoint.

Category
访问服务器

README

Neo4j MCP Gateway

A single local MCP gateway for Neo4j. Run it once, connect from VS Code and Claude Desktop, and get two categories of tools behind one stdio endpoint:

  1. Generic querying — proxied from the official neo4j/mcp server (schema introspection + read/write Cypher + GDS). These are not reimplemented: the gateway spawns the supported server as a downstream child and re-exposes its tools unchanged (get-schema, read-cypher, write-cypher, list-gds-procedures).
  2. Use-case tools — parameterized, purpose-built tools defined as YAML files in tools/. Adding one is: drop in a new *.yaml and restart. They run their own parameterized Cypher and are namespaced (usecase_*) so they never collide with the proxied tools.

The point: keep the official, supported server intact for generic work, while making it trivial to add and iterate curated use-case tools.

        ┌──────────────────────── neo4j-mcp-gateway (this repo) ─────────────────────────┐
        │                                                                                 │
 VS Code│  ┌───────────────┐   mount    ┌──────────────────────────────┐  stdio (child)  │
 Claude ─┼─▶│ FastMCP server │◀──────────│ FastMCP proxy (create_proxy) │─────────────────┼─▶ official neo4j/mcp
 Desktop│  │  (stdio)       │            └──────────────────────────────┘                 │   (uvx / docker / binary)
 (stdio)│  │                │   add_tool ┌──────────────────────────────┐  bolt           │
        │  │                │◀──────────│ YAML tools (neo4j driver)     │─────────────────┼─▶ Neo4j
        │  └───────────────┘            └──────────────────────────────┘                 │
        └─────────────────────────────────────────────────────────────────────────────────┘

Prerequisites

  • Python 3.11+
  • uv (brew install uv / pipx install uv)
  • A reachable Neo4j instance (local, Docker, or Aura) with credentials
  • The official downstream server is fetched automatically on first run via uvx neo4j-mcp-server — no manual install. (Docker / a built Go binary also work; see .env.example.)

Note: the official server verifies Neo4j connectivity at startup and exits if it cannot connect. If your credentials are wrong or Neo4j is unreachable, the proxied get-schema / *-cypher tools will not appear — check the gateway's stderr log. The YAML use-case tools still load regardless and report connection problems as clean per-call errors.


Setup

# from the project root
cp .env.example .env
# edit .env with your Neo4j URI / user / password / database
uv sync

.env (git-ignored) holds the real credentials. The same credentials flow to both the downstream official server and the YAML tool executor.

Variable Default Purpose
NEO4J_URI bolt://localhost:7687 Neo4j bolt URI (shared)
NEO4J_USERNAME neo4j Neo4j user (shared)
NEO4J_PASSWORD password Neo4j password (shared)
NEO4J_DATABASE neo4j Target database (shared)
NEO4J_MCP_CMD uvx neo4j-mcp-server How to launch the official downstream server
NEO4J_READ_ONLY (unset) true disables downstream write-cypher
NEO4J_TELEMETRY false Downstream telemetry opt-in
TOOLS_DIR tools Where YAML use-case tools are discovered
USECASE_PREFIX usecase_ Namespace prefix for YAML tool names

Run

uv run neo4j-mcp-gateway
# equivalent:
uv run python -m gateway.server

The gateway serves over stdio — that's what editors launch. On startup it logs (to stderr) the downstream command, the mounted official tools, and the YAML use-case tools it registered.

Verify with the MCP Inspector

# List the union of tools (official proxied + YAML use-case)
npx @modelcontextprotocol/inspector --cli uv run neo4j-mcp-gateway --method tools/list

# Call a generic proxied tool
npx @modelcontextprotocol/inspector --cli uv run neo4j-mcp-gateway \
  --method tools/call --tool-name get-schema

# Call a YAML use-case tool
npx @modelcontextprotocol/inspector --cli uv run neo4j-mcp-gateway \
  --method tools/call --tool-name usecase_ato_session_triage --tool-arg min_risk=5

Or launch the Inspector UI (drop --cli) and browse/click the tools.


Adding a use-case tool (the whole point)

  1. Create tools/my_tool.yaml:

    name: recent_transactions_for_customer
    description: Recent transactions performed by a customer's accounts.
    parameters:
      - name: customer_id
        type: string
        description: Customer.customerId
        required: true
      - name: limit
        type: integer
        description: Max rows to return
        required: false
        default: 25
    cypher: |
      MATCH (c:Customer {customerId: $customer_id})-[:HAS_ACCOUNT]->(:Account)
            -[:PERFORMS]->(t:Transaction)
      RETURN t.transactionId AS id, t.amount AS amount, t.date AS date
      ORDER BY t.date DESC
      LIMIT $limit
    read_only: true   # set false to run in write mode
    
  2. Restart the gateway (see Restarting). It appears as usecase_recent_transactions_for_customer.

Tools are discovered once at startup and MCP clients cache the tool list, so a new/edited YAML file needs a restart to show up — saving alone is not enough.

Schema reference

Field Required Notes
name ✅ Alphanumeric/underscore. Final tool name is <USECASE_PREFIX><name>.
description ✅ Shown to the model.
parameters — List of {name, type, description, required, default}.
parameters[].type — string · integer · number · boolean · array · object (default string).
cypher ✅ Parameters bind to $name placeholders.
read_only — true (default) → read transaction; false → write transaction.

Malformed files fail loudly at startup with a message naming the file. Results are returned as JSON: { "count": N, "records": [ ... ] }, with Neo4j temporal / spatial / graph values converted to JSON-friendly forms.


Restarting to pick up new tools

Adding or editing a YAML tool requires a restart. The cleanest way depends on how the gateway is running:

  • In VS Code / Claude Desktop (normal use): don't kill it in a terminal — let the client restart it, which stops the process by closing its stdin (a clean, instant shutdown).
    • VS Code: open .vscode/mcp.json and click Restart on the server, or run MCP: List Servers → neo4j-gateway → Restart from the command palette.
    • Claude Desktop: toggle the connector off/on (or quit and reopen Claude).
  • Running it yourself in a terminal (e.g. testing with the Inspector): a single Ctrl+C now stops it immediately. (Earlier it took several Ctrl+C because the shutdown waited on the downstream child; the gateway now installs a fast SIGINT/SIGTERM handler that exits at once and lets the child close via stdin-EOF.) kill <pid> (SIGTERM) also works instantly.

If you ever see leftover neo4j-mcp-server processes from older sessions:

pgrep -fl 'neo4j-mcp-server|neo4j-mcp-gateway'   # inspect first
pkill -f 'neo4j-mcp-server'                       # then clean up stale ones

Heads-up: pkill will also stop the instance your editor is actively using, so restart that connector afterwards.

Client configuration

Both clients launch the gateway over stdio. Credentials are read from this repo's .env (no secrets in the client config).

VS Code — .vscode/mcp.json (portable, already in this repo)

{
  "servers": {
    "neo4j-gateway": {
      "type": "stdio",
      "command": "uv",
      "args": ["run", "--directory", "${workspaceFolder}", "neo4j-mcp-gateway"]
    }
  }
}

Nothing is machine-specific here: ${workspaceFolder} resolves automatically. For the CodeLens Start/Restart buttons (and for ${workspaceFolder}) to work, open this repo folder as the workspace root (File → Open Folder → the neo4j-mcp-gateway folder), not a parent directory — VS Code only reads .vscode/mcp.json from the opened folder's root.

  • Start/stop it: click Start on the CodeLens above "neo4j-gateway", or Command Palette → MCP: List Servers → neo4j-gateway → Start.
  • Use it: in Copilot Chat switch to Agent mode, open the 🛠️ tools picker, and enable the neo4j-gateway tools.
  • If VS Code can't find uv: it was launched without your shell PATH. Either start VS Code from a terminal (cd neo4j-mcp-gateway && code .), install uv to a system-wide location, or replace "uv" with the absolute path from which uv.

Claude Desktop — claude_desktop_config.json

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json · Windows: %APPDATA%\Claude\claude_desktop_config.json

Claude Desktop has no ${workspaceFolder} and does not inherit your shell PATH, so both paths must be absolute. Fill in your own with which uv (the uv path) and pwd (this repo's path):

{
  "mcpServers": {
    "neo4j-gateway": {
      "command": "/ABSOLUTE/PATH/TO/uv",
      "args": ["run", "--directory", "/ABSOLUTE/PATH/TO/neo4j-mcp-gateway", "neo4j-mcp-gateway"]
    }
  }
}

Tip: you can add an "env": { "NEO4J_URI": "…", "NEO4J_PASSWORD": "…" } block here instead of using .env if you prefer per-client credentials.

Sharing this as a lab demo

The repo is self-contained — an attendee only needs, per machine:

git clone <repo-url> neo4j-mcp-gateway
cd neo4j-mcp-gateway
cp .env.example .env          # fill in their Neo4j URI / user / password / database
uv sync                       # creates the venv; uvx fetches the downstream on first run
code .                        # open THIS folder in VS Code, then MCP: List Servers → Start

Prerequisites they need installed: Python 3.11+, uv, and (for the Inspector smoke test) Node/npx. No absolute paths to edit for the VS Code flow; only the Claude Desktop config needs their own two paths.

Demo data (account-takeover)

data/ato_demo.cypher seeds a small, self-contained ATO dataset — realistic legitimate baseline, two fraud patterns (classic takeover + mule ring), and a false-positive traveler for precision discussion. Load it with:

cypher-shell -a "$NEO4J_URI" -u "$NEO4J_USERNAME" -p "$NEO4J_PASSWORD" -d "$NEO4J_DATABASE" -f data/ato_demo.cypher

It's idempotent and namespaced (source:'ato-demo'), so it won't disturb other data. See data/README.md for the roster, the ground-truth scoring fields, and copy-paste detection queries.

Running the lab:

  • data/README.md — the presenter runbook (drives the tools explicitly; good with the MCP Inspector).
  • data/demo_prompts.md — conversational prompts to paste into Claude Desktop so the model orchestrates the tools itself. This is the intended payoff of the lab.

Project layout

neo4j-mcp-gateway/
  gateway/
    server.py       # entrypoint: build proxy + load YAML tools + serve stdio
    proxy.py        # spawn & re-expose the official neo4j/mcp downstream
    yaml_tools.py   # YAML discovery, validation, MCP registration, Cypher execution
    config.py       # env-based config (.env)
  tools/                        # ATO use-case tools (one YAML each)
    ato_session_triage.yaml     # risk-score every login session
    ato_lifecycle.yaml          # full access -> change -> payee -> transfer chain
    event_velocity.yaml         # automated-attack event velocity
    new_device_logins.yaml      # logins from untrusted devices
    shared_device_accounts.yaml # one device across many customers (ring)
    mule_hubs.yaml              # shared high-risk beneficiaries (ring)
    contact_change_history.yaml # forensic old-vs-new contact changes
  data/
    ato_demo.cypher             # account-takeover demo dataset generator
    README.md                   # load steps + detection queries
  .vscode/mcp.json
  .env.example
  pyproject.toml
  README.md

Design notes / extending

  • Namespacing — official tools keep their original names; YAML tools are prefixed (usecase_), so names can never collide.
  • Lazy driver — the YAML executor connects to Neo4j on first tool call, so the gateway starts and lists tools even if Neo4j is briefly down; connection errors surface as clean tool errors.
  • Retrieval-ready — the YAML registry (load_tool_specs in yaml_tools.py) is cleanly separated from execution, so a future vector-index / kNN routing layer could sit in front of it without touching the executor. (Not implemented — out of scope for now.)
  • Extending routing — to add non-YAML tools, register them on the gateway server in server.py with gateway.add_tool(...).

Troubleshooting

Symptom Cause / fix
Only usecase_* tools appear Downstream couldn't reach Neo4j and exited. Fix NEO4J_URI/creds; check gateway stderr.
uvx slow on first run It downloads the official server wheel once, then caches it.
Claude Desktop can't start it Use the absolute path to uv in command.
YAML tool returns an error The message includes the Neo4j error code — verify the Cypher and params.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选