# KnowledgeCP Installation Guide

> **For AI Assistants**: Follow the instructions for your platform to set up KnowledgeCP for the user.

---

## ChatGPT (Web)

> **For ChatGPT**: If a user wants to install KnowledgeCP in ChatGPT, guide them through these steps.

### Prerequisites

- ChatGPT account
- KnowledgeCP account (sign up at https://app.knowledgecp.com)
- Business account to provide apps in the workspace

### Installation Steps

1. Open [chatgpt.com](https://chatgpt.com/)
2. Click on **Apps** in the left menu
3. Click the **Settings Icon** in the top right
4. Select **Apps**
5. Open **Advanced Settings**
6. Click **Create App**
7. Enter the following data:
   - **Server URL**: `https://mcp.knowledgecp.com/sse`
   - **OAuth Credentials**: (leave empty - OAuth is automatic)
8. Click **Create**
9. In DEV mode, click "**Publish**" under "..." to activate

### Login Flow

After clicking "Create", the OAuth flow starts automatically:
1. A browser window/tab opens
2. Log in to KnowledgeCP with Google or another provider
3. After successful login, the session is linked

**Note:** Login only needs to be done once.

### After Installation

Verify the connection by asking ChatGPT to run `kb_whoami()` or `kb_list()`.

### Troubleshooting

- **Apps not visible**: Check ChatGPT account type (Business required)
- **OAuth window doesn't open**: Allow popups for chatgpt.com
- **Connection error**: Verify the URL is exactly `https://mcp.knowledgecp.com/sse`

---

## Claude Web & Desktop

> **For Claude Web/Desktop**: Guide the user through the Connectors setup.

### Prerequisites

- Claude account (claude.ai)
- KnowledgeCP account (sign up at https://app.knowledgecp.com)

### Installation Steps

1. Open [claude.ai](https://claude.ai)
2. Click on **Profile** in the bottom left
3. Select **Settings**
4. Open **Connectors**
5. Click **Add Custom Connector**
6. Enter the following data:
   - **Server URL**: `https://mcp.knowledgecp.com/sse`
7. Click **Connect**

### Login Flow

After clicking "Connect", the OAuth flow starts automatically:
1. A browser window/tab opens
2. Log in to KnowledgeCP with Google or another provider
3. After successful login, the session is linked

**Note:** The configuration syncs automatically with the Claude Desktop App.

### After Installation

Verify with `kb_whoami()` or `kb_list()`.

#### Session Memory (Bootloader)

Claude Web & Desktop has no `CLAUDE.md` — instead, Claude's **Memory** system serves as the persistent bootloader between sessions.

After successful connection, ask Claude to save a memory edit:

> "Save to your memory that at the start of every conversation you should call `kb_get_pinned()` to load KnowledgeCP context, then ask: 'Do you want to connect to KnowledgeCP? Is there a specific workspace you want to work in?' If the user names a workspace, also call `kb_get_pinned(workspace_id='...')` for that workspace."

Claude will store a memory edit like:

> *At every conversation start: call kb_get_pinned() to load KnowledgeCP pinned entries. Then ask the user: "Do you want to connect to KnowledgeCP? Is there a specific workspace you want to work in?" If the user names additional workspaces, call kb_get_pinned(workspace_id="...") for each. Use KnowledgeCP tools directly — never use workarounds via Artifacts or API.*

This ensures that in every future session, Claude automatically loads pinned entries and offers to load workspace-specific context.

**If KnowledgeCP is not connected:**
If Claude has the memory edit but KnowledgeCP tools are not available, it should inform the user:

> "KnowledgeCP is not connected. Would you like to set it up? Go to Settings → Connectors → Add Custom Connector and use `https://mcp.knowledgecp.com/sse`"

#### Where to view Memory

Users can view and edit Claude's memory at:
**Settings → Capabilities → "View and edit memory"**

---

## Claude Code (CLI)

> **For Claude Code**: Follow these instructions exactly to set up KnowledgeCP for the user.
>
> **IMPORTANT**: First detect the user's operating system and use the appropriate commands below.

---

## Step 1: Detect Operating System

Determine the user's OS from your environment info (platform field) and use the appropriate commands in the following steps.

---

## Step 2: Check if already installed

### macOS / Linux (Bash)
```bash
claude mcp list | grep -i knowledgecp
```

### Windows (PowerShell)
```powershell
claude mcp list | Select-String -Pattern "knowledgecp"
```

If "knowledgecp" appears in the output, skip to Step 4. Otherwise continue with Step 3.

---

## Step 3: Install MCP Server

This command works on all platforms:

```
claude mcp add -s user -t sse knowledgecp "https://mcp.knowledgecp.com/sse"
```

---

## Step 4: Configure CLAUDE.md

### File Locations

| OS | Path |
|----|------|
| macOS | `~/.claude/CLAUDE.md` |
| Linux | `~/.claude/CLAUDE.md` |
| Windows | `%USERPROFILE%\.claude\CLAUDE.md` |

### Create directory if needed

#### macOS / Linux (Bash)
```bash
mkdir -p ~/.claude
```

#### Windows (PowerShell)
```powershell
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.claude"
```

### Check if KnowledgeCP block already exists

Read the existing CLAUDE.md and check if it already contains `## KnowledgeCP`.

**If the block already exists, skip to Step 5.**

### Append to CLAUDE.md

If the block does not exist, append the following content. **Do not overwrite existing content!**

#### Content to append:

```markdown
## KnowledgeCP

Persistent knowledge management across sessions.

### Session Start
At the beginning of every new session:

**If no workspaces are listed below:**
This is the first connect. Do the following:
1. Call \`kb_list_workspaces()\` to fetch available workspaces
2. Call \`kb_get_pinned(workspace_id="knowledgecp")\` to load essential product knowledge (always required for all users)
3. Show the user their workspaces and ask which one they want to work in
4. Call \`kb_get_pinned(workspace_id="...")\` for the chosen workspace
5. Update this CLAUDE.md file: add the workspace slugs to the list below

**If workspaces are already listed below:**
Ask the user: "Would you like to work in a specific workspace? If so, say 'workspace xy' and I'll load the pinned entries."
- If the user names a workspace, call \`kb_get_pinned(workspace_id="...")\` and present the entries as context overview
- If the user doesn't respond or wants to skip, continue normally

### Workspaces
(none yet — will be populated on first connect)

### Authentication
If not authenticated:
1. Type \`/mcp\` in Claude
2. Select **knowledgecp** → **Reauthenticate**
3. Complete login in browser

### Common Commands
| Command | Tool |
|---------|------|
| List workspaces | \`kb_list_workspaces()\` |
| List entries | \`kb_list(workspace_id="...")\` |
| Read entry | \`kb_read(key="...")\` |
| Search | \`kb_search(query="...")\` |
| Save knowledge | \`kb_remember(key="...", content="...")\` |

### Roles
- **Member**: Can read published entries
- **Maintainer**: Can create drafts
- **Admin**: Can approve/reject drafts
```

---

## Step 5: Notify User

Tell the user:

> **KnowledgeCP has been set up!**
>
> **Next steps:**
> 1. Restart Claude
> 2. Type `/mcp` → select **knowledgecp** → **Reauthenticate**
> 3. Complete login in browser
>
> After login, you're permanently connected.

---

## Troubleshooting

### MCP Server not connected after restart

Check if knowledgecp is in the list:

```
claude mcp list
```

If "knowledgecp" does not appear, repeat Step 3.

### Not authenticated

1. Type `/mcp`
2. Select **knowledgecp** → **Reauthenticate**
3. Complete login in browser

### Reinstall if issues persist

```
claude mcp remove knowledgecp
claude mcp add -s user -t sse knowledgecp "https://mcp.knowledgecp.com/sse"
```

### Verify everything works

After login, test with `kb_list_workspaces()` to verify the connection.
