# MIDAS Developer Manual (v3.4)

Base URL: `https://midas.pyrexxai.com`
- Secret Server Key: `Authorization: Bearer midas_live_YOUR_SECRET_KEY`
- Publishable Browser Key: `Authorization: Bearer midas_pk_YOUR_GONG_KEY` (write-only single-contact ingestion pinned to 1 Gong)

## Environment Variables
- `MIDAS_API_KEY`: Server-only secret key (`midas_live_...`)
- `MIDAS_PUBLISHABLE_KEY`: Public browser key (`midas_pk_...`)
- `MIDAS_BASE_URL`: Target MIDAS host (`https://midas.pyrexxai.com`)
- `MIDAS_WEBHOOK_SECRET`: Webhook signing secret (`whsec_...`)

## 1. Remote MCP Server & Stdio Bridge (Claude Code / Cursor / Codex)
- Remote Streamable HTTP: `POST https://midas.pyrexxai.com/api/mcp` (`initialize` and `tools/list` are publicly readable; `tools/call` requires `Bearer midas_live_...`)
- Stdio Bridge: `MIDAS_API_KEY=midas_live_... npx -y @midas-aem/client mcp`
- Tools: `midas_create_gong_channel`, `midas_get_embed_snippet`, `midas_subscribe_contact`, `midas_track_event`, `midas_send_sandbox_test`, `midas_get_campaign_health`, `midas_create_artifact`.

## 2. Shadow DOM Newsletter Embeds & Zero-CLI Next.js Proxy
```typescript
// app/api/midas/subscribe/route.ts
export { POST } from '@midas-aem/client/next';
```

```html
<script src="https://midas.pyrexxai.com/api/public/town-crier/widget.js" async></script>
<button data-town-crier-modal data-key="midas_pk_YOUR_GONG_KEY" data-gong="weekly-alpha" data-theme-mode="match-host">Subscribe</button>
```

## 3. TypeScript & Python SDK Quickstart
```typescript
import { MidasClient } from '@midas-aem/client';
const midas = new MidasClient();
await midas.subscribe({ email: 'alex@acme.com', gongId: 'weekly-alpha', cadence: 'weekly' });
await midas.trackEvent({ email: 'alex@acme.com', eventName: 'trial.started', properties: { plan: 'chief' } });
```

## 4. Town Crier Public Endpoints & Hosted Pages
- `GET /api/public/town-crier/gongs/:key/config` & `/count`: Live Gong palette/config & zero-PII subscriber count.
- `POST /api/public/town-crier/subscribe` (`midas_pk_` or `midas_live_`): Subscribe contact + trigger welcome autoresponder + cross-engine cold pause.
- `POST /api/public/town-crier/capture-partial` (`midas_pk_` or `midas_live_`): Partial progressive capture for Cart Recovery.
- `GET /api/public/town-crier/recover/:resumeToken?complete=1`: 1-click Cart Recovery completion.
- `GET /api/public/town-crier/subscribers/status` & `PATCH /subscribers/preferences` (`midas_live_`).
- `GET /g/:handle/:gongSlug`, `/issues/:broadcastId`, `/rss.xml`, `GET|POST /p/:token`.

## 5. Open Scoped APIs (`midas_live_` OR Session JWT)
- `/api/campaigns/*` (`campaigns:read|write`)
- `/api/leads/*` (`leads:read|write`)
- `/api/artifacts/*` (`campaigns:read|write`)
- `/api/sandbox/*` (`campaigns:read|write`)
- `/api/domains/*` (`domains:read|write`)
- `/api/knowledge/*` (`knowledge:read|write`)
- `/api/inbox/*` (`inbox:read|write`)
- `/api/events/track` & `/api/events/rules` (`events:read|write`)
- `POST /api/mcp` (Stateless Streamable HTTP JSON-RPC 2.0)
