Operations & MCP Reference

Every state-changing and queryable domain capability in PhrameCMS is implemented as an OperationInterface executed through PhrameCms\Core\Operation\OperationBus. Because phramecms/mcp derives its tool catalog directly from OperationRegistry, every built-in and custom operation is automatically exposed over CLI, MCP, and (when mutatesState: true and supportsDryRun: true) Change Proposals.


Built-In OperationBus Operations

PhrameCMS ships 39 built-in operations across 4 official modules (phramecms/config, phramecms/entity, phramecms/user, phramecms/proposal).

Dynamic / Scoped Permissions: Operations whose static requiredPermissions is empty ([]) enforce fine-grained target permissions inside execute() (for example, config.<name>.read or entity.<type>.<bundle>.update) and declare discoveryPermissionPatterns so McpServer (tools/list) still hides them from actors without matching scopes.

Configuration Operations (phramecms/config — 9 operations)

Operation Name MCP Tool Name Required Permission(s) Mutates State Supports Dry Run Description
config.list config_list config.read No No List configuration object names matching an optional prefix.
config.get config_get config.read or config.<name>.read (dynamic) No No Read a single configuration object by name.
config.set config_set config.write or config.<name>.write (dynamic) Yes Yes Validate and write a configuration object with automatic snapshot creation.
config.delete config_delete config.write or config.<name>.write (dynamic) Yes Yes Delete a configuration object with automatic snapshot creation.
config.diff config_diff config.read No No Compute configuration diff between active storage and a sync directory, inline config map, or snapshot.
config.export config_export config.export Yes Yes Export active configuration deterministically to sync storage or return canonical config map.
config.import config_import config.import Yes Yes Validate and atomically import configuration from an inline map or sync directory.
config.snapshots config_snapshots config.read No No List immutable configuration snapshots ordered newest-first.
config.rollback config_rollback config.import Yes Yes Roll back active configuration to an immutable snapshot after recording a pre-rollback snapshot.

Entity & Schema Operations (phramecms/entity — 13 operations)

Operation Name MCP Tool Name Required Permission(s) Mutates State Supports Dry Run Description
entity.schema entity_schema schema.read No No Compile and return JSON Schema(s) for all entity bundles, an entity type, or a single bundle.
entity_type.create entity_type_create schema.modify Yes Yes Create or update an entity type definition.
bundle.create bundle_create schema.modify Yes Yes Create or update an entity bundle definition.
field_storage.create field_storage_create schema.modify Yes Yes Create or update a reusable field storage definition on an entity type.
field_instance.attach field_instance_attach schema.modify Yes Yes Attach or update an existing field storage on an entity bundle.
entity.create entity_create entity.<type>.<bundle>.create (+ .publish if initial state is published) Yes Yes Create a new revisioned entity with bundle-scoped RBAC and JSON Schema validation.
entity.get entity_get entity.<type>.<bundle>.read (dynamic) No No Fetch a single entity by ID.
entity.list entity_list entity.<type>.<bundle>.read (dynamic) No No List entities for an entity type and bundle with optional workflow state, field filters, sorting, and pagination.
entity.update entity_update entity.<type>.<bundle>.update (dynamic) Yes Yes Update an entity by appending an immutable revision.
entity.delete entity_delete entity.<type>.<bundle>.delete (dynamic) Yes Yes Delete an entity and its revision history with referential integrity checks.
entity.transition entity_transition entity.<type>.<bundle>.publish (when targeting published) or .update (dynamic) Yes Yes Transition an entity workflow state by appending an immutable revision.
entity.revisions entity_revisions entity.<type>.<bundle>.read (dynamic) No No Return immutable revision history for an entity ordered newest-first.
entity.references entity_references entity.<type>.<bundle>.read (dynamic) No No List entities that reference a target entity via entity_reference fields.

User, RBAC, Agent Token & Audit Operations (phramecms/user — 11 operations)

Operation Name MCP Tool Name Required Permission(s) Mutates State Supports Dry Run Description
auth.whoami auth_whoami (any authenticated actor) No No Return the currently authenticated actor identity, type, scopes, roles, and effective permissions.
user.list user_list user.read No No List user accounts with pagination.
user.create user_create user.write Yes Yes Create a new user account.
user.assign_role user_assign_role user.admin Yes Yes Assign an RBAC role to an existing user.
user.set_password user_set_password user.write Yes Yes Set or reset a user account password (Argon2id, min 8 chars) and optionally revoke active sessions.
role.list role_list role.read No No List RBAC roles with pagination.
role.create role_create role.admin Yes Yes Create a new RBAC role.
agent_token.list agent_token_list agent_token.read No No List issued AI agent tokens (metadata only; never hashes or secrets).
agent_token.create agent_token_create agent_token.write Yes Yes Issue a scoped AI agent bearer token (plaintext_token returned once on live execution).
agent_token.revoke agent_token_revoke agent_token.write Yes Yes Revoke an existing AI agent bearer token.
audit.list audit_list audit.read No No Query recent immutable audit log records.

Change Proposal Operations (phramecms/proposal — 6 operations)

Operation Name MCP Tool Name Required Permission(s) Mutates State Supports Dry Run Description
proposal.create proposal_create proposal.create Yes Yes Validate and stage a mutating, dry-run-capable operation as a pending change proposal.
proposal.list proposal_list proposal.read No No List change proposals with optional status, operation, and proposer filters.
proposal.get proposal_get proposal.read No No Retrieve a single change proposal by ID.
proposal.approve proposal_approve proposal.review Yes Yes Verify live permissions and optimistic concurrency before approving and executing a pending proposal.
proposal.reject proposal_reject proposal.review Yes No Reject a pending change proposal and persist optional reviewer feedback.
proposal.cancel proposal_cancel proposal.create Yes No Cancel a pending change proposal by its original proposer or an authorized reviewer.

MCP Protocol & Transports

PhrameCms\Mcp\Server\McpServer implements the Model Context Protocol over JSON-RPC 2.0:

  • Protocol version: 2025-03-26 (configurable on McpModule)
  • Default server info: name: "phramecms-mcp", version: "0.1.0"
  • Advertised capabilities: tools, resources
  • HTTP transport (McpRouteProvider + HttpMcpHandler):
    • Route: POST /mcp (McpRouteProvider::DEFAULT_PATH), deny-by-default Bearer authentication (Authorization: Bearer <agent-token>).
    • Returns HTTP 200 (application/json) for JSON-RPC requests, HTTP 202 (empty body) for JSON-RPC notifications (no id), HTTP 400 for malformed JSON-RPC envelopes, and HTTP 401 (application/problem+json) when unauthenticated.
  • Stdio transport (StdioTransport + ./bin/phrame-mcp):
    • Newline-delimited JSON-RPC 2.0 on stdin / stdout; diagnostics written exclusively to stderr.
    • Authenticated via --token=<token> or PHRAME_MCP_TOKEN (see CLI Commands Reference).

Supported MCP JSON-RPC 2.0 Methods

Method Kind Description
initialize Request Returns protocolVersion, capabilities (tools, resources), serverInfo, and server instructions.
notifications/initialized Notification Client lifecycle acknowledgement (must omit id; sending an id returns -32600 Invalid Request).
ping Request Liveness check returning {}.
tools/list Request Lists operations visible to the authenticated actor (filtered by OperationVisibilityEnforcerInterface / PolicyEnforcerInterface).
tools/call Request Executes an operation through OperationBus and returns a JSON-encoded content[0].text payload with isError.
resources/list Request Lists static read-only phrame://... resources permitted for the authenticated actor.
resources/read Request Reads a specific phrame://... resource URI and returns contents: [{ uri, mimeType, text }].

Tool Naming, dry_run, and idempotency_key

  • Sanitized tool names: McpServer maps canonical dotted operation names to MCP-safe tool names by replacing any character outside [a-zA-Z0-9_-] with _ (maximum 64 characters, e.g., entity.create → entity_create). tools/call accepts both the sanitized tool name (entity_create) and the canonical operation name (entity.create).
  • Tool annotations: Each tool includes annotations.readOnlyHint (!$mutatesState) and annotations.destructiveHint ($mutatesState).
  • Injected safety parameters: For every operation with supportsDryRun: true, tools/list automatically adds two optional properties to inputSchema:
    • dry_run (boolean, default false): validate and compute diffs without persisting.
    • idempotency_key (string, minLength: 1): deduplicate live execution retries. McpServer strips dry_run and idempotency_key from tool arguments before forwarding the remaining payload to OperationBus inside ExecutionContext.

Error Codes & Tool Error Envelopes

Domain errors during tools/call return a JSON-RPC success frame with result.isError: true and a structured JSON error object in result.content[0].text:

  • authorization_denied (AuthorizationException) — includes operation, actor_id, required_permissions.
  • validation_failed (ValidationException) — includes operation, errors, errorsByPath.
  • operation_failed (CoreException) — includes operation, exception, message.

Protocol and resource errors return standard JSON-RPC error objects:

Code Constant / Meaning When Returned
-32700 JsonRpcError::PARSE_ERROR Malformed JSON body/line.
-32600 JsonRpcError::INVALID_REQUEST Invalid JSON-RPC envelope or notifications/initialized with an id.
-32601 JsonRpcError::METHOD_NOT_FOUND Unknown JSON-RPC method.
-32602 JsonRpcError::INVALID_PARAMS Missing/invalid name, arguments, dry_run, idempotency_key, uri, unknown operation, unsupported resource URI, or resource validation failure.
-32603 JsonRpcError::INTERNAL_ERROR Unhandled server exception.
-32002 RESOURCE_NOT_FOUND_CODE Target config object or entity does not exist during resources/read.
-32003 AUTHORIZATION_ERROR_CODE Actor lacks permission to read the requested resource URI.

Built-In phrame:// MCP Resources

phramecms/mcp registers four built-in McpResourceProviderInterface services exposing 7 read-only URI / URI-template endpoints (all returning mimeType: "application/json"):

Resource URI / Template Provider Class Backing Operation Listed in resources/list? Description
phrame://schema/config PhrameCms\Mcp\Resource\ConfigResourceProvider config.list + tagged phrame.config_schema Yes (requires config.read) Active configuration object names, count, and registered JSON Schemas by prefix.
phrame://config/{name} PhrameCms\Mcp\Resource\ConfigResourceProvider config.get Template (resources/read only) Single configuration object matching /^[a-z0-9_]+(\.[a-z0-9_]+)+$/ (e.g., phrame://config/admin.settings).
phrame://schema/entities PhrameCms\Mcp\Resource\EntityResourceProvider entity.schema Yes (requires schema.read) Compiled JSON Schemas for all registered entity types and bundles.
phrame://content/{entity_type}/{bundle}/{id} PhrameCms\Mcp\Resource\EntityResourceProvider entity.get Template (resources/read only) Single entity record verified to match {entity_type} and {bundle}.
phrame://audit/recent PhrameCms\Mcp\Resource\AuditResourceProvider audit.list Yes (requires audit.read) Recent immutable audit log records (default limit 50 in McpModule, 100 in phramecms/skeleton via PHRAME_MCP_AUDIT_DEFAULT_LIMIT, max 200).
phrame://proposals/pending PhrameCms\Mcp\Resource\ProposalResourceProvider proposal.list (status: "pending") Yes (requires proposal.read) Pending change proposals awaiting human review (default limit 25, max 200).
phrame://proposals/recent PhrameCms\Mcp\Resource\ProposalResourceProvider proposal.list Yes (requires proposal.read) Recent change proposals across all statuses, including rejected proposals with human review_note feedback.

Custom modules can expose additional phrame://... resources by implementing McpResourceProviderInterface and tagging the service with McpResourceProviderInterface::SERVICE_TAG (phrame.mcp_resource_provider).