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

# CLI Integrations

> Generate framework-specific SDK integration code

# Framework Integrations

The `mutagent integrate` command is a **skill loader for AI coding agents**. It generates ready-to-use SDK integration instructions that AI assistants (Claude Code, Cursor, etc.) can directly apply to a codebase. It does **not** auto-install packages.

<Tip>
  **For AI Agents**: Use `mutagent integrate <framework> --raw` to get clean markdown that can be directly applied to a codebase.
</Tip>

## Pre-Step: Framework Detection

Before generating integration code, you can use `mutagent explore` to auto-detect your framework by scanning the codebase:

```bash theme={null}
# Scan your project to detect AI frameworks in use
mutagent explore
```

The `explore` command inspects your `package.json` dependencies and project structure to identify which AI frameworks you are using. This is especially useful when you are unsure which integration to generate.

<Tip>
  After `mutagent auth login`, the CLI offers a guided post-onboarding flow that automatically runs `mutagent explore` and walks you through framework selection, package installation, and code generation.
</Tip>

## Quick Start

```bash theme={null}
# Detect your framework first
mutagent explore

# No framework specified - returns exploration instructions for AI agents
mutagent integrate

# Specify framework directly
mutagent integrate langchain

# Save integration guide to file
mutagent integrate langchain --output INTEGRATION.md

# Raw markdown output for AI agents (no terminal formatting)
mutagent integrate vercel-ai --raw

# Verify an existing integration
mutagent integrate openai --verify

# List all available frameworks
mutagent integrate list

# JSON output
mutagent integrate list --json
```

## Supported Frameworks

| Framework | Command                        | MutagenT Package      | Description                                 |
| --------- | ------------------------------ | --------------------- | ------------------------------------------- |
| LangChain | `mutagent integrate langchain` | `@mutagent/langchain` | Popular LLM application framework           |
| LangGraph | `mutagent integrate langgraph` | `@mutagent/langgraph` | Agent workflow framework built on LangChain |
| Vercel AI | `mutagent integrate vercel-ai` | `@mutagent/vercel-ai` | AI SDK for building streaming chat UIs      |
| OpenAI    | `mutagent integrate openai`    | `@mutagent/openai`    | Official OpenAI SDK with automatic tracing  |

<Note>
  **Python support**: Python integrations are also available for OpenAI, LangChain, and LangGraph. See the [Python Integrations](/integrations/python/overview) section for details.
</Note>

## How It Works

<Mermaid
  chart={`
flowchart LR
A["mutagent integrate"] --> B{Framework<br/>specified?}
B -->|No| C["Return exploration<br/>instructions"]
B -->|Yes| D["Load framework<br/>generator"]
D --> E["Detect package<br/>manager"]
E --> F["Generate numbered<br/>steps"]
F --> G["Step 1: Install"]
F --> H["Step 2: Code"]
F --> I["Step 3: Env vars"]

style A fill:#7C3AED,color:#fff
style C fill:#06B6D4,color:#000
style G fill:#10B981,color:#000
style H fill:#10B981,color:#000
style I fill:#10B981,color:#000
`}
/>

When a framework is specified, the CLI:

1. **Verifies** your API key is configured
2. **Detects** your package manager (bun, npm, yarn, or pnpm) from lockfiles
3. **Generates** a numbered integration guide with install commands, framework-specific code, and environment variable setup
4. **Optionally verifies** the integration with `--verify`

When no framework is specified, the CLI returns **exploration instructions** that guide AI agents to detect the framework from `package.json` dependencies or ask the user.

## Framework Examples

### OpenAI

```bash theme={null}
mutagent integrate openai
```

Generates a traced OpenAI client wrapper:

```typescript theme={null}
import OpenAI from 'openai';
import { observeOpenAI } from '@mutagent/openai';
import { initTracing } from '@mutagent/sdk/tracing';

// Initialize tracing (or set MUTAGENT_API_KEY env var for auto-init)
initTracing({
  apiKey: process.env.MUTAGENT_API_KEY!,
  endpoint: process.env.MUTAGENT_ENDPOINT,
});

// Wrap the OpenAI client for automatic tracing
const openai = observeOpenAI(new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
}));

const completion = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Hello!' }],
});
```

### LangChain

```bash theme={null}
mutagent integrate langchain
```

Generates a callback handler for LangChain chains and LLMs:

```typescript theme={null}
import { ChatOpenAI } from '@langchain/openai';
import { MutagentCallbackHandler } from '@mutagent/langchain';
import { initTracing } from '@mutagent/sdk/tracing';

initTracing({
  apiKey: process.env.MUTAGENT_API_KEY!,
  endpoint: process.env.MUTAGENT_ENDPOINT,
});

// Create callback handler (no args needed - uses SDK tracing)
const handler = new MutagentCallbackHandler();

const llm = new ChatOpenAI({
  callbacks: [handler],
});

const result = await llm.invoke('Hello world');
// Traces automatically captured via LangChain callbacks
```

### LangGraph

```bash theme={null}
mutagent integrate langgraph
```

Generates a traced LangGraph setup using the LangChain callback handler (which works for LangGraph too):

```typescript theme={null}
import { StateGraph, Annotation } from '@langchain/langgraph';
import { MutagentCallbackHandler } from '@mutagent/langchain';
import { initTracing } from '@mutagent/sdk/tracing';

initTracing({
  apiKey: process.env.MUTAGENT_API_KEY!,
  endpoint: process.env.MUTAGENT_ENDPOINT,
});

// Create callback handler (works for both LangChain and LangGraph)
const handler = new MutagentCallbackHandler();

const graph = new StateGraph(StateAnnotation)
  .addNode('agent', agentNode)
  .addNode('tools', toolNode)
  .addEdge('__start__', 'agent')
  .compile();

const result = await graph.invoke(
  { input: 'Hello' },
  { callbacks: [handler] },
);
```

### Vercel AI SDK

```bash theme={null}
mutagent integrate vercel-ai
```

Generates middleware for the Vercel AI SDK:

```typescript theme={null}
import { streamText, wrapLanguageModel } from 'ai';
import { openai } from '@ai-sdk/openai';
import { createMutagentMiddleware } from '@mutagent/vercel-ai';
import { initTracing } from '@mutagent/sdk/tracing';

initTracing({
  apiKey: process.env.MUTAGENT_API_KEY!,
  endpoint: process.env.MUTAGENT_ENDPOINT,
});

// Create middleware (no args needed - uses SDK tracing)
const middleware = createMutagentMiddleware();

// Wrap your model with MutagenT middleware
const model = wrapLanguageModel({
  model: openai('gpt-4o'),
  middleware,
});

const result = streamText({ model, messages });
```

## Options

| Option                | Description                                                           |
| --------------------- | --------------------------------------------------------------------- |
| `-o, --output <path>` | Save integration guide to file                                        |
| `--raw`               | Output raw markdown without terminal formatting (ideal for AI agents) |
| `--verify`            | Verify the integration after generation                               |
| `--json`              | Output in JSON format (on the parent command)                         |

## Exploration Mode (No Framework)

When run without a framework argument, the CLI returns **exploration instructions** designed for AI agents:

```bash theme={null}
mutagent integrate
```

The exploration instructions guide AI agents to:

1. Check `package.json` for known framework dependencies (`langchain`, `@langchain/core`, `@langchain/langgraph`, `ai`, `openai`)
2. Or ask the user which framework they are using
3. Then re-run `mutagent integrate <framework>` with the detected framework

This design keeps the CLI stateless and lets the AI agent handle the detection logic.

## List Available Frameworks

```bash theme={null}
mutagent integrate list
```

Returns metadata for all supported frameworks including the name, display name, description, npm package, and MutagenT adapter package. Supports `--json` output for programmatic use:

```bash theme={null}
mutagent integrate list --json
```

## Python Users

<Note>
  The `mutagent integrate` command generates TypeScript integration code only. For Python integration setup, see [Python Integrations](/integrations/python/overview) — the Python packages (`mutagent-anthropic`, `mutagent-openai`, `mutagent-langchain`, `mutagent-langgraph`) will be available on PyPI soon. Until then, install from the monorepo source.
</Note>
