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:
| Reader | Description |
|---|---|
| SessionReader | Read AI conversation session records |
| ComposerReader | Read Composer sessions and statistics |
| StatsReader | Read AI code generation statistics |
| ConfigReader | Read user configuration and settings |
| WorkspaceReader | Read workspace-specific data |
| TerminalHistoryReader | Read terminal command history |
| MCPServiceReader | Read MCP server information |
| AgentLayoutReader | Read Agent UI layout configuration |
| CommandPaletteReader | Read command palette usage data |
| RepositoryTrackerReader | Read repository tracking data |
| AdminSettingsReader | Read admin settings |
| AITrackingReader | Read AI code tracking data |
| IDEStateReader | Read IDE state information |
| KVReader | Read 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:
| Model | Description |
|---|---|
| Session | AI conversation session |
| Composer | Composer session data |
| DailyStats | Daily AI statistics |
| TerminalHistory | Terminal command history |
| MCPServiceData | MCP server information |
| AgentLayout | Agent 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 foundPermissionError- Permission deniedDatabaseError- Database operation failedValidationError- Invalid inputNotFoundError- Resource not found
Best Practices
- Always close resources: Use
defer client.Close() - Handle errors properly: Check and handle specific error types
- Use caching: Enable caching for frequently accessed data
- Concurrent access: The SDK is thread-safe
- Read-only: The SDK never modifies Cursor data