Skip to content

API Reference

Welcome to the Go Cursor SDK API reference. This section provides detailed documentation for all public APIs.

Core Components

CursorClient

The unified client that provides access to all Cursor IDE data.

go
client, err := cursor.NewCursorClient(config)
defer client.Close()

Configuration

Configure the client behavior with ClientConfig.

go
config := &cursor.ClientConfig{
    EnableCache: true,
    CacheTTL:    5 * time.Minute,
    LogLevel:    cursor.LogLevelInfo,
}

Data Readers

Specialized readers for different types of Cursor data:

ReaderDescription
SessionReaderRead AI conversation session records
ComposerReaderRead Composer sessions and statistics
StatsReaderRead AI code generation statistics
ConfigReaderRead user configuration and settings
WorkspaceReaderRead workspace-specific data
TerminalHistoryReaderRead terminal command history
MCPServiceReaderRead MCP server information
AgentLayoutReaderRead Agent UI layout configuration
CommandPaletteReaderRead command palette usage data
RepositoryTrackerReaderRead repository tracking data
AdminSettingsReaderRead admin settings
AITrackingReaderRead AI code tracking data
IDEStateReaderRead IDE state information
KVReaderRead arbitrary key-value pairs

Utilities

QueryBuilder

Build complex queries for filtering and sorting data.

go
query := cursor.NewQueryBuilder().
    TimeRange(start, end).
    Keyword("bug fix").
    Limit(10).
    Build()

Exporter

Export data to various formats (JSON, CSV, etc.).

go
exporter := client.Export()
exporter.ExportSessionsJSON(sessions, "sessions.json")

Cache

Manage caching for improved performance.

go
cache := client.Cache()
stats := cache.GetCacheStats()

Watcher

Watch for data changes in real-time.

go
watcher := client.Watcher()
watcher.WatchSessions(callback)
watcher.Start()

Data Models

Core data structures used throughout the SDK:

ModelDescription
SessionAI conversation session
ComposerComposer session data
DailyStatsDaily AI statistics
TerminalHistoryTerminal command history
MCPServiceDataMCP server information
AgentLayoutAgent UI layout

Quick Reference

Creating a Client

go
// Default configuration
client, err := cursor.NewCursorClient(nil)

// Custom configuration
config := &cursor.ClientConfig{
    EnableCache: true,
    CacheTTL:    10 * time.Minute,
}
client, err := cursor.NewCursorClient(config)

Accessing Readers

go
sessions := client.Sessions()
composers := client.Composers()
stats := client.Stats()
config := client.Config()
workspace, err := client.Workspace(path)
terminalHistory := client.TerminalHistory()
mcpService := client.MCPService()
agentLayout := client.AgentLayout()
commandPalette := client.CommandPalette()
repositoryTracker := client.RepositoryTracker()
adminSettings := client.AdminSettings()

Resource Management

go
// Always close the client
defer client.Close()

// Check if closed
if client.IsClosed() {
    // Client is closed
}

Error Types

The SDK provides specific error types:

  • PathNotFoundError - Storage path not found
  • PermissionError - Permission denied
  • DatabaseError - Database operation failed
  • ValidationError - Invalid input
  • NotFoundError - Resource not found

Best Practices

  1. Always close resources: Use defer client.Close()
  2. Handle errors properly: Check and handle specific error types
  3. Use caching: Enable caching for frequently accessed data
  4. Concurrent access: The SDK is thread-safe
  5. Read-only: The SDK never modifies Cursor data

Next Steps

Released under the MIT License.