Skip to content

vendor_connectors.cursor

Cursor Connector - HTTP client for Cursor Background Agent API.

This connector provides Python access to the Cursor Background Agent API for managing AI coding agents, following the patterns established in the jbcom ecosystem.

Usage: from vendor_connectors.cursor import CursorConnector

connector = CursorConnector(api_key="...")
agents = connector.list_agents()
agent = connector.launch_agent(
prompt_text="Implement feature X",
repository="org/repo",
ref="main"
)

Reference: https://cursor.com/docs/cloud-agent/api/endpoints

AgentStateAgent execution state.
AgentCursor Background Agent representation.
RepositoryRepository available for Cursor agents.
ConversationMessageSingle message in agent conversation.
ConversationAgent conversation history.
LaunchOptionsOptions for launching a new agent.
CursorConnectorCursor Background Agent API connector.
validate_agent_idValidate an agent ID to prevent injection attacks.
validate_prompt_textValidate prompt text.
validate_repositoryValidate repository name.
validate_webhook_urlValidate webhook URL to prevent SSRF attacks.
sanitize_errorSanitize error messages to prevent sensitive data leakage.
DEFAULT_BASE_URL
DEFAULT_TIMEOUT
MAX_PROMPT_LENGTH
MAX_REPO_LENGTH
AGENT_ID_PATTERN
BLOCKED_HOSTNAME_PATTERNS

https://api.cursor.com/v0’

60.0

vendor_connectors.cursor.MAX_PROMPT_LENGTH

Section titled “vendor_connectors.cursor.MAX_PROMPT_LENGTH”

100000

200

‘compile(…)’

vendor_connectors.cursor.BLOCKED_HOSTNAME_PATTERNS

Section titled “vendor_connectors.cursor.BLOCKED_HOSTNAME_PATTERNS”

None

exception vendor_connectors.cursor.CursorError(message: str, status_code: int | None = None)

Section titled “exception vendor_connectors.cursor.CursorError(message: str, status_code: int | None = None)”

Bases: Exception

Base exception for Cursor API errors.

Initialize self. See help(type(self)) for accurate signature.

exception vendor_connectors.cursor.CursorValidationError(message: str, status_code: int | None = None)

Section titled “exception vendor_connectors.cursor.CursorValidationError(message: str, status_code: int | None = None)”

Bases: vendor_connectors.cursor.CursorError

Validation error for Cursor API inputs.

Initialize self. See help(type(self)) for accurate signature.

exception vendor_connectors.cursor.CursorAPIError(message: str, status_code: int | None = None)

Section titled “exception vendor_connectors.cursor.CursorAPIError(message: str, status_code: int | None = None)”

Bases: vendor_connectors.cursor.CursorError

API error from Cursor service.

Initialize self. See help(type(self)) for accurate signature.

Bases: str, enum.Enum

Agent execution state.

Initialize self. See help(type(self)) for accurate signature.

‘pending’

‘running’

‘finished’

‘errored’

‘cancelled’

Bases: pydantic.BaseModel

Cursor Background Agent representation.

‘ConfigDict(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

Bases: pydantic.BaseModel

Repository available for Cursor agents.

‘ConfigDict(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

class vendor_connectors.cursor.ConversationMessage

Section titled “class vendor_connectors.cursor.ConversationMessage”

Bases: pydantic.BaseModel

Single message in agent conversation.

‘ConfigDict(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

class vendor_connectors.cursor.Conversation

Section titled “class vendor_connectors.cursor.Conversation”

Bases: pydantic.BaseModel

Agent conversation history.

‘ConfigDict(…)’

‘Field(…)’

‘Field(…)’

class vendor_connectors.cursor.LaunchOptions

Section titled “class vendor_connectors.cursor.LaunchOptions”

Options for launching a new agent.

None

None

None

None

True

None

True

False

None

None

Validate an agent ID to prevent injection attacks.

Args: agent_id: The agent ID to validate.

Raises: CursorValidationError: If the agent ID is invalid.

Validate prompt text.

Args: text: The prompt text to validate.

Raises: CursorValidationError: If the prompt is invalid.

Validate repository name.

Args: repository: The repository name to validate.

Raises: CursorValidationError: If the repository is invalid.

Validate webhook URL to prevent SSRF attacks.

Only allows HTTPS URLs to external hosts.

Args: url: The webhook URL to validate.

Raises: CursorValidationError: If the URL is invalid or potentially dangerous.

Sanitize error messages to prevent sensitive data leakage.

Args: error: The error to sanitize.

Returns: Sanitized error message string.

class vendor_connectors.cursor.CursorConnector(api_key: str | None = None, base_url: str | None = None, timeout: float = DEFAULT_TIMEOUT, logger: lifecyclelogging.Logging | None = None, **kwargs)

Section titled “class vendor_connectors.cursor.CursorConnector(api_key: str | None = None, base_url: str | None = None, timeout: float = DEFAULT_TIMEOUT, logger: lifecyclelogging.Logging | None = None, **kwargs)”

Bases: vendor_connectors.base.VendorConnectorBase

Cursor Background Agent API connector.

Provides HTTP client access to Cursor’s agent management API for spawning, monitoring, and coordinating AI coding agents.

Args: api_key: Cursor API key. Defaults to CURSOR_API_KEY env var. base_url: API base URL. Only override for testing. timeout: Request timeout in seconds. Default 60s. logger: Optional logger instance. **kwargs: Additional DirectedInputsClass arguments.

Example:

connector = CursorConnector() agents = connector.list_agents() for agent in agents: … print(f”{agent.id}: {agent.state}”)

Initialize the connector.

Args: api_key: API key (overrides environment variable) base_url: Base URL (overrides class default) timeout: HTTP timeout in seconds logger: Logger instance **kwargs: Passed to DirectedInputsClass

‘CURSOR_API_KEY’

None

Check if API key is available.

Returns: True if CURSOR_API_KEY is set in environment.

Make an HTTP request to the Cursor API.

Args: endpoint: API endpoint path (e.g., “/agents”). method: HTTP method. json_body: Optional JSON body for POST/PUT requests.

Returns: JSON response data or None for empty responses.

Raises: CursorAPIError: If the API returns an error.

List all agents.

Returns: List of Agent objects.

Raises: CursorAPIError: If the API request fails.

Get status of a specific agent.

Args: agent_id: The agent identifier.

Returns: Agent object with current status.

Raises: CursorValidationError: If agent_id is invalid. CursorAPIError: If the API request fails or returns empty response.

Get conversation history for an agent.

Args: agent_id: The agent identifier.

Returns: Conversation object with message history.

Raises: CursorValidationError: If agent_id is invalid. CursorAPIError: If the API request fails.

Launch a new agent.

Args: prompt_text: The task description for the agent. repository: Repository name (owner/repo) or URL. ref: Git ref (branch/tag/commit). Defaults to default branch. images: Optional list of images with data and dimensions. auto_create_pr: Whether to automatically create a PR. branch_name: Custom branch name for the PR. open_as_cursor_github_app: Open PR as Cursor GitHub App. skip_reviewer_request: Skip reviewer request on PR. webhook_url: Webhook URL for status updates. webhook_secret: Webhook secret for signature verification.

Returns: The launched Agent object.

Raises: CursorValidationError: If inputs are invalid. CursorAPIError: If the API request fails.

Send a follow-up message to an agent.

Args: agent_id: The agent identifier. prompt_text: The follow-up message text.

Raises: CursorValidationError: If inputs are invalid. CursorAPIError: If the API request fails.

List available repositories.

Returns: List of Repository objects.

Raises: CursorAPIError: If the API request fails.

List available models.

Returns: List of model names.

Raises: CursorAPIError: If the API request fails.