返回市场
蒸汽管道MCP服务器

蒸汽管道MCP服务器

作者:andrew-kurin5 星标更新:2025-04-26

项目介绍

Steampipe MCP 服务器

与 PostgreSQL 数据库交互的 MCP 服务器,主要用于 Steampipe

Steampipe 每个连接都有一个模式,并创建一个搜索路径,该路径包括所有模式,但公共模式通常为空。此外,Steampipe 的 AWS、GCP 和其他云插件有很多表,因此列出所有表并不实际。因此,推荐的方式是提示您的 Claude Desktop 如下:“在 Steampipe 使用 aws_all 模式时,给我列出所有的 EC2 实例”。这样,Claude 更有可能使用 list_tables_in_schema 命令来限制检索到的表的数量。

预备条件

1. 安装 Steampipe

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

2. 启动 Steampipe 服务

作为后台服务启动 Steampipe:

steampipe service start

您可以使用以下命令验证服务是否正在运行:

steampipe service status

3. 获取数据库 URL

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:// 才能使服务器正常工作。

4. 配置环境变量

您可以使用环境变量配置数据库连接,而不是每次传递它:

  1. 在项目目录中创建一个 .env 文件,其中包含您的数据库 URL:

    STEAMPIPE_MCP_DATABASE_URL=postgresql://steampipe:password@localhost:9193/steampipe
    
  2. 服务器启动时会自动加载此配置。

5. 在 Claude Desktop 中安装

对于发布的版本,可以直接配置 Claude Desktop:

  1. 打开 Claude Desktop
  2. 导航至设置 > 开发者 > 编辑配置
  3. 将以下配置添加到 JSON 文件中:
{
  "mcpServers": {
    "steampipe": {
      "command": "uvx",
      "args": [
        "steampipe-mcp-server",
        "--database-url",
        "postgresql://steampipe:password@localhost:9193/steampipe"
      ]
    }
  }
}
  1. 保存配置文件并重新启动 Claude Desktop

用您的实际 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

或者,您可以:

  1. 克隆仓库
  2. 创建虚拟环境:uv venv
  3. 激活环境:source .venv/bin/activate(Linux/macOS)或 .venv\Scripts\activate(Windows)
  4. 安装开发依赖:uv pip install -e .[dev]

开发

使用 Makefile

项目包含一个带有常见任务的 Makefile:

# 在开发模式下运行服务器并带有 Inspector
make dev

# 运行测试
make test

# 运行代码检查
make lint

# 运行类型检查
make typecheck

# 格式化代码
make format

# 运行所有检查(代码检查和类型检查)
make check

# 在 Claude Desktop 中安装
make install-mcp

运行 make help 查看所有可用命令。

如何运行

1. 开发模式(推荐)

# 使用 make
make dev

# 或手动
mcp dev src/steampipe_mcp_server/cli.py

这将启动服务器和 MCP Inspector,允许您交互地测试 query 工具和其他工具。

2. 使用 CLI

安装后:

# 使用 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 环境变量。

贡献

  1. 分叉仓库
  2. 为您的功能创建一个新的分支
  3. 进行更改
  4. 运行测试和检查:make check test
  5. 提交拉取请求

发布

要发布新版本的包:

  1. 更新 pyproject.toml 中的版本

  2. 运行所有检查以确保一切正常:

    make check test
    
  3. 在 GitHub 上标记发布:

    git tag v0.1.0  # 使用适当的版本号
    git push origin v0.1.0