# ChatGPT Task runtime — AdMedia MCP hybrid routing

Use this doc when scheduled **ChatGPT Tasks** fail with `Unknown tool` or
`AdMedia namespace/tools are not exposed in this runtime`, while individual
MCP calls work in normal chat.

Individual chat success proves the MCP **server** is healthy. Task failures
usually mean the **Task runtime** did not attach the connector, does not support
custom MCP, or hybrid routing sent MCP tool names to the wrong connector.

---

## Standard header (paste at top of every scheduled Task)

Paste the block below **before** your daily-changing task instructions. Keep it
identical each day; edit only the content after the end marker.

```text
=== ADMEDIA TASK RUNTIME — PASTE THIS BLOCK FIRST (DO NOT EDIT DAILY) ===

CONNECTOR ROUTING (mandatory)
This task uses TWO layers. Never call the same source through both.

PRIMARY — native plugins only (all Slack/Jira/Confluence/Drive/Fireflies evidence):
• Slack → native Slack only. Never AdMedia MCP slack_* / slack_ask.
• Jira → native Jira only. Never AdMedia MCP jira_*.
• Confluence → native Confluence only. Never AdMedia MCP confluence_*.
• Drive → native Drive only. Never AdMedia MCP gdrive_*.
• Fireflies → native Fireflies if available; else native Drive. Never AdMedia MCP fireflies_*.

ADMedia MCP — allowed tools only (when namespace is exposed):
• monitor_identity_lookup, monitor_team_activity, monitor_jira_activity, monitor_slack_activity, monitor_bitbucket_activity
• hubspot_list_accounts, hubspot_search_deals, hubspot_get_deal (Sales/BD only)
• search_affiliates, get_affiliate_report, get_advertiser_report (publisher/revenue only)
• health_stub (smoke test only)

FORBIDDEN via AdMedia MCP: slack_*, jira_*, confluence_*, gdrive_*, fireflies_*, gmail_*, gcal_*, bb_*

STARTUP (run once at the beginning of this run):
1. Try AdMedia MCP → health_stub { ping: "task-start" }
2. If step 1 succeeds → AdMedia MCP → monitor_identity_lookup { query: "<one known name>", limit: 1 }
3. Native Slack → list members or search one channel
4. Native Jira → list projects or search one known ticket

If steps 1–2 pass → AdMedia MCP is OK for Monitor/Cake/HubSpot.
If steps 3–4 pass → collab is OK via native plugins.
Proceed unless BOTH layers fail completely.

IF ADMEDIA MCP NAMESPACE IS NOT EXPOSED (health_stub unavailable, "namespace not exposed", "tools are not exposed in this runtime"):
• Do NOT fail or abort the entire task.
• Mark AdMedia MCP as UNAVAILABLE FOR THIS RUN.
• Skip ALL AdMedia MCP calls: health_stub, monitor_*, hubspot_*, search_affiliates, get_*_report, Cake/MNGT, Bitbucket via MCP.
• Continue using native Slack, Jira, Confluence, Drive, and Fireflies only.
• Label all output INTERIM / INCOMPLETE — Monitor and Cake/HubSpot layers missing for this run.
• Do not retry MCP collab tools — they will also fail if the namespace is missing.

IF ADMEDIA MCP IS EXPOSED BUT RETURNS "Unknown tool" OR SESSION ERROR:
• Do NOT declare all AdMedia MCP broken.
• Retry health_stub once { ping: "task-retry" }.
• If health_stub succeeds → use AdMedia MCP only for Monitor/Cake/HubSpot; keep all collab on native plugins.
• If health_stub fails → mark Monitor/Cake/HubSpot SOURCE UNAVAILABLE; continue on native sources; label INTERIM.

Monitor rule (when MCP available): max 92 days per monitor_* call. For 365 days use four windows: 0–92, 93–184, 185–276, 277–365 days back from run date. Monitor is corroboration only — never score from raw counts alone.

Do not verify AdMedia MCP at startup by calling HubSpot, Cake, Fireflies, Slack, Jira, or Drive through MCP.

=== END STANDARD BLOCK — DAILY TASK INSTRUCTIONS BELOW ===
```

---

## Task connector checklist

Configure in **Task → Connectors** (not only Settings → Apps & Connectors for chat):

| Setting | Value |
| --- | --- |
| AdMedia MCP URL | `https://<host>/mcp?api_key=lucos_mcp_live_…` |
| Authentication | **No Auth** (key in query string) |
| Native connectors | Slack, Jira, Confluence, Drive, Fireflies enabled |
| After any change | Start a **new** task run |

Use `/mcp` (Streamable HTTP), not `/sse`. See [`LOCAL-CHATGPT-NGROK.md`](./LOCAL-CHATGPT-NGROK.md).

---

## Diagnostic: individual chat works, Task fails

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| `health_stub` works in chat, Task says **namespace not exposed** | MCP not attached to Task, or Tasks do not support custom MCP | Attach connector on the Task; run minimal smoke Task below |
| `Unknown tool` on `jira_*` / `slack_*` in Task | Hybrid collision — MCP + native plugins | Use standard header; never call MCP collab tools |
| `Session not found` mid-run | Long Task dropped MCP session | Shorter Task runs; re-initialize |
| All MCP tools fail at startup probe | Prompt tests HubSpot + Cake + Fireflies + Slack via MCP | Remove startup MCP collab probe; use header startup only |

### Minimal Task smoke (one line)

Create a Task with **only** this instruction and AdMedia MCP attached:

```text
Call AdMedia MCP health_stub with ping "task-smoke". Report pass or fail only.
```

| Result | Meaning |
| --- | --- |
| **Pass** | MCP exposed in Tasks — use standard header for hybrid routing |
| **Namespace not exposed** | Tasks do not get MCP — header degrades gracefully; Monitor/Cake/HubSpot unavailable in Tasks until connector/platform fixed |
| **Unknown tool on health_stub** | Wrong connector URL or routing — check `/mcp?api_key=…` on the Task |

---

## What the header fixes vs does not fix

| Situation | Header helps? |
| --- | --- |
| Hybrid `Unknown tool` on collab when MCP is connected | **Yes** |
| Namespace not exposed in Task | **Degrades only** — task continues on native plugins; MCP data still missing |
| MCP not attached to Task | **No** — fix Task connector settings |
| Individual chat MCP usage | **No impact** — header is Task instructions only |

---

## Architecture (hybrid)

```text
ChatGPT Task
  ├─ Native Slack / Jira / Confluence / Drive / Fireflies  (PRIMARY collab)
  └─ AdMedia MCP  (Monitor, HubSpot, Cake/MNGT only)
        → business-mcp.lucos.com
        → monitor_* (Admin DB RO)
        → hubspot_* / get_*_report (gateway → slack-bot-service or local connectors)
```

Do **not** call `slack_*`, `jira_*`, `confluence_*`, `gdrive_*`, or `fireflies_*`
via AdMedia MCP when native plugins are enabled on the same Task.

---

## Related docs

- [`CHATGPT-TASK-RUNTIME-CODE-CHANGES.md`](./CHATGPT-TASK-RUNTIME-CODE-CHANGES.md) — engineering code change spec (CC-1 through CC-5)
- [`LOCAL-CHATGPT-NGROK.md`](./LOCAL-CHATGPT-NGROK.md) — MCP connector URL and auth
- [`COLLAB-TOOL-INTEGRATION.md`](./COLLAB-TOOL-INTEGRATION.md) — collaboration tool contracts
- [`README.md`](../README.md) — MCP server overview
