yakinikuk/swagger-mcp-server
3.1
If you are the rightful owner of swagger-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This project implements a Model Context Protocol (MCP) server that exposes an OpenAPI specification via the MCP protocol using stdio transport.
Tools
1
Resources
0
Prompts
0
Swagger MCP サーバー
このプロジェクトは、Model Context Protocol(MCP)サーバーを実装しており、OpenAPI 仕様書(swagger/sample.yaml
)を MCP プロトコル(stdio トランスポート)で公開します。@modelcontextprotocol/sdk
を使用して、MCP 対応クライアントから API メタデータ(パス・メソッド・リクエスト/レスポンスのスキーマなど)をクエリできます。
目次
前提条件
- Node.js v14 以上
- npm または yarn
- Linux/macOS/Windows 環境
インストール
# リポジトリをクローン(未取得時)
git clone <リポジトリのURL> api_div
cd api_div
# 依存パッケージをインストール
npm install
npm run build
以下の主要パッケージがインストールされます:
- js-yaml:YAML ファイルの読み込みと解析
- @modelcontextprotocol/sdk:MCP サーバー機能
- zod:入力パラメーターのバリデーション
- @apidevtools/json-schema-ref-parser:JSON Schema の
$ref
解決
開発用依存パッケージ:
- typescript:TypeScript コンパイラ
- @types/js-yaml、@types/node、@types/json-schema-ref-parser:型定義
プロジェクト構成
api_div/ # ルートワークスペース
├─ mcp-server/ # MCP サーバー実装
│ ├─ build/ # コンパイル済み出力(build/index.js)
│ ├─ src/ # ソースコード(index.ts など)
│ ├─ package.json
│ └─ tsconfig.json
├─ swagger/ # OpenAPI 仕様書
│ └─ sample.yaml
└─ api-service/ # 実際の API 実装プロジェクト(クライアントやバックエンド)
├─ src/ # サービス実装コード
├─ package.json
└─ tsconfig.json
VS Code MCP クライアントからの利用
- Model Context Protocol Client 拡張機能をインストール
- このワークスペースを VS Code で開く
- mcp.json ファイルを作成
{
"servers": {
"swagger": {
"command": "node",
"args": ["api_div/mcp-server/build/index.js"],
"env": {"SPEC_PATH": "api_div/swagger/sample.yaml"}
}
}
}
- MCP クライアントパネルから
swagger
サーバーを起動し、ツールリクエストを送信します(例:/users
,GET
)。
ツール: getEndpointInfo
MCP サーバーが提供するツールです:
- パラメーター:
path
: API URI(例:/users/{id}
)method
: HTTP メソッド(例:GET
,POST
)
- レスポンス:
description
: 要約または説明requestSchema
: リクエストボディの JSON スキーマresponses
: ステータスコード → スキーマ & 説明
MCP クライアント経由の例:
{ "method": "getEndpointInfo", "params": { "path": "/users", "method": "GET" } }
レスポンス:
{
"path": "/users",
"method": "GET",
"description": "Get all users",
"requestSchema": null,
"responses": { ... }
}