# CLI commands for AI

> The commands in this section allow you to manage AI rules and MCP server setup for enhanced AI-assisted development.

Source: https://docs.uniform.app/docs/guides/cli/commands/ai

## Overview

The commands in this section allow you to manage AI-related tools that enhance your development experience with Uniform. This includes:

| Project asset | Command |
| --- | --- |
| AI Rules | [ai rules install](#install-ai-rules), [ai rules list](#list-available-rules) |
| MCP Server | [ai mcp install](#install-mcp-server) |

## AI Rules commands

AI rules provide LLM tools with up-to-date knowledge about Uniform concepts, SDK usage, and best practices.

### Install AI rules

Installs and configures AI rules for your project. This command supports both Cursor and Claude Code.

```shell
uniform ai rules install
```

#### Options

| Option | Description | Default |
| --- | --- | --- |
| `--agent <type>`, `-a` | Specify agent type (cursor, claude, other) | Auto-detected |
| `--directory <path>`, `-d` | Custom installation directory | Auto-detected based on AI tool |
| `--help` | Show help information |  |

#### Examples

**Basic installation:**

```shell
uniform ai rules install
```

**Install for specific agent:**

```shell
uniform ai rules install --agent cursor
```

**Install to custom directory:**

```shell
uniform ai rules install --directory .cursor
```

#### What it does

1. **Detects your AI tool** - Automatically identifies whether you're using Cursor, Claude Code, or other MCP-compatible tools
2. **Downloads latest rules** - Fetches the most current AI rules from the [Uniform AI rules repository](https://github.com/uniformdev/ai-rules)
3. **Configures placement** - Places rules in the appropriate directory (`.cursor`, `.claude`, etc.)
4. **Validates setup** - Ensures rules are properly configured and accessible

#### Rules included

The installation includes essential rules for:

- **Core Uniform concepts** (`uniform.mdc`) - Fundamental principles and architecture
- **SDK usage** (`uniform-sdk.mdc`) - Uniform SDK capabilities and patterns
- **Framework-specific guidance:**

  - Next.js Page Router (`uniform-next-page-router.mdc`)
  - Next.js App Router (`uniform-next-app-router.mdc`)
- **Optional personal preferences** - Customizable defaults and coding standards

#### Usage with AI tools

**Cursor:**
After installation, the rules will be available in your `.cursor` folder. Add them to your chat context when working with Uniform projects.

**Claude Code:**
The rules will be placed in the appropriate location for Claude Code to automatically detect and use them.

### List available rules

Lists all available Uniform AI rules that can be installed.

```shell
uniform ai rules list
```

#### Examples

**List all available rules:**

```shell
uniform ai rules list
```

This command displays:

- **Rule name** - The filename and identifier
- **Description** - What the rule covers
- **Status** - Whether it's a core rule, framework-specific, or optional

## MCP Server commands

The Model Context Protocol (MCP) Server allows AI tools to directly interact with Uniform APIs to create and manage components, content types, and patterns.

### Install MCP server

Installs and configures the Uniform MCP Server for your project.

```shell
uniform ai mcp install
```

#### Options

| Option | Description | Default |
| --- | --- | --- |
| `--agent <type>`, `-a` | Specify agent type (cursor, claude, other) | Auto-detected |
| `--directory <path>`, `-d` | Custom installation directory | Auto-detected based on agent |
| `--project <id>`, `-p` | Project ID to use (skips project selection) | Interactive selection |
| `--team <id>`, `-t` | Team ID to use (skips team selection) | Interactive selection |
| `--apiKey <key>` | Uniform API key with write access (skips API key generation) | Auto-generated |
| `--apiHost <host>` | Uniform host | _For the US region:_<br>_For the EU region:_<br> |
| `--aiApiHost <host>` | Uniform AI API host | _For the US region:_<br>_For the EU region:_<br> |
| `--help` | Show help information |  |

#### Examples

**Interactive installation (recommended):**

```shell
uniform ai mcp install
```

**Non-interactive installation:**

```shell
uniform ai mcp install --project <project-id> --apiKey <api-key>
```

**Install for specific agent:**

```shell
uniform ai mcp install --agent cursor
```

**Custom directory:**

```shell
uniform ai mcp install --directory ./my-mcp-config
```

#### What it does

1. **Interactive/Non-interactive modes** - Supports both guided setup and automated installation
2. **Agent detection** - Automatically identifies your AI tool (Cursor, Claude, other)
3. **Authentication setup** - Generates API keys or uses provided ones
4. **Configuration generation** - Creates appropriate config files (`.mcp.json` for Claude, `mcp.json` for others)
5. **Directory management** - Creates necessary directories and preserves existing MCP servers

#### Prerequisites

- **Uniform account** and access to a team/project
- **AI Credits** in your Uniform team (required for create and search operations)

> **Info:**
>
> The command can run in interactive mode (walks you through team/project selection and API key generation) or non-interactive mode (requires `--project` and `--apiKey` parameters).

> **AI Credits Required:**
>
> Create and search operations performed through the MCP Server require AI Credits in your Uniform Team. If you have already used all your existing credits, please check with your Account Representative from Uniform for a top-up.

#### Configuration

The installation creates a configuration file with the following naming convention:

- **Claude Desktop/Code**: `.mcp.json` (hidden file)
- **Cursor and others**: `mcp.json`

The configuration file structure:

_For the US region:_

```json
{
  "mcpServers": {
    "Uniform": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@uniformdev/uniform-mcp"
      ],
      "env": {
        "UNIFORM_API_KEY": "your-api-key",
        "UNIFORM_PROJECT_ID": "your-project-id",
        "UNIFORM_AI_API_HOST": "https://ai.uniform.global"
      }
    }
  }
}
```

_For the EU region:_

```json
{
  "mcpServers": {
    "Uniform": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@uniformdev/uniform-mcp"
      ],
      "env": {
        "UNIFORM_API_KEY": "your-api-key",
        "UNIFORM_PROJECT_ID": "your-project-id",
        "UNIFORM_AI_API_HOST": "https://ai.eu.uniform.global"
      }
    }
  }
}
```

> **Info:**
>
> If you have existing MCP servers configured, the installer will preserve them and only add/update the Uniform server configuration.

## Troubleshooting

### AI Rules installation issues

**Rules not appearing in AI tool:**

- Ensure the rules are in the correct directory for your AI tool
- Restart your AI tool after installation
- Check file permissions and directory structure

**Installation fails:**

- Verify you have internet connectivity to download rules
- Check write permissions in the target directory
- Try specifying a custom directory with `--directory`

### MCP Server issues

**Interactive mode issues:**

- Verify you have access to at least one team and project
- Check your network connectivity

**Non-interactive mode fails:**

- Verify the project ID exists and you have access
- Ensure the API key has appropriate permissions

**MCP Server not detected in AI tool:**

- Restart your AI tool after installation
- For Cursor: Check Settings > MCP & Integrations
- For Claude: Verify the `.mcp.json` file exists in the correct location
- Check the configuration file format is valid JSON

**AI Credits exhausted:**

- Contact your Uniform Account Representative for credit top-up
- Monitor your team's AI credit usage in Uniform dashboard

For additional help, see the [CLI troubleshooting guide](https://docs.uniform.app/docs/guides/cli/troubleshooting).
