feat(gateway): add MCP server endpoint with streamable HTTP transport #137

Merged
jason.woltje merged 2 commits from feat/p7-001-mcp-endpoint into main 2026-03-15 18:11:51 +00:00
Owner

Summary

  • Adds and to
  • Creates with , , , , and in
  • Implements MCP streamable HTTP transport at (POST for JSON-RPC, GET for SSE reconnect)
  • Exposes 14 tools across three domains: brain (projects, tasks, missions, conversations), memory (search, preferences, insights), and coord (mission status, task listing)
  • Requires valid BetterAuth session for all MCP connections (401 Unauthorized if missing)
  • Stateful session management: each initialized client gets its own + pair, keyed by header
  • Uses the same low-level Fastify hook pattern as the auth handler

Test plan

  • Gateway starts without errors with new MCP module wired in
  • POST /mcp without auth returns 401
  • POST /mcp with valid session and initialize payload creates session and returns Mcp-Session-Id header
  • Subsequent requests with Mcp-Session-Id routed to correct transport
  • tools/list returns all 14 registered tools
  • tools/call executes brain/memory/coord tools correctly
  • Unknown Mcp-Session-Id returns 404
  • Gateway shutdown closes all open MCP sessions

Closes #52

🤖 Generated with Claude Code

## Summary - Adds and to - Creates with , , , , and in - Implements MCP streamable HTTP transport at (POST for JSON-RPC, GET for SSE reconnect) - Exposes 14 tools across three domains: brain (projects, tasks, missions, conversations), memory (search, preferences, insights), and coord (mission status, task listing) - Requires valid BetterAuth session for all MCP connections (401 Unauthorized if missing) - Stateful session management: each initialized client gets its own + pair, keyed by header - Uses the same low-level Fastify hook pattern as the auth handler ## Test plan - [ ] Gateway starts without errors with new MCP module wired in - [ ] POST /mcp without auth returns 401 - [ ] POST /mcp with valid session and initialize payload creates session and returns Mcp-Session-Id header - [ ] Subsequent requests with Mcp-Session-Id routed to correct transport - [ ] tools/list returns all 14 registered tools - [ ] tools/call executes brain/memory/coord tools correctly - [ ] Unknown Mcp-Session-Id returns 404 - [ ] Gateway shutdown closes all open MCP sessions Closes #52 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jason.woltje added 2 commits 2026-03-15 18:05:05 +00:00
- Fix socket singleton lifecycle: add destroySocket() and auto-reset on disconnect
  so page remounts always get a fresh authenticated connection
- Add explicit WebSocket transport preference to avoid polling fallback
- Filter socket events by conversationId to prevent cross-conversation bleed
  when switching between conversations mid-stream
- Use activeIdRef pattern so event handlers see current activeId without
  stale closures or listener re-registration on every render
- On agent:end, append accumulated text as assistant message to local state
  (matching TUI pattern; Pi session is in-memory so DB reload would miss it)
- Preserve REST persist of user messages for conversation history on reload
- Clear streaming state on conversation switch
- StreamingMessage: show animated typing indicator before first token arrives

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
feat(gateway): add MCP server endpoint with streamable HTTP transport (#52)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
e2de76ca9f
- Install @modelcontextprotocol/sdk and zod in apps/gateway
- Create McpModule with McpService and controller at /mcp endpoint
- Implement stateful streamable HTTP transport (MCP spec 2025-03-26)
- Expose 14 tools: brain (projects/tasks/missions), memory, coord
- Require valid BetterAuth session for all MCP connections
- Per-session McpServer + StreamableHTTPServerTransport instances
- Follows same Fastify onRequest hook pattern as auth handler
- Add mcp.dto.ts with McpToolDescriptor and McpServerInfo interfaces

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jason.woltje merged commit 8633823257 into main 2026-03-15 18:11:51 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaicstack/stack#137