# steipete/macos-automator-mcp architecture

> Architecture diagram of the GitHub repository steipete/macos-automator-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/steipete/macos-automator-mcp
- Repository: https://github.com/steipete/macos-automator-mcp

## Overview

1. This repository is a Node.js/TypeScript MCP server for macOS automation. Its core job is to expose a small set of MCP tools that execute AppleScript, JavaScript for Automation (JXA), and accessibility-driven UI actions on the local Mac. The runtime boundary is the host machine running the server; the server talks outward to macOS automation APIs and the accessibility framework.

2. The main external interface is the MCP protocol over stdio. The test file `tests/mcp-stdio.test.ts` and the presence of `src/server.ts` indicate the server is packaged as a command-line MCP endpoint rather than a browser or HTTP app. The published entrypoint is likely the `start.sh` wrapper, which chooses between compiled output and direct TypeScript execution during development.

3. The server exposes three primary capability groups. `execute_script` is the script runner for AppleScript/JXA. `get_scripting_tips` is the knowledge-base lookup tool that returns human-readable automation recipes. `accessibility_query` is a separate UI-automation path that queries or performs actions against macOS accessibility elements via an `ax`-style backend. These are distinct execution paths with different inputs, output shapes, and permission requirements.

4. Script execution is the central runtime subsystem. `src/ScriptExecutor.ts` likely shells out to `osascript` or equivalent, applies language-specific formatting, enforces timeouts, and returns normalized stdout/stderr content. The README shows support for inline scripts, file-based scripts, and knowledge-base script IDs, so the executor must resolve the source first, substitute inputs, then dispatch to the macOS scripting runtime.

5. The knowledge base is the repo’s largest architectural component, and it is content-driven rather than code-driven. `knowledge_base/` contains hundreds of markdown automation recipes organized by domain: core AppleScript/JXA concepts, system actions, files, terminal, browsers, editors, productivity apps, creative apps, advanced workflows, networking, and developer tools. This content is the server’s built-in automation catalog, not just documentation.

6. Knowledge-base loading is handled by `src/services/kbLoader.ts`, `src/services/KnowledgeBaseManager.ts`, and `src/services/knowledgeBaseService.ts`. Based on the README, this layer supports lazy or eager parsing, category indexing, lookup by script ID or search term, and local overrides from `~/.macos-automator/knowledge_base` or `LOCAL_KB_PATH`. That means the KB layer is both a content registry and a merge/override system.

7. Placeholder substitution is a separate data-preparation step before execution. `src/placeholderSubstitutor.ts` and the schema/type files suggest knowledge-base scripts can declare argument prompts and input placeholders that are replaced with user-supplied arguments or structured `input_data`. This creates a boundary between reusable recipe templates and the final executable script text.

8. Validation and tooling are first-class subsystems because the repo is mostly curated content. The `scripts/` directory contains validators and report generators for knowledge-base files, categories, paths, and script syntax. That implies the repository treats the KB as a schema-checked asset pipeline, with automated checks for structure, metadata, and script correctness before publish.

9. The docs directory is part of the architecture because it captures executable knowledge patterns. Files like `docs/applescript_*.md`, `docs/kb_validation.md`, and `docs/spec.md` describe the supported automation patterns and the KB contract. The `knowledge_base/_shared_handlers` directory shows another reuse boundary: shared AppleScript/JXA helpers that can be imported across tips.

10. The repo’s operational boundary is macOS permissions. The README explicitly calls out Automation and Accessibility permissions, which are required for controlling apps or querying UI elements. This matters architecturally because the server cannot self-elevate; the host application running the MCP server must already be trusted by macOS for the target apps and accessibility APIs.

11. Tooling and release flow are standard TypeScript package infrastructure. `package.json`, `pnpm-lock.yaml`, `.github/workflows/ci.yml`, and `.github/workflows/publish.yml` show pnpm-based builds/tests and npm publishing. The source/runtime split, plus `start.sh`, implies the repo supports both local development against `src/` and packaged execution from a build artifact.

12. In diagram terms, the cleanest high-level flow is: MCP client sends a tool request to the server; the server routes to script execution, KB search, or accessibility querying; the KB layer resolves recipes and substitutions when needed; execution then delegates to macOS-native automation runtimes; results return back through MCP as text content and error flags. The content repository, validators, and docs sit alongside that runtime path as the knowledge and quality-control layers.

Main entry points: [`src/server.ts`](https://github.com/steipete/macos-automator-mcp/blob/main/src/server.ts) (MCP server), [`scripts/validate-kb.ts`](https://github.com/steipete/macos-automator-mcp/blob/main/scripts/validate-kb.ts) (Validators), [`src/services/KnowledgeBaseManager.ts`](https://github.com/steipete/macos-automator-mcp/blob/main/src/services/KnowledgeBaseManager.ts) (KB manager), [`src/ScriptExecutor.ts`](https://github.com/steipete/macos-automator-mcp/blob/main/src/ScriptExecutor.ts) (Script exec)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_start_sh["start.sh<br/>entrypoint<br/>[start.sh]"]
  node_server["MCP server<br/>stdio endpoint<br/>[server.ts]"]
  node_schemas["Schemas<br/>contracts<br/>[schemas.ts]"]
  node_script_executor["Script exec<br/>runner<br/>[ScriptExecutor.ts]"]
  node_placeholder["Placeholders<br/>template prep"]
  node_macos_native(("macOS APIs<br/>native runtime"))
  node_ax_tools["Accessibility<br/>ui automation"]
end

subgraph group_knowledge["Knowledge Base"]
  node_kb_service["KB service<br/>lookup API"]
  node_kb_manager["KB manager<br/>registry"]
  node_kb_loader["KB loader<br/>content loader<br/>[kbLoader.ts]"]
  node_kb_types["KB types<br/>content model"]
  node_kb_content[("Recipes<br/>content catalog")]
end

subgraph group_tooling["Tooling"]
  node_kb_validators["Validators<br/>quality checks<br/>[validate-kb.ts]"]
  node_script_validator["Script validator<br/>syntax checks<br/>[scriptValidator.ts]"]
  node_kb_reports["KB reports<br/>reporting<br/>[kbReport.ts]"]
  node_mcp_test["MCP test<br/>integration test<br/>[mcp-stdio.test.ts]"]
end

subgraph group_docs["Docs"]
  node_spec_doc["Spec<br/>design docs<br/>[spec.md]"]
  node_kb_validation_doc["KB validation<br/>docs<br/>[kb_validation.md]"]
end

node_start_sh -->|"launches"| node_server
node_server -->|"uses"| node_schemas
node_server -->|"routes"| node_script_executor
node_server -->|"routes"| node_kb_service
node_server -->|"routes"| node_ax_tools
node_script_executor -->|"prepares"| node_placeholder
node_placeholder -->|"resolves"| node_kb_manager
node_kb_service -->|"queries"| node_kb_manager
node_kb_manager -->|"loads"| node_kb_loader
node_kb_loader -->|"reads"| node_kb_content
node_kb_manager -->|"structures"| node_kb_types
node_kb_content -->|"describes"| node_macos_native
node_script_executor -->|"delegates"| node_macos_native
node_ax_tools -->|"uses"| node_macos_native
node_kb_validators -->|"includes"| node_script_validator
node_kb_validators -->|"produces"| node_kb_reports
node_kb_validators -->|"checks"| node_kb_content
node_mcp_test -->|"exercises"| node_server
node_spec_doc -.->|"defines"| node_server
node_kb_validation_doc -.->|"documents"| node_kb_validators

click node_start_sh "https://github.com/steipete/macos-automator-mcp/blob/main/start.sh"
click node_server "https://github.com/steipete/macos-automator-mcp/blob/main/src/server.ts"
click node_schemas "https://github.com/steipete/macos-automator-mcp/blob/main/src/schemas.ts"
click node_script_executor "https://github.com/steipete/macos-automator-mcp/blob/main/src/ScriptExecutor.ts"
click node_placeholder "https://github.com/steipete/macos-automator-mcp/blob/main/src/placeholderSubstitutor.ts"
click node_kb_service "https://github.com/steipete/macos-automator-mcp/blob/main/src/services/knowledgeBaseService.ts"
click node_kb_manager "https://github.com/steipete/macos-automator-mcp/blob/main/src/services/KnowledgeBaseManager.ts"
click node_kb_loader "https://github.com/steipete/macos-automator-mcp/blob/main/src/services/kbLoader.ts"
click node_kb_types "https://github.com/steipete/macos-automator-mcp/blob/main/src/services/scriptingKnowledge.types.ts"
click node_kb_content "https://github.com/steipete/macos-automator-mcp/tree/main/knowledge_base"
click node_kb_validators "https://github.com/steipete/macos-automator-mcp/blob/main/scripts/validate-kb.ts"
click node_script_validator "https://github.com/steipete/macos-automator-mcp/blob/main/scripts/scriptValidator.ts"
click node_kb_reports "https://github.com/steipete/macos-automator-mcp/blob/main/scripts/kbReport.ts"
click node_mcp_test "https://github.com/steipete/macos-automator-mcp/blob/main/tests/mcp-stdio.test.ts"
click node_spec_doc "https://github.com/steipete/macos-automator-mcp/blob/main/docs/spec.md"
click node_kb_validation_doc "https://github.com/steipete/macos-automator-mcp/blob/main/docs/kb_validation.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_start_sh,node_server,node_schemas,node_script_executor,node_placeholder,node_macos_native,node_ax_tools toneBlue
class node_kb_service,node_kb_manager,node_kb_loader,node_kb_types,node_kb_content toneAmber
class node_kb_validators,node_script_validator,node_kb_reports,node_mcp_test toneMint
class node_spec_doc,node_kb_validation_doc toneRose
```

## Components

### Runtime

MCP server execution and macOS automation

- [start.sh](https://github.com/steipete/macos-automator-mcp/blob/main/start.sh): entrypoint · Launches compiled server or dev TypeScript runtime · `start.sh`
- [MCP server](https://github.com/steipete/macos-automator-mcp/blob/main/src/server.ts): stdio endpoint · Main MCP server and tool router · `src/server.ts`
- [Schemas](https://github.com/steipete/macos-automator-mcp/blob/main/src/schemas.ts): contracts · Shared request and response shapes · `src/schemas.ts`
- [Script exec](https://github.com/steipete/macos-automator-mcp/blob/main/src/ScriptExecutor.ts): runner · Runs AppleScript and JXA payloads on macOS · `src/ScriptExecutor.ts`
- [Placeholders](https://github.com/steipete/macos-automator-mcp/blob/main/src/placeholderSubstitutor.ts): template prep · Resolves recipe arguments into executable script text · `src/placeholderSubstitutor.ts`
- **macOS APIs**: native runtime · AppleScript, JXA, Accessibility, and system automation APIs
- **Accessibility**: ui automation · Accessibility-driven UI queries and actions

### Knowledge Base

Curated automation recipes and lookup services

- [KB service](https://github.com/steipete/macos-automator-mcp/blob/main/src/services/knowledgeBaseService.ts): lookup API · High-level knowledge-base search and retrieval · `src/services/knowledgeBaseService.ts`
- [KB manager](https://github.com/steipete/macos-automator-mcp/blob/main/src/services/KnowledgeBaseManager.ts): registry · Indexes recipes and resolves IDs and categories · `src/services/KnowledgeBaseManager.ts`
- [KB loader](https://github.com/steipete/macos-automator-mcp/blob/main/src/services/kbLoader.ts): content loader · Loads local and override knowledge-base content · `src/services/kbLoader.ts`
- [KB types](https://github.com/steipete/macos-automator-mcp/blob/main/src/services/scriptingKnowledge.types.ts): content model · Knowledge-base data structures and metadata types · `src/services/scriptingKnowledge.types.ts`
- [Recipes](https://github.com/steipete/macos-automator-mcp/tree/main/knowledge_base): content catalog · Markdown automation recipes and shared handlers · `knowledge_base`

### Tooling

Validation, testing, and release support

- [Validators](https://github.com/steipete/macos-automator-mcp/blob/main/scripts/validate-kb.ts): quality checks · KB structure, path, category, and script validation · `scripts/validate-kb.ts`
- [Script validator](https://github.com/steipete/macos-automator-mcp/blob/main/scripts/scriptValidator.ts): syntax checks · Checks script examples and automation snippets · `scripts/scriptValidator.ts`
- [KB reports](https://github.com/steipete/macos-automator-mcp/blob/main/scripts/kbReport.ts): reporting · Generates validation and inventory reports · `scripts/kbReport.ts`
- [MCP test](https://github.com/steipete/macos-automator-mcp/blob/main/tests/mcp-stdio.test.ts): integration test · Exercises the stdio MCP server boundary · `tests/mcp-stdio.test.ts`

### Docs

Executable documentation and specs

- [Spec](https://github.com/steipete/macos-automator-mcp/blob/main/docs/spec.md): design docs · Defines the MCP and knowledge-base contract · `docs/spec.md`
- [KB validation](https://github.com/steipete/macos-automator-mcp/blob/main/docs/kb_validation.md): docs · Documents validation rules and workflow · `docs/kb_validation.md`

## Connections

- start.sh → MCP server: launches · Wrapper starts the MCP server process
- MCP server → Schemas: uses · Server validates tool I/O against shared schemas
- MCP server → Script exec: routes · Tool requests that execute scripts flow to the executor
- MCP server → KB service: routes · Scripting-tip lookups flow to knowledge-base service
- MCP server → Accessibility: routes · Accessibility tool requests flow to UI automation path
- Script exec → Placeholders: prepares · Template inputs are substituted before execution
- Placeholders → KB manager: resolves · Recipe templates and IDs are resolved through KB metadata
- KB service → KB manager: queries · Search and lookup are served through the registry
- KB manager → KB loader: loads · Manager depends on loader for content ingestion
- KB loader → Recipes: reads · Loader parses markdown recipe files and overrides
- KB manager → KB types: structures · Manager uses KB data model and metadata types
- Recipes → macOS APIs: describes · Recipes encode scripts that run on macOS automation runtimes
- Script exec → macOS APIs: delegates · Execution shells out to native AppleScript/JXA tooling
- Accessibility → macOS APIs: uses · Accessibility automation talks to the host macOS UI layer
- Validators → Script validator: includes · KB validation pipeline incorporates script checks
- Validators → KB reports: produces · Validation tooling also emits reports and inventories
- Validators → Recipes: checks · Validators inspect the knowledge-base content tree
- MCP test → MCP server: exercises · Integration test covers stdio server behavior
- Spec → MCP server: defines · Spec documents the server and tool contract
- KB validation → Validators: documents · Docs explain the KB validation workflow
