Skip to content

Commit daa7ba3

Browse files
committed
feat(ai): add filePath param to takeScreenshot MCP tool
When filePath is specified, saves the screenshot to disk and returns the path instead of inline base64 image data.
1 parent 918372a commit daa7ba3

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src-node/mcp-editor-tools.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ function createEditorMcpServer(sdkModule, nodeConnector, clarificationAccessors)
8686

8787
const takeScreenshotTool = sdkModule.tool(
8888
"takeScreenshot",
89-
"Take a screenshot of the Phoenix Code editor window. Returns a PNG image. " +
89+
"Take a screenshot of the Phoenix Code editor window. " +
90+
"By default returns the screenshot as a PNG image inline. " +
91+
"If filePath is specified, saves the screenshot to that file and returns the file path instead. " +
9092
"Prefer capturing specific regions instead of the full page: " +
9193
"use selector '#panel-live-preview-frame' for the live preview content, " +
9294
"or '.editor-holder' for the code editor area. " +
@@ -95,16 +97,22 @@ function createEditorMcpServer(sdkModule, nodeConnector, clarificationAccessors)
9597
"and other editor UI elements. Use purePreview=true to temporarily hide these overlays.",
9698
{
9799
selector: z.string().optional().describe("CSS selector to capture a specific element. Use '#panel-live-preview-frame' for the live preview, '.editor-holder' for the code editor."),
98-
purePreview: z.boolean().optional().describe("When true, temporarily switches to preview mode to hide element highlight overlays and toolboxes before capturing, then restores the previous mode.")
100+
purePreview: z.boolean().optional().describe("When true, temporarily switches to preview mode to hide element highlight overlays and toolboxes before capturing, then restores the previous mode."),
101+
filePath: z.string().optional().describe("Absolute path to save the screenshot as a PNG file. If specified, returns the file path instead of inline image data.")
99102
},
100103
async function (args) {
101104
let toolResult;
102105
try {
103106
const result = await nodeConnector.execPeer("takeScreenshot", {
104107
selector: args.selector || undefined,
105-
purePreview: args.purePreview || false
108+
purePreview: args.purePreview || false,
109+
filePath: args.filePath || undefined
106110
});
107-
if (result.base64) {
111+
if (result.filePath) {
112+
toolResult = {
113+
content: [{ type: "text", text: "Screenshot saved to: " + result.filePath }]
114+
};
115+
} else if (result.base64) {
108116
toolResult = {
109117
content: [{ type: "image", data: result.base64, mimeType: "image/png" }]
110118
};

0 commit comments

Comments
 (0)