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.
func NewCursorClient(config *ClientConfig) (*CursorClient, error)Parameters:
config- Client configuration (can benilfor defaults)
Returns:
*CursorClient- The client instanceerror- Error if initialization fails
Example:
// 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.
func (c *CursorClient) Sessions() *SessionReaderExample:
sessions, err := client.Sessions().ListSessions()Composers
Returns the ComposerReader for accessing Composer data.
func (c *CursorClient) Composers() *ComposerReaderExample:
composers, err := client.Composers().ListComposers()Stats
Returns the StatsReader for accessing statistics data.
func (c *CursorClient) Stats() *StatsReaderExample:
stats, err := client.Stats().GetDailyStats(time.Now())Config
Returns the ConfigReader for accessing user configuration.
func (c *CursorClient) Config() *ConfigReaderExample:
userConfig, err := client.Config().GetUserConfig()Workspace
Returns a WorkspaceReader for the specified workspace path.
func (c *CursorClient) Workspace(path string) (*WorkspaceReader, error)Parameters:
path- Workspace path
Returns:
*WorkspaceReader- The workspace readererror- Error if path is invalid
Example:
workspace, err := client.Workspace("/path/to/workspace")
if err != nil {
log.Fatal(err)
}
defer workspace.Close()TerminalHistory
Returns the TerminalHistoryReader for accessing terminal history.
func (c *CursorClient) TerminalHistory() *TerminalHistoryReaderExample:
history, err := client.TerminalHistory().GetHistory()MCPService
Returns the MCPServiceReader for accessing MCP server information.
func (c *CursorClient) MCPService() *MCPServiceReaderExample:
mcpData, err := client.MCPService().GetMCPServiceData()AgentLayout
Returns the AgentLayoutReader for accessing Agent layout configuration.
func (c *CursorClient) AgentLayout() *AgentLayoutReaderExample:
layout, err := client.AgentLayout().GetAgentLayout()CommandPalette
Returns the CommandPaletteReader for accessing command palette data.
func (c *CursorClient) CommandPalette() *CommandPaletteReaderExample:
commands, err := client.CommandPalette().GetMostUsedCommands(10)RepositoryTracker
Returns the RepositoryTrackerReader for accessing repository tracking data.
func (c *CursorClient) RepositoryTracker() *RepositoryTrackerReaderExample:
repos, err := client.RepositoryTracker().ListRepositories()AdminSettings
Returns the AdminSettingsReader for accessing admin settings.
func (c *CursorClient) AdminSettings() *AdminSettingsReaderExample:
settings, err := client.AdminSettings().GetAllSettings()Export
Returns the Exporter for exporting data.
func (c *CursorClient) Export() *ExporterExample:
err := client.Export().ExportSessionsJSON(sessions, "sessions.json")Cache
Returns the Cache for cache management.
func (c *CursorClient) Cache() *CacheExample:
cache := client.Cache()
stats := cache.GetCacheStats()Watcher
Returns the Watcher for watching data changes.
func (c *CursorClient) Watcher() *WatcherExample:
watcher := client.Watcher()
watcher.WatchSessions(callback)
watcher.Start()Close
Closes the client and releases all resources.
func (c *CursorClient) Close() errorReturns:
error- Error if cleanup fails
Example:
defer client.Close()IsClosed
Checks if the client is closed.
func (c *CursorClient) IsClosed() boolReturns:
bool-trueif closed,falseotherwise
Example:
if client.IsClosed() {
fmt.Println("Client is closed")
}Complete Example
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:
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
- Configuration - Client configuration options
- SessionReader - Session data access
- Cache - Cache management
- Watcher - Data change watching