Skip to main content
Version: Next

API Reference

Complete reference documentation for all MCP Server API endpoints.

Base URL

http://localhost:8000/api/v1

Authentication

Currently, the API does not require authentication. Future versions will support API key authentication.

Content Types

  • Request: application/json
  • Response: application/json
  • Encoding: UTF-8

Common Response Headers

Content-Type: application/json
X-Request-ID: <unique-request-id>
X-Response-Time: <milliseconds>

Endpoints

Health Check

GET /api/v1/health

Check server health and Brobot CLI connectivity.

Response

{
"status": "ok",
"version": "0.1.0",
"brobot_connected": true,
"timestamp": "2024-01-20T10:30:00Z"
}

Status Codes

  • 200 OK: Server is healthy
  • 503 Service Unavailable: Server is unhealthy

Example

curl http://localhost:8000/api/v1/health

Get State Structure

GET /api/v1/state_structure

Retrieve the complete state structure of the target application.

Response

{
"states": [
{
"name": "main_menu",
"description": "Application main menu",
"images": [
"main_menu_logo.png",
"menu_button.png"
],
"transitions": [
{
"from_state": "main_menu",
"to_state": "login_screen",
"action": "click_login",
"probability": 0.95
}
],
"is_initial": true,
"is_final": false
}
],
"current_state": "main_menu",
"metadata": {
"application": "MyApp",
"version": "1.0.0",
"last_updated": "2024-01-20T10:30:00Z"
}
}

Response Schema

FieldTypeDescription
statesarrayList of all application states
states[].namestringUnique state identifier
states[].descriptionstringHuman-readable description
states[].imagesarrayAssociated image patterns
states[].transitionsarrayPossible state transitions
states[].is_initialbooleanWhether this is a starting state
states[].is_finalbooleanWhether this is an ending state
current_statestringCurrently active state name
metadataobjectAdditional information

Status Codes

  • 200 OK: Success
  • 500 Internal Server Error: CLI error

Example

import requests

response = requests.get("http://localhost:8000/api/v1/state_structure")
states = response.json()["states"]
print(f"Found {len(states)} states")

Get Observation

GET /api/v1/observation

Get current observation including screenshot and active states.

Query Parameters

ParameterTypeDefaultDescription
include_screenshotbooleantrueInclude base64 screenshot
formatstring"png"Screenshot format (png/jpg)

Response

{
"timestamp": "2024-01-20T10:30:00Z",
"active_states": [
{
"name": "dashboard",
"confidence": 0.95,
"matched_patterns": [
"dashboard_header.png",
"user_menu.png"
]
},
{
"name": "notifications",
"confidence": 0.72,
"matched_patterns": [
"notification_bell.png"
]
}
],
"screenshot": "iVBORw0KGgoAAAANS...",
"screen_width": 1920,
"screen_height": 1080,
"metadata": {
"capture_duration": 0.125,
"analysis_duration": 0.087,
"total_patterns_checked": 42,
"patterns_matched": 3
}
}

Response Schema

FieldTypeDescription
timestampstringISO 8601 timestamp
active_statesarrayCurrently active states
active_states[].namestringState name
active_states[].confidencefloatConfidence score (0.0-1.0)
active_states[].matched_patternsarrayPatterns that matched
screenshotstringBase64 encoded image
screen_widthintegerScreen width in pixels
screen_heightintegerScreen height in pixels
metadataobjectPerformance metrics

Status Codes

  • 200 OK: Success
  • 500 Internal Server Error: Screenshot capture failed

Example

# Get observation without screenshot
response = requests.get(
"http://localhost:8000/api/v1/observation",
params={"include_screenshot": False}
)

# Save screenshot to file
import base64
obs = response.json()
if obs.get("screenshot"):
img_data = base64.b64decode(obs["screenshot"])
with open("screen.png", "wb") as f:
f.write(img_data)

Execute Action

POST /api/v1/execute

Execute an automation action on the target application.

Request Body

{
"action_type": "click",
"parameters": {
"image_pattern": "submit_button.png",
"confidence": 0.9,
"timeout": 5.0
},
"target_state": "form_submitted",
"timeout": 10.0
}

Request Schema

FieldTypeRequiredDescription
action_typestringYesType of action to execute
parametersobjectYesAction-specific parameters
target_statestringNoExpected state after action
timeoutfloatNoAction timeout in seconds (default: 10.0)

Response

{
"success": true,
"action_type": "click",
"duration": 0.523,
"result_state": "form_submitted",
"error": null,
"metadata": {
"click_location": {
"x": 640,
"y": 480
},
"pattern_found": true,
"confidence": 0.92,
"search_time": 0.234
}
}

Response Schema

FieldTypeDescription
successbooleanWhether action succeeded
action_typestringType of action executed
durationfloatExecution time in seconds
result_statestringState after execution
errorstringError message if failed
metadataobjectAction-specific details

Status Codes

  • 200 OK: Action completed (check success field)
  • 400 Bad Request: Invalid parameters
  • 422 Unprocessable Entity: Validation error
  • 500 Internal Server Error: Execution error

Action Types

Click Action

Click on an image pattern or specific location.

Parameters

{
"action_type": "click",
"parameters": {
"image_pattern": "button.png", // OR use location
"location": {"x": 500, "y": 300},
"confidence": 0.9,
"click_type": "single", // single|double|right
"offset": {"x": 0, "y": 0}
}
}
ParameterTypeRequiredDescription
image_patternstringNo*Image file to find
locationobjectNo*Click coordinates
confidencefloatNoMin similarity (0.0-1.0)
click_typestringNoClick type (default: single)
offsetobjectNoOffset from pattern center

*Either image_pattern or location is required

Type Action

Type text at the current cursor location.

Parameters

{
"action_type": "type",
"parameters": {
"text": "Hello, World!",
"typing_speed": 300, // chars per minute
"clear_first": false,
"press_enter": true
}
}
ParameterTypeRequiredDescription
textstringYesText to type
typing_speedintegerNoTyping speed (default: 300)
clear_firstbooleanNoClear field first
press_enterbooleanNoPress Enter after typing

Drag Action

Drag from one location to another.

Parameters

{
"action_type": "drag",
"parameters": {
"start_pattern": "drag_handle.png", // OR start_x, start_y
"start_x": 100,
"start_y": 100,
"end_pattern": "drop_zone.png", // OR end_x, end_y
"end_x": 500,
"end_y": 500,
"duration": 1.0,
"button": "left" // left|right|middle
}
}
ParameterTypeRequiredDescription
start_patternstringNo*Start position pattern
start_x, start_yintegerNo*Start coordinates
end_patternstringNo*End position pattern
end_x, end_yintegerNo*End coordinates
durationfloatNoDrag duration (default: 1.0)
buttonstringNoMouse button (default: left)

*Either pattern or coordinates required for start/end

Wait Action

Wait for a specific state or condition.

Parameters

{
"action_type": "wait",
"parameters": {
"state_name": "dashboard",
"timeout": 30.0,
"check_interval": 1.0,
"stability_time": 2.0
}
}
ParameterTypeRequiredDescription
state_namestringYesState to wait for
timeoutfloatNoMax wait time (default: 30.0)
check_intervalfloatNoCheck frequency (default: 1.0)
stability_timefloatNoRequired stable time

Error Handling

Error Response Format

{
"detail": "Detailed error message",
"type": "error_type",
"loc": ["field", "name"],
"ctx": {
"additional": "context"
}
}

Common Error Codes

Status CodeError TypeDescription
400bad_requestInvalid request format
422validation_errorParameter validation failed
404not_foundResource not found
408timeoutRequest timeout
500internal_errorServer error
503service_unavailableBrobot CLI unavailable

Error Examples

Validation Error (422)

{
"detail": [
{
"loc": ["body", "action_type"],
"msg": "field required",
"type": "value_error.missing"
}
]
}

CLI Error (500)

{
"detail": "Brobot CLI error: Pattern not found",
"type": "cli_error",
"ctx": {
"pattern": "nonexistent.png",
"search_time": 5.0
}
}

Rate Limiting

Future versions will implement rate limiting:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 99
X-RateLimit-Reset: 1642521600

Pagination

Future versions will support pagination for large responses:

{
"data": [...],
"pagination": {
"page": 1,
"per_page": 20,
"total": 100,
"pages": 5
}
}

Webhooks

Future versions will support webhooks for state changes:

{
"event": "state_changed",
"timestamp": "2024-01-20T10:30:00Z",
"data": {
"from_state": "login",
"to_state": "dashboard",
"trigger": "user_action"
}
}

Client Libraries

Python

from brobot_client import BrobotClient

client = BrobotClient("http://localhost:8000")
result = client.click("button.png")

JavaScript (Coming Soon)

const client = new BrobotClient("http://localhost:8000");
await client.click("button.png");

cURL Examples

# Get observation
curl http://localhost:8000/api/v1/observation

# Execute click
curl -X POST http://localhost:8000/api/v1/execute \
-H "Content-Type: application/json" \
-d '{"action_type":"click","parameters":{"image_pattern":"button.png"}}'

# Pretty print with jq
curl http://localhost:8000/api/v1/state_structure | jq .

API Versioning

The API uses URL versioning. Current version: v1

Future versions will maintain backwards compatibility or provide migration guides.

OpenAPI Specification

Access the OpenAPI (Swagger) specification:

Support