Back to MCP directory
publicPublicdnsLocal runtime

ldap-mcp

LDAP MCP 服务器是一个通过模型上下文协议(MCP)暴露 LDAP 目录服务的工具,允许客户端执行目录搜索和增删改查操作,支持安全连接和只读模式。

article

README

🚀 LDAP MCP 服务器

LDAP MCP 服务器通过模型上下文协议(MCP)公开 LDAP 目录,使 MCP 客户端能够使用标准工具/资源工作流执行常见的目录搜索和 CRUD 操作。

🚀 快速开始

构建与测试

cd /opt/code/github/ldap-mcp
go test ./...

当前仓库没有单元测试,因此成功运行上述命令即确认项目可以编译且所有依赖项都已解决。

运行服务器

cd /opt/code/github/ldap-mcp
go run ./cmd/server \
  -url ldap://localhost:389 \
  -bind-dn "cn=admin,dc=example,dc=com" \
  -bind-password secret

关键标志说明:

  • -addr:MCP 监听地址(默认 :8080,可通过 MCP_PORT 覆盖)。
  • -url:LDAP 服务器 URL,如 ldap://host:389ldaps://host:636
  • -bind-dn / -bind-password:用于绑定到目录的凭证。你也可以通过 LDAP_BIND_PASSWORD 环境变量提供密码。
  • -starttls:将普通 LDAP 连接升级为 TLS。仅在使用 ldap:// URL 时有效。
  • -insecure:跳过 TLS 证书验证(在使用自签名证书进行测试时很有用)。
  • -read-write:启用添加/修改/删除工具。如果省略,服务器将以只读模式运行。
  • -timeout:与 LDAP 服务器通信时的每个请求超时时间(默认 30 秒)。

使用 -help 可打印完整的标志和环境变量列表。

✨ 主要特性

  • 通过 MCP 工具搜索、检索、添加、修改和删除 LDAP 条目。
  • 可选的只读模式,限制 MCP 客户端只能进行安全操作。
  • 支持 StartTLS 升级、LDAPS 端点和可配置的 TLS 验证。
  • 为目录根 DSE 和按 DN 指定的任意条目提供内置的 MCP 资源。
  • 支持优雅关闭处理和自动 LDAP 重连逻辑。

📦 安装指南

环境要求

  • Go 1.24 或更高版本
  • 能够访问 LDAP 服务器(如 OpenLDAP、Active Directory 等)
  • 支持 SSE 传输的 MCP 客户端(例如 Claude Desktop)

💻 使用示例

MCP 工具与资源

工具

  • search_entries:执行带有分页、范围选择、别名引用和大小限制的 LDAP 搜索。
  • get_entry:按可分辨名称获取单个条目。
  • add_entry:创建新条目(需要 -read-write 模式)。
  • modify_entry:应用属性修改(需要 -read-write 模式)。
  • delete_entry:删除条目(需要 -read-write 模式)。

资源

  • ldap://root-dse:以 JSON 格式返回目录根 DSE。
  • ldap://entry/{dn}:在提供 DN 时获取特定条目。

🔧 技术细节

  • LDAP 客户端包装器(internal/ldapclient)管理连接重用、StartTLS 协商以及在传输错误时自动重连。
  • MCP 工具处理程序(internal/tools)在调用 LDAP 操作之前会验证输入;例如,page_size 参数会被限制在分页结果控件使用的 uint32 范围内。
  • 使用 gofmt 格式化 Go 源代码,并在依赖项更改时通过 go mod tidy 保持模块依赖项的整洁。
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client