workbench-mcp
workbench-mcp
Fedora/Linuxシステム上での対話的なPostgreSQLデータ探索、API統合、および自動化のためのローカルPython MCPサーバー。
概要
バージョン1には以下が含まれます:
Fedora/Linuxシステム向けのPython仮想環境セットアップ
.envファイル経由で設定されるPostgreSQL 18接続以下のためのMCPツール:
テーブル、カラム、スキーマ構造の発見
読み取り専用クエリプレビューの実行
一時テーブルサポートを備えた保護されたSQLバッチの実行
PostgreSQLのストアド関数およびプロシージャの呼び出し
完全なURLリクエストによる外部APIへのアクセス
PATH内で利用可能なbashスクリプトの実行
安全性の強制:永続的なスキーマおよびデータの変更はブロックされます
SQLバッチ内でのセッションスコープの一時テーブルワークフローをサポート
Related MCP server: PostgreSQL MCP Server
Fedora / Linuxのセットアップ
まず、必要なシステムパッケージをインストールします:
sudo dnf install -y python3 python3-pip nodejs npmPython 3.12以降が必要です。複数のバージョンを管理する場合はpyenvなどを使用してください。
仮想環境のセットアップ
プロジェクトのルートから、Python仮想環境を作成して有効化します:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -e .環境変数
設定例をコピーし、PostgreSQLの接続詳細を入力します:
cp .env.example .env必須:
DB_HOST— PostgreSQLサーバーのホスト名DB_NAME— データベース名DB_USER— データベースユーザー名DB_PASSWORD— データベースパスワード
任意(チューニング):
DB_PORT— 接続ポート(デフォルト: 5432)DB_SSLMODE— SSLモード(デフォルト: prefer)DB_APPLICATION_NAME— アプリケーション識別子DB_QUERY_TIMEOUT_SECONDS— クエリタイムアウト(デフォルト: 30)DB_MAX_ROWS— 結果セットあたりの最大行数(デフォルト: 100)DB_MAX_RESULT_SETS— バッチあたりの最大結果セット数(デフォルト: 5)DB_OBJECT_PREVIEW_CHARS— 定義プレビューの最大長(デフォルト: 4000)
ローカル開発の例:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=app_dev
DB_USER=app_user
DB_PASSWORD=your-secure-password
DB_SSLMODE=prefer任意:HTTPリクエストのチューニング
HTTPツールは呼び出しごとに完全なURLを受け取り、APIプロファイルの設定は不要です。
サポートされている環境設定:
変数 | 目的 |
| HTTPリクエストのタイムアウト |
| HTTPツールによって返される最大レスポンスバイト数 |
|
|
| ツール呼び出しで |
|
|
呼び出しの形状例:
url: https://localhost:44331/api/breakouts/filter/1871161/dd-table?ParameterSetId=231022
method: GET認証が必要な呼び出しの場合、.env(またはプロセス環境変数)で API_BEARER_TOKEN を設定します。HTTPツールは、呼び出し元が独自の jwt_token を渡さない限り、自動的にこれを使用します。
認証の取り扱い
HTTPツールは2つの認証ソースをサポートしています:
ツール呼び出しで渡される
jwt_token.envまたはプロセス環境からのAPI_BEARER_TOKEN
優先順位
jwt_tokenが提供されている場合、そのトークンがAuthorization: Bearer <jwt_token>として転送されます。jwt_tokenが省略されているか空の場合、サーバーはAPI_BEARER_TOKENにフォールバックします。どちらの値も存在しない場合、リクエストは
Authorizationヘッダーなしで送信されます。
エージェントに対する重要なルール
headers.Authorization の中にベアラートークンを配置してはいけません。
MCPサーバーは headers から Authorization を取り除き、専用の jwt_token フィールドを通じた認証のみを受け付けます。
これにより、意図しないヘッダーの衝突を防ぎ、トークンの優先順位を明確にします。
例:デフォルトのサーバートークンを使用する
{
"url": "https://localhost:5001/api/v1/sales/my-sales"
}例:呼び出し元自身のトークンを転送する
{
"url": "https://localhost:5001/api/v1/sales/my-sales",
"jwt_token": "eyJhbGciOi..."
}例:追加ヘッダーと共に呼び出し元トークンを転送する
{
"url": "https://localhost:5001/api/v1/sales/my-sales",
"jwt_token": "eyJhbGciOi...",
"headers": {
"Accept": "application/json"
}
}同じ jwt_token フィールドが http_get、http_head、http_post、http_put、http_patch、および http_delete で利用可能です。
セッション認証
呼び出しごとに jwt_token を渡す代わりに、エージェントはセッションスコープのJWTを一度取得し、セッションの残りの期間、すべてのHTTPツール呼び出しで自動的にそれを使用させることができます。
仕組み
エージェントが対象ユーザーのメールアドレスを指定して
auth_start_sessionを呼び出します。MCPサーバーは、共有シークレット + メールアドレスをバックエンドブローカー (
POST /api/v1/mcp/exchange) からのスコープ付きJWTと交換します。トークンはプロセスメモリにキャッシュされます。
jwt_tokenを省略する以降のすべてのHTTPツール呼び出しは、自動的にセッショントークンを使用します。エージェントは
auth_statusでセッションを検査し、auth_switch_userでユーザーを切り替え、auth_clear_sessionでセッションをクリアできます。
トークンの優先順位(高 → 低)
優先度 | ソース |
1 | ツール呼び出しで渡された |
2 |
|
3 |
|
必要な環境変数
変数 | 目的 |
| バックエンドブローカーエンドポイントの完全なURL |
|
|
| 残り時間がN秒未満になったらリフレッシュする(デフォルト: 60) |
セッション認証ツール
ツール | 説明 |
| 指定されたメールアドレスのセッショントークンを取得する |
| アクティブなセッションを別のユーザーに切り替える(開始と同じ) |
| 現在のセッションを検査する(メール、有効期限、リフレッシュの必要性) |
| メモリからキャッシュされたセッショントークンをクリアする |
エージェント向けの完全なリファレンスについては、docs/SESSION_AUTH.md を参照してください。
ローカルでの実行
仮想環境を有効化し、依存関係をインストールした後、以下のいずれかのコマンドでMCPサーバーを起動します:
workbench-mcppython -m workbench_mcp.serverMCPインスペクター
ローカルでのMCP開発およびデバッグのために、MCPインスペクターが迅速な手動テストループを提供します:
npx @modelcontextprotocol/inspector .venv/bin/python -m workbench_mcp.serverインスペクターでブレークポイントデバッグを行うために debugpy の下でMCPサーバーを起動するには:
npx @modelcontextprotocol/inspector .venv/bin/python -m debugpy --listen 127.0.0.1:5678 -m workbench_mcp.server起動後、インスペクターUIを開き、STDIO 経由で接続し、health、describe_object、exec_proc_preview などのツールをテストします。
ブレークポイント (debugpy): デバッガーにはポート 5678 を使用してください。6274ではありません(6274はインスペクターのWeb UI専用です)。ステップバイステップのワークフローと「以前何が問題だったか」については docs/DEBUG_MCP.md に記載されています。
VS Codeのセットアップ
VS CodeにローカルMCPサーバーを登録するには、ワークスペースのMCP設定ファイルにエントリを追加します:
ワークスペースファイル:
.vscode/mcp.json
設定例:
{
"servers": {
"workbench-mcp": {
"type": "stdio",
"command": "/absolute/path/to/workbench-mcp/.venv/bin/python",
"args": ["-m", "workbench_mcp.server"]
}
}
}コマンドパスを、仮想環境のPythonへのローカルリポジトリパスに置き換えてください。
シークレットと環境値
環境値は以下のいずれかの場所に指定できます:
workbench-mcp/.env.vscode/mcp.json内のenv— VS CodeはこれらをMCPサーバープロセスに注入します。
優先順位: プロセス環境(.vscode/mcp.json → env を含む)は、同じキーに対して .env からの値を上書きします。
VS CodeでのHTTPチューニングの例:
{
"servers": {
"workbench-mcp": {
"type": "stdio",
"command": "/absolute/path/to/workbench-mcp/.venv/bin/python",
"args": ["-m", "workbench_mcp.server"],
"env": {
"API_TIMEOUT_SECONDS": "30",
"API_MAX_RESPONSE_BYTES": "2097152",
"API_VERIFY_SSL": "false"
}
}
}
}本物のトークンをコミットしてはいけません。ローカル専用のワークスペース設定を優先するか、env を省略して .env を使用してください(.env はgitから除外する必要があります)。
他のMCPサーバーが既に設定されている場合は、ファイル全体を置き換えるのではなく、既存の servers オブジェクト内に workbench-mcp を追加してください。
.vscode/mcp.json を保存した後、VS CodeをリロードするかMCPサーバーを更新して、新しいサーバーが検出されるようにします。サーバーが読み込まれたら、データベースプロシージャをテストする前に health ツールを実行してください。
初期ツール
healthdescribe_objectlist_tables_and_columnspreview_queryexecute_readonly_sqlexec_proc_previewexec_function_previewinsert_rowinsert_rowshttp_gethttp_headhttp_posthttp_puthttp_patchhttp_deleteauth_start_sessionauth_switch_userauth_statusauth_clear_sessionexecute_path_bash_script(スクリプト名はPATH経由で解決)
安全性モデル
永続的なDDLおよびDMLは、アドホックなPostgreSQLバッチではブロックされます
一時テーブルへの書き込みのみが許可されており、現在のバッチで作成された一時テーブルに対してのみ可能です
preview_queryはSELECT文とCTEベースの読み取りのみを許可しますexec_proc_previewはPostgreSQLのプロシージャと関数を実行できます。オーバーロードされたルーチンはpublic.my_func(integer, text)のようなシグネチャで渡す必要がありますexecute_path_bash_scriptはスクリプト名のみを受け付け(パスは不可)、PATH経由で解決し、bashを通じて実行します
推奨される最初のチェック
.env が設定された後の典型的な検証フローは以下の通りです:
検査対象の関数、プロシージャ、テーブル、またはビューを記述(describe)します。
そのオブジェクトを理解するために必要な設定や参照データをプレビューします。
既知の入力を使用して
exec_proc_preview、preview_query、またはexecute_readonly_sqlを実行します。返された形状を、評価中の機能、調査、またはデバッグシナリオと比較します。
関数実行の例
位置指定のPostgreSQL関数呼び出しには exec_function_preview を使用します。
PostgreSQLの配列は通常のJSONリストとして渡します。
SQLターゲットの例:
select * from sales."Fn_GetSalesChamps"(2, 2025, array[1,2,5,6,7,8,9,10,11,12,15,16,18,19], 5);同等のMCPツール入力:
{
"function_name": "sales.\"Fn_GetSalesChamps\"",
"parameters": [2, 2025, [1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 18, 19], 5]
}挿入の例
単一行の挿入:
{
"table_name": "sales.orders",
"row": {
"customer_id": 10,
"status": "new"
},
"returning_columns": ["order_id"]
}バッチ挿入:
{
"table_name": "sales.orders",
"rows": [
{"customer_id": 10, "status": "new"},
{"customer_id": 11, "status": "pending"}
]
}Available Tools
19 toolsauth_clear_sessionA
Clear the active session token from memory.
After this call HTTP tools will fall back to API_BEARER_TOKEN (if
configured) or make unauthenticated requests.
Returns
dict
{"ok": True, "message": "Session cleared."}.
Inputs: no named parameters. Returns: object
auth_start_sessionA
Acquire a session-scoped JWT for email from the backend broker.
After a successful call every HTTP tool call in this session will
automatically use the returned token (unless the tool call provides
its own jwt_token).
Parameters
email: The user whose identity the MCP session will impersonate. reason: Optional free-text description of why this session is needed. Stored in the JWT claims for audit purposes.
Returns
dict
ok=True with email, display_name, user_name,
store on success; ok=False with error on failure.
Inputs: email (required), reason. Returns: object
auth_statusA
Return the current session status without exposing the raw token.
Returns
dict
active=False when no session is set; otherwise active=True
with email, display_name, expires_in_seconds, and
needs_refresh.
Inputs: no named parameters. Returns: object
auth_switch_userA
Switch the active session to a different user.
Equivalent to calling auth_start_session — provided as a semantic
alias when the intent is to change the active user rather than start a
fresh session.
Parameters
email: The new user to impersonate. reason: Optional free-text description of why the switch is needed.
Returns
dict
Same shape as auth_start_session.
Inputs: email (required), reason. Returns: object
describe_objectB
Retrieve structural details, parameters, and definition for a database object.
Inputs: object_name (required). Returns: object
exec_function_previewA
Execute a PostgreSQL function with positional parameters and return preview rows.
Use this tool for function calls such as
sales."Fn_GetSalesChamps"(2, 2025, ARRAY[1,2,5], 5).
Pass arguments in positional order using JSON-compatible values:
scalars:
2,2025,5arrays:
[1, 2, 5]null:
null
PostgreSQL array parameters should be passed as normal lists; psycopg adapts them to PostgreSQL arrays automatically.
Inputs: function_name (required), parameters, max_rows. Returns: object
exec_proc_previewB
Execute PostgreSQL functions or procedures with optional parameters and result limiting.
Inputs: proc_name (required), parameters, max_rows. Returns: object
execute_readonly_sqlC
Execute read-only SQL batches with support for temporary tables within the session.
Inputs: sql (required), max_rows. Returns: object
healthB
Provide system status and configuration details without exposing secrets.
Inputs: no named parameters. Returns: object
http_deleteA
Send an HTTP DELETE request.
Use for delete operations. Some APIs allow delete payloads; if needed,
provide body as JSON object/array or UTF-8 text.
Pass jwt_token to forward the caller's JWT for this request only.
Inputs: url (required), body, content_type, headers, +1 more. Returns: object
http_getA
Send an HTTP GET request.
Use for read-only resource retrieval. Provide a full URL.
Pass jwt_token to forward the caller's JWT for this request only.
If jwt_token is omitted, API_BEARER_TOKEN is used when configured.
headers.Authorization is ignored; use jwt_token instead.
Inputs: url (required), headers, jwt_token. Returns: object
http_headA
Send an HTTP HEAD request.
Use for metadata/status checks without retrieving a full body.
Pass jwt_token to override the default environment token for this call.
headers.Authorization is ignored; use jwt_token instead.
Inputs: url (required), headers, jwt_token. Returns: object
http_patchA
Send an HTTP PATCH request.
Use for partial updates.
body accepts JSON object/array or UTF-8 text.
Pass jwt_token to forward the caller's JWT for this request only.
Inputs: url (required), body, content_type, headers, +1 more. Returns: object
http_postA
Send an HTTP POST request.
Use for create/actions. Provide a full URL.
body accepts JSON object/array or UTF-8 text.
content_type optionally overrides the Content-Type header.
Pass jwt_token to forward the caller's JWT for this request only.
Inputs: url (required), body, content_type, headers, +1 more. Returns: object
http_putA
Send an HTTP PUT request.
Use for full updates/replacements.
body accepts JSON object/array or UTF-8 text.
Pass jwt_token to forward the caller's JWT for this request only.
Inputs: url (required), body, content_type, headers, +1 more. Returns: object
insert_rowA
Insert a single row into a PostgreSQL table.
Use this tool when you need one explicit insert with structured values.
table_name: table target, optionally schema-qualifiedrow: object mapping column names to valuesreturning_columns: optional list of columns to return viaRETURNING
Example:
table_name:sales.ordersrow:{ "customer_id": 10, "status": "new" }returning_columns:["order_id"]
Inputs: table_name (required), row (required), returning_columns. Returns: object
insert_rowsA
Insert multiple rows into a PostgreSQL table in one batch.
Use this tool for bulk inserts where every row has the same columns.
table_name: table target, optionally schema-qualifiedrows: list of objects mapping column names to valuesreturning_columns: optional list of columns to return from inserted rows
Notes:
Every row must use the same columns in the same order.
Arrays can be passed as JSON lists and psycopg adapts them automatically.
Inputs: table_name (required), rows (required), returning_columns. Returns: object
list_tables_and_columnsB
Discover tables and columns with optional filtering by schema or keyword search.
Inputs: schema_name, search_term, limit. Returns: object
preview_queryA
Execute read-only SELECT statements and CTEs with safety validation and row limits.
Inputs: sql (required), max_rows. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 19 tools
Most tools have distinct purposes, but there is some overlap between exec_function_preview and exec_proc_preview, which both execute PostgreSQL functions/procedures with similar parameters. The HTTP tools (http_get, http_post, etc.) are clearly differentiated by HTTP method, and auth tools are well-separated. Overall, the descriptions help clarify boundaries, but the function/procedure execution tools could cause confusion.
Tool names follow a highly consistent snake_case pattern with clear verb_noun structures. Auth tools use auth_ prefix (e.g., auth_clear_session), HTTP tools use http_ prefix (e.g., http_get), and database tools use descriptive verbs like describe_, exec_, insert_, list_, preview_. There are no deviations in naming style across the set.
With 19 tools, the count is slightly high but reasonable for a workbench server that combines authentication, HTTP operations, and database interactions. It covers multiple domains comprehensively without being excessive. A few tools might be consolidated (e.g., the two function execution tools), but overall the scope justifies the number.
The toolset provides complete coverage for its intended domains: authentication (session management), HTTP operations (full CRUD via different methods), and PostgreSQL database interactions (querying, inserting, describing objects, executing functions). There are no obvious gaps; agents can perform end-to-end workflows involving data retrieval, manipulation, and API calls with proper auth handling.
Maintenance
Related MCP Connectors
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Hosted PostgreSQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn 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.11 npmMIT
- AlicenseAqualityCmaintenanceFull-featured MCP server that exposes 36 tools for interacting with PostgreSQL databases, covering schema introspection, query execution, data exploration, performance monitoring, security auditing, and maintenance.367 npmMIT
- AlicenseNot gradedqualityDmaintenanceA Python MCP server that provides PostgreSQL database connectivity for Text-to-SQL workflows, enabling AI agents to explore schemas and execute parameterized SQL queries across multiple data marts.MIT
- AlicenseNot gradedqualityCmaintenanceA Python MCP server that enables schema discovery, read-only SQL queries, table previews, and index/relationship analysis on PostgreSQL databases.1MIT