Skip to main content
Glama

SAG MCP Server

Python 3.10+ License: MIT MCP

Inglés | 中文

Servidor MCP de lectura/escritura completo para la base de conocimiento de SAG. Expone 18 herramientas a través del transporte Streamable HTTP, compatible con Claude Desktop, Cursor, VS Code y cualquier cliente MCP.


Características

  • 18 herramientas: CRUD de fuentes/documentos, búsqueda semántica, consultas al grafo de conocimiento, configuración de modelos

  • Streamable HTTP: conéctate desde cualquier cliente MCP sin dependencias locales

  • Autenticación Bearer: autenticación con token JWT integrada

  • Cero configuración: funciona con una instancia de SAG en ejecución sin ajustes adicionales

Related MCP server: LightRAG MCP Server

Inicio rápido

1. Requisitos previos

Una instancia de SAG en ejecución (Docker o nativa). Consulta la guía de despliegue de SAG.

2. Instalación

pip install sag-mcp-server

O desde el código fuente:

git clone https://github.com/Zleap-AI/sag-mcp-server.git
cd sag-mcp-server
pip install -e .

3. Ejecutar

Modo HTTP (recomendado):

export SAG_API_URL=http://your-sag-host:9002
sag-mcp-server http 9003

Modo stdio (para integración local):

sag-mcp-server stdio

4. Conectar desde Claude Desktop

Añade a claude_desktop_config.json:

{
  "mcpServers": {
    "sag": {
      "type": "http",
      "url": "http://your-sag-host:9003/mcp/",
      "headers": {
        "Authorization": "Bearer <your-jwt-token>"
      }
    }
  }
}

Obtén un token:

curl -s -X POST http://your-sag-host:9002/api/v1/auth/login \
  -H 'Content-Type: application/json' -d '{"name":"Admin"}' \
  | python3 -c "import sys,json;print(json.load(sys.stdin)['access_token'])"

Herramientas

Categoría

Herramienta

Descripción

Fuentes

list_sources

Lista todas las fuentes de la base de conocimiento

create_source

Crea una nueva fuente

delete_source

Elimina una fuente y todos sus datos

Documentos

list_documents

Lista los documentos de una fuente

upload_document

Sube un archivo local (autoanaliza y extrae)

ingest_text

Escribe texto directamente (sin necesidad de archivo)

reprocess_document

Reprocesa un documento

pause_document

Pausa el procesamiento

resume_document

Reanuda el procesamiento

delete_document

Elimina un documento

Recuperación

search

Búsqueda semántica con resumen LLM

get_entity

Consulta una entidad del grafo de conocimiento

outline

Obtiene el esquema del documento

grep

Búsqueda por palabra clave o expresión regular

read_document

Lee el texto completo del documento

Configuración

get_model_config

Ver la configuración del modelo

update_model_config

Actualizar los ajustes del modelo

test_model_config

Probar la conectividad del modelo

Configuración

Toda la configuración se realiza mediante variables de entorno:

Variable

Por defecto

Descripción

SAG_API_URL

http://localhost:9002

URL base de la API de SAG

SAG_TOKEN

(vacío = auto-login)

Token Bearer JWT

SAG_LOGIN_NAME

Admin

Nombre de usuario (cuando el token está vacío)

SAG_MCP_PORT

9003

Puerto del servidor HTTP

Configuración del cliente

Claude Desktop

{
  "mcpServers": {
    "sag": {
      "type": "http",
      "url": "http://your-sag-host:9003/mcp/",
      "headers": { "Authorization": "Bearer <token>" }
    }
  }
}

Cursor

~/.cursor/mcp.json:

{
  "mcpServers": {
    "sag": {
      "type": "http",
      "url": "http://your-sag-host:9003/mcp/",
      "headers": { "Authorization": "Bearer <token>" }
    }
  }
}

Dify

  • Tipo: Streamable HTTP

  • URL: http://your-sag-host:9003/mcp/

  • Cabecera: Authorization: Bearer <token>

Docker

Ejecuta como contenedor junto a SAG:

# docker-compose.yml addition
services:
  mcp:
    build: .
    environment:
      SAG_API_URL: http://api:8000
      SAG_SECRET_KEY: ${SAG_SECRET_KEY}
    ports:
      - "9003:9003"
    command: ["sag-mcp-server", "http", "9003"]
    depends_on:
      api:
        condition: service_healthy

Desarrollo

git clone https://github.com/Zleap-AI/sag-mcp-server.git
cd sag-mcp-server
pip install -e ".[dev]"

# Run tests
pytest

# Lint
ruff check src/

Compatibilidad de API

Requiere SAG v0.7.x+ con los siguientes endpoints:

  • POST /api/v1/auth/login — Autenticación JWT

  • GET/POST/DELETE /api/v1/sources — CRUD de fuentes

  • GET/POST/DELETE /api/v1/sources/{id}/documents — CRUD de documentos

  • POST /api/v1/search — Búsqueda semántica

  • GET /api/v1/system/model-config — Configuración del modelo

Licencia

Licencia MIT. Consulta LICENSE para más detalles.


中文文档

Inglés | 中文

基于 SAG 知识库的读写 MCP Server。通过 Streamable HTTP 暴露 18 个工具,兼容 Claude Desktop、Cursor、VS Code 及所有 MCP 客户端。


特性

  • 18 个工具:信源/文档增删改查、语义检索、知识图谱查询、模型配置

  • Streamable HTTP:无需本地安装任何依赖,客户端通过 HTTP 直连

  • Bearer 鉴权:内置 JWT token 认证

  • 零配置:与运行中的 SAG 实例直接配合使用

快速开始

1. 前提条件

运行中的 SAG 实例(Docker 或原生部署)。参见 SAG 部署指南

2. 安装

pip install sag-mcp-server

或从源码安装:

git clone https://github.com/Zleap-AI/sag-mcp-server.git
cd sag-mcp-server
pip install -e .

3. 启动

HTTP 模式(推荐):

export SAG_API_URL=http://your-sag-host:9002
sag-mcp-server http 9003

stdio 模式(本地集成):

sag-mcp-server stdio

4. 连接 Claude Desktop

编辑 claude_desktop_config.json

{
  "mcpServers": {
    "sag": {
      "type": "http",
      "url": "http://your-sag-host:9003/mcp/",
      "headers": {
        "Authorization": "Bearer <your-jwt-token>"
      }
    }
  }
}

获取 token:

curl -s -X POST http://your-sag-host:9002/api/v1/auth/login \
  -H 'Content-Type: application/json' -d '{"name":"Admin"}' \
  | python3 -c "import sys,json;print(json.load(sys.stdin)['access_token'])"

工具清单

类别

工具

说明

信源

list_sources

列出所有知识库信源

create_source

创建新信源

delete_source

删除信源及全部数据

文档

list_documents

列出信源下文档

upload_document

上传本地文件(自动解析+抽取)

ingest_text

直接写入文本(无需文件)

reprocess_document

重新处理文档

pause_document

暂停处理

resume_document

恢复处理

delete_document

删除文档

检索

search

语义检索(含 LLM 摘要)

get_entity

查询知识图谱实体

outline

获取文档大纲

grep

关键词/正则检索

read_document

读取文档全文

模型

get_model_config

查看模型配置

update_model_config

更新模型设置

test_model_config

测试模型连通性

配置说明

所有配置通过环境变量:

变量

默认值

说明

SAG_API_URL

http://localhost:9002

SAG API 地址

SAG_TOKEN

(空=自动登录)

JWT Bearer token

SAG_LOGIN_NAME

Admin

登录用户名(token 为空时生效)

SAG_MCP_PORT

9003

HTTP 服务端口

客户端配置

Claude Desktop

{
  "mcpServers": {
    "sag": {
      "type": "http",
      "url": "http://your-sag-host:9003/mcp/",
      "headers": { "Authorization": "Bearer <token>" }
    }
  }
}

Cursor

~/.cursor/mcp.json

{
  "mcpServers": {
    "sag": {
      "type": "http",
      "url": "http://your-sag-host:9003/mcp/",
      "headers": { "Authorization": "Bearer <token>" }
    }
  }
}

Dify

  • 类型:Streamable HTTP

  • URL:http://your-sag-host:9003/mcp/

  • 请求头:Authorization: Bearer <token>

Docker 部署

与 SAG 一起以容器方式运行:

# 添加到 docker-compose.yml
services:
  mcp:
    build: .
    environment:
      SAG_API_URL: http://api:8000
      SAG_SECRET_KEY: ${SAG_SECRET_KEY}
    ports:
      - "9003:9003"
    command: ["sag-mcp-server", "http", "9003"]
    depends_on:
      api:
        condition: service_healthy

开发指南

git clone https://github.com/Zleap-AI/sag-mcp-server.git
cd sag-mcp-server
pip install -e ".[dev]"

# 运行测试
pytest

# 代码检查
ruff check src/

API 兼容性

需要 SAG v0.7.x+,支持以下接口:

  • POST /api/v1/auth/login — JWT 认证

  • GET/POST/DELETE /api/v1/sources — 信源增删改查

  • GET/POST/DELETE /api/v1/sources/{id}/documents — 文档增删改查

  • POST /api/v1/search — 语义检索

  • GET /api/v1/system/model-config — 模型配置

许可证

MIT License。详见 LICENSE

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • Knowledge coverage map and health score. Ingest docs into a governed knowledge graph via MCP.

  • Manage SRG+ hubs, channels, content, assets, users, and workspaces from any MCP-aware AI agent.

  • Shared, governed long-term memory for AI agents across tools and sessions via MCP and REST.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/guazixiong/sag-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server