图数据库查询服务

age-mcp是为Apache AGE图数据库提供的服务器,支持AI助手通过Model Context Protocol查询和修改图数据。

  • by Neftedollar
  • F#
  • 本地部署
  • 更新于
在 GitHub 查看 Neftedollar/age-mcp

使用说明

年龄mcp

MCP服务器 阿帕奇时代 图形数据库。让AI助手(Claude、ChatGPT、Copilot等)通过 模型上下文协议.

内置F#。NET 10——1300行,21个工具,零Python依赖。

快速开始

# 1. Start the database
docker compose up -d

# 2. Install the tool
dotnet tool install --global AgeMcp

# 3. Run
AGE_CONNECTION_STRING="Host=localhost;Port=5435;Database=agemcp;Username=agemcp;Password=agemcp" age-mcp

克劳德桌面/克劳德代码

{
  "mcpServers": {
    "age-mcp": {
      "type": "stdio",
      "command": "age-mcp",
      "env": {
        "AGE_CONNECTION_STRING": "Host=localhost;Port=5435;Database=agemcp;Username=agemcp;Password=agemcp",
        "TENANT_ID": "default"
      }
    }
  }
}

工具(21)

图管理

工具 说明
get_or_create_graph 按名称获取或创建图形
list_graphs 列出所有图表(租户范围)
drop_graphs 删除一个或多个图形

顶点和边缘

工具 说明
upsert_vertex 插入或更新顶点(在识别时合并)
upsert_edge 插入或更新定向边
upsert_graph 批量追加顶点+边(事务性)
drop_vertex 删除顶点及其所有边
drop_edge 通过标识删除边缘

查询

工具 说明
cypher_query 执行读取Cypher查询
cypher_write 执行写Cypher查询,返回受影响的计数
search_vertices 按标签和/或属性搜索
search_edges 按标签搜索边
get_neighbors N跳遍历(1-5跳,定向)
get_schema 所有节点标签和计数

出口/进口

工具 说明
export_graph 将图形导出为JSON
import_graph 从JSON导入(如果需要,创建图形)

可视化和搜索

工具 说明
generate_visualization 交互式vis.js HTML图形
semantic_search 向量相似性搜索(pgvector)
graph_context 图RAG:语义种子+N跳扩展

OpenBrain桥

工具 说明
sync_to_openbrain 将顶点导出为OpenBrain内存
import_from_openbrain 从OpenBrain记忆构建图表

配置

变量 必填 默认 描述
AGE_CONNECTION_STRING yes 本地主机测试数据库 Npgsql连接字符串
TENANT_ID 没有 default 图名称的租户前缀
EMBEDDING_API_URL 否 -- OpenAI兼容嵌入API
EMBEDDING_API_KEY 没有 -- 用于嵌入的API密钥
EMBEDDING_MODEL 没有 text-embedding-3-small 嵌入模型名称
EMBEDDING_DIMENSIONS 没有 384 矢量维度

码头工人

附带的Docker设置运行PostgreSQL 17+Apache AGE 1.6.0+pgvector:

docker compose up -d

版本和凭据可通过以下方式配置 .env (参见 .env.example):

PG_MAJOR=17  AGE_VERSION=1.6.0  DB_PORT=5435  docker compose up -d

数据兼容性

设计为可直接替代 agemcp python相同的租户前缀(t_{TENANT_ID}__),相同顶点 ident 属性,相同边缘 start_ident/end_ident 物业。现有数据无需迁移即可工作。

演出

苹果M1 Pro上的BenchmarkDotNet。NET 10.0.5:

操作 延迟 已分配
列表图 62 ns 216 B
get_schema 117 ns 344 B
密码查询(1个顶点) 1.0毫秒 58 KB
search_vertices 1.0毫秒 36 KB
get_neighbors(深度=1) 92毫秒 233 KB
导出图形(40个实体) 71毫秒 472 KB

从源头构建

git clone https://github.com/Neftedollar/age-mcp.git
cd age-mcp
dotnet build

# Run directly
dotnet run

# Or install as tool
dotnet pack -c Release
dotnet tool install --global AgeMcp

依赖关系(FsMcp。核心, FsMcp。服务器, 费珀)会自动从NuGet还原。

许可证

麻省理工学院