> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmcp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Import from Swagger 2.0

> Parse a Swagger 2.0 spec and import the selected operations as tools.

This endpoint mirrors `/import-openapi` but targets the older Swagger 2.0 schema. The same two-phase parse-then-commit flow applies.

<Note>
  Phase 1 (no `commit` flag) parses the spec and returns candidates with `temp_id`s. Phase 2 (`commit: true`) takes `selected_temp_ids` and writes the chosen tools. Use the `/import-openapi` endpoint instead for OpenAPI 3.x — passing a 3.x document here will fail with `unsupported_version`.
</Note>

## Path Parameters

<ParamField path="server_id" type="string" required>
  The UUID of the server to import into (e.g. `836995ae-1cff-41ec-823e-a4f07ccca3a0`). Numeric IDs are also accepted for backwards compatibility.
</ParamField>

## Body Parameters

<ParamField body="source" type="string" default="text">
  Where the spec content comes from. One of: `text` (use `content`), `url` (use `url`).
</ParamField>

<ParamField body="content" type="string">
  The raw spec body (JSON or YAML). Required when `source` is `text`. Hard cap of 10 MB.
</ParamField>

<ParamField body="url" type="string">
  Public URL to fetch the spec from. Required when `source` is `url`. Followed up to 3 redirects, 10 s timeout.
</ParamField>

<ParamField body="commit" type="boolean" default="false">
  When `false` (default), parse and return candidates only. When `true`, persist the candidates listed in `selected_temp_ids`.
</ParamField>

<ParamField body="selected_temp_ids" type="array">
  Array of `temp_id` strings identifying which candidates to create. Required when `commit` is `true`.
</ParamField>

<ParamField body="on_conflict" type="string" default="skip">
  Slug-collision policy. One of: `skip`, `duplicate`.
</ParamField>

<ParamField body="imported_status" type="string" default="draft">
  Status for newly created tools. One of: `draft`, `active`.
</ParamField>

<RequestExample>
  ```bash cURL — Phase 1 (parse) theme={null}
  curl --request POST \
       --url https://yoursite.com/wp-json/getmcp/v1/servers/836995ae-1cff-41ec-823e-a4f07ccca3a0/tools/import-swagger \
       --header 'Authorization: Bearer gmcp_your_api_key' \
       --header 'content-type: application/json' \
       --data '{
         "source": "url",
         "url": "https://example.com/swagger-2.0.json"
       }'
  ```

  ```bash cURL — Phase 2 (commit) theme={null}
  curl --request POST \
       --url https://yoursite.com/wp-json/getmcp/v1/servers/836995ae-1cff-41ec-823e-a4f07ccca3a0/tools/import-swagger \
       --header 'Authorization: Bearer gmcp_your_api_key' \
       --header 'content-type: application/json' \
       --data '{
         "source": "url",
         "url": "https://example.com/swagger-2.0.json",
         "commit": true,
         "selected_temp_ids": ["op_0", "op_2"],
         "imported_status": "draft"
       }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://yoursite.com/wp-json/getmcp/v1/servers/836995ae-1cff-41ec-823e-a4f07ccca3a0/tools/import-swagger"
  headers = {
      "Authorization": "Bearer gmcp_your_api_key",
      "Content-Type": "application/json",
  }

  with open("./swagger.json") as f:
      spec = f.read()

  parse = requests.post(url, headers=headers, json={
      "source": "text",
      "content": spec,
  }).json()

  commit = requests.post(url, headers=headers, json={
      "source": "text",
      "content": spec,
      "commit": True,
      "selected_temp_ids": [c["temp_id"] for c in parse["candidates"]],
  }).json()
  ```

  ```javascript JavaScript theme={null}
  const url = "https://yoursite.com/wp-json/getmcp/v1/servers/836995ae-1cff-41ec-823e-a4f07ccca3a0/tools/import-swagger";
  const headers = {
    "Authorization": "Bearer gmcp_your_api_key",
    "Content-Type": "application/json",
  };

  const parse = await (await fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify({ source: "url", url: "https://example.com/swagger-2.0.json" }),
  })).json();

  const commit = await (await fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify({
      source: "url",
      url: "https://example.com/swagger-2.0.json",
      commit: true,
      selected_temp_ids: parse.candidates.map(c => c.temp_id),
    }),
  })).json();
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK — Phase 1 (parse) theme={null}
  {
    "candidates": [
      {
        "temp_id": "op_0",
        "name": "Get User",
        "slug": "get_user",
        "description": "Fetch a user by ID.",
        "endpoint_url": "https://api.example.com/v1/users/{id}",
        "http_method": "GET",
        "input_schema": {
          "type": "object",
          "properties": {
            "id": { "type": "string" }
          },
          "required": ["id"]
        },
        "headers": null,
        "tags": ["users"]
      }
    ],
    "info": {
      "title": "Example API",
      "version": "1.0.0"
    }
  }
  ```

  ```json 200 OK — Phase 2 (commit) theme={null}
  {
    "created": [
      { "tool_id": 51, "uuid": "5376af81-6bb8-4b01-800c-508d7672e394", "name": "Get User", "slug": "get_user" }
    ],
    "skipped": [],
    "failed": []
  }
  ```

  ```json 400 Bad Request — wrong version theme={null}
  {
    "code": "unsupported_version",
    "message": "unsupported_version: spec is OpenAPI 3.x — use the import-openapi endpoint.",
    "data": { "status": 400 }
  }
  ```

  ```json 403 Forbidden — tier limit theme={null}
  {
    "code": "tier_limit_import_method",
    "message": "Importing tools from SWAGGER is not available on your FREE plan.",
    "data": {
      "status": 403,
      "tier": "free",
      "upgrade_url": "https://getmcp.com/pricing"
    }
  }
  ```
</ResponseExample>

## Status Codes

| Code  | Meaning                                                     |
| ----- | ----------------------------------------------------------- |
| `200` | Spec parsed (phase 1) or commit completed (phase 2).        |
| `400` | Bad spec, empty content, wrong version, or unfetchable URL. |
| `402` | 14-day trial expired and no active license.                 |
| `403` | Current license tier does not allow Swagger import.         |
| `404` | Server not found.                                           |
