PostgreSQL Explorer MCP Server

PostgreSQL Explorer MCP Server

A FastMCP server for read-only introspection of PostgreSQL databases, providing tools to list databases, schemas, tables, columns, and relations.

Category
访问服务器

README

mcp-registry

A small, end-to-end walkthrough of the MLflow MCP Server Registry: build MCP servers with FastMCP, call them with a FastMCP client, then register them in MLflow so they are discoverable — with versions, access endpoints, and auto-discovered tools.

The repo has three moving parts:

Part Path What it does
MCP servers src/ Two FastMCP servers — a toy greeting server and a real PostgreSQL explorer
MCP clients clients/ Thin FastMCP clients that invoke tools over streamable HTTP
Registry utility mlflow_mcp_registry_util.py Registers servers with MLflow, refreshes their tools, lists access endpoints

Requirements

  • Python ≥ 3.13
  • An MLflow tracking server (v3.15+) running locally — the registry APIs are server-side
  • PostgreSQL, if you want to exercise the PostgreSQL server
  • uv (the repo ships a uv.lock)

Dependencies (pyproject.toml): fastmcp>=3.4.7, mlflow>=3.15.1, psycopg2 + psycopg2-binary, python-dotenv.

uv sync

Configuration

The PostgreSQL server reads its connection settings from a .env file in the repo root (loaded via python-dotenv). .env is gitignored — create your own:

PGHOST=localhost
PGPORT=5432
PGUSER=root
PGPASSWORD=root
PGSSLMODE=prefer
PGADMINDB=postgres
Variable Default Purpose
PGHOST localhost Server host
PGPORT 5432 Server port
PGUSER root Login role
PGPASSWORD root Password
PGSSLMODE prefer libpq SSL mode
PGADMINDB postgres Database used for server-wide queries (ListDatabases)

src/simple_server.py needs no configuration.


1. Start an MLflow tracking server

mlflow_mcp_registry_util.py points at http://127.0.0.1:5000. The repo already contains a mlflow.db (gitignored) from a SQLite-backed run:

uv run mlflow server --backend-store-uri sqlite:///mlflow.db --host 127.0.0.1 --port 5000

If your server lives elsewhere, edit the mlflow.set_tracking_uri(...) call at the top of mlflow_mcp_registry_util.py.


2. Run an MCP server

Both servers bind port 8000 over streamable HTTP (http://localhost:8000/mcp), so run one at a time — or change the port in the mcp.run(...) call.

Simple greeting server — two tools, Greeting and Sendoff:

uv run python src/simple_server.py

PostgreSQL explorer — read-only introspection of a live PostgreSQL server:

uv run python src/postgresql_mcp.py

Or via the FastMCP CLI:

uv run fastmcp run src/postgresql_mcp.py --transport http --port 8000

PostgreSQL tools

Tool Arguments Returns
ListDatabases — Non-template databases with owner and pretty-printed size
ListSchemas database User-defined schemas (system schemas and temp schemas excluded)
ListTables database, schema Tables and views in the schema, with table_type
ListTableColumns database, schema, table Column name, type, nullability, default — in ordinal order
ListTableRelations database, schema, table Foreign keys split into outgoing (this table → others) and incoming (others → this table)
ListSchemaRelations database, schema Flat edge list from_table.from_column → to_table.to_column for the whole schema — an ERD in list form

Every tool goes through _query(), which opens a fresh connection to the named database, runs a single parameterised SELECT through a RealDictCursor, and closes the connection. Nothing writes.


3. Call a server from a client

With a server running on port 8000:

uv run python clients/postgres_server_client.py   # calls ListDatabases, prints each database name
uv run python clients/simple_server_client.py     # calls the greeting tool with "Ford"

clients/postgres_server_client.py unwraps the FastMCP result: each item in result.content carries a JSON text payload, which it parses and reads database from.

Note: clients/simple_server_client.py calls client.call_tool("greet", ...), but the tool in src/simple_server.py is registered under the name Greeting (greet is only the Python function name). Use "Greeting" for the call to resolve.


4. Register servers with MLflow

mlflow_mcp_registry_util.py holds four coroutines, each demonstrating one registry API:

register_postgresql_mcp_server()

Registers a remote server — one that is already running and reachable over HTTP:

mlflow.genai.register_mcp_server(
    server_json={
        "name": "io.github.pavanjava/postgresql-server",
        "version": "0.1.0",
        "description": "PostgreSQL FastMCP server exposing DB tools",
        "remotes": [{"url": "http://localhost:8000/mcp", "type": "streamable-http"}],
    },
    status="active",
    source="local dev server via fastmcp",
    create_access_endpoints_from_remotes=True,
)

create_access_endpoints_from_remotes=True turns each entry in remotes into an MLflow access endpoint, so consumers can resolve a connection URL from the registry instead of hardcoding it.

register_qdrant_mcp_server()

Registers a packaged server instead — no running process required. The entry describes how to launch it (uvx mcp-server-qdrant over stdio) and declares its environment variables, including which are required and which are secret (QDRANT_API_KEY).

discover_tools()

Calls refresh_mcp_server_version_tools(...). MLflow connects to the registered server version, enumerates its tools, and persists them on the version — after which server_version.tools lists the discovered tool names. This requires the server to actually be reachable.

list_endpoints()

Calls search_mcp_access_endpoints(server_name=...) and prints each endpoint's URL, transport type, and the server version it resolves to.

Running it

The __main__ block runs one coroutine at a time; the rest are commented out. Uncomment the one you want:

if __name__ == "__main__":
    # asyncio.run(register_postgresql_mcp_server())
    asyncio.run(register_qdrant_mcp_server())
    # asyncio.run(discover_tools())
    # asyncio.run(list_endpoints())
uv run python mlflow_mcp_registry_util.py

Registered servers then show up under the MCP Servers section of the MLflow UI at http://127.0.0.1:5000.


Suggested end-to-end path

  1. Start MLflow on port 5000.
  2. Start the PostgreSQL MCP server on port 8000.
  3. Verify it answers: uv run python clients/postgres_server_client.py.
  4. Register it: uncomment register_postgresql_mcp_server() and run the util.
  5. Discover its tools: switch to discover_tools() and run again — the six tools above should print.
  6. Inspect its access endpoint: switch to list_endpoints().
  7. Browse the result in the MLflow UI.

Repository layout

.
├── src/
│   ├── simple_server.py        # FastMCP "My MCP Server" — Greeting + Sendoff tools
│   └── postgresql_mcp.py       # FastMCP "PostgreSQL Explorer" — 6 read-only introspection tools
├── clients/
│   ├── simple_server_client.py     # calls a tool on the greeting server
│   └── postgres_server_client.py   # calls ListDatabases and prints database names
├── mlflow_mcp_registry_util.py # MLflow MCP registry: register / refresh tools / list endpoints
├── pyproject.toml
└── uv.lock

mlflow.db, .env, .venv, and .idea are gitignored.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选