Skip to content

Add Agent Bridge addon (AI control bridge + MCP server) - #934

Draft
brianmcaudill wants to merge 1 commit into
gramps-project:maintenance/gramps60from
brianmcaudill:agentbridge60
Draft

Add Agent Bridge addon (AI control bridge + MCP server)#934
brianmcaudill wants to merge 1 commit into
gramps-project:maintenance/gramps60from
brianmcaudill:agentbridge60

Conversation

@brianmcaudill

Copy link
Copy Markdown
Contributor

Draft / RFC — submitting for discussion per CONTRIBUTING's guidance on novel addons, especially around the security model below.

What it is

Agent Bridge embeds a control bridge inside a running Gramps session so an AI agent can drive the live application — read/modify the tree, operate the UI, and create and load plugins on the fly. It ships an MCP (Model Context Protocol) server, so any MCP-capable AI (Claude, etc.) can drive Gramps through standard tools with no custom glue.

Architecture

AI client ── MCP (stdio) ──> gramps_mcp_server.py ── watched dir (~/.gramps_agent) ──> Agent Bridge gramplet ──> live Gramps

The gramplet polls a control directory on the GTK main thread via GLib.timeout_add, so injected code can safely touch the database and the GUI. Code runs in a persistent namespace with dbstate, db, uistate, gui, gramps_lib, and bridge bound (assign result to return a value). The MCP server is a thin stdio adapter over that directory — it needs the mcp package, not Gramps' interpreter.

Tools exposed: gramps_status, gramps_eval, gramps_install_plugin, gramps_people_count, gramps_search_people, gramps_active_person, gramps_set_active_person.

Security (please weigh in)

This executes arbitrary Python at the user's privileges, by design — comparable to the built-in Python Shell gramplet, but drivable by an external agent. Mitigations: no network port (control is file-only under ~/.gramps_agent, i.e. the user-account trust boundary), audience=DEVELOPER, and prominent warnings in the README. Happy to add a token gate (a secret file the bridge checks per request) for defense-in-depth if maintainers prefer.

Testing

Verified end-to-end on GrampsAIO 6.0.8 (Windows) against an 868-person tree: bridge ping, live eval (db/uistate access), name search, on-the-fly plugin install with auto-registration (reg_plugins(..., rescan=True)), and a full MCP client→server→bridge→Gramps round-trip exercising the tools above.

Notes for reviewers

  • Targets gramps_target_version="6.0" on maintenance/gramps60; can port to 6.1.
  • gramps_mcp_server.py and agent_send.py are a standalone MCP server and a debug CLI; they are not registered as Gramps plugins.
  • po/template.pot was hand-generated (no gettext toolchain on the dev box); happy to regenerate via the build.

Agent Bridge embeds a control bridge in a running Gramps session so an AI
agent can drive the live application: read and modify the tree, operate the
UI, and create and load plugins on the fly.

It ships an MCP (Model Context Protocol) server so any MCP-capable AI can
drive Gramps through standard tools. The gramplet polls a watched control
directory on the GTK main thread and executes submitted Python in a
persistent namespace with dbstate, db, uistate, gui and gramps_lib bound;
the MCP server is a thin stdio adapter over that directory. No network port
is opened.

As defense-in-depth, every request must carry a shared secret token. The
gramplet generates it on first run at ~/.gramps_agent/token (owner-only) and
refuses any request without it; the MCP server and the debug CLI read the
same file automatically. GRAMPS_AGENT_TOKEN overrides the file.
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