Skip to main content
Glama
pavanjava

PostgreSQL Explorer MCP Server

by pavanjava

mcp-registry

MLflow MCP Server Registry のエンドツーエンドの簡易ウォークスルーです。FastMCP で MCP サーバーを構築し、FastMCP クライアントで呼び出し、MLflow に登録して、バージョン、アクセスエンドポイント、自動検出されたツールと共に検出可能にします。

このリポジトリには 3 つのコンポーネントがあります:

コンポーネント

パス

説明

MCP サーバー

src/

2 つの FastMCP サーバー — おもちゃの挨拶サーバーと実際の PostgreSQL エクスプローラー

MCP クライアント

clients/

ストリーミング可能な HTTP 上でツールを呼び出す薄い FastMCP クライアント

レジストリユーティリティ

mlflow_mcp_registry_util.py

サーバーを MLflow に登録し、ツールを更新し、アクセスエンドポイントを一覧表示する


要件

  • Python ≥ 3.13

  • ローカルで実行中の MLflow トラッキングサーバー(v3.15+) — レジストリ API はサーバーサイドにあります

  • PostgreSQL(PostgreSQL サーバーを試す場合)

  • uv(リポジトリには uv.lock が同梱されています)

依存関係(pyproject.toml): fastmcp>=3.4.7mlflow>=3.15.1psycopg2 + psycopg2-binarypython-dotenv

uv sync

Related MCP server: postgres-mcp-readonly

設定

PostgreSQL サーバーは、リポジトリルートの .env ファイルから接続設定を読み取ります(python-dotenv 経由で読み込み)。.env は gitignore されています — 自分で作成してください:

PGHOST=localhost
PGPORT=5432
PGUSER=root
PGPASSWORD=root
PGSSLMODE=prefer
PGADMINDB=postgres

変数

デフォルト

目的

PGHOST

localhost

サーバーホスト

PGPORT

5432

サーバーポート

PGUSER

root

ログインロール

PGPASSWORD

root

パスワード

PGSSLMODE

prefer

libpq SSL モード

PGADMINDB

postgres

サーバー全体のクエリ(ListDatabases)に使用するデータベース

src/simple_server.py は設定不要です。


1. MLflow トラッキングサーバーを起動する

mlflow_mcp_registry_util.pyhttp://127.0.0.1:5000 を指しています。リポジトリにはすでに SQLite バックアップの実行から mlflow.db(gitignore されています)が含まれています:

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

サーバーが別の場所にある場合は、mlflow_mcp_registry_util.py の先頭にある mlflow.set_tracking_uri(...) 呼び出しを編集してください。


2. MCP サーバーを実行する

両方のサーバーは、ストリーミング可能な HTTP(http://localhost:8000/mcp)で ポート 8000 にバインドするため、一度に 1 つずつ実行するか、mcp.run(...) 呼び出しでポートを変更してください。

シンプルな挨拶サーバー — 2 つのツール、GreetingSendoff:

uv run python src/simple_server.py

PostgreSQL エクスプローラー — 実行中の PostgreSQL サーバーへの読み取り専用イントロスペクション:

uv run python src/postgresql_mcp.py

または FastMCP CLI 経由:

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

PostgreSQL ツール

ツール

引数

戻り値

ListDatabases

テンプレート以外のデータベースを所有者と整形されたサイズと共に

ListSchemas

database

ユーザー定義スキーマ(システムスキーマと一時スキーマを除く)

ListTables

databaseschema

スキーマ内のテーブルとビュー、table_type を含む

ListTableColumns

databaseschematable

列名、型、NULL 許容性、デフォルト値 — 順序順

ListTableRelations

databaseschematable

外部キーを outgoing(このテーブル→他テーブル)と incoming(他テーブル→このテーブル)に分割したもの

ListSchemaRelations

databaseschema

スキーマ全体のフラットなエッジリスト from_table.from_column → to_table.to_column — リスト形式の ERD

すべてのツールは _query() を経由し、名前付きデータベースへの新しい接続を開き、RealDictCursor を通して単一のパラメータ化された SELECT を実行し、接続を閉じます。書き込みは行いません。


3. クライアントからサーバーを呼び出す

ポート 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 は FastMCP の結果を展開します: result.content の各アイテムには JSON text ペイロードが含まれており、それを解析して database を読み取ります。

注: clients/simple_server_client.pyclient.call_tool("greet", ...) を呼び出しますが、src/simple_server.py のツールは Greeting という名前で登録されています(greet は Python 関数名にすぎません)。呼び出しを解決するには "Greeting" を使用してください。


4. サーバーを MLflow に登録する

mlflow_mcp_registry_util.py には 4 つのコルーチンがあり、それぞれが 1 つのレジストリ API を示しています:

register_postgresql_mcp_server()

リモート サーバー — すでに実行中で 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 により、remotes 内の各エントリが MLflow アクセスエンドポイント に変換され、コンシューマーは接続 URL をハードコーディングする代わりにレジストリから解決できるようになります。

register_qdrant_mcp_server()

代わりに パッケージ化された サーバーを登録します — 実行中のプロセスは不要です。エントリは起動方法(uvx mcp-server-qdrant over stdio)を記述し、環境変数(必要なものと秘密のもの(QDRANT_API_KEY)を含む)を宣言します。

discover_tools()

refresh_mcp_server_version_tools(...) を呼び出します。MLflow は登録されたサーバーバージョンに接続し、そのツールを列挙し、バージョンに永続化します。その後、server_version.tools に検出されたツール名がリストされます。これにはサーバーが実際に到達可能である必要があります。

list_endpoints()

search_mcp_access_endpoints(server_name=...) を呼び出し、各エンドポイントの URL、トランスポートタイプ、および解決されるサーバーバージョンを出力します。

実行方法

__main__ ブロックは一度に 1 つのコルーチンを実行し、残りはコメントアウトされています。必要なコルーチンのコメントを解除してください:

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

登録されたサーバーは、MLflow UI の MCP Servers セクション(http://127.0.0.1:5000)に表示されます。


推奨エンドツーエンドパス

  1. ポート 5000 で MLflow を起動します。

  2. ポート 8000 で PostgreSQL MCP サーバーを起動します。

  3. 応答を確認: uv run python clients/postgres_server_client.py

  4. 登録: register_postgresql_mcp_server() のコメントを解除してユーティリティを実行します。

  5. ツールを検出: discover_tools() に切り替えて再度実行 — 上記の 6 つのツールが表示されるはずです。

  6. アクセスエンドポイントを検査: list_endpoints() に切り替えます。

  7. MLflow UI で結果を参照します。


リポジトリレイアウト

.
├── 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、および .idea は gitignore されています。

F
license - not found
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    D
    maintenance
    An open-source MCP server for PostgreSQL schema introspection and guarded read-only queries. It enables MCP clients to discover schemas, tables, columns, indexes, relationships, and safe queryable data from a configured PostgreSQL database.
    13
    MIT
  • A
    license
    A
    quality
    B
    maintenance
    MCP server for PostgreSQL that enables safe read-only database queries, table schema inspection, and query execution planning.
    6
    34
    BSD 3-Clause

View all related MCP servers

Related MCP Connectors

  • MCP server for managing Prisma Postgres.

  • MCP server for interacting with the Supabase platform

  • A basic MCP server to operate on the Postman API.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pavanjava/mcp_course'

If you have feedback or need assistance with the MCP directory API, please join our Discord server