Skip to content

Commit 617bdc4

Browse files
Merge pull request #14 from joshrutkowski/readme
update readme
2 parents fc0b0f6 + 63bb869 commit 617bdc4

File tree

1 file changed

+79
-8
lines changed

1 file changed

+79
-8
lines changed

README.md

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This server provides a standardized interface for AI applications to control sys
1616
- 📬 Mail (create new email, list emails, get email)
1717
- 🔄 Shortcuts automation
1818
- 💬 Messages (list chats, get messages, search messages, send a message)
19-
- 🗒️ Notes (create formatted notes, list notes)
19+
- 🗒️ Notes (create formatted notes, list notes, search notes)
2020
- 📄 Pages (create documents)
2121

2222
### Planned Features
@@ -206,7 +206,7 @@ Find the email from [email protected] about "Project Update"
206206

207207
| Command | Description | Parameters |
208208
| ----------------- | -------------------------------------------- | --------------------------------------------------------- |
209-
| `list_chats` | List available iMessage and SMS chats | `includeParticipantDetails` (optional) |
209+
| `list_chats` | List available iMessage and SMS chats | `includeParticipantDetails` (optional, default: false) |
210210
| `get_messages` | Get messages from the Messages app | `limit` (optional, default: 100) |
211211
| `search_messages` | Search for messages containing specific text | `searchText`, `sender` (optional), `chatId` (optional), `limit` (optional, default: 50), `daysBack` (optional, default: 30) |
212212
| `compose_message` | Open Messages app with pre-filled message or auto-send | `recipient` (required), `body` (optional), `auto` (optional, default: false) |
@@ -240,8 +240,8 @@ Send a message to 555-123-4567 saying "I'll be there in 10 minutes"
240240
#### Examples
241241

242242
```
243-
// Create a new note
244-
Create a note titled "Meeting Minutes" with content "# Discussion Points\n- Project timeline\n- Budget review\n- Next steps"
243+
// Create a new note with markdown formatting
244+
Create a note titled "Meeting Minutes" with content "# Discussion Points\n- Project timeline\n- Budget review\n- Next steps" and format headings and lists
245245
246246
// Create a note with HTML
247247
Create a note titled "Formatted Report" with HTML content "<h1>Quarterly Report</h1><p>Sales increased by <strong>15%</strong></p>"
@@ -269,6 +269,43 @@ Find notes containing "recipe" in my "Cooking" folder
269269
Create a Pages document with the content "Project Proposal\n\nThis document outlines the scope and timeline for the upcoming project."
270270
```
271271

272+
## Architecture
273+
274+
The applescript-mcp server is built using TypeScript and follows a modular architecture:
275+
276+
### Core Components
277+
278+
1. **AppleScriptFramework** (`framework.ts`): The main server class that:
279+
- Manages MCP protocol communication
280+
- Handles tool registration and execution
281+
- Provides logging functionality
282+
- Executes AppleScript commands
283+
284+
2. **Categories** (`src/categories/*.ts`): Modular script collections organized by functionality:
285+
- Each category contains related scripts (e.g., calendar, system, notes)
286+
- Categories are registered with the framework in `index.ts`
287+
288+
3. **Types** (`src/types/index.ts`): TypeScript interfaces defining:
289+
- `ScriptDefinition`: Structure for individual scripts
290+
- `ScriptCategory`: Collection of related scripts
291+
- `LogLevel`: Standard logging levels
292+
- `FrameworkOptions`: Configuration options
293+
294+
### Execution Flow
295+
296+
1. Client sends a tool request via MCP protocol
297+
2. Server identifies the appropriate category and script
298+
3. Script content is generated (static or dynamically via function)
299+
4. AppleScript is executed via macOS `osascript` command
300+
5. Results are returned to the client
301+
302+
### Logging System
303+
304+
The framework includes a comprehensive logging system that:
305+
- Logs to both stderr and MCP logging protocol
306+
- Supports multiple severity levels (debug, info, warning, error, etc.)
307+
- Provides detailed execution information for troubleshooting
308+
272309
## Development
273310

274311
### Setup
@@ -337,6 +374,41 @@ import { newCategory } from "./categories/newcategory.js";
337374
server.addCategory(newCategory);
338375
```
339376

377+
### Advanced Script Development
378+
379+
For more complex scripts, you can:
380+
381+
1. **Use dynamic script generation**:
382+
```typescript
383+
script: (args) => {
384+
// Process arguments and build script dynamically
385+
let scriptContent = `tell application "App"\n`;
386+
387+
if (args.condition) {
388+
scriptContent += ` // Conditional logic\n`;
389+
}
390+
391+
scriptContent += `end tell`;
392+
return scriptContent;
393+
}
394+
```
395+
396+
2. **Process complex data**:
397+
```typescript
398+
// Example from Notes category
399+
function generateNoteHtml(args: any): string {
400+
// Process markdown-like syntax into HTML
401+
let processedContent = content;
402+
403+
if (format.headings) {
404+
processedContent = processedContent.replace(/^# (.+)$/gm, '<h1>$1</h1>');
405+
// ...
406+
}
407+
408+
return processedContent;
409+
}
410+
```
411+
340412
## Debugging
341413

342414
### Using MCP Inspector
@@ -367,15 +439,14 @@ After running `npm run build` add the following to your `mcp.json` file:
367439
}
368440
}
369441
}
370-
371-
372442
```
373443

374444
### Common Issues
375445

376-
- **Permission Errors**: Check System Preferences > Security & Privacy
377-
- **Script Failures**: Test scripts directly in Script Editor.app
446+
- **Permission Errors**: Check System Preferences > Security & Privacy > Privacy > Automation
447+
- **Script Failures**: Test scripts directly in Script Editor.app before integration
378448
- **Communication Issues**: Check stdio streams aren't being redirected
449+
- **Database Access**: Some features (like Messages) require Full Disk Access permission
379450

380451
## Resources
381452

0 commit comments

Comments
 (0)