Skip to content

mcp: heal stale preconfigured agent tokens on stdio startup#73

Merged
khaliqgant merged 1 commit intomainfrom
fix/agent-token-write-path-20260309-204028
Mar 10, 2026
Merged

mcp: heal stale preconfigured agent tokens on stdio startup#73
khaliqgant merged 1 commit intomainfrom
fix/agent-token-write-path-20260309-204028

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

@khaliqgant khaliqgant commented Mar 9, 2026

Summary

  • validate the preconfigured MCP agent token on stdio startup instead of blindly trusting it
  • auto-heal stale/unauthorized tokens by calling registerOrRotate when the workspace key + agent name are available
  • accept RELAY_CLAW_NAME as an alias for RELAY_AGENT_NAME
  • add tests covering valid token reuse, stale token rotation, and name-only bootstrap

Why

We hit a confusing partial-success state in a real OpenClaw + Relaycast setup:

  • workspace key/config was valid
  • list_agents worked
  • inbound messages injected correctly
  • but post_message / reply_to_thread failed because the preconfigured RELAY_AGENT_TOKEN was stale/unauthorized

The MCP stdio process was trusting that token forever. This change makes startup defensive:

  • if the token still works, keep it
  • if it fails auth and we know the intended agent name, self-heal by rotating/refreshing it

Notes

This is the Relaycast-side half of the fix. The companion OpenClaw-side change should ensure setup passes the agent name through to the MCP environment so this startup healing has the identity it needs.

Validation

  • npm exec vitest -- run packages/mcp/src/__tests__/transports.test.ts

Open with Devin

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 9, 2026

Preview deployed!

Environment URL
API https://pr73-api.relaycast.dev
Health https://pr73-api.relaycast.dev/health
Observer https://pr73-observer.relaycast.dev/observer

This preview shares the staging database and will be cleaned up when the PR is merged or closed.

Run E2E tests

npm run e2e -- https://pr73-api.relaycast.dev --ci

Open observer dashboard

https://pr73-observer.relaycast.dev/observer

@khaliqgant khaliqgant merged commit fc71aba into main Mar 10, 2026
4 checks passed
@khaliqgant khaliqgant deleted the fix/agent-token-write-path-20260309-204028 branch March 10, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant