Mcp_server_template

Mcp_server_template

🚀 PostgreSQL 模型上下文协议(Model Context Protocol)服务器

该服务器提供对 PostgreSQL 数据库的只读访问权限,让大型语言模型(LLMs)能够查看数据库架构并执行只读查询,有效助力模型与数据库交互。

🚀 快速开始

要将此服务器与 Claude Desktop 应用一起使用,请在 claude_desktop_config.json 文件的 "mcpServers" 部分添加以下配置:

Docker

  • 当在 macOS 上运行 Docker 时,如果服务器运行在主机网络上(例如 localhost),请使用 host.docker.internal
  • 用户名/密码可通过 PostgreSQL URL 添加,格式为 postgresql://user:password@host:port/db-name
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"
]
}
}
}

NPX

{
"mcpServers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}

⚠️ 重要提示

请将 /mydb 替换为您自己的数据库名称。

✨ 主要特性

工具

  • query
    • 执行针对连接数据库的只读 SQL 查询
    • 输入:sql (字符串):要执行的 SQL 查询
    • 所有查询均在只读事务中执行

资源

该服务器提供每个表的架构信息:

  • 表格架构 (postgres:////schema)
    • 每个表的 JSON 架构信息
    • 包括列名和数据类型
    • 自动从数据库元数据中发现

    📦 安装指南

    Docker

    docker build -t mcp/postgres -f src/postgres/Dockerfile .
    

    📄 许可证

    该 MCP 服务器基于 MIT License 许可证。这意味着您可以自由使用、修改和分发软件,但需遵守 MIT License 的条款。有关详细信息,请参阅项目仓库中的 LICENSE 文件。

    • 0 关注
    • 0 收藏,11 浏览
    • system 提出于 2025-09-24 20:15

    相似服务问题