Skip to content

Expose live Moshcode sessions over remote MCP - #496

Merged
ralyodio merged 7 commits into
mainfrom
feat/0014-remote-mcp-session-gateway
Sep 11, 2026
Merged

Expose live Moshcode sessions over remote MCP#496
ralyodio merged 7 commits into
mainfrom
feat/0014-remote-mcp-session-gateway

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

What

Implements OpenPRD 0014: a remote MCP + OAuth gateway over Moshcode's existing live CLI session mirror.

MCP

  • POST /mcp stateless remote MCP endpoint
  • MCP 2026-07-28 server/discover path plus 2025 handshake compatibility
  • moshcode_sessions_list
  • moshcode_session_read with after_seq cursors
  • moshcode_session_send using the existing command queue
  • moshcode_session_key using the existing negotiated keys capability
  • read/control tool annotations and scoped discovery

OAuth / security

  • OAuth Authorization Code + PKCE S256
  • Dynamic Client Registration compatibility
  • OAuth authorization-server + protected-resource metadata
  • short-lived hashed access tokens
  • rotating hashed refresh tokens
  • replay-resistant single-use authorization codes
  • sessions:read and sessions:control scopes (control implies read)
  • optional authorization binding to one owned Moshcode session
  • read-only default when a client omits scope
  • session deletion revokes session-bound grants via cascading FKs
  • shell/key tools advertised as potentially destructive to MCP hosts

Architecture

This deliberately reuses the existing cli_sessions, sequenced session_output, and exactly-once session_commands queue. It does not add another shell daemon, expose SSH credentials, or add a runtime MCP SDK dependency.

Tests

Adds integration coverage for:

  • missing/invalid bearer challenge
  • PKCE verification + authorization-code replay
  • refresh-token rotation/replay
  • read-only scoped tool discovery
  • session-bound control queueing
  • denial of cross-session access

I also syntax-checked all new/modified .mjs files with node --check before pushing.

Known follow-up

The existing CLI long-poll wake signal is in-process. MCP commands inserted by a different app instance may wait for the normal poll timeout instead of waking the parked request immediately. The PRD tracks a shared/cross-instance wake mechanism as P1; correctness is preserved in v1, only worst-case command latency is affected.

See prd/0014-remote-mcp-session-gateway.md.

}
params.push(limit);
const rows = await all(
`SELECT * FROM cli_sessions WHERE ${where} ORDER BY last_seen_at DESC LIMIT ?`,
@github-actions

Copy link
Copy Markdown

ThreatCrush Security Scan

1 finding(s) in the 7 file(s) this pull request changes.

MEDIUM: 1

Severity Rule Location
MEDIUM sql-template-interpolation apps/pwa/src/routes/mcp.mjs:76
92 pre-existing finding(s) elsewhere in the repository — **HIGH/CRITICAL**: 8 | **MEDIUM**: 74 | **LOW**: 10

Not introduced by this pull request. The full set is in the Security tab.

Severity Rule Location
HIGH js-ssrf-outbound-request apps/pwa/public/sw.js:45
HIGH tls-verification-disabled apps/pwa/src/lib/moshpit-gateway.mjs:299
HIGH sh-remote-script-execution install.sh:86
HIGH sh-remote-script-execution install.sh:90
HIGH sh-remote-script-execution install.sh:202
HIGH sh-remote-script-execution install.sh:213
HIGH sh-remote-script-execution install.sh:219
HIGH tls-verification-disabled src/dns.mjs:766
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:139
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:153
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:179
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:373
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:377
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:422
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:671
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:867
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:869
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:928
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:974
MEDIUM sql-template-interpolation apps/pwa/src/moshpit.mjs:1044

…and 72 more. Full results in the Security tab.

Snippets are redacted; ThreatCrush never prints matched credential material.

@ralyodio
ralyodio merged commit e744d57 into main Sep 11, 2026
6 checks passed
@ralyodio
ralyodio deleted the feat/0014-remote-mcp-session-gateway branch September 11, 2026 17:55
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.

2 participants