Module: Pgbus::MCP::Server

Defined in:
lib/pgbus/mcp/server.rb

Overview

Assembles the read-only pgbus diagnostic MCP server: registers every diagnostic tool and wires a DataSource (plus the payload gate) into the server context so tools never touch the database directly or leak payloads by default.

This class only builds the MCP::Server instance — transport is the caller’s concern (Runner drives stdio). Keeping them separate means the same server can later be mounted over HTTP without changing tool code.

Constant Summary collapse

TOOLS =

The fixed, curated tool set. No arbitrary-SQL tool, no mutation tool —adding one here would violate the issue #180 security contract.

[
  Tools::HealthTool,
  Tools::QueuesTool,
  Tools::QueueDetailTool,
  Tools::ProcessesTool,
  Tools::JobsTool,
  Tools::JobDetailTool,
  Tools::DlqTool,
  Tools::DlqDetailTool,
  Tools::LocksTool,
  Tools::ThroughputTool,
  Tools::StatsTool,
  Tools::RecurringTool
].freeze
INSTRUCTIONS =
<<~TEXT
  Read-only diagnostic tools for a pgbus (PostgreSQL/PGMQ) deployment.
  Start with pgbus_health for a one-call OK/DEGRADED/STALLED verdict,
  then drill in with pgbus_queues, pgbus_processes, pgbus_jobs,
  pgbus_dlq, and pgbus_locks. No tool mutates state. Message payloads
  are redacted unless the server was started with payloads explicitly
  allowed.
TEXT

Class Method Summary collapse

Class Method Details

.build(data_source: Pgbus::Web::DataSource.new, allow_payloads: false) ⇒ Object

Build an MCP::Server with all diagnostic tools registered.

Parameters:

  • data_source (Pgbus::Web::DataSource) (defaults to: Pgbus::Web::DataSource.new)

    read layer the tools query.

  • allow_payloads (Boolean) (defaults to: false)

    when true, tools honor a per-call include_payloads flag; otherwise payloads are always redacted.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pgbus/mcp/server.rb', line 47

def build(data_source: Pgbus::Web::DataSource.new, allow_payloads: false)
  ::MCP::Server.new(
    name: "pgbus",
    title: "Pgbus Diagnostics",
    version: Pgbus::VERSION,
    instructions: INSTRUCTIONS,
    tools: TOOLS.dup,
    server_context: {
      data_source: data_source,
      allow_payloads: allow_payloads
    }
  )
end