File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ This directory contains all MCP tools available in MCP Appium.
2525 - ` double-tap.ts ` - Double tap elements
2626 - ` set-value.ts ` - Enter text
2727 - ` get-text.ts ` - Get element text
28+ - ` get-page-source.ts ` - Get page source (XML) from current screen
2829 - ` screenshot.ts ` - Capture screenshots
2930 - ` activate-app.ts ` - Activate apps
3031 - ` terminate-app.ts ` - Terminate apps
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import clickElement from './interactions/click.js';
3131import doubleTap from './interactions/double-tap.js' ;
3232import setValue from './interactions/set-value.js' ;
3333import getText from './interactions/get-text.js' ;
34+ import getPageSource from './interactions/get-page-source.js' ;
3435import screenshot from './interactions/screenshot.js' ;
3536import activateApp from './interactions/activate-app.js' ;
3637import installApp from './interactions/install-app.js' ;
@@ -127,6 +128,7 @@ export default function registerTools(server: FastMCP): void {
127128 doubleTap ( server ) ;
128129 setValue ( server ) ;
129130 getText ( server ) ;
131+ getPageSource ( server ) ;
130132 screenshot ( server ) ;
131133 generateTest ( server ) ;
132134 log . info ( 'All tools registered' ) ;
Original file line number Diff line number Diff line change 1+ import { FastMCP } from 'fastmcp/dist/FastMCP.js' ;
2+ import { z } from 'zod' ;
3+ import { getDriver } from '../session-store.js' ;
4+
5+ export default function getPageSource ( server : FastMCP ) : void {
6+ server . addTool ( {
7+ name : 'appium_get_page_source' ,
8+ description : 'Get the page source (XML) from the current screen' ,
9+ parameters : z . object ( { } ) ,
10+ annotations : {
11+ readOnlyHint : true ,
12+ openWorldHint : false ,
13+ } ,
14+ execute : async ( args : any , context : any ) : Promise < any > => {
15+ const driver = getDriver ( ) ;
16+ if ( ! driver ) {
17+ throw new Error ( 'No driver found. Please create a session first.' ) ;
18+ }
19+
20+ try {
21+ const pageSource = await driver . getPageSource ( ) ;
22+
23+ if ( ! pageSource ) {
24+ throw new Error ( 'Page source is empty or null' ) ;
25+ }
26+
27+ return {
28+ content : [
29+ {
30+ type : 'text' ,
31+ text :
32+ 'Page source retrieved successfully: \n' +
33+ '```xml ' +
34+ pageSource +
35+ '```' ,
36+ } ,
37+ ] ,
38+ } ;
39+ } catch ( err : any ) {
40+ return {
41+ content : [
42+ {
43+ type : 'text' ,
44+ text : `Failed to get page source. Error: ${ err . toString ( ) } ` ,
45+ } ,
46+ ] ,
47+ isError : true ,
48+ } ;
49+ }
50+ } ,
51+ } ) ;
52+ }
You can’t perform that action at this time.
0 commit comments