mcpField
A
applescript-mcp MCP Server

applescript-mcp MCP Server

本地服务
github.com/joshrutkowski生产力39480 周前更新

关于 applescript-mcp MCP Server

applescript-mcp 是一个面向 macOS 的 MCP 服务,通过 AppleScript 让 LLM 应用控制系统功能、管理文件并发送通知。它以 TypeScript 实现,按功能分类组织脚本,便于扩展。

主要功能

  1. 01日历、提醒事项与备忘录操作
  2. 02邮件、信息与 Finder 集成
  3. 03系统音量、深色模式与应用控制
  4. 04剪贴板、快捷指令与 iTerm 集成
  5. 05通过 osascript 执行脚本并返回结果

适用场景

  1. 01让 AI 助手创建日历事件或查询当天日程
  2. 02在 Mail 或 Messages 中搜索与撰写消息
  3. 03通过快捷指令自动化 macOS 任务

MCP 相关

作为 MCP 服务运行,将各类 AppleScript 脚本封装为工具,供 MCP 客户端调用以控制 macOS 功能。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"applescript-mcp-joshrutkowski": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/inspector"
]
}
}
}
启动命令npx -y @modelcontextprotocol/inspector

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npm@modelcontextprotocol/inspector

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

applescript-mcp MCP 服务

一个模型上下文协议服务,可通过 AppleScript 让大模型应用与 macOS 交互。 此服务提供标准化接口,供 AI 应用控制系统功能、管理文件、处理通知等。

Node.js CI

applescript-mcp MCP server

功能

  • 🗓️ 日历管理(事件、提醒事项)
  • 📋 剪贴板操作
  • 🔍 Finder 集成
  • 🔔 系统通知
  • ⚙️ 系统控制(音量、深色模式、应用)
  • 📟 iTerm 终端集成
  • 📬 邮件(创建新邮件、列出邮件、获取邮件)
  • 🔄 快捷指令自动化
  • 💬 信息(列出聊天、获取消息、搜索消息、发送消息)
  • 🗒️ 备忘录(创建格式化备忘录、列出备忘录、搜索备忘录)
  • 📄 Pages(创建文稿)
计划中的功能
  • 🧭 Safari(在 Safari 中打开、保存页面内容、获取选中的页面/标签页)
  • ✅ 提醒事项(创建、获取)

前置条件

  • macOS 10.15 或更高版本
  • Node.js 18 或更高版本

可用类别

日历
命令描述参数
add创建日历事件title、startDate、endDate、calendar(可选)
list列出今天的事件无
示例
// Create a new calendar event
Create a calendar event titled "Team Meeting" starting tomorrow at 2pm for 1 hour

// List today's events
What events do I have scheduled for today?
剪贴板
命令描述参数
set_clipboard复制到剪贴板content
get_clipboard获取剪贴板内容无
clear_clipboard清空剪贴板无
示例
// Copy text to clipboard
Copy "Remember to buy groceries" to my clipboard

// Get clipboard contents
What's currently in my clipboard?

// Clear clipboard
Clear my clipboard
Finder
命令描述参数
get_selected_files获取选中的文件无
search_files搜索文件query、location(可选)
quick_look预览文件path
示例
// Get selected files in Finder
What files do I currently have selected in Finder?

// Search for files
Find all PDF files in my Documents folder

// Preview a file
Show me a preview of ~/Documents/report.pdf
通知

注意:发送通知需要在“系统设置”>“通知”>“脚本编辑器”中启用通知。

命令描述参数
send_notification显示通知title、message、sound(可选)
toggle_do_not_disturb切换勿扰模式无
示例
// Send a notification
Send me a notification with the title "Reminder" and message "Time to take a break"

// Toggle Do Not Disturb
Turn on Do Not Disturb mode
系统
命令描述参数
volume设置系统音量level(0-100)
get_frontmost_app获取当前活动应用无
launch_app打开应用程序name
quit_app关闭应用程序name、force(可选)
toggle_dark_mode切换深色模式无
示例
// Set system volume
Set my Mac's volume to 50%

// Get active application
What app am I currently using?

// Launch an application
Open Safari

// Quit an application
Close Spotify

// Toggle dark mode
Switch to dark mode
iTerm
命令描述参数
paste_clipboard粘贴到 iTerm无
run执行命令command、newWindow(可选)
示例
// Paste clipboard to iTerm
Paste my clipboard contents into iTerm

// Run a command in iTerm
Run "ls -la" in iTerm

// Run a command in a new iTerm window
Run "top" in a new iTerm window
快捷指令
命令描述参数
run_shortcut运行快捷指令name、input(可选)
list_shortcuts列出所有可用的快捷指令limit(可选)
示例
// List available shortcuts
List all my available shortcuts

// List with limit
Show me my top 5 shortcuts

// Run a shortcut
Run my "Daily Note in Bear" shortcut

// Run a shortcut with input
Run my "Add to-do" shortcut with input "Buy groceries"
邮件
命令描述参数
create_email在 Mail.app 中创建新邮件recipient、subject、body
list_emails列出邮箱中的邮件mailbox(可选)、count(可选)、unreadOnly(可选)
get_email根据搜索条件获取特定邮件subject(可选)、sender(可选)、dateReceived(可选)、mailbox(可选)、account(可选)、unreadOnly(可选)、includeBody(可选)
示例
// Create a new email
Compose an email to [email protected] with subject "Meeting Tomorrow" and body "Hi John, Can we meet tomorrow at 2pm?"

// List emails
Show me my 10 most recent unread emails

// Get a specific email
Find the email from [email protected] about "Project Update"
信息
命令描述参数
list_chats列出可用的 iMessage 和 SMS 聊天includeParticipantDetails(可选,默认值:false)
get_messages从 Messages 应用中获取信息limit(可选,默认值:100)
search_messages搜索包含特定文本的信息searchText、sender(可选)、chatId(可选)、limit(可选,默认值:50)、daysBack(可选,默认值:30)
compose_message打开 Messages 应用并预填信息,或自动发送recipient(必填)、body(可选)、auto(可选,默认值:false)
示例
// List available chats
Show me my recent message conversations

// Get recent messages
Show me my last 20 messages

// Search messages
Find messages containing "dinner plans" from John in the last week

// Compose a message
Send a message to 555-123-4567 saying "I'll be there in 10 minutes"
备忘录
命令描述参数
create创建支持类似 Markdown 格式的备忘录title、content、format(可选,包含格式选项)
createRawHtml直接使用 HTML 内容创建备忘录title、html
list列出备忘录,也可指定文件夹folder(可选)
get根据标题获取特定备忘录title、folder(可选)
search搜索包含特定文本的备忘录query、folder(可选)、limit(可选,默认值:5)、includeBody(可选,默认值:true)
示例
// Create a new note with markdown formatting
Create a note titled "Meeting Minutes" with content "# Discussion Points\n- Project timeline\n- Budget review\n- Next steps" and format headings and lists

// Create a note with HTML
Create a note titled "Formatted Report" with HTML content "<h1>Quarterly Report</h1><p>Sales increased by <strong>15%</strong></p>"

// List notes
Show me all my notes in the "Work" folder

// Get a specific note
Show me my note titled "Shopping List"

// Search notes
Find notes containing "recipe" in my "Cooking" folder
Pages
命令描述参数
create_document使用纯文本创建新的 Pages 文稿content
示例
// Create a new Pages document
Create a Pages document with the content "Project Proposal\n\nThis document outlines the scope and timeline for the upcoming project."

架构

applescript-mcp 服务使用 TypeScript 构建,并采用模块化架构:

核心组件
  1. AppleScriptFramework(framework.ts):主要服务类,负责:

    • 管理 MCP 协议通信
    • 处理工具注册与执行
    • 提供日志记录功能
    • 执行 AppleScript 命令
  2. 分类(src/categories/*.ts):按功能组织的模块化脚本集合:

    • 每个分类包含相关脚本(例如日历、系统、备忘录)
    • 在 index.ts 中将分类注册到框架
  3. 类型(src/types/index.ts):定义以下内容的 TypeScript 接口:

    • ScriptDefinition:单个脚本的结构
    • ScriptCategory:相关脚本的集合
    • LogLevel:标准日志级别
    • FrameworkOptions:配置选项
执行流程
  1. 客户端通过 MCP 协议发送工具请求
  2. 服务识别相应的分类和脚本
  3. 生成脚本内容(静态生成或通过函数动态生成)
  4. 通过 macOS osascript 命令执行 AppleScript
  5. 将结果返回给客户端
日志系统

该框架包含一套完整的日志系统,可以:

  • 同时记录到 stderr 和 MCP 日志协议
  • 支持多个严重级别(调试、信息、警告、错误等)
  • 提供详细的执行信息以便排查问题

开发

设置
# Install dependencies
npm install

# Build the server
npm run build

# Launch MCP Inspector
# See: https://modelcontextprotocol.io/docs/tools/inspector
npx @modelcontextprotocol/inspector node path/to/server/index.js args...
添加新功能
1. 创建分类文件

创建 src/categories/newcategory.ts:

import { ScriptCategory } from "../types/index.js";

export const newCategory: ScriptCategory = {
  name: "category_name",
  description: "Category description",
  scripts: [
    // Scripts will go here
  ],
};
2. 添加脚本
{
  name: "script_name",
  description: "What the script does",
  schema: {
    type: "object",
    properties: {
      paramName: {
        type: "string",
        description: "Parameter description"
      }
    },
    required: ["paramName"]
  },
  script: (args) => `
    tell application "App"
      // AppleScript code using ${args.paramName}
    end tell
  `
}
3. 注册分类

更新 src/index.ts:

import { newCategory } from "./categories/newcategory.js";
// ...
server.addCategory(newCategory);
高级脚本开发

对于更复杂的脚本,你可以:

  1. 使用动态脚本生成:

    script: (args) => {
      // Process arguments and build script dynamically
      let scriptContent = `tell application "App"\n`;
      
      if (args.condition) {
        scriptContent += `  // Conditional logic\n`;
      }
      
      scriptContent += `end tell`;
      return scriptContent;
    }
    
  2. 处理复杂数据:

    // Example from Notes category
    function generateNoteHtml(args: any): string {
      // Process markdown-like syntax into HTML
      let processedContent = content;
      
      if (format.headings) {
        processedContent = processedContent.replace(/^# (.+)$/gm, '<h1>$1</h1>');
        // ...
      }
      
      return processedContent;
    }
    

调试

使用 MCP Inspector

MCP Inspector 提供了一个 Web 界面,可用于测试和调试你的服务:

npm run inspector
日志记录

设置环境变量以启用调试日志:

DEBUG=applescript-mcp* npm start
示例配置

运行 npm run build 后,将以下内容添加到 mcp.json 文件中:

{
  "mcpServers": {
    "applescript-mcp-server": {
      "command": "node",
      "args": ["/path/to/applescript-mcp/dist/index.js"]
    }
  }
}
常见问题
  • 权限错误:检查“系统偏好设置”>“安全性与隐私”>“隐私”>“自动化”
  • 脚本失败:集成前,先在 Script Editor.app 中直接测试脚本
  • 通信问题:检查是否有标准输入输出流被重定向
  • 数据库访问:某些功能(例如 Messages)需要“完全磁盘访问”权限

资源

贡献

  1. Fork 此仓库
  2. 创建功能分支
  3. 提交你的更改
  4. 推送到该分支
  5. 创建 Pull Request

许可证

MIT 许可证——详情请参阅 LICENSE

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。