Skip to content

arch: MCP server + stateful sessions + SPARK as autonomous agent #36

Description

@adrianwedd

Summary

Three interconnected architectural improvements, planned and documented in docs/mcp-server-plan.md.

Layer 1 — MCP Server (do first)

Expose all 41 SPARK tools to the Claude Code dev session on the Pi via the Model Context Protocol. From the dev terminal, Claude Code can control the robot directly — no voice loop needed.

  • bin/mcp-server — stdio JSON-RPC 2.0 server
  • src/pxh/mcp_server.py — server implementation
  • src/pxh/schemas.py — declarative tool parameter schemas (generated from validate_action)
  • .mcp.json — Claude Code auto-discovers and spawns the server
  • MCP resources: spark://session, spark://thoughts, spark://notes

Layer 2 — Stateful Conversation Buffer

Replace fully stateless --no-session-persistence with a rolling conversation window. SPARK remembers what it said 2 turns ago without relying entirely on file injection.

  • state/conversation-{persona}.jsonl — last 10 turns (user + SPARK) per persona
  • Injected into build_model_prompt() as "Recent conversation" section
  • Also fixes statefulness gap in the web UI chat

Layer 3 — SPARK as Autonomous Agent

SPARK can suggest features, implement them, commit to a feature branch, and create GH issues — prompted by Obi mid-conversation.

  • claude-voice-bridge: remove --allowedTools "", allow Read,Write,Edit,Bash,WebSearch
  • Remove --no-session-persistence (requires Layer 2 first)
  • SPARK operates on spark/auto branch — Adrian reviews via PR
  • Safety rules in spark-voice-system.md and Bash restrictions

Web UI (already implemented)

GET / serves a self-contained dark-theme dashboard at port 8420. Sidebar buttons for every tool + chat input → POST /api/v1/chat. Gaps: no conversation history, no live session updates — both fixed by Layer 2.

Design doc

See full plan with implementation order, file list, trade-offs, and open questions:
docs/mcp-server-plan.md

Open questions (for Adrian + Obi to decide)

  • How much autonomy should SPARK have when modifying code? Always ask? Commit silently?
  • Review flow: per-change PR notification or batched?
  • Should SPARK narrate what it's doing in kid-friendly terms as it codes?
  • Session window length: per wake-word session / all day / reset at midnight?
  • Feature branch name: spark/auto? Let Obi name it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiREST API (port 8420)enhancementNew feature or requestsparkSPARK persona — child companion & regulation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions