minitap-mcp 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- minitap/mcp/core/agents/compare_screenshots.md +62 -0
- minitap/mcp/core/agents/compare_screenshots.py +65 -0
- minitap/mcp/core/agents/extract_figma_assets.md +64 -0
- minitap/mcp/core/agents/extract_figma_assets.py +65 -0
- minitap/mcp/core/config.py +3 -0
- minitap/mcp/core/models.py +59 -0
- minitap/mcp/main.py +30 -20
- minitap/mcp/server/poller.py +49 -9
- minitap/mcp/tools/compare_screenshot_with_figma.py +132 -0
- minitap/mcp/tools/execute_mobile_command.py +1 -1
- minitap/mcp/tools/save_figma_assets.py +258 -0
- {minitap_mcp-0.3.0.dist-info → minitap_mcp-0.4.0.dist-info}/METADATA +28 -18
- minitap_mcp-0.4.0.dist-info/RECORD +25 -0
- {minitap_mcp-0.3.0.dist-info → minitap_mcp-0.4.0.dist-info}/WHEEL +1 -1
- minitap_mcp-0.3.0.dist-info/RECORD +0 -18
- /minitap/mcp/core/{agents.py → sdk_agent.py} +0 -0
- {minitap_mcp-0.3.0.dist-info → minitap_mcp-0.4.0.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
You will be given _two screenshots_.
|
|
2
|
+
|
|
3
|
+
1. "Expected screenshot" — this is the design from Figma.
|
|
4
|
+
2. "Implemented screenshot" — this is the actual phone screen that has been built.
|
|
5
|
+
|
|
6
|
+
Your task is to **compare the two screenshots** in detail, and generate a structured report that includes:
|
|
7
|
+
|
|
8
|
+
- A comprehensive list of **all visible differences** between the expected design and the implemented screen.
|
|
9
|
+
- For each difference, provide:
|
|
10
|
+
- A clear **description** of what changed (for example: "The 'Submit' button label changed from 'Submit' to 'Send'", "The icon moved 8px to the right", "The background colour of header changed from #FFFFFF to #F6F6F6", etc.).
|
|
11
|
+
- The **type of change** (e.g., text change, color change, position/movement, size change, added element, removed element, style change).
|
|
12
|
+
- The **location** of the change (for example: "bottom-centre of screen", "top header area", "to the right of search bar"). If possible, approximate coordinates or bounding box (e.g., "approx. 240×180 px at screen width 1080").
|
|
13
|
+
- The **impact on implementation** (i.e., reasoning about what this means: "The implemented version uses a different text label – so behaviour may differ", "The icon moved and may overlap another element", etc.).
|
|
14
|
+
- A **recommendation** if relevant (e.g., "Should revert to #FFFFFF to match design", "Check alignment of icon relative to search bar", etc.).
|
|
15
|
+
|
|
16
|
+
**Important**:
|
|
17
|
+
|
|
18
|
+
- Assume the screenshots are aligned (same resolution and scale); if not aligned mention that as a difference.
|
|
19
|
+
- Focus on _visible UI differences_ (layout, text, style, iconography) – you do _not_ need to inspect source code, only what is visually rendered.
|
|
20
|
+
- Do _not_ produce generic comments like "looks like a difference" – aim for _precise, actionable descriptions_.
|
|
21
|
+
- **IGNORE dynamic/personal content** that naturally differs between mockups and real implementations:
|
|
22
|
+
- User profile information (names, usernames, email addresses, profile pictures)
|
|
23
|
+
- Time-based information (current time, dates, timestamps, "2 hours ago", etc.)
|
|
24
|
+
- Dynamic data (notification counts, unread badges, live statistics)
|
|
25
|
+
- Sample/placeholder content that varies (e.g., "John Doe" vs "Jane Smith")
|
|
26
|
+
- System status information (battery level, signal strength, network indicators)
|
|
27
|
+
- Only flag these as differences if the _structure, layout, or styling_ of these elements differs, not the content itself.
|
|
28
|
+
- Output in a structured format, for example:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
1. Location: [top header – full width]
|
|
33
|
+
Change: Background colour changed from #FFFFFF → #F6F6F6
|
|
34
|
+
Type: Colour change
|
|
35
|
+
Impact: The header will appear darker than design; text contrast may be lower.
|
|
36
|
+
Recommendation: Update header background to #FFFFFF as in design.
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- At the end produce a summary with ONLY:
|
|
41
|
+
- Total number of differences found
|
|
42
|
+
- Overall "match score" out of 100 (your estimation of how closely the implementation matches the design)
|
|
43
|
+
- Do NOT include any recap, overview, or macro-level summary of changes - all details are already captured in the differences list above.
|
|
44
|
+
|
|
45
|
+
### Input:
|
|
46
|
+
|
|
47
|
+
- Screenshot A: Expected (Figma)
|
|
48
|
+
- Screenshot B: Implemented (Phone)
|
|
49
|
+
Provide both screenshots and then the prompt.
|
|
50
|
+
|
|
51
|
+
### Output:
|
|
52
|
+
|
|
53
|
+
Structured list of differences + summary.
|
|
54
|
+
|
|
55
|
+
Please use the following to start the analysis.
|
|
56
|
+
**Input:**
|
|
57
|
+
First screen is the Figma screenshot (what is expected)
|
|
58
|
+
Second screen is what is expected (taken from the phone, after the implementation)
|
|
59
|
+
|
|
60
|
+
You will have this data in the next messages sent by the user.
|
|
61
|
+
|
|
62
|
+
Go ahead and generate your report.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from uuid import uuid4
|
|
4
|
+
|
|
5
|
+
from jinja2 import Template
|
|
6
|
+
from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage
|
|
7
|
+
from pydantic import BaseModel
|
|
8
|
+
|
|
9
|
+
from minitap.mcp.core.device import capture_screenshot, find_mobile_device
|
|
10
|
+
from minitap.mcp.core.llm import get_minitap_llm
|
|
11
|
+
from minitap.mcp.core.utils import get_screenshot_message_for_llm
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CompareScreenshotsOutput(BaseModel):
|
|
15
|
+
comparison_text: str
|
|
16
|
+
expected_screenshot_base64: str
|
|
17
|
+
current_screenshot_base64: str
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
async def compare_screenshots(
|
|
21
|
+
expected_screenshot_base64: str,
|
|
22
|
+
) -> CompareScreenshotsOutput:
|
|
23
|
+
"""
|
|
24
|
+
Compare screenshots and return the comparison text along with both screenshots.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
CompareScreenshotsOutput
|
|
28
|
+
"""
|
|
29
|
+
system_message = Template(
|
|
30
|
+
Path(__file__).parent.joinpath("compare_screenshots.md").read_text(encoding="utf-8")
|
|
31
|
+
).render()
|
|
32
|
+
|
|
33
|
+
device = find_mobile_device()
|
|
34
|
+
current_screenshot = capture_screenshot(device)
|
|
35
|
+
|
|
36
|
+
messages: list[BaseMessage] = [
|
|
37
|
+
SystemMessage(content=system_message),
|
|
38
|
+
HumanMessage(content="Here is the Figma screenshot (what needs to be matched):"),
|
|
39
|
+
get_screenshot_message_for_llm(expected_screenshot_base64),
|
|
40
|
+
HumanMessage(content="Here is the screenshot of the mobile device:"),
|
|
41
|
+
get_screenshot_message_for_llm(current_screenshot),
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
llm = get_minitap_llm(
|
|
45
|
+
trace_id=str(uuid4()),
|
|
46
|
+
remote_tracing=True,
|
|
47
|
+
model="google/gemini-2.5-pro",
|
|
48
|
+
temperature=1,
|
|
49
|
+
)
|
|
50
|
+
response = await llm.ainvoke(messages)
|
|
51
|
+
return CompareScreenshotsOutput(
|
|
52
|
+
comparison_text=str(response.content),
|
|
53
|
+
expected_screenshot_base64=expected_screenshot_base64,
|
|
54
|
+
current_screenshot_base64=current_screenshot,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def main():
|
|
59
|
+
expected_screenshot_base64 = "Base64 encoded screenshot to compare with."
|
|
60
|
+
result = await compare_screenshots(expected_screenshot_base64)
|
|
61
|
+
print(result.model_dump_json(indent=2))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
You are an expert at parsing React/TypeScript code to extract asset URLs and generate clean, documented code implementations.
|
|
2
|
+
|
|
3
|
+
Your task is to:
|
|
4
|
+
|
|
5
|
+
1. Extract all asset URLs from the provided code snippet
|
|
6
|
+
2. Generate a clean `code_implementation` output that includes the React code with embedded comments referencing implementation and node guidelines
|
|
7
|
+
|
|
8
|
+
**Instructions:**
|
|
9
|
+
|
|
10
|
+
## Part 1: Extract Asset URLs
|
|
11
|
+
|
|
12
|
+
1. Look for all constant declarations that contain URLs pointing to assets (images, SVGs, etc.)
|
|
13
|
+
2. These constants typically follow patterns like:
|
|
14
|
+
|
|
15
|
+
- `const imgVariableName = "http://localhost:3845/assets/[hash].[extension]";`
|
|
16
|
+
- The variable names usually start with `img` followed by a descriptive name in camelCase
|
|
17
|
+
|
|
18
|
+
3. For each asset URL found, extract:
|
|
19
|
+
- The **variable name** (e.g., `imgSignal`, `imgBatteryThreeQuarters`)
|
|
20
|
+
- The **full URL** (e.g., `http://localhost:3845/assets/685c5ac58caa29556e29737cf8f8c9605d9c8571.svg`)
|
|
21
|
+
- The **file extension** from the URL (e.g., `svg`, `png`, `jpg`)
|
|
22
|
+
|
|
23
|
+
## Part 2: Generate Code Implementation
|
|
24
|
+
|
|
25
|
+
The `code_implementation` field should contain:
|
|
26
|
+
|
|
27
|
+
1. The React/TypeScript code with **LOCAL asset imports** instead of HTTP URLs:
|
|
28
|
+
|
|
29
|
+
- Convert `const imgSignal = "http://localhost:3845/assets/[hash].svg";`
|
|
30
|
+
- To `import imgSignal from './assets/imgSignal.svg';` (or appropriate relative path)
|
|
31
|
+
- Use the **exact same variable names** as in the original const declarations
|
|
32
|
+
- **CRITICAL**: Preserve the variable naming convention
|
|
33
|
+
|
|
34
|
+
2. Preserve all `data-node-id` attributes and other metadata in the code
|
|
35
|
+
|
|
36
|
+
## Part 3: Return Format
|
|
37
|
+
|
|
38
|
+
Return a JSON object with two fields:
|
|
39
|
+
|
|
40
|
+
- `assets`: Array of extracted asset objects
|
|
41
|
+
- `code_implementation`: String containing the React code with embedded guideline comments
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"assets": [
|
|
46
|
+
{
|
|
47
|
+
"variable_name": "imgSignal",
|
|
48
|
+
"url": "http://localhost:3845/assets/685c5ac58caa29556e29737cf8f8c9605d9c8571.svg",
|
|
49
|
+
"extension": "svg"
|
|
50
|
+
},
|
|
51
|
+
...
|
|
52
|
+
],
|
|
53
|
+
"code_implementation": "import ... function ..."
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Important:**
|
|
58
|
+
|
|
59
|
+
- Only extract asset URLs
|
|
60
|
+
- Preserve the exact variable names as they appear in the code
|
|
61
|
+
- DO NOT MISS any assets
|
|
62
|
+
- If no assets are found, return an empty array for `assets`
|
|
63
|
+
- Return ONLY the JSON object with both `assets` and `code_implementation` fields
|
|
64
|
+
- Do NOT include the const declarations of the assets in the code_implementation output - convert them to imports.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Agent to extract Figma asset URLs from design context code."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from uuid import uuid4
|
|
5
|
+
|
|
6
|
+
from jinja2 import Template
|
|
7
|
+
from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage
|
|
8
|
+
from pydantic import BaseModel, Field
|
|
9
|
+
|
|
10
|
+
from minitap.mcp.core.llm import get_minitap_llm
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FigmaAsset(BaseModel):
|
|
14
|
+
"""Represents a single Figma asset."""
|
|
15
|
+
|
|
16
|
+
variable_name: str = Field(description="The variable name from the code (e.g., imgSignal)")
|
|
17
|
+
url: str = Field(description="The full URL to the asset")
|
|
18
|
+
extension: str = Field(description="The file extension (e.g., svg, png, jpg)")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ExtractedAssets(BaseModel):
|
|
22
|
+
"""Container for all extracted Figma assets."""
|
|
23
|
+
|
|
24
|
+
assets: list[FigmaAsset] = Field(
|
|
25
|
+
default_factory=list,
|
|
26
|
+
description="List of all extracted assets from the Figma design context",
|
|
27
|
+
)
|
|
28
|
+
code_implementation: str = Field(
|
|
29
|
+
description=(
|
|
30
|
+
"The React/TypeScript code\n"
|
|
31
|
+
"with the local url declarations turned into const declarations"
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
async def extract_figma_assets(design_context_code: str) -> ExtractedAssets:
|
|
37
|
+
"""Extract asset URLs from Figma design context code.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
design_context_code: The React/TypeScript code from get_design_context
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
List of dictionaries containing variable_name, url, and extension
|
|
44
|
+
"""
|
|
45
|
+
system_message = Template(
|
|
46
|
+
Path(__file__).parent.joinpath("extract_figma_assets.md").read_text(encoding="utf-8")
|
|
47
|
+
).render()
|
|
48
|
+
|
|
49
|
+
messages: list[BaseMessage] = [
|
|
50
|
+
SystemMessage(content=system_message),
|
|
51
|
+
HumanMessage(
|
|
52
|
+
content=f"Here is the code to analyze:\n\n```typescript\n{design_context_code}\n```"
|
|
53
|
+
),
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
llm = get_minitap_llm(
|
|
57
|
+
trace_id=str(uuid4()),
|
|
58
|
+
remote_tracing=True,
|
|
59
|
+
model="google/gemini-2.5-pro",
|
|
60
|
+
temperature=0,
|
|
61
|
+
).with_structured_output(ExtractedAssets)
|
|
62
|
+
|
|
63
|
+
result: ExtractedAssets = await llm.ainvoke(messages) # type: ignore
|
|
64
|
+
|
|
65
|
+
return result
|
minitap/mcp/core/config.py
CHANGED
|
@@ -19,6 +19,9 @@ class MCPSettings(BaseSettings):
|
|
|
19
19
|
|
|
20
20
|
VISION_MODEL: str = Field(default="qwen/qwen-2.5-vl-7b-instruct")
|
|
21
21
|
|
|
22
|
+
# Figma MCP server configuration
|
|
23
|
+
FIGMA_MCP_SERVER_URL: str = Field(default="http://127.0.0.1:3845/mcp")
|
|
24
|
+
|
|
22
25
|
# MCP server configuration (optional, for remote access)
|
|
23
26
|
MCP_SERVER_HOST: str = Field(default="0.0.0.0")
|
|
24
27
|
MCP_SERVER_PORT: int = Field(default=8000)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Core models for the MCP server."""
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FigmaAsset(BaseModel):
|
|
9
|
+
"""Represents a single Figma asset."""
|
|
10
|
+
|
|
11
|
+
variable_name: str = Field(description="The variable name from the code (e.g., imgSignal)")
|
|
12
|
+
url: str = Field(description="The full URL to the asset")
|
|
13
|
+
extension: str = Field(description="The file extension (e.g., svg, png, jpg)")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class FigmaDesignContextOutput(BaseModel):
|
|
17
|
+
"""Output from Figma design context containing code and guidelines."""
|
|
18
|
+
|
|
19
|
+
code_implementation: str = Field(description="The React/TypeScript code implementation")
|
|
20
|
+
code_implementation_guidelines: str | None = Field(
|
|
21
|
+
default=None, description="Guidelines for implementing the code"
|
|
22
|
+
)
|
|
23
|
+
nodes_guidelines: str | None = Field(
|
|
24
|
+
default=None, description="Guidelines specific to the nodes"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class DownloadStatus(str, Enum):
|
|
29
|
+
"""Status of asset download operation."""
|
|
30
|
+
|
|
31
|
+
SUCCESS = "success"
|
|
32
|
+
FAILED = "failed"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class AssetDownloadResult(BaseModel):
|
|
36
|
+
"""Result of downloading a single asset."""
|
|
37
|
+
|
|
38
|
+
filename: str = Field(description="The filename of the asset")
|
|
39
|
+
status: DownloadStatus = Field(description="The download status")
|
|
40
|
+
error: str | None = Field(default=None, description="Error message if download failed")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class AssetDownloadSummary(BaseModel):
|
|
44
|
+
"""Summary of all asset download operations."""
|
|
45
|
+
|
|
46
|
+
successful: list[AssetDownloadResult] = Field(
|
|
47
|
+
default_factory=list, description="List of successfully downloaded assets"
|
|
48
|
+
)
|
|
49
|
+
failed: list[AssetDownloadResult] = Field(
|
|
50
|
+
default_factory=list, description="List of failed asset downloads"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
def success_count(self) -> int:
|
|
54
|
+
"""Return the number of successful downloads."""
|
|
55
|
+
return len(self.successful)
|
|
56
|
+
|
|
57
|
+
def failure_count(self) -> int:
|
|
58
|
+
"""Return the number of failed downloads."""
|
|
59
|
+
return len(self.failed)
|
minitap/mcp/main.py
CHANGED
|
@@ -23,13 +23,11 @@ if sys.platform == "win32":
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
from fastmcp import FastMCP # noqa: E402
|
|
26
|
+
from minitap.mobile_use.config import settings as sdk_settings
|
|
26
27
|
|
|
27
28
|
from minitap.mcp.core.config import settings # noqa: E402
|
|
28
|
-
from minitap.
|
|
29
|
-
from minitap.mcp.core.device import
|
|
30
|
-
DeviceInfo, # noqa: E402
|
|
31
|
-
list_available_devices,
|
|
32
|
-
)
|
|
29
|
+
from minitap.mcp.core.device import DeviceInfo # noqa: E402
|
|
30
|
+
from minitap.mcp.core.device import list_available_devices
|
|
33
31
|
from minitap.mcp.server.middleware import MaestroCheckerMiddleware
|
|
34
32
|
from minitap.mcp.server.poller import device_health_poller
|
|
35
33
|
|
|
@@ -39,6 +37,7 @@ def main() -> None:
|
|
|
39
37
|
|
|
40
38
|
parser = argparse.ArgumentParser(description="Mobile Use MCP Server")
|
|
41
39
|
parser.add_argument("--api-key", type=str, required=False, default=None)
|
|
40
|
+
parser.add_argument("--llm-profile", type=str, required=False, default=None)
|
|
42
41
|
parser.add_argument(
|
|
43
42
|
"--server",
|
|
44
43
|
action="store_true",
|
|
@@ -46,14 +45,17 @@ def main() -> None:
|
|
|
46
45
|
)
|
|
47
46
|
|
|
48
47
|
args = parser.parse_args()
|
|
49
|
-
print("parsing args")
|
|
50
|
-
print(args)
|
|
51
48
|
|
|
52
49
|
if args.api_key:
|
|
53
50
|
os.environ["MINITAP_API_KEY"] = args.api_key
|
|
54
51
|
settings.__init__()
|
|
55
52
|
sdk_settings.__init__()
|
|
56
53
|
|
|
54
|
+
if args.llm_profile:
|
|
55
|
+
os.environ["MINITAP_LLM_PROFILE_NAME"] = args.llm_profile
|
|
56
|
+
settings.__init__()
|
|
57
|
+
sdk_settings.__init__()
|
|
58
|
+
|
|
57
59
|
if not settings.MINITAP_API_KEY:
|
|
58
60
|
raise ValueError("Minitap API key is required to run the MCP")
|
|
59
61
|
|
|
@@ -80,11 +82,10 @@ mcp = FastMCP(
|
|
|
80
82
|
Call get_available_devices() to list them.
|
|
81
83
|
""",
|
|
82
84
|
)
|
|
83
|
-
|
|
84
|
-
from minitap.mcp.tools import
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
85
|
+
from minitap.mcp.tools import analyze_screen # noqa: E402, F401
|
|
86
|
+
from minitap.mcp.tools import compare_screenshot_with_figma # noqa: E402, F401
|
|
87
|
+
from minitap.mcp.tools import execute_mobile_command # noqa: E402, F401
|
|
88
|
+
from minitap.mcp.tools import save_figma_assets # noqa: E402, F401
|
|
88
89
|
|
|
89
90
|
|
|
90
91
|
@mcp.resource("data://devices")
|
|
@@ -94,7 +95,7 @@ def get_available_devices() -> list[DeviceInfo]:
|
|
|
94
95
|
|
|
95
96
|
|
|
96
97
|
def mcp_lifespan(**mcp_run_kwargs):
|
|
97
|
-
from minitap.mcp.core.
|
|
98
|
+
from minitap.mcp.core.sdk_agent import get_mobile_use_agent # noqa: E402
|
|
98
99
|
|
|
99
100
|
agent = get_mobile_use_agent()
|
|
100
101
|
mcp.add_middleware(MaestroCheckerMiddleware(agent))
|
|
@@ -108,16 +109,25 @@ def mcp_lifespan(**mcp_run_kwargs):
|
|
|
108
109
|
stop_event,
|
|
109
110
|
agent,
|
|
110
111
|
),
|
|
112
|
+
daemon=True,
|
|
111
113
|
)
|
|
112
114
|
poller_thread.start()
|
|
113
115
|
|
|
114
116
|
try:
|
|
115
117
|
mcp.run(**mcp_run_kwargs)
|
|
116
118
|
except KeyboardInterrupt:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
logger.info("Keyboard interrupt received, shutting down...")
|
|
120
|
+
except Exception as e:
|
|
121
|
+
logger.error(f"Error running MCP server: {e}")
|
|
122
|
+
finally:
|
|
123
|
+
# Stop device health poller
|
|
124
|
+
logger.info("Stopping device health poller...")
|
|
125
|
+
stop_event.set()
|
|
126
|
+
|
|
127
|
+
# Give the poller thread a reasonable time to stop gracefully
|
|
128
|
+
poller_thread.join(timeout=10.0)
|
|
129
|
+
|
|
130
|
+
if poller_thread.is_alive():
|
|
131
|
+
logger.warning("Device health poller thread did not stop gracefully")
|
|
132
|
+
else:
|
|
133
|
+
logger.info("Device health poller stopped successfully")
|
minitap/mcp/server/poller.py
CHANGED
|
@@ -1,38 +1,78 @@
|
|
|
1
1
|
"""Device health monitoring poller for the MCP server."""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
3
4
|
import logging
|
|
4
|
-
import time
|
|
5
5
|
import threading
|
|
6
6
|
|
|
7
|
-
from minitap.mcp.core.device import list_available_devices
|
|
8
7
|
from minitap.mobile_use.sdk import Agent
|
|
9
8
|
|
|
9
|
+
from minitap.mcp.core.device import list_available_devices
|
|
10
|
+
|
|
10
11
|
logger = logging.getLogger(__name__)
|
|
11
12
|
|
|
12
13
|
|
|
13
|
-
def
|
|
14
|
+
async def _async_device_health_poller(stop_event: threading.Event, agent: Agent) -> None:
|
|
14
15
|
"""
|
|
15
|
-
|
|
16
|
-
Runs every 5 seconds to ensure a device is connected and the agent is healthy.
|
|
16
|
+
Async implementation of device health poller.
|
|
17
17
|
|
|
18
18
|
Args:
|
|
19
|
+
stop_event: Threading event to signal when to stop polling.
|
|
19
20
|
agent: The Agent instance to monitor and reinitialize if needed.
|
|
20
21
|
"""
|
|
21
22
|
while not stop_event.is_set():
|
|
22
23
|
try:
|
|
23
|
-
|
|
24
|
+
# Sleep in smaller chunks to be more responsive to stop signal
|
|
25
|
+
for _ in range(50): # 50 * 0.1 = 5 seconds total
|
|
26
|
+
if stop_event.is_set():
|
|
27
|
+
break
|
|
28
|
+
await asyncio.sleep(0.1)
|
|
29
|
+
|
|
30
|
+
if stop_event.is_set():
|
|
31
|
+
break
|
|
24
32
|
|
|
25
33
|
devices = list_available_devices()
|
|
26
34
|
|
|
27
35
|
if len(devices) > 0:
|
|
28
36
|
if not agent.is_healthy():
|
|
29
37
|
logger.warning("Agent is not healthy. Reinitializing...")
|
|
30
|
-
agent.clean(force=True)
|
|
31
|
-
agent.init()
|
|
38
|
+
await agent.clean(force=True)
|
|
39
|
+
await agent.init()
|
|
32
40
|
logger.info("Agent reinitialized successfully")
|
|
33
41
|
else:
|
|
34
42
|
logger.info("No mobile device found, retrying in 5 seconds...")
|
|
35
43
|
|
|
36
44
|
except Exception as e:
|
|
37
45
|
logger.error(f"Error in device health poller: {e}")
|
|
38
|
-
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
await agent.clean(force=True)
|
|
49
|
+
logger.info("Agent cleaned up successfully")
|
|
50
|
+
except Exception as e:
|
|
51
|
+
logger.error(f"Error cleaning up agent: {e}")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def device_health_poller(stop_event: threading.Event, agent: Agent) -> None:
|
|
55
|
+
"""
|
|
56
|
+
Background poller that monitors device availability and agent health.
|
|
57
|
+
Runs every 5 seconds to ensure a device is connected and the agent is healthy.
|
|
58
|
+
|
|
59
|
+
This is a sync wrapper that runs the async poller in a new event loop.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
stop_event: Threading event to signal when to stop polling.
|
|
63
|
+
agent: The Agent instance to monitor and reinitialize if needed.
|
|
64
|
+
"""
|
|
65
|
+
loop = None
|
|
66
|
+
try:
|
|
67
|
+
loop = asyncio.new_event_loop()
|
|
68
|
+
asyncio.set_event_loop(loop)
|
|
69
|
+
|
|
70
|
+
loop.run_until_complete(_async_device_health_poller(stop_event, agent))
|
|
71
|
+
except Exception as e:
|
|
72
|
+
logger.error(f"Error in device health poller thread: {e}")
|
|
73
|
+
finally:
|
|
74
|
+
if loop is not None:
|
|
75
|
+
try:
|
|
76
|
+
loop.close()
|
|
77
|
+
except Exception:
|
|
78
|
+
pass
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""Tool for navigating to a screen and comparing it with Figma design."""
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
from io import BytesIO
|
|
5
|
+
|
|
6
|
+
import mcp as mcp_ref
|
|
7
|
+
from fastmcp import Client
|
|
8
|
+
from fastmcp.client.client import CallToolResult
|
|
9
|
+
from fastmcp.exceptions import ToolError
|
|
10
|
+
from fastmcp.tools.tool import ToolResult
|
|
11
|
+
from PIL import Image
|
|
12
|
+
from pydantic import Field
|
|
13
|
+
|
|
14
|
+
from minitap.mcp.core.agents.compare_screenshots import compare_screenshots
|
|
15
|
+
from minitap.mcp.core.config import settings
|
|
16
|
+
from minitap.mcp.core.decorators import handle_tool_errors
|
|
17
|
+
from minitap.mcp.main import mcp
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@mcp.tool(
|
|
21
|
+
name="compare_screenshot_with_figma",
|
|
22
|
+
description="""
|
|
23
|
+
Compare a screenshot of the current state with a Figma design.
|
|
24
|
+
|
|
25
|
+
This tool:
|
|
26
|
+
1. Captures a screenshot of the current state
|
|
27
|
+
2. Compares the live device screenshot with the Figma design
|
|
28
|
+
3. Returns a detailed comparison report with both screenshots for visual context
|
|
29
|
+
""",
|
|
30
|
+
)
|
|
31
|
+
@handle_tool_errors
|
|
32
|
+
async def compare_screenshot_with_figma(
|
|
33
|
+
node_id: str = Field(
|
|
34
|
+
description=(
|
|
35
|
+
"The node ID of the Figma design. Expected format is ':' separated.\n"
|
|
36
|
+
"Example: If given the URL https://figma.com/design/:fileKey/:fileName?node-id=1-2,\n"
|
|
37
|
+
"the extracted nodeId would be 1:2. Strictly respect this format."
|
|
38
|
+
)
|
|
39
|
+
),
|
|
40
|
+
) -> ToolResult:
|
|
41
|
+
expected_screenshot_base64 = await get_figma_screenshot(node_id)
|
|
42
|
+
|
|
43
|
+
result = await compare_screenshots(
|
|
44
|
+
expected_screenshot_base64=expected_screenshot_base64,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
compressed_expected = compress_image_base64(result.expected_screenshot_base64)
|
|
48
|
+
compressed_current = compress_image_base64(result.current_screenshot_base64)
|
|
49
|
+
|
|
50
|
+
return ToolResult(
|
|
51
|
+
content=[
|
|
52
|
+
mcp_ref.types.TextContent(
|
|
53
|
+
type="text",
|
|
54
|
+
text="## Comparison Analysis\n\n" + str(result.comparison_text),
|
|
55
|
+
),
|
|
56
|
+
mcp_ref.types.ImageContent(
|
|
57
|
+
type="image",
|
|
58
|
+
data=compressed_expected,
|
|
59
|
+
mimeType="image/jpeg",
|
|
60
|
+
),
|
|
61
|
+
mcp_ref.types.TextContent(
|
|
62
|
+
type="text",
|
|
63
|
+
text="**Expected (Figma design)** ↑\n\n**Actual (Current device)** ↓",
|
|
64
|
+
),
|
|
65
|
+
mcp_ref.types.ImageContent(
|
|
66
|
+
type="image",
|
|
67
|
+
data=compressed_current,
|
|
68
|
+
mimeType="image/jpeg",
|
|
69
|
+
),
|
|
70
|
+
]
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def compress_image_base64(base64_str: str, max_width: int = 800, quality: int = 75) -> str:
|
|
75
|
+
"""Compress and resize a base64-encoded image to reduce size.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
base64_str: Base64-encoded image string
|
|
79
|
+
max_width: Maximum width for the resized image
|
|
80
|
+
quality: JPEG quality (1-95, lower = smaller file)
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
Compressed base64-encoded image string
|
|
84
|
+
"""
|
|
85
|
+
try:
|
|
86
|
+
img_data = base64.b64decode(base64_str)
|
|
87
|
+
img = Image.open(BytesIO(img_data))
|
|
88
|
+
|
|
89
|
+
if img.mode in ("RGBA", "P", "LA"):
|
|
90
|
+
background = Image.new("RGB", img.size, (255, 255, 255))
|
|
91
|
+
if img.mode == "P":
|
|
92
|
+
img = img.convert("RGBA")
|
|
93
|
+
if "A" in img.mode:
|
|
94
|
+
background.paste(img, mask=img.split()[-1])
|
|
95
|
+
else:
|
|
96
|
+
background.paste(img)
|
|
97
|
+
img = background
|
|
98
|
+
elif img.mode != "RGB":
|
|
99
|
+
img = img.convert("RGB")
|
|
100
|
+
|
|
101
|
+
if img.width > max_width:
|
|
102
|
+
ratio = max_width / img.width
|
|
103
|
+
new_height = int(img.height * ratio)
|
|
104
|
+
img = img.resize((max_width, new_height), Image.Resampling.LANCZOS)
|
|
105
|
+
|
|
106
|
+
buffer = BytesIO()
|
|
107
|
+
img.save(buffer, format="JPEG", quality=quality, optimize=True)
|
|
108
|
+
compressed_data = buffer.getvalue()
|
|
109
|
+
|
|
110
|
+
return base64.b64encode(compressed_data).decode("utf-8")
|
|
111
|
+
except Exception:
|
|
112
|
+
return base64_str
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
async def get_figma_screenshot(node_id: str) -> str:
|
|
116
|
+
try:
|
|
117
|
+
async with Client(settings.FIGMA_MCP_SERVER_URL) as client:
|
|
118
|
+
result: CallToolResult = await client.call_tool(
|
|
119
|
+
"get_screenshot",
|
|
120
|
+
{
|
|
121
|
+
"nodeId": node_id,
|
|
122
|
+
"clientLanguages": "javascript",
|
|
123
|
+
"clientFrameworks": "react",
|
|
124
|
+
},
|
|
125
|
+
)
|
|
126
|
+
if len(result.content) == 0 or not isinstance(
|
|
127
|
+
result.content[0], mcp_ref.types.ImageContent
|
|
128
|
+
):
|
|
129
|
+
raise ToolError("Failed to fetch screenshot from Figma")
|
|
130
|
+
return result.content[0].data
|
|
131
|
+
except Exception as e:
|
|
132
|
+
raise ToolError(f"Failed to fetch screenshot from Figma: {str(e)}")
|
|
@@ -8,8 +8,8 @@ from minitap.mobile_use.sdk.types import ManualTaskConfig
|
|
|
8
8
|
from minitap.mobile_use.sdk.types.task import PlatformTaskRequest
|
|
9
9
|
from pydantic import Field
|
|
10
10
|
|
|
11
|
-
from minitap.mcp.core.agents import get_mobile_use_agent
|
|
12
11
|
from minitap.mcp.core.decorators import handle_tool_errors
|
|
12
|
+
from minitap.mcp.core.sdk_agent import get_mobile_use_agent
|
|
13
13
|
from minitap.mcp.main import mcp
|
|
14
14
|
|
|
15
15
|
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"""Tool for fetching and saving Figma assets locally."""
|
|
2
|
+
|
|
3
|
+
import shutil
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import mcp as mcp_ref
|
|
7
|
+
import requests
|
|
8
|
+
from fastmcp import Client
|
|
9
|
+
from fastmcp.client.client import CallToolResult
|
|
10
|
+
from fastmcp.exceptions import ToolError
|
|
11
|
+
from fastmcp.tools.tool import ToolResult
|
|
12
|
+
from pydantic import Field
|
|
13
|
+
|
|
14
|
+
from minitap.mcp.core.agents.extract_figma_assets import (
|
|
15
|
+
ExtractedAssets,
|
|
16
|
+
FigmaAsset,
|
|
17
|
+
extract_figma_assets,
|
|
18
|
+
)
|
|
19
|
+
from minitap.mcp.core.config import settings
|
|
20
|
+
from minitap.mcp.core.decorators import handle_tool_errors
|
|
21
|
+
from minitap.mcp.core.models import (
|
|
22
|
+
AssetDownloadResult,
|
|
23
|
+
AssetDownloadSummary,
|
|
24
|
+
DownloadStatus,
|
|
25
|
+
FigmaDesignContextOutput,
|
|
26
|
+
)
|
|
27
|
+
from minitap.mcp.main import mcp
|
|
28
|
+
from minitap.mcp.tools.compare_screenshot_with_figma import (
|
|
29
|
+
compress_image_base64,
|
|
30
|
+
get_figma_screenshot,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@mcp.tool(
|
|
35
|
+
name="save_figma_assets",
|
|
36
|
+
description="""
|
|
37
|
+
Fetch Figma design assets/react implementation code and save them locally in the workspace.
|
|
38
|
+
|
|
39
|
+
This tool:
|
|
40
|
+
1. Calls get_design_context from Figma MCP to get the React/TypeScript code
|
|
41
|
+
2. Extracts all asset URLs and code implementation from the code
|
|
42
|
+
3. Downloads each asset to .mobile-use/figma_assets/<node-id>/ folder
|
|
43
|
+
4. Saves the code implementation to .mobile-use/figma_assets/<node-id>/code_implementation.ts
|
|
44
|
+
5. Returns a list of downloaded files
|
|
45
|
+
""",
|
|
46
|
+
)
|
|
47
|
+
@handle_tool_errors
|
|
48
|
+
async def save_figma_assets(
|
|
49
|
+
node_id: str = Field(
|
|
50
|
+
description=(
|
|
51
|
+
"The node ID of the Figma design. Expected format is ':' separated.\n"
|
|
52
|
+
"Example: If given the URL https://figma.com/design/:fileKey/:fileName?node-id=1-2,\n"
|
|
53
|
+
"the extracted nodeId would be 1:2. Strictly respect this format."
|
|
54
|
+
)
|
|
55
|
+
),
|
|
56
|
+
file_key: str = Field(
|
|
57
|
+
description=(
|
|
58
|
+
"The file key of the Figma file.\n"
|
|
59
|
+
"Example: If given the URL https://figma.com/design/abc123/MyFile?node-id=1-2,\n"
|
|
60
|
+
"the extracted fileKey would be 'abc123'."
|
|
61
|
+
)
|
|
62
|
+
),
|
|
63
|
+
workspace_path: str = Field(
|
|
64
|
+
default=".",
|
|
65
|
+
description=(
|
|
66
|
+
"The workspace path where assets should be saved. Defaults to current directory."
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
) -> ToolResult:
|
|
70
|
+
"""Fetch and save Figma assets locally."""
|
|
71
|
+
|
|
72
|
+
# Step 1: Get design context from Figma MCP
|
|
73
|
+
design_context = await get_design_context(node_id, file_key)
|
|
74
|
+
|
|
75
|
+
# Step 2: Extract asset URLs using LLM agent
|
|
76
|
+
extracted_context: ExtractedAssets = await extract_figma_assets(
|
|
77
|
+
design_context.code_implementation
|
|
78
|
+
)
|
|
79
|
+
if not extracted_context.assets:
|
|
80
|
+
raise ToolError("No assets found in the Figma design context.")
|
|
81
|
+
|
|
82
|
+
# Step 3: Create directory structure
|
|
83
|
+
# Convert node_id format (1:2) to folder name (1-2)
|
|
84
|
+
folder_name = node_id.replace(":", "-")
|
|
85
|
+
assets_dir = Path(workspace_path) / ".mobile-use" / "figma_assets" / folder_name
|
|
86
|
+
|
|
87
|
+
# Delete existing directory to remove stale assets
|
|
88
|
+
if assets_dir.exists():
|
|
89
|
+
shutil.rmtree(assets_dir)
|
|
90
|
+
|
|
91
|
+
# Create fresh directory
|
|
92
|
+
assets_dir.mkdir(parents=True, exist_ok=True)
|
|
93
|
+
|
|
94
|
+
# Step 4: Download assets with resilient error handling
|
|
95
|
+
download_summary = AssetDownloadSummary()
|
|
96
|
+
|
|
97
|
+
for asset in extracted_context.assets:
|
|
98
|
+
result = download_asset(asset, assets_dir)
|
|
99
|
+
if result.status == DownloadStatus.SUCCESS:
|
|
100
|
+
download_summary.successful.append(result)
|
|
101
|
+
else:
|
|
102
|
+
download_summary.failed.append(result)
|
|
103
|
+
|
|
104
|
+
# Step 4.5: Save code implementation
|
|
105
|
+
code_implementation_file = assets_dir / "code_implementation.ts"
|
|
106
|
+
|
|
107
|
+
commented_code_implementation_guidelines = ""
|
|
108
|
+
if design_context.code_implementation_guidelines:
|
|
109
|
+
commented_code_implementation_guidelines = "\n".join(
|
|
110
|
+
["// " + line for line in design_context.code_implementation_guidelines.split("\n")]
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
commented_nodes_guidelines = ""
|
|
114
|
+
if design_context.nodes_guidelines:
|
|
115
|
+
commented_nodes_guidelines = "\n".join(
|
|
116
|
+
["// " + line for line in design_context.nodes_guidelines.split("\n")]
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
code_implementation_file.write_text(
|
|
120
|
+
extracted_context.code_implementation
|
|
121
|
+
+ "\n\n"
|
|
122
|
+
+ commented_code_implementation_guidelines
|
|
123
|
+
+ "\n\n"
|
|
124
|
+
+ commented_nodes_guidelines
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# Step 5: Generate friendly output message
|
|
128
|
+
result_parts = []
|
|
129
|
+
|
|
130
|
+
if download_summary.successful:
|
|
131
|
+
result_parts.append(
|
|
132
|
+
f"✅ Successfully downloaded {download_summary.success_count()} asset(s) "
|
|
133
|
+
f"to .mobile-use/figma_assets/{folder_name}/:\n"
|
|
134
|
+
)
|
|
135
|
+
for asset_result in download_summary.successful:
|
|
136
|
+
result_parts.append(f" • {asset_result.filename}")
|
|
137
|
+
|
|
138
|
+
if download_summary.failed:
|
|
139
|
+
result_parts.append(
|
|
140
|
+
f"\n\n⚠️ Failed to download {download_summary.failure_count()} asset(s):"
|
|
141
|
+
)
|
|
142
|
+
for asset_result in download_summary.failed:
|
|
143
|
+
error_msg = f": {asset_result.error}" if asset_result.error else ""
|
|
144
|
+
result_parts.append(f" • {asset_result.filename}{error_msg}")
|
|
145
|
+
|
|
146
|
+
if code_implementation_file.exists():
|
|
147
|
+
result_parts.append(
|
|
148
|
+
f"\n\n✅ Successfully saved code implementation to {code_implementation_file.name}"
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
expected_screenshot = await get_figma_screenshot(node_id)
|
|
152
|
+
compressed_expected = compress_image_base64(expected_screenshot)
|
|
153
|
+
|
|
154
|
+
return ToolResult(
|
|
155
|
+
content=[
|
|
156
|
+
mcp_ref.types.TextContent(
|
|
157
|
+
type="text",
|
|
158
|
+
text="\n".join(result_parts),
|
|
159
|
+
),
|
|
160
|
+
mcp_ref.types.TextContent(
|
|
161
|
+
type="text",
|
|
162
|
+
text="**Expected (Figma design)**",
|
|
163
|
+
),
|
|
164
|
+
mcp_ref.types.ImageContent(
|
|
165
|
+
type="image",
|
|
166
|
+
data=compressed_expected,
|
|
167
|
+
mimeType="image/jpeg",
|
|
168
|
+
),
|
|
169
|
+
]
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
async def get_design_context(node_id: str, file_key: str) -> FigmaDesignContextOutput:
|
|
174
|
+
"""Fetch design context from Figma MCP server.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
node_id: The Figma node ID in format "1:2"
|
|
178
|
+
file_key: The Figma file key
|
|
179
|
+
|
|
180
|
+
Returns:
|
|
181
|
+
The React/TypeScript code as a string
|
|
182
|
+
|
|
183
|
+
Raises:
|
|
184
|
+
ToolError: If fetching fails
|
|
185
|
+
"""
|
|
186
|
+
try:
|
|
187
|
+
async with Client(settings.FIGMA_MCP_SERVER_URL) as client:
|
|
188
|
+
result: CallToolResult = await client.call_tool(
|
|
189
|
+
"get_design_context",
|
|
190
|
+
{
|
|
191
|
+
"nodeId": node_id,
|
|
192
|
+
"fileKey": file_key,
|
|
193
|
+
"clientLanguages": "typescript",
|
|
194
|
+
"clientFrameworks": "react",
|
|
195
|
+
},
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
code_implementation = ""
|
|
199
|
+
code_implementation_guidelines = None
|
|
200
|
+
nodes_guidelines = None
|
|
201
|
+
|
|
202
|
+
if len(result.content) > 0 and isinstance(result.content[0], mcp_ref.types.TextContent):
|
|
203
|
+
code_implementation = result.content[0].text
|
|
204
|
+
else:
|
|
205
|
+
raise ToolError("Failed to fetch design context from Figma")
|
|
206
|
+
|
|
207
|
+
if len(result.content) > 1:
|
|
208
|
+
if isinstance(result.content[1], mcp_ref.types.TextContent):
|
|
209
|
+
code_implementation_guidelines = result.content[1].text
|
|
210
|
+
if len(result.content) > 2 and isinstance(result.content[2], mcp_ref.types.TextContent):
|
|
211
|
+
nodes_guidelines = result.content[2].text
|
|
212
|
+
|
|
213
|
+
return FigmaDesignContextOutput(
|
|
214
|
+
code_implementation=code_implementation,
|
|
215
|
+
code_implementation_guidelines=code_implementation_guidelines,
|
|
216
|
+
nodes_guidelines=nodes_guidelines,
|
|
217
|
+
)
|
|
218
|
+
except Exception as e:
|
|
219
|
+
raise ToolError(
|
|
220
|
+
f"Failed to fetch design context from Figma: {str(e)}.\n"
|
|
221
|
+
"Ensure the Figma MCP server is running through the official Figma desktop app."
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def download_asset(asset: FigmaAsset, assets_dir: Path) -> AssetDownloadResult:
|
|
226
|
+
"""Download a single asset with error handling.
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
asset: FigmaAsset model with variable_name, url, and extension
|
|
230
|
+
assets_dir: Directory to save the asset
|
|
231
|
+
|
|
232
|
+
Returns:
|
|
233
|
+
AssetDownloadResult with status and optional error message
|
|
234
|
+
"""
|
|
235
|
+
variable_name = asset.variable_name
|
|
236
|
+
url = asset.url
|
|
237
|
+
extension = asset.extension
|
|
238
|
+
|
|
239
|
+
# Convert camelCase variable name to filename
|
|
240
|
+
# e.g., imgSignal -> imgSignal.svg
|
|
241
|
+
filename = f"{variable_name}.{extension}"
|
|
242
|
+
filepath = assets_dir / filename
|
|
243
|
+
|
|
244
|
+
try:
|
|
245
|
+
response = requests.get(url, timeout=30)
|
|
246
|
+
if response.status_code == 200:
|
|
247
|
+
filepath.write_bytes(response.content)
|
|
248
|
+
return AssetDownloadResult(filename=filename, status=DownloadStatus.SUCCESS)
|
|
249
|
+
else:
|
|
250
|
+
return AssetDownloadResult(
|
|
251
|
+
filename=filename,
|
|
252
|
+
status=DownloadStatus.FAILED,
|
|
253
|
+
error=f"HTTP {response.status_code}",
|
|
254
|
+
)
|
|
255
|
+
except requests.exceptions.Timeout:
|
|
256
|
+
return AssetDownloadResult(filename=filename, status=DownloadStatus.FAILED, error="Timeout")
|
|
257
|
+
except Exception as e:
|
|
258
|
+
return AssetDownloadResult(filename=filename, status=DownloadStatus.FAILED, error=str(e))
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: minitap-mcp
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Model Context Protocol server for controlling Android & iOS devices with natural language
|
|
5
5
|
Author: Pierre-Louis Favreau, Jean-Pierre Lo, Clément Guiguet
|
|
6
6
|
Requires-Dist: fastmcp>=2.12.4
|
|
7
7
|
Requires-Dist: python-dotenv>=1.1.1
|
|
8
8
|
Requires-Dist: pydantic>=2.12.0
|
|
9
9
|
Requires-Dist: pydantic-settings>=2.10.1
|
|
10
|
-
Requires-Dist: minitap-mobile-use>=2.
|
|
10
|
+
Requires-Dist: minitap-mobile-use>=2.8.1
|
|
11
11
|
Requires-Dist: jinja2>=3.1.6
|
|
12
12
|
Requires-Dist: langchain-core>=0.3.75
|
|
13
|
+
Requires-Dist: pillow>=11.1.0
|
|
13
14
|
Requires-Dist: ruff==0.5.3 ; extra == 'dev'
|
|
14
15
|
Requires-Dist: pytest==8.4.1 ; extra == 'dev'
|
|
15
16
|
Requires-Dist: pytest-cov==5.0.0 ; extra == 'dev'
|
|
@@ -37,41 +38,50 @@ Before running the MCP server, ensure you have the required mobile automation to
|
|
|
37
38
|
|
|
38
39
|
- **For Android devices:**
|
|
39
40
|
- [ADB (Android Debug Bridge)](https://developer.android.com/tools/adb) - For device communication
|
|
40
|
-
- [Maestro](https://maestro.mobile.dev/) - For mobile automation
|
|
41
|
+
- [Maestro](https://maestro.mobile.dev/) - For mobile automation
|
|
41
42
|
|
|
42
43
|
- **For iOS devices (macOS only):**
|
|
43
44
|
- Xcode Command Line Tools with `xcrun`
|
|
44
|
-
- [Maestro](https://maestro.mobile.dev/) - For mobile automation
|
|
45
|
+
- [Maestro](https://maestro.mobile.dev/) - For mobile automation
|
|
45
46
|
|
|
46
47
|
For detailed setup instructions, see the [mobile-use repository](https://github.com/minitap-ai/mobile-use).
|
|
47
48
|
|
|
48
|
-
###
|
|
49
|
+
### Running the Server
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
The simplest way to start:
|
|
51
52
|
|
|
52
53
|
```bash
|
|
53
|
-
|
|
54
|
-
export MINITAP_API_BASE_URL="https://platform.minitap.ai/api/v1"
|
|
55
|
-
export MINITAP_LLM_PROFILE_NAME="default"
|
|
54
|
+
minitap-mcp --server --api-key your_minitap_api_key
|
|
56
55
|
```
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
This starts the server on `localhost:8000` with your API key. Get your free API key at [platform.minitap.ai/api-keys](https://platform.minitap.ai/api-keys).
|
|
59
58
|
|
|
60
|
-
|
|
59
|
+
**Available CLI options:**
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
minitap-mcp --server --api-key YOUR_KEY --llm-profile PROFILE_NAME
|
|
63
|
+
```
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
- `--api-key`: Your Minitap API key (overrides `MINITAP_API_KEY` env var). Get yours at [platform.minitap.ai/api-keys](https://platform.minitap.ai/api-keys).
|
|
66
|
+
- `--llm-profile`: LLM profile name to use (overrides `MINITAP_LLM_PROFILE_NAME` env var). If unset, uses the default profile. Configure profiles at [platform.minitap.ai/llm-profiles](https://platform.minitap.ai/llm-profiles).
|
|
67
|
+
|
|
68
|
+
### Configuration (Optional)
|
|
69
|
+
|
|
70
|
+
Alternatively, you can set environment variables instead of using CLI flags:
|
|
63
71
|
|
|
64
72
|
```bash
|
|
65
|
-
|
|
73
|
+
export MINITAP_API_KEY="your_minitap_api_key"
|
|
74
|
+
export MINITAP_API_BASE_URL="https://platform.minitap.ai/api/v1"
|
|
75
|
+
export MINITAP_LLM_PROFILE_NAME="default"
|
|
66
76
|
```
|
|
67
77
|
|
|
68
|
-
|
|
78
|
+
You can set these in your `.bashrc` or equivalent, then simply run:
|
|
69
79
|
|
|
70
80
|
```bash
|
|
71
|
-
minitap-mcp --server
|
|
81
|
+
minitap-mcp --server
|
|
72
82
|
```
|
|
73
83
|
|
|
74
|
-
|
|
84
|
+
CLI flags always override environment variables when both are present.
|
|
75
85
|
|
|
76
86
|
By default, the server will bind to `0.0.0.0:8000`. Configure via environment variables:
|
|
77
87
|
|
|
@@ -82,7 +92,7 @@ export MCP_SERVER_PORT="8000"
|
|
|
82
92
|
|
|
83
93
|
## IDE Integration
|
|
84
94
|
|
|
85
|
-
1. Start the server: `minitap-mcp --server`
|
|
95
|
+
1. Start the server: `minitap-mcp --server --api-key your_minitap_api_key`
|
|
86
96
|
2. Add to your IDE MCP settings file:
|
|
87
97
|
|
|
88
98
|
```jsonc
|
|
@@ -118,7 +128,7 @@ Execute natural language commands on your mobile device using the Minitap SDK. T
|
|
|
118
128
|
|
|
119
129
|
**Parameters:**
|
|
120
130
|
- `goal` (required): High-level goal describing the action to perform
|
|
121
|
-
- `output_description` (optional):
|
|
131
|
+
- `output_description` (optional): Natural language description of the desired output format. Results are returned as structured JSON (e.g., "An array with sender and subject for each email")
|
|
122
132
|
- `profile` (optional): Profile name to use (defaults to "default")
|
|
123
133
|
|
|
124
134
|
**Examples:**
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
minitap/mcp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
minitap/mcp/core/agents/compare_screenshots.md,sha256=Gt27HVzXzu71BxcanKPokz1dFPvq90vXbjE2HOn5X0I,3559
|
|
3
|
+
minitap/mcp/core/agents/compare_screenshots.py,sha256=Yb7kR8Cv0gWzXyNf-6IS7_9l1npfqYmL-SONJJGgzM4,2060
|
|
4
|
+
minitap/mcp/core/agents/extract_figma_assets.md,sha256=JrXuWF8-2PeQpVix-kf-p6zmu2gQVf9Z6ptTK1cedDk,2413
|
|
5
|
+
minitap/mcp/core/agents/extract_figma_assets.py,sha256=WAmn4CvN1ONJkJp2KH9l080hhZ_ge0Pdan6ejk_GWOo,2038
|
|
6
|
+
minitap/mcp/core/config.py,sha256=gfx-cXJsgB_W2dSNHnb5jeWEYfe3VBZUMeF1nbNAdiQ,962
|
|
7
|
+
minitap/mcp/core/decorators.py,sha256=iekv181o_rkv0upacFWkmPqxsZRTzuLFyOZ0sIDtQnQ,1317
|
|
8
|
+
minitap/mcp/core/device.py,sha256=sEO3Z-8F325hDOObdH1YBhZE60f17FmIclt5UlhY_nU,7875
|
|
9
|
+
minitap/mcp/core/llm.py,sha256=z_pYZkZcAchsiWPh4W79frQPANsfYyFPUe8DJo8lZO0,822
|
|
10
|
+
minitap/mcp/core/models.py,sha256=egLScxPAMo4u5cqY33UKba7z7DsdgqfPW409UAqW1Jg,1942
|
|
11
|
+
minitap/mcp/core/sdk_agent.py,sha256=-9l1YetD93dzxOeSFOT_j8dDfDFjhJLiir8bhzEjI3Y,900
|
|
12
|
+
minitap/mcp/core/utils.py,sha256=3uExpRoh7affIieZx3TLlZTmZCcoxWfx1YpPbwhjiJY,1791
|
|
13
|
+
minitap/mcp/main.py,sha256=B7KE6_5UNGKanS0WMJYBq8vp0HE_Lr0BG9KR4BwYxwU,4341
|
|
14
|
+
minitap/mcp/server/middleware.py,sha256=fbry_IiHmwUxVjsWgOU2goybcS1kLRXFZZ89KPH1d8E,880
|
|
15
|
+
minitap/mcp/server/poller.py,sha256=Qakq4yO3EJ9dXmRqtE3sJjyk0ij7VBU-NuupHhTf37g,2539
|
|
16
|
+
minitap/mcp/tools/analyze_screen.py,sha256=fjcjf3tTZDlxzmiQFHFNgw38bxPz4eisw57zuxshN2A,1984
|
|
17
|
+
minitap/mcp/tools/compare_screenshot_with_figma.py,sha256=G69F6vRFI2tE2wW-oFYPjnY8oFMD9nRZH0H-yvtD4gE,4575
|
|
18
|
+
minitap/mcp/tools/execute_mobile_command.py,sha256=qY3UfcDq1BtYcny1YlEF4WV9LwUJxLAmLJCm1VBzxS8,2442
|
|
19
|
+
minitap/mcp/tools/go_back.py,sha256=lEmADkDkXu8JGm-sY7zL7M6GlBy-lD7Iffv4yzwoQfo,1301
|
|
20
|
+
minitap/mcp/tools/save_figma_assets.py,sha256=EN0u0TkCUXoz8guehxm-CywKYYmZFg_d4x35eTNAovQ,9182
|
|
21
|
+
minitap/mcp/tools/screen_analyzer.md,sha256=TTO80JQWusbA9cKAZn-9cqhgVHm6F_qJh5w152hG3YM,734
|
|
22
|
+
minitap_mcp-0.4.0.dist-info/WHEEL,sha256=5w2T7AS2mz1-rW9CNagNYWRCaB0iQqBMYLwKdlgiR4Q,78
|
|
23
|
+
minitap_mcp-0.4.0.dist-info/entry_points.txt,sha256=rYVoXm7tSQCqQTtHx4Lovgn1YsjwtEEHfddKrfEVHuY,55
|
|
24
|
+
minitap_mcp-0.4.0.dist-info/METADATA,sha256=27wi_Bedtm971es6fHljAF8wE45uCkSoYYwwqqFvmY0,5885
|
|
25
|
+
minitap_mcp-0.4.0.dist-info/RECORD,,
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
minitap/mcp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
minitap/mcp/core/agents.py,sha256=-9l1YetD93dzxOeSFOT_j8dDfDFjhJLiir8bhzEjI3Y,900
|
|
3
|
-
minitap/mcp/core/config.py,sha256=ohJ50qQp6wKFBcX8hr0IbSGnrlbWg1YAwrgJ9I1_vLE,849
|
|
4
|
-
minitap/mcp/core/decorators.py,sha256=iekv181o_rkv0upacFWkmPqxsZRTzuLFyOZ0sIDtQnQ,1317
|
|
5
|
-
minitap/mcp/core/device.py,sha256=sEO3Z-8F325hDOObdH1YBhZE60f17FmIclt5UlhY_nU,7875
|
|
6
|
-
minitap/mcp/core/llm.py,sha256=z_pYZkZcAchsiWPh4W79frQPANsfYyFPUe8DJo8lZO0,822
|
|
7
|
-
minitap/mcp/core/utils.py,sha256=3uExpRoh7affIieZx3TLlZTmZCcoxWfx1YpPbwhjiJY,1791
|
|
8
|
-
minitap/mcp/main.py,sha256=eoF-wDgXmS_eZYpWBJBXTQaOOGhHHxY-IIwG0C6cW9s,3557
|
|
9
|
-
minitap/mcp/server/middleware.py,sha256=fbry_IiHmwUxVjsWgOU2goybcS1kLRXFZZ89KPH1d8E,880
|
|
10
|
-
minitap/mcp/server/poller.py,sha256=C2h5Ir3nY5gZ6qTDOHBw_Tb8PfAY54A-we2HrwjNLvg,1222
|
|
11
|
-
minitap/mcp/tools/analyze_screen.py,sha256=fjcjf3tTZDlxzmiQFHFNgw38bxPz4eisw57zuxshN2A,1984
|
|
12
|
-
minitap/mcp/tools/execute_mobile_command.py,sha256=f5yObnn9r2pZ33w0I2TwvCZKKepqlKbpVANZnUkfFjU,2439
|
|
13
|
-
minitap/mcp/tools/go_back.py,sha256=lEmADkDkXu8JGm-sY7zL7M6GlBy-lD7Iffv4yzwoQfo,1301
|
|
14
|
-
minitap/mcp/tools/screen_analyzer.md,sha256=TTO80JQWusbA9cKAZn-9cqhgVHm6F_qJh5w152hG3YM,734
|
|
15
|
-
minitap_mcp-0.3.0.dist-info/WHEEL,sha256=k57ZwB-NkeM_6AsPnuOHv5gI5KM5kPD6Vx85WmGEcI0,78
|
|
16
|
-
minitap_mcp-0.3.0.dist-info/entry_points.txt,sha256=rYVoXm7tSQCqQTtHx4Lovgn1YsjwtEEHfddKrfEVHuY,55
|
|
17
|
-
minitap_mcp-0.3.0.dist-info/METADATA,sha256=5BB82VEtjp_R5mcyxD40DspuYXdgEOijlFf9nFqr3NM,5128
|
|
18
|
-
minitap_mcp-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|