Repository navigation
feat(skills): admin keys manage library sources over MCP (abilityai/trinity-enterprise#692) - #3514
Conversation
…ansport (Abilityai/trinity-enterprise#692) Adds §21.5.1: MCP tools for source management, admitted for the principals require_admin already admits; agent and connector keys stay refused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…status (Abilityai/trinity-enterprise#692) - POST /api/skills/sources/apply: register-or-update keyed on the repository URL (201 created / 200 updated|unchanged / 409 ambiguous_source), same URL boundary as create, same admin gates. - POST /api/skills/sources accepts an optional priority. - GET /api/skills/library/status carries last_fleet_reinject, counts only; the per-agent failures map stays on the admin routes. - routers/skills.py # mcp: header names the new skill_sources.ts tools. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…/trinity-enterprise#692) list_skill_sources, register_skill_source (idempotent apply), update_skill_source, delete_skill_source, sync_skill_source and sync_skill_library: thin proxies over the require_admin source routes. canAccess is an allow-list of user/system scope, re-checked in-tool; agent and connector keys are never advertised them and the backend refuses them regardless. Sync tools report ran / refused_busy / failed and where a started fleet re-inject's outcome lands. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…se#692) architecture/mcp-server.md tool table + count, api-endpoints.md apply route, skills-library-sync feature flow, user-doc tool counts and rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ong-typed re-inject report (Abilityai/trinity-enterprise#692) Two review findings on the source-apply / library-status changes: - `apply_skill_source`: when the matched row is deleted between the match and the update, `update_skill_source` answers None. The service reported `("updated", None)` and the router 500'd on `source.id` in the audit call. It now re-resolves (bounded), so the declared source is re-created. - `_read_last_fleet_reinject`: a parseable dict with a wrong-typed field (null/string count, non-string timestamp) passed the isinstance check and failed `FleetReinjectSummary` at response validation, 500-ing the open `GET /api/skills/library/status`. The blob is now validated against that model inside the fail-soft read and degrades to null. Both tests were red before the change (6 failures) and are green after. Learnings fragment added for the response_model-projection class. Co-Authored-By: Claude Opus 5.5 <[email protected]>
/review ReportBranch:
Execution coverage (Step 2.5)
Fix mutation: this is a feature PR, so there was no prior fix to revert. For the two review fixes, the new tests failed against the pre-fix code (6 red: Critical Findings (block merge)[C1] Race / error handling: a concurrent DELETE during [C2] Error handling: the open Informational Findings (review required)[I1] Scope / product: one repo on two refs can't be driven by [I2] Concurrency: two concurrent applies of the same repo on different refs can both insert. (Confidence: 7/10) [I3] Matching edge: [I4] Honesty: [I5] Consistency: [I6] MCP: in dev mode ( Clean Categories
Summary
Verification after fixes
Learnings fragment: 🤖 Generated with Claude Code |
…n the ent692 client (Abilityai/trinity-enterprise#692) test_duplicate_create_still_409s failed in CI's full-suite regression diff: a file that evicts db.* after routers.skills is imported leaves the router catching a stale DuplicateSkillSource, so the facade's raise escaped as a raw exception instead of a 409. Reproduced locally with a forced eviction; the client now rebinds DuplicateSkillSource/DefaultSourceExists to the module the facade raises from. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Skill-library sources can now be managed over MCP by the principals that already hold that authority over REST: an admin's own user-scoped key (and the system agent). Agent-scoped and connector keys are still refused.
New MCP tools (
src/mcp-server/src/tools/skill_sources.ts), each a thin proxy over an existing admin route:list_skill_sourcesGET /api/skills/sourcesregister_skill_sourcePOST /api/skills/sources/apply(new, idempotent on url)update_skill_sourcePUT /api/skills/sources/{id}delete_skill_sourceDELETE /api/skills/sources/{id}sync_skill_sourcePOST /api/skills/sources/{id}/syncsync_skill_libraryPOST /api/skills/library/syncBackend additions:
POST /api/skills/sources/apply: register-or-update keyed on the repository URL. Returns 201created, or 200updated/unchanged(no write). Only the named fields are patched, and a re-apply never creates a duplicate row. Two rows for one repo on different refs return 409{code: ambiguous_source, source_ids}; it never guesses. It applies the same URL checks as create (reject_embedded_credentials+validate_skills_library_url, same 400 text) and the same gates (require_admin+reject_agent_principal). Matching uses_same_skills_repo, so the bundled default's scheme-less spelling matches.POST /api/skills/sourcestakes an optionalpriority. Its 409-on-duplicate contract is unchanged, because the Settings panel relies on it.GET /api/skills/library/statusnow carrieslast_fleet_reinjectwith counts only: timestamps, trigger, commit and the four agent counts. The per-agentfailuresmap stays on the admin routes. Per-sourceurlandlast_errorare still stripped from this public projection (ent#334).Design: the fence is the principal, not the transport
require_adminalready admitsADMIN_GATE_SCOPES = {None, user, system}and refuses agent and connector principals itself (#1890, #2323). Exposing the same operations over MCP to that same set of principals grants no new authority. It only removes a transport asymmetry that also kept out the admin's own key.canAccesstoSOURCE_ADMIN_SCOPES = {user, system}. Agent, connector, anonymous,opsand unknown scopes are never shown the tools. Calling one by name over the real transport fails, and the tool re-checks scope before any backend call, usingaccessDeniedso the refusal is audited.Admin access required.SOURCE_ADMIN_SCOPESand be opted in per route viarequire_admin_allowing(...)(the ops-key pattern), never by wideningADMIN_GATE_SCOPES.{success:false, status, error: <route detail>}, so the embedded-credential refusal keeps its text; a 5xx propagates. The sync tools return{outcome: ran|refused_busy|failed, result, fleet_reinject}. When a re-inject started, they nameget_skills_library_status → last_fleet_reinjectas the place to read its outcome.requirements/skills.md§21.5 no longer says "REST-only". New §21.5.1 says source management is fenced to non-agent principals.Tests
tests/unit/test_ent692_skill_sources_mcp.py: 32 tests, red before the change and green after. They cover:priorityon create;require_admin, with the per-routereject_agent_principalneutralised. This proves the refusal comes from the gate itself, not a per-endpoint add-on (AC 2);# mcp:header.src/mcp-server/src/tools/skill_sources.test.ts: 32 tests. They cover:canAccessallowlist, plus a pin on the scope set;createServerand MCP client over streamable HTTP: user and system keys list all six tools; agent and connector keys list none, cannot call one by name, and never reach the backend route.test_ent237_skill_sources.py: the new route is added to the reviewedMUTATINGlist (that guard caught it, as intended).npm test, 868/868 passed;tsc --noEmitclean.Product decisions taken (please confirm)
/applyroute, not by changingPOST /api/skills/sources. The create route keeps its 409 for the Settings UI.update_skill_sourceby id.namedefaults toowner/repowhen an apply creates a row without one, and is never overwritten unless it is named.require_adminadmits it today.Fixes abilityai/trinity-enterprise#692
🤖 Generated with Claude Code