# Wire SDK

For teams building agents, harnesses, or AI infrastructure who want Wire container connectivity as a first-class part of the product. Three methods. Your user authorizes in their browser; you get back a scoped MCP endpoint and API key to hand to your agent.

You don't run the storage. You don't build the const client = new WireClient({ appId: 'my-app' });

    const connection = await client.connect({ label: 'my-laptop' });

    // Hand these to your agent's MCP client:
    const mcp = new MCPClient({
      url: connection.mcpUrl,
      headers: { 'x-api-key': connection.apiKey },
    });
    ```
  </TabItem>
</Tabs>

`connect()` shows the user a short code and opens their browser. The user types the code on the connect screen, picks a container, and `connect()` resolves with the result.

If you need to drive the prompt yourself (custom UI, no stdout):

<Tabs syncKey="lang">
  <TabItem label="TypeScript">
    ```typescript
    const connection = await client.connect({
      onUserPrompt: ({ code, url }) => {
        myUi.show(`Code: ${code}`);
        myBrowser.open(url);
      },
    });
    ```
  </TabItem>
</Tabs>

## What you get

<Tabs syncKey="lang">
  <TabItem label="TypeScript">
    ```typescript
    interface Connection {
      mcpUrl: string;
      apiUrl: string;
      apiKey: string;
      containerId: string;
      containerName: string;
      orgSlug: string | null;
      expiresAt: Date | null;   // ephemeral containers only
      appId: string;
      credentialId: string;
      deviceKey: DeviceKey;
      connectedAt: Date;
      label?: string;
    }
    ```
  </TabItem>
</Tabs>

The SDK persists nothing. Keep whatever fields you want from the result, however you want.

## Reuse the install identity

`deviceKey` identifies the install across reconnects. Persist it if you want the same user and machine to appear as the same install instead of a fresh one every time:

<Tabs syncKey="lang">
  <TabItem label="TypeScript">
    ```typescript
    // First run
    const conn = await client.connect();
    saveSomewhere(conn.deviceKey);

    // Later
    const client2 = new WireClient({
      appId: 'my-app',
      deviceKey: loadSomewhere(),
    });
    const conn2 = await client2.connect();
    ```
  </TabItem>
</Tabs>

Local file, OS keychain, secrets manager, your call.

## Disconnect and status

<Tabs syncKey="lang">
  <TabItem label="TypeScript">
    ```typescript
    await client.disconnect(connection.apiKey);
    await client.getStatus(connection.apiKey);
    ```
  </TabItem>
</Tabs>

`disconnect` revokes the apiKey but keeps the install identity, so reconnect from the same `deviceKey` still works.

## Errors

Rejected promises throw `WireSdkError` with a `code` and HTTP `status` when applicable.

## Source

[github.com/usewire/wire-sdk](https://github.com/usewire/wire-sdk) · [@usewire/sdk on npm](https://www.npmjs.com/package/@usewire/sdk) · MIT licensed.