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

# Magic Patterns plugin

> AI design and prototyping tool with 47 operations: create MagicOS projects, add prototypes, frames, canvases and slides, read, write, edit and search their files, type-check and preview designs, generate images, hand work to the MagicOS agent, read project threads, and work with legacy editor designs and design systems.

Use **Magic Patterns** through Corsair: one client, typed API calls.

Calls go to Magic Patterns' hosted MCP server with an `mp_` API key (Magic Patterns > Settings > API Keys). Most operations take an `osId` from `projects.list` (the id in magicpatterns.com/os/\<osId>); read `projects.guide` before writing to a project. Pass the same short `conversation` name on every call of one task so Magic Patterns counts it as one writer. `magicos.ask`, `images.generate` and the legacy prompt operations spend the workspace's Magic Patterns credits. `legacy.*` operations are for designs made in the old editor (magicpatterns.com/c/\<id>), which Magic Patterns has deprecated.

**What you get:**

* 47 typed API operations

## Setup

**1. Install**

```bash npm theme={null}
npm install corsair @corsair-dev/magicpatterns better-sqlite3
npm install --save-dev @types/better-sqlite3
```

```bash yarn theme={null}
yarn add corsair @corsair-dev/magicpatterns better-sqlite3
yarn add --dev @types/better-sqlite3
```

```bash pnpm theme={null}
pnpm install corsair @corsair-dev/magicpatterns better-sqlite3
pnpm install --save-dev @types/better-sqlite3
```

```bash bun theme={null}
bun add corsair @corsair-dev/magicpatterns better-sqlite3
bun add --dev @types/better-sqlite3
```

**2. Add the plugin**

```ts corsair.ts theme={null}
import Database from 'better-sqlite3';
import { createCorsair } from 'corsair';
import { magicpatterns } from '@corsair-dev/magicpatterns';

export const corsair = createCorsair({
	plugins: [
		magicpatterns(),
	],
	database: new Database('corsair.db'),
	kek: process.env.CORSAIR_KEK!,
	multiTenancy: true,
	hub: {
		projectApiKey: process.env.CORSAIR_API_KEY!,
		signingSecret: process.env.CORSAIR_SIGNING_SECRET!,
	},
});
```

With `multiTenancy: true`, scope calls with `corsair.withTenant(id)`. See [Quick start](https://docs.corsair.dev/quick-start.md) for KEK + Hub keys, and [Multi-tenancy](https://docs.corsair.dev/concepts/multi-tenancy.md) for account isolation.

**3. Choose authentication**

> [tab] API Key (Recommended)
>
> Store the Magic Patterns API key before the first call: `pnpm corsair setup --plugin=magicpatterns --tenant=acme api_key=<your-key>` (leave out `--tenant` without `multiTenancy`), or pass it as `key` in the plugin options. With Hub, each tenant enters their own key on the connect page. See [API key auth](https://docs.corsair.dev/concepts/api-key).
>
> ```ts theme={null}
> magicpatterns()
> ```
>
> More: [API Key](https://docs.corsair.dev/concepts/api-key)

**4. Connect a tenant**

Mint a connect link and send the tenant to it. Hub hosts the page and delivers the result to your app — see [Connect / OAuth](https://docs.corsair.dev/management/connect).

```ts theme={null}
const { connectUrl } = await corsair.manage.connect.createLink({
	plugin: 'magicpatterns',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**List the files in a project**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.magicpatterns.api.files.list({ osId: 'Z3ZDUguQKLKB1rTvrQsQry', conversation: 'checkout-redesign' });
```

**Write a file in a project**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.magicpatterns.api.files.write({
	osId: 'Z3ZDUguQKLKB1rTvrQsQry',
	osFile: '54PVSAUzQjaTeeV1UuPZmv',
	path: 'components/OrderSummary.tsx',
	content: 'export default function OrderSummary() {\n  return <h2>Order summary</h2>;\n}\n',
	conversation: 'checkout-redesign',
});
```

See the full list on the [API](https://docs.corsair.dev/plugins/magicpatterns/api.md) page.

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/magicpatterns/api.md)
>
> Every `magicpatterns.api.*` operation with input and output types.

> [card] [Connect / OAuth](https://docs.corsair.dev/management/connect)
>
> createLink, Hub delivery, and tenant connect flows.

> [card] [Use with agents](https://docs.corsair.dev/mcp-adapters/mcp-adapters)
>
> Expose this plugin's operations as MCP tools.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.