api.mcp

connect()

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.

check, then contacthttps onlyno tool allowed by default
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

urlstringrequired

The server's address. https only.

namestring

Its name here. Derived from the domain when absent.

tokenstring

The access token. Encrypted at rest, never put in a URL.

toolsstring[]none

Which tools are allowed. Without this list, none is.

categorystringexec

read · write · exec — the permission its tools carry.

labelstring

A display name.

The four steps

  • 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

// 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" });
# 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")

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() is the usual shape.

exec by default, deliberately

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

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

CodeStatusWhen
url_required400No address.
url_not_https400Plain http would send the token unencrypted.
url_blocked400The address does not resolve publicly.
mcp_token_malformed400The token contains a space.
mcp_token_required · mcp_unauthorized401The server wants a token, or refused the one given.
mcp_redirect502The server answered with a redirect. They are never followed.
mcp_protocol_unsupported502No revision in common.
mcp_unreachable · mcp_timeout502 · 504No answer in time.