Files
ai-agent/backend/schemas/plugin_commands.py
gabrielvidalandClaude Opus 5.5 319560f8d9 feat(plugins): live plugins add their own ai-agent CLI commands and MCP tools
A plugin declares `commands` in plugin.json — each one names a declared
action, with a summary, its args and how to print the answer — and gets
`ai-agent plugin <id> <command> …` and, opt-in (`"mcp": true`), the MCP
tool `plugin_<id>_<command>`. Core no longer names any plugin
(Gabriel's form ai-agent-cli-and-mcp-for-live-plugins_fevcts: manifest
commands, namespaced under `plugin`, MCP opt-in, guests by their grants).

- backend/plugins/commands.py: validation (names, typed args, positional
  order, output text|rows, ≤ 64-char tool names, no commands for a plugin
  named like a core verb) and the caller's catalogue; GET
  /api/plugins/commands (plugins.use — a guest's CLI and AI-app connection
  see the plugins granted to them, never an ownerOnly action). Not in the
  approval fingerprint: a command only reaches an action the plugin already
  declares, through the same route. The consent card lists them.
- cli/plugin_commands.py: the per-plugin argparse parser, table/text
  printing, `ai-agent plugin commands`, `ai-agent plugin call ID ACTION`
  (any action, raw), and the MCP tool specs. readOnly actions go by GET
  ?payload=, so read-only MCP connections work.
- cli/mcp_tools.py: tools/list appends the plugin tools (read group when
  readOnly, run otherwise; none on a worker-bound connection);
  tools/call runs them.
- Removed the hard-coded plugin surfaces: `ai-agent plans|memories|goals`,
  MCP browse plans|goals|memories, read_document, work_on_goal (goals is
  not used — Gabriel). Plans and memories come back as their plugins'
  commands. This also fixes read-only MCP connections, which got "this
  connection is read-only" on plans and memories since they moved to
  plugins (the CLI POSTed). `ai-agent plans` now says where its commands are.
- openapi.json + orval regenerated, authz golden matrix (+1 route), docs
  (plugins.md "Commands", mcp.md, CLAUDE.md, create-plugin skill).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 23:17:09 +01:00

54 lines
1.5 KiB
Python

"""Plugin commands — what live plugins add to the ``ai-agent`` CLI and the
hub's MCP server (``GET /api/plugins/commands``, ``plugins/commands.py``)."""
from __future__ import annotations
from typing import Literal, Optional, Union
from .base import Schema
__all__ = [
"PluginCommandArg",
"PluginCommandOutput",
"PluginCommand",
"PluginCommandsResponse",
]
class PluginCommandArg(Schema):
name: str
type: Literal["string", "integer", "number", "boolean", "array"]
help: str = ""
required: bool = False
positional: bool = False
enum: Optional[list[str]] = None
default: Optional[Union[bool, int, float, str, list[str]]] = None
class PluginCommandOutput(Schema):
"""How to print the action's answer: one text field, or a list field as
rows of ``columns``; absent = the JSON answer."""
text: Optional[str] = None
rows: Optional[str] = None
columns: Optional[list[str]] = None
class PluginCommand(Schema):
"""``ai-agent plugin <plugin> <name> …``; with ``mcp`` also the MCP tool
``tool``. ``readOnly`` (the action's) = called by GET."""
plugin: str
pluginName: str
name: str
summary: str
description: str = ""
action: str
readOnly: bool = False
args: list[PluginCommandArg] = []
output: Optional[PluginCommandOutput] = None
mcp: bool = False
destructive: bool = False
tool: Optional[str] = None
class PluginCommandsResponse(Schema):
commands: list[PluginCommand] = []