API
Programmatic access for developers
Overview
Agentation exposes callbacks that let you integrate annotations into your own workflows — send to a backend, pipe to terminal, trigger automations, or build custom AI integrations.
- Sync annotations to a database or backend service
- Build analytics dashboards tracking feedback patterns
- Create custom AI integrations (MCP servers, agent tools)
Props
onAnnotationAdd(annotation: Annotation) => voidCalled when an annotation is created
onAnnotationDelete(annotation: Annotation) => voidCalled when an annotation is deleted
onAnnotationUpdate(annotation: Annotation) => voidCalled when an annotation comment is edited
onAnnotationsClear(annotations: Annotation[]) => voidCalled when all annotations are cleared
onCopy(markdown: string) => voidCallback with the markdown output when copy is clicked
onSubmit(output: string, annotations: Annotation[]) => voidCalled when "Send Annotations" is clicked
copyToClipboardbooleandefault: trueSet to false to prevent writing to clipboard (if handling via onCopy)
endpointstringMCP server URL for syncing annotations
sessionIdstringPre-existing session ID to use
onSessionCreated(sessionId: string) => voidCalled when a new session is created
webhookUrlstringWebhook URL to receive annotation events
Basic usage
Receive annotation data directly in your code:
import { Agentation, Annotation } from "agentation";function App() {const handleAnnotation = (annotation: Annotation) => {console.log(annotation.element, annotation.comment);};return (<><YourApp /><Agentation onAnnotationAdd={handleAnnotation} /></>);}
Annotation type
The Annotation object passed to callbacks. See Agentation Format for the full schema.
type Annotation = {// Requiredid: string; // Unique identifiercomment: string; // User's annotation textelementPath: string; // CSS selector pathtimestamp: number; // Unix timestamp (ms)x: number; // % of viewport width (0-100)y: number; // px from document topelement: string; // Tag name ("button", "div")// Recommendedurl?: string; // Page URLboundingBox?: { // Element dimensionsx: number;y: number;width: number;height: number;};// Context (varies by output format)reactComponents?: string; // Component treecssClasses?: string;computedStyles?: string;accessibility?: string;nearbyText?: string;selectedText?: string; // If text was selected// Browser component fieldsisFixed?: boolean; // Fixed-position elementisMultiSelect?: boolean; // Created via drag selection};
HTTP API
The agentation-mcp server provides a REST API for programmatic access:
Sessions
| POST | /sessions | Create a new session |
| GET | /sessions | List all sessions |
| GET | /sessions/:id | Get session with annotations |
Annotations
| POST | /sessions/:id/annotations | Add annotation |
| GET | /annotations/:id | Get annotation |
| PATCH | /annotations/:id | Update annotation |
| DELETE | /annotations/:id | Delete annotation |
| POST | /annotations/:id/thread | Add thread message |
| GET | /sessions/:id/pending | Get pending annotations |
| GET | /pending | Get all pending annotations |
Events (SSE)
| GET | /sessions/:id/events | Session event stream |
| GET | /events | Global event stream (optionally filter with ?domain=...) |
Health
| GET | /health | Health check |
| GET | /status | Server status |
Real-Time Events
Subscribe to real-time events via Server-Sent Events:
# Session-level: events for a single pagecurl -N http://localhost:4747/sessions/:id/events# Global: events across ALL sessionscurl -N http://localhost:4747/events# Filtered by domain: events for pages on a specific domaincurl -N "http://localhost:4747/events?domain=localhost:3001"# Reconnect after disconnect (replay missed events)curl -N -H "Last-Event-ID: 42" http://localhost:4747/sessions/:id/events
Event types
annotation.created— New annotation addedannotation.updated— Annotation modified (comment, status, etc.)annotation.deleted— Annotation removedsession.created— New session startedsession.updated— Session updatedsession.closed— Session closedaction.requested— Agent action requestedthread.message— New message in annotation thread
Environment Variables
| Variable | Description | Default |
|---|---|---|
| AGENTATION_STORE | Storage backend (memory or sqlite) | sqlite |
| AGENTATION_EVENT_RETENTION_DAYS | Days to keep events | 7 |
Storage
By default, data is persisted to SQLite at ~/.agentation/store.db. To use in-memory storage:
AGENTATION_STORE=memory npx agentation-mcp server
Programmatic Usage
import { startHttpServer, startMcpServer } from 'agentation-mcp';// Start HTTP server on port 4747startHttpServer(4747);// Start MCP server (connects via stdio)await startMcpServer('http://localhost:4747');
See MCP Server for AI agent integration and available tools.