Skip to content

MCP server for AI-led rehosting (Phase 1)#835

Draft
lacraig2 wants to merge 1 commit into
mainfrom
feature/mcp-server
Draft

MCP server for AI-led rehosting (Phase 1)#835
lacraig2 wants to merge 1 commit into
mainfrom
feature/mcp-server

Conversation

@lacraig2

Copy link
Copy Markdown
Collaborator

Draft — Phase 1 of an in-container MCP server that exposes Penguin's rehosting loop to an LLM agent as discrete tools, instead of the current "hand-edit YAML → reboot the VM → grep multi-KB result files" loop. This is the interface the old docs/llm_knowledge_base imagined (an add_pseudofile tool, an env tool), now grounded in what Penguin actually has. (See #833 / #834 for the stale-docs cleanup that motivated this.)

What's here (src/penguin/mcp/)

  • Lifecycle: run(project_dir, timeout?) — runs one emulation via run_from_config and returns the new results/N dir + a health summary.
  • Config mutations: set_env, set_nvram, set_uboot_env, add_netdev, block_signal, add_pseudofile, add_static_file, show_patch, reset_patch. Each deep-merges into a single patch_90_mcp.yaml (auto-merged by auto_patching) — config.yaml is never edited, changes are auditable, and reset_patch reverts them.
  • Structured diagnostics: health, missing_env, pseudofile_failures, netbinds, console(pattern), db_query(SELECT over plugins.db), missing_files(procname) — parsed JSON, not file dumps (the token-efficiency win).
  • penguin mcp CLI subcommand starts the server (stdio transport).

Design

  • diagnostics.py + mutations.py are dependency-free (pyyaml + stdlib) and unit-tested — tests/unit_tests/test_mcp.py (7 tests, all green), no container or mcp package needed.
  • server.py is the only module importing mcp/FastMCP; loaded by penguin mcp.
  • mcp added to install_requires with a python_version >= "3.10" marker (the SDK needs 3.10; package still declares 3.8).

Verified: py_compile clean, flake8 clean, pytest tests/unit_tests/test_mcp.py → 7 passed.

Still to do before un-drafting

  • In-container launch plumbing: confirm the ./penguin wrapper runs penguin mcp with stdin attached (docker run -i) so an MCP client can speak stdio through the container. The subcommand + server are in place; the wrapper flag wiring needs a smoke test.
  • A container-level smoke test of the full run tool against a fixture project.

Phase 2 (follow-up)

Live control via the remotectrl Unix socket (add uprobes/syscall hooks, toggle plugins on a running guest — no reboot) and guest interaction (guest_cmd, VPN-bridge reachability).

Adds src/penguin/mcp/, an in-container Model Context Protocol server that exposes
Penguin's rehosting loop to an LLM agent as discrete tools, replacing the
"hand-edit YAML -> reboot VM -> grep multi-KB result files" loop.

Tools:
- lifecycle: run(project_dir) -> runs one emulation, returns results dir + health
- mutate: set_env / set_nvram / set_uboot_env / add_netdev / block_signal /
  add_pseudofile / add_static_file / show_patch / reset_patch. Each deep-merges
  into a single reviewable patch_90_mcp.yaml (auto-merged via auto_patching);
  config.yaml is never edited, and reset_patch reverts everything.
- diagnose: health / missing_env / pseudofile_failures / netbinds / console(grep) /
  db_query(SELECT over plugins.db) / missing_files. Returns parsed JSON, not dumps.

Design:
- diagnostics.py + mutations.py are dependency-free (pyyaml + stdlib) and unit-tested
  (tests/unit_tests/test_mcp.py, 7 tests) — no container or mcp package needed.
- server.py is the only module importing mcp (FastMCP); loaded by `penguin mcp`.
- `penguin mcp` CLI subcommand starts the server (stdio transport).
- mcp added to install_requires (env-markered for py>=3.10).

Phase 2 (follow-up): live control via the remotectrl socket (uprobes/syscall hooks/
plugin toggles on a running guest) and guest interaction.
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