Files
conversation-history/SquareMCP/deployments/2026-06-16-communications-chatgpt-oauth-deploy-handoff.md

8.8 KiB

Communications — ChatGPT/OAuth Scoping — Engineering Handoff for kimi-cli

Date: 2026-06-16 Branch: main Author: Claude Code Status: READY TO DEPLOY — code complete, npx tsc --noEmit clean, full test suite passes (421/421, including 3 new tests). NOT yet committed. Purpose: This is the backend prerequisite for exposing the Chat-First Communications Manager as a Custom GPT in the ChatGPT Store, following the exact same pattern as the already-live "Living Brief" GPT (obsidian-scoped). It does NOT create the GPT itself — that's a manual ChatGPT Builder step for after this deploys (see "What's still needed" below).


⚠️ CRITICAL — DO NOT LEAVE DOCKER RUNNING

After building and pushing the image, stop and remove all local Docker containers before kubectl apply. Docker left running has previously caused port conflicts with the production Kubernetes cluster, breaking live services.

docker stop $(docker ps -q) 2>/dev/null || true
docker rm $(docker ps -aq) 2>/dev/null || true
ss -tlnp | grep -E ':(80|443|3000|8080)'

Only proceed with kubectl apply once Docker containers are confirmed stopped.

Also remember: MySQL runs as a local Docker container that Hermes depends on (127.0.0.1:3306). Per the previous deploy's notes, after the stop/remove step you must restart it before the app will connect:

docker run -d --name mysql --restart unless-stopped \
  -e MYSQL_ROOT_PASSWORD=fetcherpay \
  -e MYSQL_DATABASE=fetcherpay \
  -p 3306:3306 \
  -v fetcherpay_mysql_data:/var/lib/mysql \
  mysql:8.0 --bind-address=0.0.0.0

Why this exists

The Communications routes (/api/communications/*) were originally built only for the first-party dashboard (meterMiddleware — API key or session cookie only). That middleware does not recognize OAuth Bearer tokens, so a ChatGPT Custom GPT (which authenticates via OAuth) could never call these endpoints, scoped or not. This change brings Communications in line with every other domain (obsidian, email, whatsapp, linkedin, telegram, discord, instagram, twitter, facebook, tiktok), all of which use requireAuth, requireCapability('<domain>').

What was built

  1. src/oauth.ts — added 'communications' to the OAUTH_CAPABILITIES const array.
  2. src/index.ts — replaced meterMiddleware with requireAuth, requireCapability('communications') on all 12 /api/communications/* routes (profile GET/PUT, generate-onboarding, examples, chat, drafts GET/PUT, regenerate, reject, approve, status GET/PUT). The dashboard's existing session-cookie login still works fine — requireAuth accepts session cookies too, plus it's a strict superset of what meterMiddleware supported (also accepts the global API key and OAuth Bearer tokens).
  3. src/manifest.ts:
    • Added full OpenAPI path definitions for all /api/communications/* endpoints to the base getOpenApiSpec() (they didn't exist in any spec before this).
    • Added COMMUNICATIONS_PATHS set + getOpenApiSpecCommunications(), mirroring getOpenApiSpecLivingBrief().
  4. src/index.ts — added GET /openapi-communications.json route.
  5. src/index.ts (main()) — added a third ensureOAuthAppRegistered() call, env-var-driven (COMMUNICATIONS_OAUTH_CLIENT_ID / COMMUNICATIONS_OAUTH_CLIENT_SECRET), registering a dedicated OAuth client scoped to ['communications'] only — same pattern as the Living Brief client.
  6. src/manifest.test.ts — added a describe('getOpenApiSpecCommunications') block: path inclusion/exclusion, GET+PUT both present on the draft-edit path, title/description checks.
 src/index.ts         |  40 +++++++----
 src/manifest.test.ts |  36 ++++++++++
 src/manifest.ts      | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/oauth.ts         |   1 +
 4 files changed, 259 insertions(+), 13 deletions(-)

No changes to

  • package.json — no new dependencies
  • src/db.ts / schema — no new tables or columns
  • Any other domain's routes, capabilities, or OpenAPI specs

Verified this session

  • npx tsc --noEmit — clean.
  • npx vitest run — 421/421 tests pass (30 test files), including the 3 new Communications manifest tests.

Not verified (no-docker/no-server constraint this session): live request against a running server, OAuth client registration against a real database, or an actual ChatGPT Action call. All of that requires the deploy below.


Deploy commands

# 1. Commit
git add src/oauth.ts src/index.ts src/manifest.ts src/manifest.test.ts
git commit -m "feat(communications): scope OAuth capability + ChatGPT OpenAPI spec for Communications GPT"
git push origin main

# 2. Build and push image
docker build -t localhost:32000/hermes-mcp:<sha> -t localhost:32000/hermes-mcp:latest .
docker push localhost:32000/hermes-mcp:<sha>
docker push localhost:32000/hermes-mcp:latest

# ⚠️ 3. STOP DOCKER, then restart MySQL, before touching k8s — see warning block above

# 4. Generate a new OAuth client id/secret for the Communications GPT (do NOT reuse Living Brief's)
COMM_CLIENT_ID=$(openssl rand -hex 16)
COMM_CLIENT_SECRET=$(openssl rand -hex 32)
echo "COMMUNICATIONS_OAUTH_CLIENT_ID=$COMM_CLIENT_ID"
echo "COMMUNICATIONS_OAUTH_CLIENT_SECRET=$COMM_CLIENT_SECRET"
# Add both as env vars in hermes-k8s.yaml (gitignored — do not commit these values to git)

# 5. Update image SHA in hermes-k8s.yaml, then apply
microk8s kubectl apply -f hermes-k8s.yaml
microk8s kubectl rollout status deployment/hermes-mcp -n fetcherpay

Expected log line on startup:

[oauth] Communications client <COMM_CLIENT_ID> ensured with communications capability

Verification

BASE=https://hermes.squaremcp.com

# 1. New scoped spec is live
curl -s "$BASE/openapi-communications.json" | python3 -c "import json,sys; d=json.load(sys.stdin); print(list(d['paths'].keys()))"
# Expected: only /api/communications/* paths

# 2. Existing specs unaffected
curl -s "$BASE/openapi-living-brief.json" | python3 -c "import json,sys; d=json.load(sys.stdin); print(list(d['paths'].keys()))"
# Expected: unchanged — only /api/obsidian/* paths

# 3. Communications routes now reject unauthenticated requests (previously meterMiddleware would 401 too, but confirm shape is consistent)
curl -s -o /dev/null -w "%{http_code}\n" "$BASE/api/communications/status"
# Expected: 401

# 4. Communications still works with the existing dashboard session/API key (regression check — use the same x-api-key flow as before)
API_KEY=<an existing customer api key>
curl -s -H "x-api-key: $API_KEY" "$BASE/api/communications/status"
# Expected: 200 { approved_posts_count, autonomous_mode_enabled } — same as before this change

# 5. New OAuth client was registered (check DB directly, or just confirm the startup log line above appeared)
docker exec mysql mysql -uroot -pfetcherpay -e "SELECT client_id, allowed_capabilities FROM hermes_oauth.oauth_clients WHERE client_id = '<COMM_CLIENT_ID>';"
# Expected: one row, allowed_capabilities = ["communications"]

What's still needed after this deploys (manual ChatGPT Builder work — not code)

This deploy only makes the scoped spec and OAuth client available. To actually list Communications in the GPT Store:

  1. In ChatGPT → Create a GPT → Actions → Import from URL → https://hermes.squaremcp.com/openapi-communications.json.
  2. Configure OAuth: Client ID / Secret = the COMM_CLIENT_ID/COMM_CLIENT_SECRET generated in deploy step 4 above. Authorization URL https://hermes.squaremcp.com/oauth/authorize, Token URL https://hermes.squaremcp.com/oauth/token.
  3. Name, description, and a profile icon for the GPT.
  4. Click through the full flow live in the GPT (profile → chat → draft edit → approve/publish) to confirm the OAuth-authenticated path actually works end-to-end — this is the first real test of Communications over OAuth rather than session cookie/API key.
  5. Confirm privacy.html/terms.html (squaremcp.com) adequately describe Communications' data handling (NMLS info, draft content storage, social publishing) before setting the GPT to Public.
  6. Set visibility to Public to list in the GPT Store.

  • Week 1+2 backend handoff: SquareMCP/deployments/2026-06-15-phase1-communications-deploy-handoff.md
  • Week 3 chat UI handoff: SquareMCP/deployments/2026-06-16-phase1-week3-chat-ui-deploy-handoff.md
  • Week 3 chat UI deploy result: SquareMCP/deployments/2026-06-16-phase1-week3-chat-ui-deploy-result.md
  • Living Brief precedent (capability enforcement pattern): SquareMCP/2026-06-13-option-a-capability-enforcement-kimi-handoff.md, SquareMCP/2026-06-13-capability-enforcement-deploy.md

Changelog

Date Author Note
2026-06-16 Claude Code Initial handoff — Communications OAuth capability + scoped OpenAPI spec, not yet committed