# connect()

Canonical URL: https://developers.iagenify.com/sdk/ref/mcp/connect/
Language: en

`api.mcp.connect({ url, name?, token?, tools?, category?, label? }) → Promise<Server>`

Checks the address, shakes hands, reads the server's tools, and saves the connection. Four steps, in that order — and the order is the security.

Status: check, then contact · https only · no tool allowed by default

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `url` | string | required | The server's address. **https only.** |
| `name` | string |  | Its name here. Derived from the domain when absent. |
| `token` | string |  | The access token. Encrypted at rest, never put in a URL. |
| `tools` | string[] | none | **Which tools are allowed.** Without this list, none is. |
| `category` | string | exec | `read` · `write` · `exec` — the permission its tools carry. |
| `label` | string |  | A display name. |

## The four steps {#order}

- The address is checked by the platform — scheme, and that it resolves to a public address.
- The package shakes hands with the checked address and negotiates a revision.
- It reads the server's tool list.
- The connection is saved, with the catalogue and the revision that was agreed.

> **The check comes before the package touches anything**
>
> In an application the package often runs on a server of yours. An unchecked address would be a request from inside your network to wherever the address pointed — and the answer handed back. Checking first is what makes an address somebody typed safe to accept.

## Nothing is allowed unless you list it {#tools}

```javascript
// Connected, and completely inert — no tool is allowed
await api.mcp.connect({ url, name: "example" });

// Two tools, read-only
await api.mcp.connect({ url, name: "example", tools: ["search_docs", "get_issue"], category: "read" });
```

A declaration costs tokens on every turn, so a server offering ninety tools would add a fixed cost to every step of every run without anyone asking for it. Connecting first and choosing afterwards with [update()](/sdk/ref/mcp/update) is the usual shape.

## exec by default, deliberately {#category}

The protocol carries a read-only hint, but the server declares it about itself. `exec` means its tools are asked in every mode but full access — set `read` only when you know what the tools do.

## The token is cleaned once {#token}

Surrounding spaces, quotes and a copied « Bearer » are removed — they make some servers refuse the header without ever reading the token. A space *inside* is refused rather than patched: guessing which token was meant is worse than saying so.

## Errors {#errors}

| Code | Status | When |
| --- | --- | --- |
| url_required | 400 | No address. |
| url_not_https | 400 | Plain http would send the token unencrypted. |
| url_blocked | 400 | The address does not resolve publicly. |
| mcp_token_malformed | 400 | The token contains a space. |
| mcp_token_required · mcp_unauthorized | 401 | The server wants a token, or refused the one given. |
| mcp_redirect | 502 | The server answered with a redirect. They are never followed. |
| mcp_protocol_unsupported | 502 | No revision in common. |
| mcp_unreachable · mcp_timeout | 502 · 504 | No answer in time. |

- [Address check](/sdk/mcp/address-check): What the check does.
- [Allowed tools](/sdk/mcp/allowed-tools): Why none is allowed by default.
- [Errors](/sdk/mcp/errors): Every code and what to do about it.

```python
# Connected, and completely inert — no tool is allowed
api.mcp.connect(url=url, name="example")

# Two tools, read-only
api.mcp.connect(url=url, name="example", tools=["search_docs", "get_issue"], category="read")
```
