Token导航 LogoToken导航TokenDH.com
Project-Heimdall logo
数据服务未说明官方级别未说明来源级核验

Project-Heimdall

MCP Server

Project Heimdall是一款高安全性的中间件,作为PostgreSQL数据库的模型上下文协议(MCP)守门员,允许大型语言模型(如Claude或Cursor)安全查询数据库,同时严格阻止任何修改、删除或破坏数据的尝试。

工具数

3

提示词数

0

GitHub Stars

0

资源数

0
大型语言模型GoClaude中间件Claude DesktopClaudeCursor

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

AnubhavMadhav

提供方

AnubhavMadhav

最后核验

2026/5/17 20:21

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

Project Heimdall

*"Heimdall sees all, hears all, and guards the Bifrost. No enemy shall pass through to Asgard."*

Project Heimdall is a high-security middleware that acts as a Model Context Protocol (MCP) Gatekeeper for PostgreSQL databases. It allows Large Language Models (like Claude or Cursor) to query your database to answer questions, while strictly blocking any attempt to modify, delete, or destroy data.


What is Project-Heimdall?

The Layman's Explanation (The Asgard Analogy)

Imagine your Production Database is Asgard—a realm of infinite value that must be protected. The LLM (Claude/AI) is a traveler trying to cross the Bifrost (the bridge) to see what is inside. Heimdall stands at the gate.

  • He allows travelers to look around ("Show me the users," "List the tables").
  • But if a traveler tries to burn a village (DROP TABLE) or steal gold (DELETE FROM), Heimdall summons his sword and strictly blocks the path.

The Technical Explanation

Heimdall is an MCP Server written in Golang. It sits between the AI client and the PostgreSQL database. Instead of passing SQL queries directly to the driver, it passes them through a custom Abstract Syntax Tree (AST) Parser. This parser deconstructs the SQL command into its grammatical components to ensure it is a read-only SELECT statement. If any mutation keywords (INSERT, UPDATE, DELETE, DROP, ALTER) are detected in the syntax tree, the query is rejected before it ever touches a database connection.

LLM (Client)MCP ServerAST Security LayerPostgreSQL

Key Features

  • AST-Based Security: Uses sqlparser to tokenize and analyze queries, strictly rejecting any non-SELECT statements (superior to regex matching).
  • Model Context Protocol (MCP): Native integration with the Anthropic ecosystem, exposing list_tables, get_schema, and safe_query as standardized tools.
  • High-Performance Driver: Built on pgx/v5 for efficient connection pooling and type handling.

Heimdall Build & Test


Tech Stack & Rationale

We didn't just pick "popular" tools; we picked the *safest* tools for high-concurrency infrastructure.

ComponentChoiceWhy we chose it (vs. Alternatives)
LanguageGolangPros: Strict typing prevents runtime surprises. Goroutines handle concurrent MCP requests efficiently.
Cons: More verbose than Python, but safer for infrastructure.
Protocolmcp-goPros: Native implementation of the Model Context Protocol. Handles the JSON-RPC handshake so we focus on logic.
Driverpgx/v5Pros: Uses the PostgreSQL binary protocol (faster than text). Better connection pooling than standard database/sql.
Securityxwb1989/sqlparserPros: Parses SQL into an Abstract Syntax Tree (AST).
Why not Regex? Regex is easily tricked (e.g., SeLeCt vs SELECT). An AST understands the *intent* of the code, making it nearly impossible to bypass.
ArchitectureHexagonalPros: Decouples the "Security Layer" from the "Database Layer." Allows us to swap the database or protocol later without rewriting the core logic.

How to Setup Locally

Follow these steps to deploy Heimdall on your local machine (Mac, Linux, or Windows WSL).

Prerequisites

1. Clone & Build

git clone 
cd Project-Heimdall
cd heimdall
go mod tidy
go build -o heimdall cmd/heimdall/main.go

Note: This creates a binary executable named heimdall in your folder.

2. Start a Local Database (Docker)

If you don't have a database, spin up a safe sandbox:

# Run Postgres on port 5432
- docker run --name heimdall-db -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres

# Create some dummy data to test
- docker exec -it heimdall-db psql -U postgres -c "CREATE TABLE heroes (id SERIAL, name TEXT, role TEXT);"
- docker exec -it heimdall-db psql -U postgres -c "INSERT INTO heroes (name, role) VALUES ('Thor', 'God of Thunder'), ('Loki', 'Trickster');"

# (Crucial) Export the DB URL for manual testing
- export DATABASE_URL="postgres://postgres:password@localhost:5432/postgres?sslmode=disable"

3. Configure Claude Desktop

Tell Claude where to find your Gatekeeper.

  • Mac/Linux: Edit ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: Edit %APPDATA%\Claude\claude_desktop_config.json

Add this configuration (Update the path to your actual project folder!):

{
  "mcpServers": {
    "heimdall": {
      "command": "`/YOUR/FULL/PATH/TO/Project-Heimdall/heimdall/heimdall",
      "args": [],
      "env": {
        "DATABASE_URL": "postgres://postgres:password@localhost:5432/postgres?sslmode=disable"
      }
    }
  }
}

4. Restart & Chat

Restart Claude Desktop. You should see the 🔌 (plug/connector) connection icon. Ask: "Check the heimdall database. Who are the heroes?"


Demo: Heimdall in Action

See Heimdall protecting the database in real-time interactions with Claude Desktop.

1. Discovery & Safe Access

Heimdall allows the LLM to explore the schema and read data safely.

Scenario 1: Schema DiscoveryScenario 2: Safe Data Retrieval
Reading Data
*Claude asks to see available tables.**Claude executes a standard SELECT * query.*

2. The Gatekeeper (Security Enforcement)

This is the core feature. Notice how Heimdall intercepts the AST before it reaches the database.

Scenario 3: Blocking a DELETEScenario 4: Preventing SQL Injection
Blocked DeleteBlocked Injection
*Claude attempts a DELETE command. Heimdall detects the *sqlparser.Delete node and rejects it.**A stacked query (SELECT; DROP) is caught by the parser.*

Security Deep Dive: AST vs. Regex

Heimdall doesn't use Regular Expressions (Regex) for security because:

The Regex Problem: A naive filter might block strings containing DELETE.

  • Attack: "Select * from deleted_users" -> Blocked (False Positive)
  • Attack: "D E L E T E from users" -> Allowed (False Negative)

The Heimdall (AST) Solution: Heimdall converts the SQL string into a structured tree object. It checks the Node Type.

  • Is stmt of type *sqlparser.Select? Pass.
  • Is stmt of type *sqlparser.Delete? Fail.

This ensures that SELECT * FROM deleted_users is allowed (because it's a SELECT node), but DELETE FROM users is blocked, no matter how you format the whitespace.


Project Structure

We follow the Standard Go Layout with Hexagonal Architecture:

heimdall/
├── cmd/main.go           # Entry point (Wiring & Config)
├── internal/
│   ├── core/             # Pure Business Logic
│   │   ├── ports/        # Interfaces (Gatekeeper)
│   │   └── services/     # Implementation (The Guard)
│   └── adapters/         # Infrastructure
│       ├── mcp/          # The Interface (Claude)
│       ├── postgres/     # The Storage (Asgard)
│       └── security/     # The Firewall (AST Parser)
└── pkg/logger/           # Structured Logging

*Built with ❤️ and Golang by Anubhav Madhav.*

目录标签

目录标签

大型语言模型GoClaude中间件数据库安全本地部署PostgreSQLAST解析

支持客户端

Claude DesktopClaudeCursor

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

3

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP