Skip to content

CursorClient

CursorClient is the unified entry point for accessing all Cursor IDE data. It manages connections, caching, and provides access to specialized readers.

Constructor

NewCursorClient

Creates a new CursorClient instance.

go
func NewCursorClient(config *ClientConfig) (*CursorClient, error)

Parameters:

  • config - Client configuration (can be nil for defaults)

Returns:

  • *CursorClient - The client instance
  • error - Error if initialization fails

Example:

go
// Default configuration
client, err := cursor.NewCursorClient(nil)
if err != nil {
    log.Fatal(err)
}
defer client.Close()

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

Methods

Sessions

Returns the SessionReader for accessing session data.

go
func (c *CursorClient) Sessions() *SessionReader

Example:

go
sessions, err := client.Sessions().ListSessions()

Composers

Returns the ComposerReader for accessing Composer data.

go
func (c *CursorClient) Composers() *ComposerReader

Example:

go
composers, err := client.Composers().ListComposers()

Stats

Returns the StatsReader for accessing statistics data.

go
func (c *CursorClient) Stats() *StatsReader

Example:

go
stats, err := client.Stats().GetDailyStats(time.Now())

Config

Returns the ConfigReader for accessing user configuration.

go
func (c *CursorClient) Config() *ConfigReader

Example:

go
userConfig, err := client.Config().GetUserConfig()

Workspace

Returns a WorkspaceReader for the specified workspace path.

go
func (c *CursorClient) Workspace(path string) (*WorkspaceReader, error)

Parameters:

  • path - Workspace path

Returns:

  • *WorkspaceReader - The workspace reader
  • error - Error if path is invalid

Example:

go
workspace, err := client.Workspace("/path/to/workspace")
if err != nil {
    log.Fatal(err)
}
defer workspace.Close()

TerminalHistory

Returns the TerminalHistoryReader for accessing terminal history.

go
func (c *CursorClient) TerminalHistory() *TerminalHistoryReader

Example:

go
history, err := client.TerminalHistory().GetHistory()

MCPService

Returns the MCPServiceReader for accessing MCP server information.

go
func (c *CursorClient) MCPService() *MCPServiceReader

Example:

go
mcpData, err := client.MCPService().GetMCPServiceData()

AgentLayout

Returns the AgentLayoutReader for accessing Agent layout configuration.

go
func (c *CursorClient) AgentLayout() *AgentLayoutReader

Example:

go
layout, err := client.AgentLayout().GetAgentLayout()

CommandPalette

Returns the CommandPaletteReader for accessing command palette data.

go
func (c *CursorClient) CommandPalette() *CommandPaletteReader

Example:

go
commands, err := client.CommandPalette().GetMostUsedCommands(10)

RepositoryTracker

Returns the RepositoryTrackerReader for accessing repository tracking data.

go
func (c *CursorClient) RepositoryTracker() *RepositoryTrackerReader

Example:

go
repos, err := client.RepositoryTracker().ListRepositories()

AdminSettings

Returns the AdminSettingsReader for accessing admin settings.

go
func (c *CursorClient) AdminSettings() *AdminSettingsReader

Example:

go
settings, err := client.AdminSettings().GetAllSettings()

Export

Returns the Exporter for exporting data.

go
func (c *CursorClient) Export() *Exporter

Example:

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

Cache

Returns the Cache for cache management.

go
func (c *CursorClient) Cache() *Cache

Example:

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

Watcher

Returns the Watcher for watching data changes.

go
func (c *CursorClient) Watcher() *Watcher

Example:

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

Close

Closes the client and releases all resources.

go
func (c *CursorClient) Close() error

Returns:

  • error - Error if cleanup fails

Example:

go
defer client.Close()

IsClosed

Checks if the client is closed.

go
func (c *CursorClient) IsClosed() bool

Returns:

  • bool - true if closed, false otherwise

Example:

go
if client.IsClosed() {
    fmt.Println("Client is closed")
}

Complete Example

go
package main

import (
    "fmt"
    "log"
    "time"
    
    cursor "github.com/vibe-coding-labs/go-cursor-sdk"
)

func main() {
    // Create client with configuration
    config := &cursor.ClientConfig{
        EnableCache: true,
        CacheTTL:    10 * time.Minute,
        LogLevel:    cursor.LogLevelInfo,
    }
    
    client, err := cursor.NewCursorClient(config)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()
    
    // Access different types of data
    sessions, err := client.Sessions().ListSessions()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Sessions: %d\n", len(sessions))
    
    composers, err := client.Composers().ListComposers()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Composers: %d\n", len(composers))
    
    stats, err := client.Stats().GetDailyStats(time.Now())
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Today's stats: %+v\n", stats)
    
    // Check cache statistics
    cacheStats := client.Cache().GetCacheStats()
    fmt.Printf("Cache hit rate: %.2f%%\n", cacheStats.HitRate*100)
}

Thread Safety

CursorClient is thread-safe and can be safely used from multiple goroutines:

go
var wg sync.WaitGroup

wg.Add(2)

go func() {
    defer wg.Done()
    sessions, _ := client.Sessions().ListSessions()
    fmt.Printf("Sessions: %d\n", len(sessions))
}()

go func() {
    defer wg.Done()
    composers, _ := client.Composers().ListComposers()
    fmt.Printf("Composers: %d\n", len(composers))
}()

wg.Wait()

See Also

Released under the MIT License.