mcp macos窗口管理器
macOS窗口管理器MCP服务器
一种模型上下文协议(MCP)服务器,通过AppleScript自动化为macOS提供全面的窗口管理功能。允许AI助手在多个显示器上控制、移动和组织应用程序窗口。
特性
窗口管理
- 列出所有窗口 -从所有正在运行的应用程序中获取所有可见窗口
- 获取应用程序窗口 -检索特定应用程序的所有窗口
- 移动和调整窗口大小 -根据坐标精确定位窗口
- 多窗口支持 -为具有多个窗口的应用程序按索引定位特定窗口
多显示器支持
- 列出所有显示器 -枚举所有连接的物理监视器及其边界
- 屏幕检测 -使用自动检测
system_profiler具有回退支持 - 虚拟桌面映射 -多显示器设置的正确坐标系处理
便利功能
- 移动到屏幕预设 -使用预设快速定位:
- center -屏幕中央窗口(50%宽/高) - maximize -填充整个屏幕 - left-half, right-half -屏幕左/右50% - top-half, bottom-half -屏幕顶部/底部50% - custom -用户指定的位置和大小
MCP工具
move_resize_app-移动应用程序最前面的窗口并调整其大小get_app_window_geometry-获取应用程序最前面窗口的位置和大小get_main_screen_bounds-获取主要桌面/屏幕尺寸list_all_windows-列出所有正在运行的应用程序的所有可见窗口get_app_all_windows-获取特定应用程序的所有窗口move_resize_app_window-按索引移动和调整特定窗口的大小list_all_screens-列出所有连接的物理显示器/监视器move_app_to_screen-将应用程序移动到具有定位预设的特定屏幕
先决条件
- macOS(在macOS Sonoma及更高版本上测试)
- 转到1.23+(从源代码构建)
- macOS辅助功能权限(窗口控制所需)
安装
选项1:从源代码构建
# Clone or download this repository
cd wm-mcp
# Initialize Go module and download dependencies
go mod init github.com/yourusername/wm-mcp
go mod tidy
# Build the executable
go build -o wm-mcp main.go
# The executable is now ready at ./wm-mcp选项2:使用预构建二进制文件
如果您有预构建的二进制文件,请确保它具有执行权限:
chmod +x wm-mcpmacOS权限
此MCP服务器需要macOS辅助功能权限来控制其他应用程序:
- 首选 系统偏好设置 → 安全与隐私 → 隐私 → 无障碍
- 单击锁图标进行更改
- 添加您正在使用的终端应用程序(例如terminal.app、iTerm.app)或AI客户端应用程序
- 确保复选框已启用
用法
独立运行
# Run directly
./wm-mcp
# Or with Go
go run main.go服务器使用模型上下文协议通过stdio进行通信。
与AI工具集成
支持的AI工具:
- 克劳德桌面(拟人)
- 克劳德代码/法典(VS代码、游标等)
- 光标
- 帆板运动
- 码极
- GitHub Copilot命令行界面
- 双子座(通过谷歌人工智能工作室)
- 任何兼容MCP的客户端
______________________________________________________________________
获取绝对路径: 在配置之前,获取可执行文件的完整路径:
# Navigate to your wm-mcp directory
cd /path/to/wm-mcp
# Get absolute path
pwd
# Output example: /Users/yourusername/code/wm-mcp
# Your full command path will be: /Users/yourusername/code/wm-mcp/wm-mcp快速安装(推荐)
一些工具支持通过命令行添加MCP服务器:
Claude Desktop(支持CLI)
如果您的Claude Desktop版本支持CLI:
# Add the server
claude mcp add apple-window-manager /absolute/path/to/wm-mcp
# Or using the config command
claude mcp install /absolute/path/to/wm-mcp --name apple-window-manager光标/风帆
# From your project directory
cursor mcp add /absolute/path/to/wm-mcp
# Or globally
cursor mcp add --global /absolute/path/to/wm-mcp码极
codeium mcp add apple-window-manager /absolute/path/to/wm-mcp______________________________________________________________________
手动配置
如果您的工具不支持快速命令,请手动编辑配置文件:
克劳德桌面版
配置文件: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"apple-window-manager": {
"command": "/absolute/path/to/wm-mcp",
"args": []
}
}
}设置步骤:
- 替换
/absolute/path/to/wm-mcp具有完整路径(例如。,/Users/yourusername/code/wm-mcp/wm-mcp) - 重新启动克劳德桌面
- 在提示时授予辅助功能权限
- 窗口管理工具现在应该可用
克劳德法典
配置文件: .claude/mcp.json 在工作区或全局设置中
对于VS Code、Cursor或其他使用Claude Code的编辑器:
{
"mcpServers": {
"apple-window-manager": {
"command": "/absolute/path/to/wm-mcp",
"args": []
}
}
}全局配置位置:
- macOS:
~/.config/claude-code/mcp.json - VS代码:添加到工作区
.vscode/mcp.json
帆板运动
配置文件: ~/.windsurf/mcp_config.json
{
"mcpServers": {
"apple-window-manager": {
"command": "/absolute/path/to/wm-mcp",
"args": []
}
}
}光标(手动)
配置文件: ~/.cursor/mcp.json
{
"mcpServers": {
"apple-window-manager": {
"command": "/absolute/path/to/wm-mcp",
"args": []
}
}
}码极
配置文件: ~/.codeium/mcp.json
{
"mcpServers": {
"apple-window-manager": {
"command": "/absolute/path/to/wm-mcp",
"args": []
}
}
}双子座(通过谷歌人工智能工作室)
如果通过Google AI Studio或兼容客户端使用支持MCP的Gemini:
{
"servers": {
"apple-window-manager": {
"type": "stdio",
"command": "/absolute/path/to/wm-mcp",
"args": []
}
}
}GitHub Copilot命令行界面
配置文件: ~/.config/github-copilot/mcp.json
{
"mcpServers": {
"apple-window-manager": {
"command": "/absolute/path/to/wm-mcp",
"args": []
}
}
}或者通过环境变量:
export GITHUB_COPILOT_MCP_CONFIG='{"apple-window-manager":{"command":"/absolute/path/to/wm-mcp"}}'或者使用Copilot CLI(如果支持):
gh copilot mcp add apple-window-manager /absolute/path/to/wm-mcpAI使用示例
配置后,您可以询问您的AI助手:
"List all my open windows"
"Move Chrome to the left half of my screen"
"Show me all my connected displays"
"Move Safari to my second monitor and maximize it"
"Get all windows for Finder"
"Move the second Chrome window to position 100,100 with size 800x600"建筑
- 单文件Go应用程序 -所有代码
main.go - AppleScript集成 -窗口操作通过
osascript - 系统命令 -通过多显示器检测
system_profiler - MCP-SDK -用途
github.com/modelcontextprotocol/go-sdk/mcp - 标准运输 -通过标准输入/输出进行通信
坐标系
macOS使用坐标系,其中:
- (0, 0) 位于主显示器(带有菜单栏的显示器)的左上角
- 显示在左侧 具有负X坐标
- 上方显示 具有负Y坐标
- 所有显示器 形成一个连续的虚拟坐标空间
发展
# Run the server
go run main.go
# Build executable
go build -o wm-mcp main.go
# Test AppleScript functionality
osascript -e 'tell application "System Events" to get name of every application process whose visible is true'故障排除
“权限被拒绝”错误
- 为您的终端或AI客户端应用程序授予辅助功能权限
- 检查系统首选项→ 安全与隐私→ 隐私→ 无障碍
“应用程序未运行”错误
- 确保应用程序名称与进程名称完全匹配
- 使用
list_all_windows查看可用的应用程序名称
“未检测到显示器”
- 如果出现以下情况,服务器将回退到单显示模式
system_profiler失败 - 检查
system_profiler SPDisplaysDataType -json在您的终端中工作
MCP服务器未出现在AI客户端中
- 验证可执行文件的路径是绝对的,而不是相对的
- 检查AI客户端日志中的连接错误
- 配置更改后重新启动AI客户端
- 确保可执行文件具有适当的权限(
chmod +x)
版本
当前版本: 0.3.0
许可证
MIT许可证-可根据需要自由使用和修改。
贡献
欢迎投稿!这是一个个人项目,但有待改进。
