3.0.1 • Published 6 months ago

@codai/glass-sdk v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@codai/glass-sdk

TypeScript SDK for GlassMCP - Machine Control Protocol client library for Windows automation.

Installation

npm install @codai/glass-sdk

Quick Start

import { GlassMCPClient } from '@codai/glass-sdk';

// Initialize client
const client = new GlassMCPClient({
  baseUrl: 'http://localhost:7700',
  token: 'your-auth-token',
});

// Focus a window
await client.window.focus({ title: 'Visual Studio Code' });

// Type some text
await client.keyboard.type({ text: 'Hello from GlassMCP!' });

// Move mouse
await client.mouse.move({ x: 100, y: 200 });

// Click mouse
await client.mouse.click({ x: 100, y: 200 });

// Get clipboard content
const clipboardText = await client.clipboard.getText();

// Set clipboard content
await client.clipboard.setText({ text: 'Hello World' });

// Execute system command
const result = await client.system.exec({ command: 'dir' });

// Read file
const content = await client.filesystem.readFile({
  path: 'C:\\temp\\file.txt',
});

// Write file
await client.filesystem.writeFile({
  path: 'C:\\temp\\output.txt',
  content: 'Hello World',
});

API Reference

Window Control

  • window.focus(options) - Focus window by title
  • window.list() - Get list of open windows
  • window.close(options) - Close window by title or process ID
  • window.minimize(options) - Minimize window
  • window.maximize(options) - Maximize window

Keyboard Control

  • keyboard.type(options) - Type text
  • keyboard.press(options) - Press key combination
  • keyboard.hotkey(options) - Send hotkey sequence

Mouse Control

  • mouse.move(options) - Move mouse to coordinates
  • mouse.click(options) - Click at coordinates
  • mouse.scroll(options) - Scroll mouse wheel

Clipboard Control

  • clipboard.getText() - Get clipboard text
  • clipboard.setText(options) - Set clipboard text
  • clipboard.getFiles() - Get clipboard file list
  • clipboard.clear() - Clear clipboard

System Control

  • system.exec(options) - Execute system command
  • system.getProcesses() - List running processes
  • system.killProcess(options) - Kill process by ID
  • system.getSystemInfo() - Get system information

Filesystem Control

  • filesystem.readFile(options) - Read file content
  • filesystem.writeFile(options) - Write file content
  • filesystem.exists(options) - Check if file exists
  • filesystem.delete(options) - Delete file
  • filesystem.copy(options) - Copy file
  • filesystem.move(options) - Move file
  • filesystem.createDirectory(options) - Create directory
  • filesystem.listDirectory(options) - List directory contents

Configuration

The client accepts the following configuration options:

interface ClientConfig {
  baseUrl: string; // GlassMCP server URL (default: http://localhost:7700)
  token: string; // Authentication token
  timeout?: number; // Request timeout in ms (default: 30000)
  retries?: number; // Number of retries (default: 3)
}

Error Handling

The SDK throws specific error types for different scenarios:

import { GlassMCPError } from '@codai/glass-sdk';

try {
  await client.window.focus({ title: 'NonExistent' });
} catch (error) {
  if (error instanceof GlassMCPError) {
    console.log('Error code:', error.code);
    console.log('Error message:', error.message);
  }
}

WebSocket Support

For real-time events and notifications:

import { GlassMCPWebSocketClient } from '@codai/glass-sdk';

const wsClient = new GlassMCPWebSocketClient({
  url: 'ws://localhost:7700/ws',
  token: 'your-auth-token',
});

wsClient.on('window.focus', event => {
  console.log('Window focused:', event.windowTitle);
});

await wsClient.connect();

License

MIT - see LICENSE file for details.