Skip to content

Specs

Spec は API ドメインまたはサービスを表す論理コンテナです(例:YouTube、Binance、Open-Meteo)。各 spec は一意の domainbase_url、オプションの auth を持ち、1 つ以上の collection を含みます。

Collections は OpenAPI/Swagger/Postman ファイルを指します — spec 自体はファイルではなく、それらをグループ化するものです。

Domain — 命名規則

domain は spec の一意識別子です。システム全体で主キーとして使用されます。

ルール制約
文字a-z0-9_- のみ
長さ1〜60 文字
一意性重複不可 — 2 つのアクティブな spec が同じ domain を共有できません

有効な例: meteobinancegithub-apimy_serviceopenai-v1

無効な例: Meteo(大文字)、my api(スペース)、my.api(ドット)、a-very-long-domain-name-that-exceeds-sixty-characters(長すぎる)

Spec フィールド

フィールドYAML キー必須説明
Domaindomain一意の API 識別子(1〜60 文字、a-z0-9_-
LLM Titlellm_titleLLM がこの API を参照するための人間可読名(5〜120 文字)
LLM Instructionllm_instructionswag2mcp システムプロンプトに注入される短いヒント(最大 500 文字)
Base URLbase_urlすべての API リクエストのベース URL(有効な URL)
Disabledisable読み込みとインデックス化時にこの spec をスキップ
Tagstagsフィルタリング用のタグ(例:["public", "demo"]
Authauth認証設定
HTTP Clienthttp_clientspec ごとの HTTP 設定(ヘッダー、Cookie)
Collectionscollections1〜30 の collection のリスト

検証

swag2mcp が設定を検証するとき、各 spec に対して以下のルールがチェックされます:

チェックルール
重複ドメイン2 つのアクティブな spec が同じ domain を共有してはいけません
ドメイン形式^[a-z0-9_-]{1,60}$ に一致する必要があります
LLM Title必須、5〜120 文字、英字/数字/スペース/基本句読点
LLM Instruction最大 500 文字、タイトルと同じ文字セット
Base URL必須、有効な URL である必要があります
Collections必須、1〜30 項目
Auth認証タイプごとに検証(例:bearer は token、basic は username + password が必要)
Location各 collection の location は有効な URL またはファイルパスである必要があります(5〜250 文字)

検証は swag2mcp mcp の起動のたびに実行されます。失敗した場合、MCP サーバーは起動しません — 一部の IDE では、サーバーが単に接続せず、LLM は何を修正すべきかを説明する明確なエラーメッセージを受け取ります。

サーバーを起動する前に問題を診断するには、validate コマンドを使用します:

bash
# デフォルトワークスペースを検証(~/.swag2mcp)
swag2mcp validate

# カスタムプロジェクトワークスペースを検証
swag2mcp validate ./my-project

LLM Instruction

各 spec に llm_instruction を設定することを推奨します — この API の目的と使用タイミングを LLM に伝える短いヒント(最大 500 文字)です。この指示は swag2mcp システムプロンプトに注入され、追加のコンテキストなしで LLM が spec の目的を理解するのに役立ちます。

yaml
specs:
  - domain: jokes
    llm_title: Dad Joke API
    llm_instruction: "Use this API to get random dad jokes or search for specific jokes by keyword."
    base_url: https://icanhazdadjoke.com
    collections:
      - llm_title: Jokes
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/dadjoke.yaml

Collection も独自の llm_instruction(最大 360 文字)を持ち、より具体的なガイダンスを提供できます。

Auth

認証は spec レベルで設定され、そのすべての collection に適用されます。swag2mcp は 9 つの認証方式をサポートしています:

方式YAML タイプ主要フィールド
Nonenone
Basicbasicusernamepassword
Bearerbearertoken
Digestdigestusernamepassword
OAuth2 Client Credentialsoauth2-ccclient_idclient_secrettoken_url
OAuth2 Passwordoauth2-pwdusernamepasswordclient_idtoken_url
API Keyapi-keykeyvalueinheader または query
HMAChmacapi_keysecret_key
Scriptscriptdomain

各方式の詳細は Auth Overview を参照してください。

HTTP Client

spec レベルで HTTP 設定を上書きできます。これらはこの spec の collection が行うすべてのリクエストに適用されます。

yaml
specs:
  - domain: slow-api
    llm_title: Slow API
    base_url: https://slow-api.example.com
    http_client:
      headers:
        X-API-Version: "2"
      cookies:
        - name: session
          value: abc123
    collections:
      - llm_title: Default
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/dadjoke.yaml

設定のカスケード:グローバル → spec → collection。詳細は Configuration Cascade を参照してください。

Tags

タグを使用すると、カテゴリで spec をフィルタリングできます。swag2mcp ls またはブートストラップ時に --tags フラグとともに使用します。

yaml
specs:
  - domain: meteo
    llm_title: Open-Meteo Weather APIs
    base_url: https://api.open-meteo.com
    tags: ["weather", "public"]
    collections:
      - llm_title: Forecast
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/meteo/forecast.yml
bash
# "weather" タグが付いた spec のみを一覧表示
swag2mcp ls --tags weather

Disable

disable: true を設定して spec を完全にスキップします。読み込まれず、インデックス化されず、LLM が利用できなくなります。

yaml
specs:
  - domain: old-api
    llm_title: Old API (Deprecated)
    base_url: https://old-api.example.com
    disable: true
    collections:
      - llm_title: Default
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/dadjoke.yaml

最小限の Spec

yaml
specs:
  - domain: dadjokes
    llm_title: Dad Joke API
    base_url: https://icanhazdadjoke.com
    collections:
      - llm_title: Jokes
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/dadjoke.yaml

認証付き Spec

yaml
specs:
  - domain: binance
    llm_title: Binance Market Data API
    base_url: https://api.binance.com
    auth:
      type: hmac
      config:
        api_key: $(BINANCE_API_KEY)
        secret_key: $(BINANCE_SECRET_KEY)
    collections:
      - llm_title: Market Data
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/binance.yaml

複数 Collection の Spec

yaml
specs:
  - domain: meteo
    llm_title: Open-Meteo Weather APIs
    base_url: https://api.open-meteo.com
    collections:
      - llm_title: Forecast
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/meteo/forecast.yml
      - llm_title: Air Quality
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/meteo/air-quality.yml
      - llm_title: Marine
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/meteo/marine.yml

LLM Instruction と Tags 付き Spec

yaml
specs:
  - domain: rickandmorty
    llm_title: Rick and Morty API
    llm_instruction: "Use this API to get information about characters, episodes, and locations from the Rick and Morty show."
    base_url: https://rickandmortyapi.com/api
    tags: ["entertainment", "public"]
    collections:
      - llm_title: Characters
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/rick-and-morty.json

関連項目