# Connect MCP servers (with OAuth) | Creght

> Call Linear, Notion, Sentry and other MCP servers from Creght Func with ctx.mcp. The platform handles OAuth and token refresh, with your account or each visitor's own.

Overview

- [Creght API for AI](/api.md)
- [Connect to Creght over MCP](/api/mcp-server.md)

Discoverability

- [How to optimize llms.txt](/api/optimize-llms-txt.md)

Site configuration

- [Configure talizen.config.ts](/api/talizen-config.md)
- [Implement domain-based locale routing](/api/domain-locale-routing.md)

Backend

- [Calling external APIs on the server and managing the cache](/api/ssr-external-api-cache.md)
- [Build site backend workflows with Func](/api/func-backend.md)
- [JSON tables: definition, reads, and queries](/api/func-json-tables.md)
- [Uploads: signed direct upload and Func-generated files](/api/func-assets-upload.md)
- [Timeouts and streaming responses](/api/func-timeout-streaming.md)
- [Integrate Alipay PC Web Payment with Func](/api/func-alipay-payment.md)
- [Form submission webhooks: real-time delivery and signatures](/api/form-webhook.md)

Integrations

- [Send Email and Verification Codes with Integrations](/api/func-email-integration.md)
- [Take Alipay payments with an integration](/api/func-alipay-integration.md)
- [Take Stripe payments with an integration](/api/func-stripe-integration.md)
- [Call OpenAI models with an integration](/api/func-ai-integration.md)
- [Connect MCP servers (with OAuth)](/api/func-mcp-integration.md)
- [Add text to speech with an integration](/api/func-tts-integration.md)

Auth

- [Require a Verified Email to Sign Up](/api/auth-verified-registration.md)
- [Reset and Change Passwords](/api/auth-password-reset.md)
- [Sign In From a Func](/api/auth-func-login.md)
- [Query users from a Func](/api/func-user-directory.md)

On this page

- [Add an MCP server](#connect)
- [Call it from Func](#call)
- [Each visitor connects their own account](#visitor)
- [Security and limits](#security)

Overview

- [Creght API for AI](/api.md)
- [Connect to Creght over MCP](/api/mcp-server.md)

Discoverability

- [How to optimize llms.txt](/api/optimize-llms-txt.md)

Site configuration

- [Configure talizen.config.ts](/api/talizen-config.md)
- [Implement domain-based locale routing](/api/domain-locale-routing.md)

Backend

- [Calling external APIs on the server and managing the cache](/api/ssr-external-api-cache.md)
- [Build site backend workflows with Func](/api/func-backend.md)
- [JSON tables: definition, reads, and queries](/api/func-json-tables.md)
- [Uploads: signed direct upload and Func-generated files](/api/func-assets-upload.md)
- [Timeouts and streaming responses](/api/func-timeout-streaming.md)
- [Integrate Alipay PC Web Payment with Func](/api/func-alipay-payment.md)
- [Form submission webhooks: real-time delivery and signatures](/api/form-webhook.md)

Integrations

- [Send Email and Verification Codes with Integrations](/api/func-email-integration.md)
- [Take Alipay payments with an integration](/api/func-alipay-integration.md)
- [Take Stripe payments with an integration](/api/func-stripe-integration.md)
- [Call OpenAI models with an integration](/api/func-ai-integration.md)
- [Connect MCP servers (with OAuth)](/api/func-mcp-integration.md)
- [Add text to speech with an integration](/api/func-tts-integration.md)

Auth

- [Require a Verified Email to Sign Up](/api/auth-verified-registration.md)
- [Reset and Change Passwords](/api/auth-password-reset.md)
- [Sign In From a Func](/api/auth-func-login.md)
- [Query users from a Func](/api/func-user-directory.md)

Integrations/Connect MCP servers (with OAuth)

# Connect MCP servers (with OAuth)

Add an MCP server under integrations and call its tools from Func with ctx.mcp. Servers that need OAuth sign-in work too, with either your account or each visitor's own. The platform keeps the tokens; Func never sees them.

Copy Markdown link

Add an MCP server under integrations and Func can call its tools with `ctx.mcp('name', tool, args)`, including servers that require sign-in (OAuth) such as Linear, Notion or Sentry. The platform runs the authorization and holds the tokens; your code never sees them.

**Two ways to authorize**

**Your account**: authorize once in the editor and every visitor's call uses it. Good for wiring your own tools into the site.

**Each visitor's own account**: visitors sign in to the site, then connect their own account. Good for features like "manage your own Linear issues here".

## Add an MCP server

Open **Backend → Integrations** in the editor, click **MCP** and fill in the table below. Saving connects to the server once, so a wrong URL or auth setting fails right away.

| Field | What to enter | Required |
| --- | --- | --- |
| Name | The server name in code, e.g. `linear`. Letters, digits, `-` and `_` only; `creght` is reserved | Yes |
| Server URL | The MCP Streamable HTTP endpoint, usually ending in `/mcp`, e.g. `https://mcp.linear.app/mcp`. https only | Yes |
| Authentication | **OAuth**: servers that need sign-in (default). **Token**: the server gave you a fixed token. **None**: public servers | Yes |
| Whose account | With OAuth: **Mine** or **Each visitor connects their own** | With OAuth |
| Scopes | Leave blank to request what the server asks for | No |
| OAuth client ID / secret | Only for servers without dynamic client registration. Most servers (Linear, Notion, Sentry, Atlassian) support it, so leave these blank | No |

With "Mine", click **Authorize** on the card after saving, then sign in and approve in the popup. The card shows the authorization state and every tool the server offers.

## Call it from Func

```ts
export async function createTask(input, ctx) {
  const tools = await ctx.mcp.tools('linear')          // [{ name, description, input_schema }]
  const issue = await ctx.mcp('linear', 'create_issue', {
    title: input.title,
    team: 'ENG',
  })
  return issue
}
```

| Method | Description |
| --- | --- |
| `ctx.mcp(name, tool, args?)` | Calls a tool. Resolves to its structured result; text-only results are parsed when they are JSON and returned as-is otherwise. A tool error rejects |
| `ctx.mcp.tools(name)` | Lists the tools: `name`, `description`, `input_schema`. Check it before writing code; tool names and arguments come from here |
| `ctx.mcp.status(name)` | Whether it can be called now: `connected`, `connect_as`, `signed_in`, `authorize_url` |
| `ctx.mcp.disconnect(name)` | Removes the current visitor's own authorization. Only for "each visitor" servers |

**When there is no authorization**

The call rejects with `code` set to `mcp_authorization_required`. With your account, authorize again under integrations. With visitor accounts, send the visitor to `authorize_url` as shown below.

## Each visitor connects their own account

The platform has no visitor-facing UI: your pages render the button and the messages. What the platform gives you is an authorization entry point:

```
/auth/mcp/start?server=linear&redirect=/dashboard
```

The visitor must be signed in to the site. The platform takes them to the server to sign in and approve, then sends them back to the `redirect` path with `?mcp_connected=linear`, or `?mcp_error=reason` on failure. From then on that visitor's calls use their own account.

Return "needs connecting" as a normal value instead of making the page handle exceptions:

```ts
import type { TalizenFuncContext } from 'talizen/func-runtime'

export async function myIssues(input: unknown, ctx: TalizenFuncContext) {
  ctx.auth.requireUser()
  const st = await ctx.mcp.status('linear')
  if (!st.connected) return { needConnect: true, url: st.authorize_url }
  try {
    const issues = await ctx.mcp('linear', 'list_issues', { assignee: 'me' })
    return { needConnect: false, issues }
  } catch (e: any) {
    if (e.code === 'mcp_authorization_required') {
      return { needConnect: true, url: st.authorize_url }
    }
    throw e
  }
}

export async function disconnect(input: unknown, ctx: TalizenFuncContext) {
  ctx.auth.requireUser()
  return ctx.mcp.disconnect('linear')
}
```

In the page:

```tsx
import { invoke } from 'talizen/func'

const res = await invoke('linear.myIssues', {})
if (res.needConnect) {
  const href = res.url + '&redirect=' + encodeURIComponent(location.pathname)
  // render <a href={href}>Connect Linear</a>
}
```

The visitor is the site's signed-in user ( `ctx.auth`) first, then the project member ( `ctx.member`). So when you try a Func in the editor, it uses the authorization you made with "Connect my account" on the integration card.

## Security and limits

- Tokens stay on the platform, encrypted, and never enter Func. They are refreshed before they expire; when refreshing fails, calls return `mcp_authorization_required`.
- Do not implement MCP authorization in Func or call the server with `fetch`. Only with Token auth can you turn on "expose to Func" and call it yourself with the environment variable.
- Only Streamable HTTP is supported, not the older HTTP + SSE transport or local stdio servers.
- Each call opens a new connection, one extra round trip compared with a plain API call, so avoid dozens of calls in one request.
- Changing the server URL, authentication, account mode or client ID invalidates every existing authorization.

On this page

- [Add an MCP server](#connect)
- [Call it from Func](#call)
- [Each visitor connects their own account](#visitor)
- [Security and limits](#security)

> Full page index: [/llms.txt](/llms.txt)
