# Demo 05 — Deploy to Fly.io and Integrate with Claude Desktop

**Platform aspects**: `ai deploy --target fly`, production serving, MCP integration with Claude Desktop, `ai web` on a custom domain
**Graph**: Neo4j Recommendations (movie agent from Demo 01, promoted to production)
**Audience**: Developers going from prototype to production; Claude Desktop users

---

## The Scenario

You've built and tested the movie recommendation agent locally (Demo 01). Now you want to:
1. Deploy it to Fly.io so it's accessible anywhere, not just on your laptop
2. Connect it to Claude Desktop as an MCP server so team members can use it from their
   AI assistant without any CLI
3. Verify the deployment with the web UI

This is the **"from laptop to production"** story — one command to deploy, one config
line to integrate with Claude.

---

## Prerequisites

```bash
# Completed Demo 01 — agent.toml and toolbox.yaml already exist in my-movie-agent/
cd my-movie-agent

# Fly.io CLI installed and authenticated
fly auth login

# Your AI CLI
ai --version
# ai version 0.4.1
```

---

## Step 1 — Deploy to Fly.io

```bash
ai deploy --target fly
```

The deploy command:
1. Generates a `fly.toml` from your `agent.toml`
2. Creates a Fly app in your account
3. Sets secrets (API keys from your environment)
4. Builds and deploys the Go binary
5. Configures health checks and auto-restart

```
Deploying movie-assistant to Fly.io...

Reading agent.toml...
  name: movie-assistant
  model: claude-sonnet-4-6
  mcp-toolbox: configured (neo4j+s://demo.neo4jlabs.com:7687)

Generating fly.toml...
Creating Fly app: movie-assistant-ai...
  ✓ App created in region: ord (Chicago)

Setting secrets...
  ✓ ANTHROPIC_API_KEY → set
  ✓ NEO4J_URI         → set
  ✓ NEO4J_USERNAME    → set
  ✓ NEO4J_PASSWORD    → set (encrypted)

Building image...
  → docker build --platform linux/amd64 .
  ✓ Image built (82.4 MB)

Deploying...
  ✓ Machine 148ed627f49489 [started]

Waiting for health checks...
  ✓ /health 200 OK (a2a-server :8080)
  ✓ /health 200 OK (mcp-server :8081)

═══════════════════════════════════════
 Deployment successful!

 A2A endpoint:  https://movie-assistant-ai.fly.dev/a2a
 MCP endpoint:  https://movie-assistant-ai.fly.dev/mcp  (Streamable HTTP)
 MCP endpoint:  https://movie-assistant-ai.fly.dev/sse  (legacy SSE)
 Web console:   https://movie-assistant-ai.fly.dev/web
 Agent card:    https://movie-assistant-ai.fly.dev/.well-known/agent.json
═══════════════════════════════════════
```

---

## Step 2 — Verify the deployment

```bash
ai deploy status
```

```
App:        movie-assistant-ai
Region:     ord (Chicago, IL)
Machines:   1 running

MACHINE              STATE    REGION  CREATED
148ed627f49489       started  ord     2026-03-09T15:01:22Z

Health checks:
  a2a-server  ✓ passing  (last: 200 OK, 12ms)
  mcp-server  ✓ passing  (last: 200 OK, 11ms)

Recent activity:
  15:01:22  deploy  completed  (82.4 MB, 48s)
```

Test the agent directly:

```bash
ai run --endpoint https://movie-assistant-ai.fly.dev/a2a \
       "Recommend 5 comedies similar to The Grand Budapest Hotel"
```

```
Thinking...
  → find_movies_by_genre(genre="Comedy")
  → find_similar_movies(title="The Grand Budapest Hotel")

Here are 5 comedies with a similar quirky, visually-distinctive tone:

1. **Moonrise Kingdom** (2012, 7.8★) — Wes Anderson again; a whimsical adventure
2. **The Royal Tenenbaums** (2001, 7.5★) — dysfunctional family comedy-drama
3. **Amélie** (2001, 8.3★) — French quirky-romantic; visual storytelling
4. **Rushmore** (1998, 7.6★) — early Anderson; same deadpan sensibility
5. **O Brother, Where Art Thou?** (2000, 7.7★) — off-beat Coens comedy

All five share: meticulous visual style, deadpan performances, ensemble casts.
```

---

## Step 3 — Integrate with Claude Desktop as an MCP server

Claude Desktop supports MCP servers. Add your deployed agent as a tool source:

**On macOS**, edit `~/Library/Application Support/Claude/claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "movie-assistant": {
      "url": "https://movie-assistant-ai.fly.dev/mcp",
      "headers": {
        "Authorization": "Bearer <your-bearer-token>"
      }
    }
  }
}
```

**On Windows**: `%APPDATA%\Claude\claude_desktop_config.json`

Restart Claude Desktop. The tool icon shows `movie-assistant` as an available server.
See the [Claude Desktop Integration reference](../api.html#claude-desktop) for full config options and multi-server setup.

Now in any Claude conversation you can:

```
Human: Use the movie-assistant tool to find films where Tom Hanks and
       Meg Ryan appeared together

Claude: I'll use the movie-assistant agent to look that up.
        [calling agent_run with query: "Find movies starring both Tom Hanks and Meg Ryan"]

        The movie-assistant found 3 films:
        - You've Got Mail (1998) — romantic comedy
        - Sleepless in Seattle (1993) — romantic drama
        - Joe Versus the Volcano (1990) — comedy
```

Claude Desktop users don't need to know anything about the CLI, the graph, or Cypher —
they just use the agent as a tool in their existing workflow.

---

## Step 4 — Embed the `ai show` output into the agent card

The agent card (`/.well-known/agent.json`) is how other A2A agents discover your agent.
View what it currently advertises:

```bash
curl -s https://movie-assistant-ai.fly.dev/.well-known/agent.json | jq .
```

```json
{
  "name": "movie-assistant",
  "description": "Recommend movies and answer questions about films using a graph database",
  "version": "0.4.1",
  "url": "https://movie-assistant-ai.fly.dev",
  "capabilities": {
    "streaming": true,
    "human_approval": false,
    "skills": ["movie-recommendations"]
  },
  "authentication": {
    "schemes": ["bearer"]
  },
  "endpoints": {
    "a2a": "https://movie-assistant-ai.fly.dev/a2a",
    "mcp": "https://movie-assistant-ai.fly.dev/mcp",
    "mcp_sse": "https://movie-assistant-ai.fly.dev/sse"
  }
}
```

This is automatically populated from `agent.toml`. No manual JSON editing required.

---

## Step 5 — Open the hosted web console

```bash
ai web --a2a https://movie-assistant-ai.fly.dev/a2a
```

```
Opening web console connected to production agent...
→ http://localhost:8888 (proxying to https://movie-assistant-ai.fly.dev)
```

Or navigate directly to the hosted web UI:
```
https://movie-assistant-ai.fly.dev/web
```

The hosted web console works without the local CLI — share the URL with team members
who can use the agent from a browser with just a bearer token.

---

## Step 6 — Stream deployment logs

```bash
ai deploy logs
```

```
2026-03-09T15:14:02Z [app] Starting agent-intelligence.ai v0.4.1
2026-03-09T15:14:02Z [mcp-toolbox] Connecting to neo4j+s://demo.neo4jlabs.com:7687...
2026-03-09T15:14:03Z [mcp-toolbox] ✓ Connected. Loaded 4 tools.
2026-03-09T15:14:03Z [a2a-server] Listening on :8080
2026-03-09T15:14:03Z [mcp-server] Listening on :8081
2026-03-09T15:14:15Z [a2a] POST /a2a 202 Accepted task_01JQ5...  (agent_run: "Recommend 5 comedies...")
2026-03-09T15:14:17Z [mcp-toolbox] find_movies_by_genre: 38ms
2026-03-09T15:14:18Z [mcp-toolbox] find_similar_movies: 41ms
2026-03-09T15:14:19Z [a2a] GET /a2a/task_01JQ5.../stream → completed  (2.1s, 847 tokens)
```

---

## Step 7 — Update the deployment

When you update `agent.toml` or `toolbox.yaml`, redeploy with:

```bash
ai deploy --target fly
```

```
Deploying update to movie-assistant-ai...
  ✓ Config diff applied
  ✓ Image rebuilt
  ✓ Rolling restart (zero-downtime)
  ✓ Health checks passing

Update complete. No requests dropped.
```

---

## What you just demonstrated

| Before | After |
|---|---|
| Agent runs on your laptop | Agent runs on Fly.io, globally accessible |
| `ai run` in a terminal | Claude Desktop users call it as an MCP tool |
| Local `ai web` at :8888 | Hosted web UI at fly.dev domain |
| API key in local env | Secrets encrypted in Fly vault |
| Manual restart on changes | `ai deploy --target fly` redeploy |

The same agent that started with `ai init` and five minutes of work now serves production
traffic, integrates with Claude Desktop, and has a shareable web UI — without any
infrastructure configuration beyond `fly auth login`.

---

## Appendix — Fixture files

```bash
# Quick-start with pre-built fixtures (agent.toml + toolbox.yaml + fly.toml.example):
curl -fsSL https://agent-intelligence.ai/downloads/demo-05-fixtures.tar.gz | tar xz
cd demo-05 && ai sidecar install && fly auth login && ai deploy --target fly
```

Fixture files: [`fixtures/demo-05/agent.toml`](fixtures/demo-05/agent.toml),
[`fixtures/demo-05/toolbox.yaml`](fixtures/demo-05/toolbox.yaml),
[`fixtures/demo-05/fly.toml.example`](fixtures/demo-05/fly.toml.example)

---

## Appendix — Cloud Run deployment

Not a Fly.io user? Cloud Run works too:

```bash
ai deploy --target cloudrun
```

```
Deploying movie-assistant to Cloud Run...
  ✓ Container pushed to gcr.io/my-gcp-project/movie-assistant
  ✓ Service created: https://movie-assistant-<hash>-uc.a.run.app
  ✓ Health checks passing
```

The same `agent.toml` works for both targets — `ai deploy` handles the platform differences.

---

*This completes the five-demo series. Start from Demo 01 for a linear walkthrough,
or jump to any demo that matches your use case.*
