3.0.1 • Published 6 months ago
@codai/glass-sdk v3.0.1
@codai/glass-sdk
TypeScript SDK for GlassMCP - Machine Control Protocol client library for Windows automation.
Installation
npm install @codai/glass-sdkQuick 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 titlewindow.list()- Get list of open windowswindow.close(options)- Close window by title or process IDwindow.minimize(options)- Minimize windowwindow.maximize(options)- Maximize window
Keyboard Control
keyboard.type(options)- Type textkeyboard.press(options)- Press key combinationkeyboard.hotkey(options)- Send hotkey sequence
Mouse Control
mouse.move(options)- Move mouse to coordinatesmouse.click(options)- Click at coordinatesmouse.scroll(options)- Scroll mouse wheel
Clipboard Control
clipboard.getText()- Get clipboard textclipboard.setText(options)- Set clipboard textclipboard.getFiles()- Get clipboard file listclipboard.clear()- Clear clipboard
System Control
system.exec(options)- Execute system commandsystem.getProcesses()- List running processessystem.killProcess(options)- Kill process by IDsystem.getSystemInfo()- Get system information
Filesystem Control
filesystem.readFile(options)- Read file contentfilesystem.writeFile(options)- Write file contentfilesystem.exists(options)- Check if file existsfilesystem.delete(options)- Delete filefilesystem.copy(options)- Copy filefilesystem.move(options)- Move filefilesystem.createDirectory(options)- Create directoryfilesystem.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.