使用说明
Steampipe MCP服务器
与PostgreSQL数据库交互的MCP服务器,主要用于 蒸汽管.
Steampipe为每个连接创建一个模式,并创建一个包含所有模式的search_path,但公共模式通常为空。除此之外,AWS、GCP和其他云的Steampipe插件有很多表,所以仅仅列出所有表是不切实际的。因此,建议的提示Claude Desktop的方式是这样说:“在使用aws_all模式的steampipe中,给我一个所有ec2实例的列表”。这样,Claude更有可能在schema命令中使用list_tables_in_schema来限制检索到的表的数量。
先决条件
1.安装蒸汽管
macOS:
brew tap turbot/tap
brew install steampipe
Linux:
sudo /bin/sh -c "$(curl -fsSL https://steampipe.io/install/steampipe.sh)"
窗户:
iwr -useb https://steampipe.io/install/steampipe.ps1 | iex
2.启动蒸汽管道服务
启动Steampipe作为后台服务:
steampipe service start
您可以通过以下方式验证服务是否正在运行:
steampipe service status
3.获取数据库URL
可以找到Steampipe PostgreSQL连接字符串:
steampipe service status
寻找 Database URL 在输出中,通常看起来像:
postgres://steampipe:password@localhost:9193/steampipe
您可以在 --database-url 运行服务器时的参数:
steampipe-mcp-server --database-url postgresql://steampipe:password@localhost:9193/steampipe
注:协议必须 postgresql:// 以便服务器正常工作。
4.配置环境变量
您可以使用环境变量配置数据库连接,而不是每次都传递它:
-
创建一个
.env项目目录中包含数据库URL的文件:STEAMPIPE_MCP_DATABASE_URL=postgresql://steampipe:password@localhost:9193/steampipe -
服务器将在启动时自动加载此配置。
5.安装在克劳德桌面
对于已发布的版本,您可以直接配置Claude Desktop:
- 打开克劳德桌面
- 导航到“设置”>“开发人员”>“编辑配置”
- 将以下配置添加到JSON文件中:
{
"mcpServers": {
"steampipe": {
"command": "uvx",
"args": [
"steampipe-mcp-server",
"--database-url",
"postgresql://steampipe:password@localhost:9193/steampipe"
]
}
}
}
- 保存配置文件并重新启动Claude Desktop
将数据库URL替换为实际的Steampipe数据库URL。此配置使用 uvx 直接执行已发布的包。
这些工具将在Claude中提供 steampipe 命名空间。
可用工具
此MCP服务器提供了几个与PostgreSQL数据库交互的有用工具:
query
对数据库运行只读SQL查询,并以JSON格式返回结果。
list_all_tables
列出数据库搜索路径中所有模式中的所有可用表。蒸汽管不使用 public 模式,每个连接都有模式。
list_tables_in_schema
列出特定架构中的所有表。有助于限制表的数量,特别是在只使用一个模式时。
get_table_schema
检索特定表的列名和数据类型,表的格式应如下 schema.table.
安装
开发设置(推荐)
最简单的入门方法是使用附带的Makefile:
# Create a virtual environment first
uv venv
# Install development dependencies
make dev-install
# View all available commands
make help
或者,您可以:
- 克隆存储库
- 创建虚拟环境:
uv venv - 激活环境:
source .venv/bin/activate(Linux/macOS)或.venv\Scripts\activate(Windows) - 安装开发依赖项:
uv pip install -e .[dev]
发展
使用Makefile
该项目包括一个包含常见任务的Makefile:
# Run the server in development mode with Inspector
make dev
# Run tests
make test
# Run linting
make lint
# Run type checking
make typecheck
# Format code
make format
# Run all checks (lint and typecheck)
make check
# Install in Claude Desktop
make install-mcp
跑 make help 查看所有可用命令。
如何跑步
1.开发模式(推荐)
# Using make
make dev
# OR manually
mcp dev src/steampipe_mcp_server/cli.py
这将启动服务器和MCP检查器,允许您测试 query 工具和其他工具交互。
2.使用CLI
安装后:
# Using make
make server
# OR with explicit URL
steampipe-mcp-server --database-url postgresql://steampipe:password@localhost:9193/steampipe
# OR with environment variable
export STEAMPIPE_MCP_DATABASE_URL=postgresql://steampipe:password@localhost:9193/steampipe
steampipe-mcp-server
测试
使用以下工具运行测试:
# Using make
make test
# OR manually
pytest
对于需要数据库连接的测试,请设置 TEST_DB_URL 环境变量。
贡献
- 分叉存储库
- 为您的功能创建新分支
- 进行更改
- 运行测试和检查:
make check test - 提交拉取请求
释放
要发布软件包的新版本,请执行以下操作:
-
更新中的版本
pyproject.toml -
运行所有检查以确保一切正常:
make check test -
在GitHub上标记发布:
git tag v0.1.0 # Use appropriate version number git push origin v0.1.0
