set_geolocation
Override GPS coordinates for browser and mobile sessions to simulate specific locations. Requires location permissions to be granted.
Instructions
Overrides GPS coordinates for the session. Affects navigator.geolocation in browsers and location services on mobile. Location permissions must already be granted to the app.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| latitude | Yes | Latitude coordinate | |
| longitude | Yes | Longitude coordinate | |
| altitude | No | Altitude in meters (optional) |
Implementation Reference
- src/tools/device.tool.ts:71-96 (handler)The `setGeolocationTool` async function that executes the tool logic. It calls `browser.setGeoLocation()` with the provided latitude, longitude, and optional altitude.
export const setGeolocationTool: ToolCallback = async (args: { latitude: number; longitude: number; altitude?: number; }): Promise<CallToolResult> => { try { const browser = getBrowser(); const { latitude, longitude, altitude } = args; await browser.setGeoLocation({ latitude, longitude, altitude }); return { content: [ { type: 'text', text: `Geolocation set to:\n Latitude: ${latitude}\n Longitude: ${longitude}${altitude ? `\n Altitude: ${altitude}m` : ''}`, }, ], }; } catch (e) { return { isError: true, content: [{ type: 'text', text: `Error setting geolocation: ${e}` }], }; } }; - src/tools/device.tool.ts:23-32 (schema)The `setGeolocationToolDefinition` object defining the tool's name ('set_geolocation'), description, and input schema (latitude, longitude, optional altitude) using Zod validation.
export const setGeolocationToolDefinition: ToolDefinition = { name: 'set_geolocation', description: 'Overrides GPS coordinates for the session. Affects navigator.geolocation in browsers and location services on mobile. Location permissions must already be granted to the app.', annotations: { title: 'Set Geolocation', destructiveHint: false, idempotentHint: true }, inputSchema: { latitude: z.number().min(-90).max(90).describe('Latitude coordinate'), longitude: z.number().min(-180).max(180).describe('Longitude coordinate'), altitude: z.number().optional().describe('Altitude in meters (optional)'), }, }; - src/server.ts:148-148 (registration)Registration of the `set_geolocation` tool in the MCP server via `registerTool(setGeolocationToolDefinition, setGeolocationTool)`.
registerTool(setGeolocationToolDefinition, setGeolocationTool); - src/session/state.ts:18-24 (helper)The `getBrowser()` helper function that retrieves the current active WebdriverIO browser instance from the session state, used by the tool handler.
export function getBrowser(): WebdriverIO.Browser { const browser = state.browsers.get(state.currentSession); if (!browser) { throw new Error('No active browser session'); } return browser; }