mirror of
https://github.com/web-infra-dev/midscene.git
synced 2025-12-28 07:30:02 +00:00
feat(mcp): add playwright example tool to help generate playwright test code (#660)
* fix(mcp): resolve server close logic * feat(mcp): add playwright example tools
This commit is contained in:
parent
33d2733c77
commit
762b602940
@ -9,9 +9,7 @@
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"bin": {
|
||||
"midscene-mcp": "dist/index.cjs"
|
||||
},
|
||||
"bin": "dist/index.cjs",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -17,6 +17,23 @@ const server = new McpServer({
|
||||
'Midscene MCP Server: Control the browser using natural language commands for navigation, clicking, input, hovering, and achieving goals. Also supports screenshots and JavaScript execution.',
|
||||
});
|
||||
|
||||
server.tool(
|
||||
'midscene_playwright_example',
|
||||
'Provides Playwright code examples for Midscene. If users need to generate Midscene test cases, they can call this method to get sample Midscene Playwright test cases for generating end-user test cases. Each step must first be verified using the mcp method, and then the final test case is generated based on the playwright example according to the steps executed by mcp',
|
||||
{},
|
||||
async () => {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: PROMPTS.PLAYWRIGHT_CODE_EXAMPLE,
|
||||
},
|
||||
],
|
||||
isError: false,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
server.resource(
|
||||
'playwright-example',
|
||||
'file:///playwright-example.mdx',
|
||||
@ -56,6 +73,6 @@ runServer().catch(console.error);
|
||||
|
||||
process.stdin.on('close', () => {
|
||||
console.error('Midscene MCP Server closing, cleaning up browser...');
|
||||
midsceneManager.closeBrowser().catch(console.error);
|
||||
server.close();
|
||||
midsceneManager.closeBrowser().catch(console.error);
|
||||
});
|
||||
|
||||
@ -105,10 +105,7 @@ export class MidsceneManager {
|
||||
const agent = await this.initAgent(true);
|
||||
await agent.connectNewTabWithUrl(url);
|
||||
return {
|
||||
content: [
|
||||
{ type: 'text', text: `Navigated to ${url}` },
|
||||
{ type: 'text', text: `report file: ${agent.reportFile}` },
|
||||
],
|
||||
content: [{ type: 'text', text: `Navigated to ${url}` }],
|
||||
isError: false,
|
||||
};
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user