# MCP server

Connect your AI assistant to Wayline using [MCP](https://modelcontextprotocol.io)
(Model Context Protocol). Compatible assistants can discover Wayline's tools and
use them to read listings, search knowledge and make changes you authorize.

For example, ask your assistant to find available listings or update a pet policy.
For a backend sync or another software integration, start with the
[REST API and an API key](https://docs.wayline.com/authentication.md).

- **URL:** `https://mcp.wayline.com`
- **Authentication:** sign in with your Wayline account when you connect (see [connecting](#connecting)), or an [API key](https://docs.wayline.com/authentication.md)
- **Transport:** Streamable HTTP. Each request is answered in full as JSON; there are no sessions or event streams.

## Same API, same rules

Every endpoint is one tool, and each tool behaves exactly like its endpoint: the same
fields, the same validation, the same organization scoping and the same errors. Each
connection, and each API key, has its own rate limit ([conventions](https://docs.wayline.com/conventions.md#rate-limits));
an agent and an integration using the same key share one budget.

A tool's arguments are what you would send the endpoint, side by side in one object:

- the ids in the endpoint's path, named for what they identify (`listingId`, `questionId`, `externalId`),
- its query parameters, by the same names (`status`, `cursor`, `limit`, `updated_since`),
- and the fields of its request body, unchanged.

For example, `PATCH /v1/listings/800` with the body `{"rent": 2500}` is the
`update_listing` tool with the arguments `{"listingId": 800, "rent": 2500}`.

A tool returns the endpoint's JSON response as text. A delete, which the REST API
answers with an empty `204`, returns `{"deleted": true}`. A failed call is marked as
an error and returns the API's error object, `{"error": {"code", "message", "field"?}}`;
the message says what to fix.

## Connecting

### By signing in (Claude, ChatGPT and other AI tools)

Use this option when your assistant supports remote MCP servers with OAuth sign-in.
You don't need to generate or paste an API key.

1. In your AI tool, add a custom connector (or MCP server) with the URL `https://mcp.wayline.com`.
2. The tool opens Wayline. Sign in with your Wayline account, if you aren't already.
3. Wayline shows what the tool will be able to do. Leave **Make changes** ticked to let it
   create and edit listings and knowledge, or untick it to let it only read. Choose **Connect**.

The tool then works in Wayline as you. What it creates is recorded as yours.

- An organization's **admins and staff** can connect. The tool works in your
  organization; it never needs to name it.
- **Wayline support staff** belong to no one organization. The tool asks which
  organization to work in and passes its key as `organizationKey` on each call: the part
  of the organization's Wayline URL after `app.wayline.com/`.
- Prospects, residents, owners, vendors and brokers can't connect.

A connection lasts as long as the tool keeps using it (it refreshes itself) and stops
working at once if your account is deactivated, your role changes, or you move to another
organization. Connect again to make changes after connecting read-only.

Signing in uses OAuth with PKCE. AI tools identify themselves with a Client ID Metadata
Document, the method the MCP specification prefers; Wayline's sign-in settings are at
`https://app.wayline.com/.well-known/oauth-authorization-server`.

### With an API key

If your client supports custom authorization headers, scripts and developer tools can send an [API key](https://docs.wayline.com/authentication.md) instead, as
`Authorization: Bearer wapi_…`. A key works in its organization with full access. With
Claude Code:

```bash
claude mcp add --transport http wayline https://mcp.wayline.com \
  --header "Authorization: Bearer $WAYLINE_API_KEY"
```

### Errors

A request without a valid sign-in or key is answered `401` before any tool runs, with a
`WWW-Authenticate` header naming `https://mcp.wayline.com/.well-known/oauth-protected-resource`,
which tells the AI tool where to sign in.

| Code | When |
|------|------|
| `missing_credentials` | No `Authorization` header |
| `invalid_token` | The sign-in expired, was disconnected, or no longer holds (deactivated, role or organization changed); sign in again |
| `invalid_api_key` | As for the REST API ([authentication](https://docs.wayline.com/authentication.md)) |
| `insufficient_scope` | A read-only connection tried to make a change |
| `organization_required` | Wayline support staff left out `organizationKey` |
| `wrong_organization` | `organizationKey` named an organization other than the connection's or key's own |

## Tools

| Tool | Endpoint |
|------|----------|
| `list_listings` | `GET /v1/listings` |
| `create_listing` | `POST /v1/listings` |
| `put_listing` | `PUT /v1/listings/external/{externalId}` |
| `get_listing` | `GET /v1/listings/{id}` |
| `update_listing` | `PATCH /v1/listings/{id}` |
| `list_properties` | `GET /v1/properties` |
| `list_units` | `GET /v1/properties/{id}/units` |
| `list_property_groups` | `GET /v1/property-groups` |
| `list_questions` | `GET /v1/knowledge/questions` |
| `create_question` | `POST /v1/knowledge/questions` |
| `get_question` | `GET /v1/knowledge/questions/{id}` |
| `update_question` | `PATCH /v1/knowledge/questions/{id}` |
| `delete_question` | `DELETE /v1/knowledge/questions/{id}` |
| `add_answer` | `POST /v1/knowledge/questions/{id}/answers` |
| `update_answer` | `PATCH /v1/knowledge/answers/{id}` |
| `delete_answer` | `DELETE /v1/knowledge/answers/{id}` |
| `search_knowledge` | `GET /v1/knowledge/search` |
| `list_guardrails` | `GET /v1/knowledge/guardrails` |
| `create_guardrail` | `POST /v1/knowledge/guardrails` |
| `get_guardrail` | `GET /v1/knowledge/guardrails/{id}` |
| `update_guardrail` | `PATCH /v1/knowledge/guardrails/{id}` |
| `delete_guardrail` | `DELETE /v1/knowledge/guardrails/{id}` |
| `create_upload` | `POST /v1/knowledge/uploads` |
| `create_import` | `POST /v1/knowledge/imports` |
| `list_imports` | `GET /v1/knowledge/imports` |
| `get_import` | `GET /v1/knowledge/imports/{id}` |

Each tool also says whether it only reads, and whether it can change or remove what's
there, so your AI tool can ask before running it.
