Skip to content

Annotations Context

Submodule of Annotations. Assembles annotation data into a structured PHP array payload and ships two renderers (markdown, HTML render arrays) plus an admin preview UI.

The payload is the stable API surface: format-agnostic, permission-aware, and extensible via alter hook. annotations_ai_context consumes it to build LLM context; the preview page and markdown export are human-readable views of the same data.


Requirements

  • annotations (core Annotations module)

Installation

ddev drush en annotations_context

What it provides

  • Context preview at /admin/config/annotations/context — live HTML preview of assembled context, filterable by role, target, reference depth, and field metadata.
  • Role simulation — preview context as any Drupal role sees it (respects consume {type} annotations permissions).
  • Markdown export at /admin/config/annotations/context/export — downloads context as a .md file.
  • JSON API endpoint at /api/annotations/{target_id} — returns the assembled payload for a single target as JSON. Requires view annotations context or administer annotations. Type visibility respects the caller's consume {type} annotations permissions.
  • MCP endpoint at /api/annotations/mcp — exposes each annotation target as an MCP resource (MCP Streamable HTTP, 2025-03-26 spec). Suitable for AI development tools and custom agents.
  • Drush export via annotations_export's drush ann:ex --format=markdown — assembles context and prints it as markdown.

Permissions

Permission Notes
view annotations context Access to the preview page, markdown export, JSON API, and MCP endpoint. restrict access: true — grants role simulation (preview context as any role), so assign deliberately (e.g. to project managers reviewing documentation).

administer annotations also grants access (OR logic in routing).


See DEVELOPING.md for the ContextAssembler PHP API, renderer details, entity-reference traversal, the hook_annotations_context_alter extension hook, Drush command options, JSON API response shape, and MCP endpoint auth.