mcpField
M
MCP Spectral

MCP Spectral

ローカル
github.com/mark-sivill開発ツール169 週間前に更新

MCP Spectral について

MCP Spectralは、Spectral CLIをDocker内で動かすMCPサーバーです。OpenAPI仕様の検査やルールセット指定の検査、Spectralのバージョン確認をLLMから利用できます。

主な機能

  1. 01OpenAPI仕様のリント
  2. 02指定ルールセットでのリント
  3. 03Spectralバージョンの確認
  4. 04Docker経由での実行

活用シーン

  1. 01OpenAPI仕様の問題を検出
  2. 02チームのルールに沿ってAPI定義を検証
  3. 03利用中のSpectralバージョンを確認

MCP 対応

MCPクライアントにOpenAPIのリントとSpectralバージョン確認のツールを公開し、LLMからSpectralを実行できるようにします。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

mcp.json · 共通設定
{
"mcpServers": {
"spectral": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"marksivill/mcp-spectral"
]
}
}
}
起動コマンドdocker run -i --rm marksivill/mcp-spectral

ローカルサーバーにはマシン上の実行環境(Node.js 18 以上など)が必要です。設定ファイルの場所はクライアントごとに異なります。

パッケージ
ocimarksivill/mcp-spectral

ツール

ツール一覧はまだ取得されていません

ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。

詳細

MCP Spectral

OpenAPI 仕様をリンティングする Spectral 用の Model Context Protocol(MCP)サーバー

概要

Model Context Protocol(MCP)サーバーを使用して、大規模言語モデル(LLM)がOpenAPI 仕様の有効性を確認できるようにします。

MCP Spectral サーバーは、Docker イメージ内で Spectral のコマンドラインをラップします。

OpenAPI 仕様を使って API を記述すると、API 間で一貫性を保ち、API をドキュメント化し、API の使用方法に関する契約を定め、API の利用側と提供側のコードスタブを生成し、API のバージョン管理を行えます。これらの機能により、API 開発の迅速化、API サービスの導入促進、API 保守の負担軽減が可能になります。

MCP Spectral を使用すると、OpenAPI 仕様の作成段階を支援し、API 開発にかかる時間をさらに短縮できます。

利用可能なツール

MCP Spectral が提供するツール

  • lint_openapi - OpenAPI 仕様をリンティングします
  • lint_openapi_with_ruleset - Spectral ルールセットを使って OpenAPI 仕様をリンティングします
  • spectral_version - 使用中の Spectral のバージョンを返します

セットアップ手順

この手順では、Anthropic の Claude Desktop が MCP Spectral サーバーとやり取りすることを想定しています。別の大規模言語モデルツールを使用する場合は、それに応じてセットアップ手順を変更してください。

インストールの前提条件

ローカルマシンに以下のアプリケーションがインストールされていることを確認してください。

Claude Desktop の更新

Claude Desktop に MCP Spectral へのアクセス方法を伝えるため、Claude Desktop のインストール先にある claude_desktop_config.json ファイルに以下を追加してください。

{
  "mcpServers": {
    "OpenAPI linting (Spectral)": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "marksivill/mcp-spectral"
      ]
    }
  }
}

たとえば、MCP Spectral とともに mcp/fetch もインストールする場合、claude_desktop_config.json の全体は次のようになります。

{
  "mcpServers": {
    "fetch": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "mcp/fetch"
      ]
    },
    "OpenAPI linting (Spectral)": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "marksivill/mcp-spectral"
      ]
    }
  }
}

ファイルを更新したら、Claude Desktop を再起動してください。

Claude Desktop は、Docker Hub から MCP Spectral の最新 Docker バージョンを自動的に取得します。

ローカルビルド

Docker Hub から取得する代わりに、必要に応じて次のコマンドを使用して Docker イメージをローカルでビルドできます。

docker build --tag marksivill/mcp-spectral:latest .

たとえば、ソースコードやデフォルトのルールセットを変更する必要がある場合に便利です。

Claude Desktop のプロンプト例

以下は Claude Desktop 向けのプロンプト例です。MCP Spectral を呼び出す他の大規模言語モデル(LLM)ツールでも使用できる場合があります。

注:URL を取得するために、Claude Desktop に mcp/fetch もインストールする必要がある場合があります。

プロンプト 1

What version of Spectral do we have access to

プロンプト 2

Validate the OpenAPI specification from OpenWeatherMap API.
If any errors are found, fix them, then revalidate, repeat the last steps until the OpenAPI specification is valid.

プロンプト 3

Using the API documentation found at https://wheretheiss.at/w/developer build an OpenAPI specification.
Ensure that there are no validation errors.
If any errors are found, fix them, then revalidate, repeat the last steps until the OpenAPI specification is valid.

プロンプト 4

Build an OpenAPI specification version 3.1 for the Rick and Morty API.
Ensure that there are no validation errors.
If any errors are found, fix them, then revalidate, repeat the last steps until the OpenAPI specification is valid.

プロンプト 5

Using the API documentation found at https://wheretheiss.at/w/developer build an OpenAPI specification version 3.1 using the rules
1) ensure all operationIds use kebab case
2) add info and contact information using your details
3) ensure servers are defined
4) ensure all operations contains a description
5) ensure all operations have one or more relevant tags
6) ensure there is a tag section

Ensure that there are no validation errors.
If any errors are found, fix them, then revalidate, repeat the last steps until the OpenAPI specification is valid.

便利なリンク

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。