Skip to content

Commit 497091b

Browse files
committed
chore: fix pr comment
1 parent c5933a0 commit 497091b

File tree

3 files changed

+38
-68
lines changed

3 files changed

+38
-68
lines changed

docs/tool-reference.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,8 @@
195195

196196
**Parameters:**
197197

198-
- **clearGeolocation** (boolean) _(optional)_: Set to true to clear the geolocation override.
199198
- **cpuThrottlingRate** (number) _(optional)_: Represents the CPU slowdown factor. Set the rate to 1 to disable throttling. If omitted, throttling remains unchanged.
200-
- **latitude** (number) _(optional)_: Latitude between -90 and 90 for geolocation emulation. Must be provided together with longitude.
201-
- **longitude** (number) _(optional)_: Longitude between -180 and 180 for geolocation emulation. Must be provided together with latitude.
199+
- **geolocation** (unknown) _(optional)_: Geolocation to [`emulate`](#emulate). Set to null to clear the geolocation override.
202200
- **networkConditions** (enum: "No emulation", "Offline", "Slow 3G", "Fast 3G", "Slow 4G", "Fast 4G") _(optional)_: Throttle network. Set to "No emulation" to disable. If omitted, conditions remain unchanged.
203201

204202
---

src/tools/emulation.ts

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,28 @@ export const emulate = defineTool({
3737
.describe(
3838
'Represents the CPU slowdown factor. Set the rate to 1 to disable throttling. If omitted, throttling remains unchanged.',
3939
),
40-
latitude: zod
41-
.number()
42-
.min(-90)
43-
.max(90)
44-
.optional()
45-
.describe(
46-
'Latitude between -90 and 90 for geolocation emulation. Must be provided together with longitude.',
47-
),
48-
longitude: zod
49-
.number()
50-
.min(-180)
51-
.max(180)
40+
geolocation: zod
41+
.object({
42+
latitude: zod
43+
.number()
44+
.min(-90)
45+
.max(90)
46+
.describe('Latitude between -90 and 90.'),
47+
longitude: zod
48+
.number()
49+
.min(-180)
50+
.max(180)
51+
.describe('Longitude between -180 and 180.'),
52+
})
53+
.nullable()
5254
.optional()
5355
.describe(
54-
'Longitude between -180 and 180 for geolocation emulation. Must be provided together with latitude.',
56+
'Geolocation to emulate. Set to null to clear the geolocation override.',
5557
),
56-
clearGeolocation: zod
57-
.boolean()
58-
.optional()
59-
.describe('Set to true to clear the geolocation override.'),
6058
},
6159
handler: async (request, _response, context) => {
6260
const page = context.getSelectedPage();
63-
const {
64-
networkConditions,
65-
cpuThrottlingRate,
66-
latitude,
67-
longitude,
68-
clearGeolocation,
69-
} = request.params;
61+
const {networkConditions, cpuThrottlingRate, geolocation} = request.params;
7062

7163
if (networkConditions) {
7264
if (networkConditions === 'No emulation') {
@@ -95,17 +87,13 @@ export const emulate = defineTool({
9587
context.setCpuThrottlingRate(cpuThrottlingRate);
9688
}
9789

98-
if (clearGeolocation) {
99-
await page.setGeolocation({latitude: 0, longitude: 0});
100-
context.setGeolocation(null);
101-
} else if (latitude !== undefined || longitude !== undefined) {
102-
if (latitude !== undefined && longitude !== undefined) {
103-
await page.setGeolocation({latitude, longitude});
104-
context.setGeolocation({latitude, longitude});
90+
if (geolocation !== undefined) {
91+
if (geolocation === null) {
92+
await page.setGeolocation({latitude: 0, longitude: 0});
93+
context.setGeolocation(null);
10594
} else {
106-
throw new Error(
107-
'Both latitude and longitude must be provided together for geolocation emulation.',
108-
);
95+
await page.setGeolocation(geolocation);
96+
context.setGeolocation(geolocation);
10997
}
11098
}
11199
},

tests/tools/emulation.test.ts

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ describe('emulation', () => {
159159
await emulate.handler(
160160
{
161161
params: {
162-
latitude: 48.137154,
163-
longitude: 11.576124,
162+
geolocation: {
163+
latitude: 48.137154,
164+
longitude: 11.576124,
165+
},
164166
},
165167
},
166168
response,
@@ -173,14 +175,16 @@ describe('emulation', () => {
173175
});
174176
});
175177

176-
it('clears geolocation override when clearGeolocation is true', async () => {
178+
it('clears geolocation override when geolocation is set to null', async () => {
177179
await withMcpContext(async (response, context) => {
178180
// First set a geolocation
179181
await emulate.handler(
180182
{
181183
params: {
182-
latitude: 48.137154,
183-
longitude: 11.576124,
184+
geolocation: {
185+
latitude: 48.137154,
186+
longitude: 11.576124,
187+
},
184188
},
185189
},
186190
response,
@@ -189,11 +193,11 @@ describe('emulation', () => {
189193

190194
assert.notStrictEqual(context.getGeolocation(), null);
191195

192-
// Then clear it using clearGeolocation
196+
// Then clear it by setting geolocation to null
193197
await emulate.handler(
194198
{
195199
params: {
196-
clearGeolocation: true,
200+
geolocation: null,
197201
},
198202
},
199203
response,
@@ -204,35 +208,15 @@ describe('emulation', () => {
204208
});
205209
});
206210

207-
it('throws error when only latitude is provided', async () => {
208-
await withMcpContext(async (response, context) => {
209-
await assert.rejects(
210-
async () => {
211-
await emulate.handler(
212-
{
213-
params: {
214-
latitude: 48.137154,
215-
},
216-
},
217-
response,
218-
context,
219-
);
220-
},
221-
{
222-
message:
223-
'Both latitude and longitude must be provided together for geolocation emulation.',
224-
},
225-
);
226-
});
227-
});
228-
229211
it('reports correctly for the currently selected page', async () => {
230212
await withMcpContext(async (response, context) => {
231213
await emulate.handler(
232214
{
233215
params: {
234-
latitude: 48.137154,
235-
longitude: 11.576124,
216+
geolocation: {
217+
latitude: 48.137154,
218+
longitude: 11.576124,
219+
},
236220
},
237221
},
238222
response,

0 commit comments

Comments
 (0)