Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
eb65dc5
tools: 增加一个压力测试的脚本,旨在测试脚本执行maamcp的运行速度,为后面进行优化做准备。
KhazixW2 Dec 17, 2025
c0f041f
fix: 修复脚本引用错误的情况
KhazixW2 Dec 17, 2025
8d66dab
test: 增加测试的多线程main函数,但是好像还有问题,先暂时提交
KhazixW2 Dec 17, 2025
ae74b37
feat: 多线程流水线运行模式,旨在后台多开一个线程处理截图操作,然后主线程就不用ai来调度截图了,减少了部分流程的速度。
KhazixW2 Dec 18, 2025
6fcfa4d
merge: 合并解决冲突
KhazixW2 Dec 19, 2025
5023734
fix: 修掉一个merge过程中未保存导致的错误
KhazixW2 Dec 19, 2025
b6fc45e
chore:统一注册器格式
KhazixW2 Dec 19, 2025
fc11984
doc: 增加流水线运行流程的文档说明
KhazixW2 Dec 19, 2025
6261682
refactor: 优化整个结构,去掉logger输出到控制台。去掉config类的键映射实际上用不到,其余全局参数直接合并到 pipel…
KhazixW2 Dec 20, 2025
eab8a08
docs: readme文档增加大模型提示词和性能建议(使用flash类的快速响应模型
KhazixW2 Dec 23, 2025
2629b16
Update README_EN.md
KhazixW2 Dec 23, 2025
6d734b3
Update README_EN.md
KhazixW2 Dec 23, 2025
9491366
Merge branch 'MAA-AI:main' into main
KhazixW2 Mar 22, 2026
f9d90b8
refactor: 流水线模式从截图模式重构为OCR模式
KhazixW2 Mar 22, 2026
6e2af56
perf: swipe描述更新,在默认情况下使用slow_duration来滑动,避免一次滑动过远导致滑动非预期行为。
KhazixW2 Mar 22, 2026
fedac41
Merge branch 'main' of github.com:KhazixW2/MaaMCP
KhazixW2 Mar 22, 2026
c6e9b38
fix: 修复测试ci可能出现问题
KhazixW2 Mar 23, 2026
639e4c6
Update README_EN.md
KhazixW2 Mar 23, 2026
773c249
fix: 修复 PR #28 审查反馈问题
KhazixW2 Mar 23, 2026
37791b1
Merge branch 'main' of github.com:KhazixW2/MaaMCP
KhazixW2 Mar 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
{
"mcpServers": {
"MaaMCP": {
"command": "python",
"args": [
"-m",
"maa_mcp"
],
"cwd": "${workspaceFolder}"
}
"permissions": {
"allow": [
"Bash(python -c \"import maa_mcp.pipeline_server\")",
"mcp__maa-*",
"mcp__maa-mcp__ocr",
"mcp__maa-mcp__click",
"mcp__maa-mcp__wait",
"mcp__maa-mcp__click_key",
"mcp__maa-mcp__connect_adb_device",
"mcp__maa-mcp__swipe",
"mcp__maa-mcp__find_adb_device_list",
"mcp__maa-mcp__test_sweep"
],
"defaultMode": "bypassPermissions"
},
"enableAllProjectMcpServers": true,
"enabledMcpjsonServers": [
"maa-mcp"
],
"mcpServers": {
"MaaMCP": {
"command": "python",
"args": [
"-m",
"maa_mcp"
],
"cwd": "${workspaceFolder}"
}
}
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,7 @@ install
tools/ImageCropper/**/*.png

config
debug
debug
output
.claude/skills
comment.txt
11 changes: 11 additions & 0 deletions .mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"mcpServers": {
"maa-mcp": {
"command": "python",
"args": [
"-m",
"maa_mcp.pipeline_server"
]
}
}
}
88 changes: 88 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

MaaMCP is an MCP (Model Context Protocol) server that exposes MaaFramework's automation capabilities to AI assistants. It provides Android device control via ADB and Windows desktop automation via window handles.

## Development Commands

```bash
# Install dependencies in development mode
pip install -e .

# Run MCP server (standard serial mode)
maa-mcp
# or
python -m maa_mcp

# Run MCP server (pipeline mode with background screenshot thread)
maa-mcp-server
# or
python -m maa_mcp.pipeline_server

# Run tests
pytest tests/ -v
pytest tests/test_basic.py -v # run specific file
```

## Architecture

### Entry Points

The package has multiple entry points defined in `pyproject.toml`:
- `maa-mcp` / `maa_mcp`: Standard MCP server ([__main__.py](maa_mcp/__main__.py))
- `maa-mcp-server` / `maa_mcp_server`: Pipeline server with multi-threaded background monitoring ([pipeline_server.py](maa_mcp/pipeline_server.py))

### Core Components

- **[core.py](maa_mcp/core.py)**: Creates the FastMCP server instance, global registries (`object_registry`, `controller_info_registry`), and `ControllerInfo` dataclass
- **[registry.py](maa_mcp/registry.py)**: `ObjectRegistry` class for managing controller instances by ID
- **[paths.py](maa_mcp/paths.py)**: Cross-platform data directory management using `platformdirs`

### Module Responsibilities

| Module | Purpose |
|--------|---------|
| `adb.py` | ADB device discovery (`find_adb_device_list`) and connection (`connect_adb_device`) |
| `win32.py` | Windows window discovery (`find_window_list`) and connection (`connect_window`) |
| `vision.py` | Screen capture (`screencap`) and OCR recognition (`ocr`) |
| `control.py` | Input operations: `click`, `double_click`, `swipe`, `input_text`, `click_key`, `keyboard_shortcut`, `scroll` |
| `resource.py` | OCR resource download and tasker management |
| `download.py` | OCR model file download utilities |
| `pipeline/` | Pipeline mode state management and logging |

### Two Operation Modes

1. **Serial Mode**: Synchronous execution where each operation waits for the previous to complete
2. **Pipeline Mode**: Multi-threaded mode where a background thread continuously captures screenshots and caches them in a queue for the main thread to process decisions

### Controller Pattern

All device/window control flows through:
1. Discovery functions return device/window identifiers
2. Connection functions create `AdbController` or `Win32Controller` instances (from `maafw`) and register them in `object_registry`
3. Operations use `controller_id` to look up the controller in `object_registry`
4. `controller_info_registry` stores metadata (controller type, connection params) for each `controller_id`

### Key Dependencies

- `maafw>=5.2.6`: Core automation framework (MaaFramework)
- `fastmcp>=2.0.0`: MCP server framework
- `opencv-python>=4.0.0`: Image processing for screenshots
- `loguru>=0.7.0`: Logging
- `platformdirs>=4.0.0`: Cross-platform paths

## Data Storage

OCR models and screenshots are stored in platform-specific directories:
- Windows: `C:\Users\<user>\AppData\Local\MaaMCP\`
- macOS: `~/Library/Application Support/MaaMCP/`
- Linux: `~/.local/share/MaaMCP/`

## Localization

- [CLAUDE_CN.md](CLAUDE_CN.md): Chinese version of this document

__Rule__: When updating this file, always sync changes to [CLAUDE_CN.md](CLAUDE_CN.md)
82 changes: 82 additions & 0 deletions CLAUDE_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# CLAUDE_CN.md

本文件为 Claude Code (claude.ai/code) 在本仓库中工作时提供指导。

## 项目概述

MaaMCP 是一个 MCP(Model Context Protocol)服务器,将 MaaFramework 的自动化能力暴露给 AI 助手。它通过 ADB 提供 Android 设备控制,通过窗口句柄提供 Windows 桌面自动化。

## 开发命令

```bash
# 以开发模式安装依赖
pip install -e .

# 运行 MCP 服务器(标准串行模式)
maa-mcp
# 或
python -m maa_mcp

# 运行 MCP 服务器(流水线模式,带后台截图线程)
maa-mcp-server
# 或
python -m maa_mcp.pipeline_server

# 运行测试
pytest tests/ -v
pytest tests/test_basic.py -v # 运行特定文件
```

## 架构

### 入口点

包在 `pyproject.toml` 中定义了多个入口点:
- `maa-mcp` / `maa_mcp`:标准 MCP 服务器([__main__.py](maa_mcp/__main__.py))
- `maa-mcp-server` / `maa_mcp_server`:带多线程后台监控的流水线服务器([pipeline_server.py](maa_mcp/pipeline_server.py))

### 核心组件

- **[core.py](maa_mcp/core.py)**:创建 FastMCP 服务器实例、全局注册表(`object_registry`、`controller_info_registry`)和 `ControllerInfo` 数据类
- **[registry.py](maa_mcp/registry.py)**:`ObjectRegistry` 类,用于通过 ID 管理控制器实例
- **[paths.py](maa_mcp/paths.py)**:使用 `platformdirs` 的跨平台数据目录管理

### 模块职责

| 模块 | 用途 |
|------|------|
| `adb.py` | ADB 设备发现(`find_adb_device_list`)和连接(`connect_adb_device`) |
| `win32.py` | Windows 窗口发现(`find_window_list`)和连接(`connect_window`) |
| `vision.py` | 屏幕截图(`screencap`)和 OCR 识别(`ocr`) |
| `control.py` | 输入操作:`click`、`double_click`、`swipe`、`input_text`、`click_key`、`keyboard_shortcut`、`scroll` |
| `resource.py` | OCR 资源下载和任务管理 |
| `download.py` | OCR 模型文件下载工具 |
| `pipeline/` | 流水线模式状态管理和日志 |

### 两种操作模式

1. **串行模式**:同步执行,每个操作等待前一个完成
2. **流水线模式**:多线程模式,后台线程持续截图并缓存在队列中,供主线程处理决策

### 控制器模式

所有设备/窗口控制都通过以下流程:
1. 发现函数返回设备/窗口标识符
2. 连接函数创建 `AdbController` 或 `Win32Controller` 实例(来自 `maafw`)并注册到 `object_registry`
3. 操作使用 `controller_id` 在 `object_registry` 中查找控制器
4. `controller_info_registry` 存储每个 `controller_id` 的元数据(控制器类型、连接参数)

### 关键依赖

- `maafw>=5.2.6`:核心自动化框架(MaaFramework)
- `fastmcp>=2.0.0`:MCP 服务器框架
- `opencv-python>=4.0.0`:截图图像处理
- `loguru>=0.7.0`:日志
- `platformdirs>=4.0.0`:跨平台路径

## 数据存储

OCR 模型和截图存储在平台特定的目录中:
- Windows:`C:\Users\<user>\AppData\Local\MaaMCP\`
- macOS:`~/Library/Application Support/MaaMCP/`
- Linux:`~/.local/share/MaaMCP/`
Loading
Loading