AppleScript MCP服务器
MCP(模型上下文协议)服务器,使AI助手能够在macOS上执行预先注册的AppleScript命令。它提供了一种安全的、基于注册表的方法,用于使用MCP外部管理的脚本执行AppleScript自动化。
特性
- 脚本注册表:管理JSON格式的可重用AppleScripts
- 模板支撑:使用动态参数
{{placeholder}}语法 - 安全验证:执行前的脚本验证
- 3个MCP工具:
- run_applescript -执行已注册的脚本 - list_scripts -列出所有已注册的脚本 - get_script_info -获取特定脚本的详细信息
- 单独的脚本管理:通过添加/删除脚本
manage-scripts.js公用事业,而不是通过MCP
需求
- macOS(需要AppleScript)
- Node.js 16+
- npm或纱线
安装
# Install dependencies
npm install
# Build TypeScript
npm run build用法
发展
npm run dev生产
npm start脚本管理
# Add a script from JSON file
node manage-scripts.js add my-script.json
# Remove a script
node manage-scripts.js remove script_name
# List all scripts
node manage-scripts.js list
# Get script details
node manage-scripts.js info script_name运行测试
# Run all tests
./tests/test-batch.sh
# Run individual tests
./tests/test-individual.sh项目结构
.
├── src/ # Source code
│ ├── server.ts # MCP server implementation
│ ├── applescript.ts # AppleScript execution engine
│ ├── registry.ts # Script registry management
│ └── types.ts # TypeScript type definitions
├── dist/ # Compiled JavaScript
├── tests/ # Test files
│ ├── test-batch.sh # Batch test runner
│ ├── test-individual.sh # Individual test runner
│ └── test-messages.jsonl # Test messages
├── manage-scripts.js # Script management utility
├── scripts-registry.json # Registered scripts storage
├── package.json # npm configuration
├── tsconfig.json # TypeScript configuration
└── CLAUDE.md # AI development guidelines脚本示例
执行已注册的脚本
{
"method": "tools/call",
"params": {
"name": "run_applescript",
"arguments": {
"script_name": "show_notification",
"parameters": {
"message": "Hello from AppleScript!"
}
}
}
}添加新脚本
创建一个带有脚本定义的JSON文件:
{
"name": "my_script",
"script": "display dialog \"{{message}}\"",
"description": "Show a dialog with custom message",
"args": [
{
"name": "message",
"type": "string",
"description": "Message to display",
"required": true
}
],
"usage": "my_script(message=\"Hello\")",
"category": "ui"
}然后添加它:
node manage-scripts.js add my-script.json安全
- 所有脚本在执行前都经过验证
- 危险指令(
do shell script,System Events等)被阻塞 - 脚本被持久化
scripts-registry.json
私有脚本
要将您的个人AppleScripts设置为私有:
- 您的自定义脚本存储在
scripts-registry.json(忽略) - 存储库包括
scripts-registry.sample.json带有示例脚本 - 首次运行时,复制示例注册表以创建您的私有注册表
- 您的私有脚本永远不会提交到存储库
许可证
MIT许可证
贡献
欢迎拉取请求。对于重大更改,请先打开一个问题来讨论您想要更改的内容。
