API Docs MCP について
API Docs MCPは、ローカルファイルやリモートURLからGraphQL、OpenAPI/Swagger、gRPCのドキュメントを読み込み、API定義の検索に利用できます。スキーマをキャッシュして定期更新し、2つのツールでメソッド一覧と詳細を提供します。
主な機能
- 01GraphQL、OpenAPI/Swagger、gRPCに対応
- 02ローカルファイルまたはリモートURLを読み込み
- 03利用可能なAPIメソッドの一覧表示
- 04メソッド定義の詳細取得
- 05スキーマのキャッシュと定期更新
活用シーン
- 01設定したAPIのメソッド確認
- 02エンドポイントのリクエストとレスポンス構造の検索
- 03複数のスキーマソースにまたがるドキュメント検索
MCP 対応
MCPクライアント向けに、APIメソッド一覧を取得する`api_docs`と詳細を検索する`api_search`を提供します。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
ツール
2掲載時のツール一覧 · 2 週間前に更新
| パラメーター | 型 | 必須 | 説明 |
|---|---|---|---|
| sourceName | string | いいえ | MCP 設定環境変数で指定された API ソース名(例:"GitHub")。指定しない場合は、すべてのソースのドキュメントが返されます。 |
詳細
API Docs MCP
API ドキュメントとやり取りするためのツールを提供する Model Context Protocol(MCP)サーバーです。GraphQL、OpenAPI/Swagger、gRPC の仕様に対応し、さまざまなソース(ローカルファイルまたはリモート URL)からスキーマ定義を取得してキャッシュし、一連のツールを通じて公開します。
目次
MCP プラットフォーム
機能
- ツールの動的登録:指定されたディレクトリからツールを自動的に検出して登録します。
- API ドキュメントの取得:利用可能な API メソッドの一覧表示(
api_docs)と、特定のメソッドの詳細なドキュメント取得(api_search)を行うツールを提供します。 - スキーマのキャッシュ:API スキーマ情報をキャッシュし、重複した取得を減らしてパフォーマンスを向上させます。
- 複数ソースへの対応:
- GraphQL:
graphql/gqlファイル、またはjsonのイントロスペクション結果から GraphQL スキーマを読み込めます(ローカルファイルまたはリモート URL)。 - OpenAPI/Swagger:ローカルファイルまたはリモート URL から OpenAPI/Swagger の
yaml/yml/jsonスキーマを読み込めます。 - gRPC:
protoファイル、またはリモート URL からの gRPC リフレクションを通じて gRPC スキーマを読み込めます。
- GraphQL:
- 環境変数による設定:
API_SOURCES環境変数を使って API ソースを設定でき、柔軟なデプロイと管理が可能です。 - キャッシュの自動更新:スキーマデータのキャッシュを定期的に更新し、ドキュメントを最新の状態に保ちます。
ユースケースの例
OpenAPI Petstore ドキュメントの取得
GraphQL ドキュメントの取得
複数ソースからのドキュメント取得
アーキテクチャ
api-docs-mcp プロジェクトは、さまざまな API ドキュメントソースと連携する MCP サーバーとして設計されています。
graph TD
mcpServer[MCP Server] e1@--> tools(Tools:<br/>api_docs / api_search);
tools e2@--> cacheManager{Cache Manager};
cacheManager e3@--> configuration[Configuration:<br/>API_SOURCES env var];
configuration e4@--> schemaSources{Schema Sources};
schemaSources e5@-- FileSource--> localFiles(Local Files:<br/>.graphql, .json, .yaml, .proto);
schemaSources e6@-- UrlSource--> remoteUrls(Remote URLs:<br/>GraphQL Endpoints, OpenAPI/Swagger Endpoints, gRPC Endpoints);
localFiles e7@--> processor[Schema Processors];
remoteUrls e8@--> processor;
processor e9@--> cacheManager;
processor e10@--> openAPIProcessor(OpenAPI Processor:<br/>OpenAPI/Swagger);
processor e11@--> graphQLProcessor(GraphQL Processor);
processor e12@--> grpcProcessor(gRPC Processor)
cacheManager e13@--Cached Data--> tools;
subgraph Core Components
mcpServer
tools
cacheManager
configuration
end
subgraph Data Flow
schemaSources
localFiles
remoteUrls
processor
openAPIProcessor
graphQLProcessor
grpcProcessor
end
e1@{ animate: true }
e2@{ animate: true }
e3@{ animate: true }
e4@{ animate: true }
e5@{ animate: true }
e6@{ animate: true }
e7@{ animate: true }
e8@{ animate: true }
e9@{ animate: true }
e10@{ animate: true }
e11@{ animate: true }
e12@{ animate: true }
e13@{ animate: true }
処理の流れ:
- サーバーの初期化:エントリーポイントの
index.tsが MCP サーバーを初期化し、src/toolsディレクトリで定義されているツールを動的に登録します。 - 設定の読み込み:
CacheManagerは、src/utils/config.tsを介してAPI_SOURCES環境変数から API ソースの設定を読み込みます。 - スキーマの取得とキャッシュ:
- 設定されたソース(ファイルベースまたは URL ベース)に応じて、
CacheManagerが API スキーマを取得します。 - ファイルソースの場合、ローカルファイル(
graphql、gql、json、yaml、yml、proto)を読み込みます。 - URL ソースの場合、GraphQL、OpenAPI、または gRPC エンドポイントに HTTP リクエストを送信します。
- その後、スキーマは専用のハンドラー(OpenAPI 用の
src/api/api.ts、GraphQL 用のsrc/gql/gql.ts、gRPC 用のsrc/grpc/grpc.ts)で処理されます。 - 処理されたドキュメントは、指定された TTL(有効期間)でインメモリキャッシュ(
src/utils/cache.ts)に保存されます。 - キャッシュは定期的に更新されます。
- 設定されたソース(ファイルベースまたは URL ベース)に応じて、
- ツールの使用:
api_docs:呼び出されると、キャッシュから利用可能なすべての API リソースの一覧を取得します。sourceが指定されている場合は、それで絞り込みます。api_search:detailNameを指定して呼び出すと、キャッシュから特定の API リソースの詳細ドキュメント(リクエスト、レスポンス、エラー構造)を返します。
インストール
api-docs-mcp サーバーをセットアップするには、次の手順に従ってください。
-
リポジトリをクローンします:
git clone https://github.com/EliFuzz/api-docs-mcp.git cd api-docs-mcp -
依存関係をインストールします:
pnpm install -
プロジェクトをビルドします:
pnpm build
設定
サーバーの動作は API_SOURCES 環境変数によって制御されます。この変数には、SchemaSource オブジェクトの配列を表す JSON 文字列を指定します。各 SchemaSource は、FileSource または UrlSource のいずれかです。
FileSource の例
ローカルの GraphQL スキーマの場合:
{
"name": "MyGraphQLFile",
"path": "/path/to/your/schema.graphql",
"type": "gql"
}
ローカルの OpenAPI JSON スキーマの場合:
{
"name": "MyOpenAPIFile",
"path": "/path/to/your/openapi.json",
"type": "api"
}
ローカルの gRPC proto ファイルの場合:
{
"name": "MyGrpcFile",
"path": "/path/to/your/service.proto",
"type": "grpc"
}
UrlSource の例
リモートの GraphQL エンドポイントの場合:
{
"name": "GitHubGraphQL",
"method": "POST",
"url": "https://api.github.com/graphql",
"headers": {
"Authorization": "Bearer YOUR_GITHUB_TOKEN"
},
"type": "gql"
}
リモートの OpenAPI エンドポイントの場合:
{
"name": "PetstoreAPI",
"method": "GET",
"url": "https://petstore.swagger.io/v2/swagger.json",
"type": "api"
}
リフレクションを使用するリモートの gRPC エンドポイントの場合:
{
"name": "MyGrpcService",
"url": "grpc://localhost:9090",
"type": "grpc"
}
API_SOURCES 環境変数の設定
サーバーの実行前に、シェルで設定できます。
export API_SOURCES='[{"name": "MyGraphQLFile", "path": "./example/fixtures/graphql/graphql-schema.graphql", "type": "gql"}, {"name": "PetstoreAPI", "method": "GET", "url": "https://petstore.swagger.io/v2/swagger.json", "type": "api"}]'
または、MCP の実行用に mcp.json で設定できます。
"api-docs-mcp": {
"type": "stdio",
"command": "npx",
"args": [ "api-docs-mcp" ],
"env": {
"API_SOURCES": "[{\"name\": \"MyGraphQLFile\", \"path\": \"./example/fixtures/graphql/graphql-schema.graphql\", \"type\": \"gql\"}, {\"name\": \"PetstoreAPI\", \"method\": \"GET\", \"url\": \"https://petstore.swagger.io/v2/swagger.json\", \"type\": \"api\"}]"
}
}
使用方法
設定して実行すると、api-docs-mcp サーバーは主要なツールとして api_docs と api_search を提供します。
API Docs ツール
このツールは、設定されたソースから利用可能なすべての API メソッドの一覧を返します。
名前:api_docs
説明:利用可能なすべての API メソッドの一覧を取得します。
入力スキーマ:
{
sourceName?: string; // The name of the API source (e.g., "GitHub") from MCP configuration environment variables. If not provided, docs from all sources will be returned.
}
出力スキーマ:
{
sources: Array<{
sourceName: string; // The name of the source API
resources: Array<{
resourceName: string; // The name of the API resource
resourceType: string; // The type of the API resource (e.g., "POST", "GET", "mutation", "query")
resourceDescription: string; // A brief description of the API resource
}>;
}>;
}
出力例:
{
"sources": [
{
"sourceName": "GitHubGraphQL",
"resources": [
{
"resourceName": "getUser",
"resourceType": "query",
"resourceDescription": "Fetch a user by username"
},
{
"resourceName": "createIssue",
"resourceType": "mutation",
"resourceDescription": "Create a new issue in a repository"
}
]
},
{
"sourceName": "PetstoreAPI",
"resources": [
{
"resourceName": "getPetById",
"resourceType": "GET",
"resourceDescription": "Find pet by ID"
},
{
"resourceName": "addPet",
"resourceType": "POST",
"resourceDescription": "Add a new pet to the store"
}
]
}
]
}
API Search ツール
このツールは、特定の API メソッドの詳細なドキュメントを返します。
名前:api_search
説明:名前で特定の API メソッドを検索し、その完全な定義を取得します。
入力スキーマ:
{
resourceName: string; // The exact resource name of the API method to search for that was provided in `api_docs` tool's output
}
出力スキーマ:
{
details: Array<{
sourceName: string; // The name of the source API
resources: Array<{
resourceName: string; // The name of the resource
resourceType: "query" | "mutation" | "subscription"; // The type of GraphQL resource
resourceDescription: string; // Context or description of the resource
details: {
request?: string; // The request structure or input parameters for the API method
response?: string; // The response structure or output format for the API method
error?: string; // Error information or error handling details for the API method
};
}>;
}>;
}
出力例:
{
"details": [
{
"sourceName": "GitHubGraphQL",
"resources": [
{
"resourceName": "getUser",
"resourceType": "query",
"resourceDescription": "Fetch a user by username",
"details": {
"request": "{ username: String! }",
"response": "{ id: ID!, login: String!, name: String }",
"error": "{ message: String!, code: Int! }"
}
}
]
}
]
}
開発
サーバーをローカルで実行する
-
設定のセクションで説明されているとおりに、
API_SOURCES環境変数を設定します。 -
サーバーを起動します:
pnpm start
サーバーは StdioServerTransport に接続し、標準入力/出力を介して通信します。
プロジェクト構成
.
├── src/
│ ├── api/ # OpenAPI/Swagger schema processing
│ │ └── api.ts
│ ├── gql/ # GraphQL schema processing
│ │ └── gql.ts
│ ├── grpc/ # gRPC schema processing
│ │ └── grpc.ts
│ ├── tools/ # MCP tools definitions
│ │ ├── api_docs.ts
│ │ └── api_search.ts
│ ├── utils/ # Utility functions (cache, config, fetch, file, source)
│ │ ├── cache.ts
│ │ ├── config.ts
│ │ ├── fetch.ts
│ │ ├── file.ts
│ │ └── source.ts
│ ├── index.ts # Main entry point
│ └── server.ts # MCP server setup and tool registration
└── package.json # Project dependencies and scripts
└── README.md # This file
貢献
貢献を歓迎します!お気軽にイシューを作成するか、プルリクエストを送信してください。
ライセンス
このプロジェクトは Apache 2.0 ライセンスのもとでライセンスされています。詳細は LICENSE ファイルをご覧ください。
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。