MCP server for AI-led rehosting (Phase 1)#835
Draft
lacraig2 wants to merge 1 commit into
Draft
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_baseimagined (anadd_pseudofiletool, 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/)run(project_dir, timeout?)— runs one emulation viarun_from_configand returns the newresults/Ndir + a health summary.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 singlepatch_90_mcp.yaml(auto-merged byauto_patching) —config.yamlis never edited, changes are auditable, andreset_patchreverts them.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 mcpCLI subcommand starts the server (stdio transport).Design
diagnostics.py+mutations.pyare dependency-free (pyyaml + stdlib) and unit-tested —tests/unit_tests/test_mcp.py(7 tests, all green), no container ormcppackage needed.server.pyis the only module importingmcp/FastMCP; loaded bypenguin mcp.mcpadded toinstall_requireswith apython_version >= "3.10"marker (the SDK needs 3.10; package still declares 3.8).Verified:
py_compileclean,flake8clean,pytest tests/unit_tests/test_mcp.py→ 7 passed.Still to do before un-drafting
./penguinwrapper runspenguin mcpwith 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.runtool against a fixture project.Phase 2 (follow-up)
Live control via the
remotectrlUnix socket (add uprobes/syscall hooks, toggle plugins on a running guest — no reboot) and guest interaction (guest_cmd, VPN-bridge reachability).