与 PostgreSQL 数据库交互的 MCP 服务器,主要用于 Steampipe。
Steampipe 每个连接都有一个模式,并创建一个搜索路径,该路径包括所有模式,但公共模式通常为空。此外,Steampipe 的 AWS、GCP 和其他云插件有很多表,因此列出所有表并不实际。因此,推荐的方式是提示您的 Claude Desktop 如下:“在 Steampipe 使用 aws_all 模式时,给我列出所有的 EC2 实例”。这样,Claude 更有可能使用 list_tables_in_schema 命令来限制检索到的表的数量。
macOS:
brew tap turbot/tap
brew install steampipe
Linux:
sudo /bin/sh -c "$(curl -fsSL https://steampipe.io/install/steampipe.sh)"
Windows:
iwr -useb https://steampipe.io/install/steampipe.ps1 | iex
作为后台服务启动 Steampipe:
steampipe service start
您可以使用以下命令验证服务是否正在运行:
steampipe service status
Steampipe 的 PostgreSQL 连接字符串可以找到:
steampipe service status
查找输出中的 Database URL,通常如下所示:
postgres://steampipe:password@localhost:9193/steampipe
您可以在运行服务器时提供此 URL 作为 --database-url 参数:
steampipe-mcp-server --database-url postgresql://steampipe:password@localhost:9193/steampipe
注意:协议必须是 postgresql:// 才能使服务器正常工作。
您可以使用环境变量配置数据库连接,而不是每次传递它:
在项目目录中创建一个 .env 文件,其中包含您的数据库 URL:
STEAMPIPE_MCP_DATABASE_URL=postgresql://steampipe:password@localhost:9193/steampipe
服务器启动时会自动加载此配置。
对于发布的版本,可以直接配置 Claude Desktop:
{
"mcpServers": {
"steampipe": {
"command": "uvx",
"args": [
"steampipe-mcp-server",
"--database-url",
"postgresql://steampipe:password@localhost:9193/steampipe"
]
}
}
}
用您的实际 Steampipe 数据库 URL 替换上述 URL。此配置使用 uvx 直接执行发布的包。
工具将在 Claude 下的 steampipe 命名空间内可用。
此 MCP 服务器提供了几个有用的工具,用于与您的 PostgreSQL 数据库交互:
query对数据库执行只读 SQL 查询,并以 JSON 格式返回结果。
list_all_tables列出数据库搜索路径中所有模式下的所有可用表。Steampipe 不使用 public 模式,每个连接都有一个模式。
list_tables_in_schema列出特定模式内的所有表。这对于限制表的数量特别有用,尤其是在仅处理一个模式时。
get_table_schema获取特定表的列名和数据类型,表应以 schema.table 格式表示。
最简单的开始方式是使用包含的 Makefile:
# 首先创建虚拟环境
uv venv
# 安装开发依赖
make dev-install
# 查看所有可用命令
make help
或者,您可以:
uv venvsource .venv/bin/activate(Linux/macOS)或 .venv\Scripts\activate(Windows)uv pip install -e .[dev]项目包含一个带有常见任务的 Makefile:
# 在开发模式下运行服务器并带有 Inspector
make dev
# 运行测试
make test
# 运行代码检查
make lint
# 运行类型检查
make typecheck
# 格式化代码
make format
# 运行所有检查(代码检查和类型检查)
make check
# 在 Claude Desktop 中安装
make install-mcp
运行 make help 查看所有可用命令。
# 使用 make
make dev
# 或手动
mcp dev src/steampipe_mcp_server/cli.py
这将启动服务器和 MCP Inspector,允许您交互地测试 query 工具和其他工具。
安装后:
# 使用 make
make server
# 或使用明确的 URL
steampipe-mcp-server --database-url postgresql://steampipe:password@localhost:9193/steampipe
# 或使用环境变量
export STEAMPIPE_MCP_DATABASE_URL=postgresql://steampipe:password@localhost:9193/steampipe
steampipe-m
cp-server
运行测试:
# 使用 make
make test
# 或手动
pytest
对于需要数据库连接的测试,请设置 TEST_DB_URL 环境变量。
make check test要发布新版本的包:
更新 pyproject.toml 中的版本
运行所有检查以确保一切正常:
make check test
在 GitHub 上标记发布:
git tag v0.1.0 # 使用适当的版本号
git push origin v0.1.0