Guide · Amazon Location Service · Geofencing

Amazon Location Service Geofencing for MCP Servers — PutGeofenceCommand, EventBridge Entry/Exit Events

Amazon Location Service geofencing lets MCP servers define virtual geographic boundaries and receive notifications when tracked devices or user-submitted positions cross those boundaries. Geofences are stored in named collections; they can be circles or arbitrary GeoJSON polygons. This guide covers creating geofence collections, defining and listing geofences, synchronously evaluating positions with BatchEvaluateGeofencesCommand, and wiring a tracker-to-collection association to receive automatic EventBridge entry/exit events.

TL;DR

Create a geofence collection, then add geofences with PutGeofenceCommand (circle or polygon). To test whether a position is inside a fence, call BatchEvaluateGeofencesCommand — it returns entry/exit events synchronously. For automatic event-driven geofencing (device positions trigger EventBridge), associate a tracker with the collection and use BatchUpdateDevicePositionCommand; Amazon Location Service then emits ENTER / EXIT events automatically. All coordinates are [longitude, latitude] (GeoJSON order).

Why geofencing in MCP servers

Geofencing adds a spatial trigger layer to MCP server architectures. Common patterns:

Creating a geofence collection

A geofence collection is a named persistent resource that holds geofence definitions. Create it once:

import {
  LocationClient,
  CreateGeofenceCollectionCommand,
} from "@aws-sdk/client-location";

const location = new LocationClient({ region: "us-east-1" });

await location.send(new CreateGeofenceCollectionCommand({
  CollectionName: "my-mcp-geofences",
  Description: "Geofences for MCP server spatial triggers",
  KmsKeyId: undefined,  // optional KMS key for envelope encryption of geofence data
  Tags: { "mcp-server": "true" },
}));

Geofence collections are free to create. You are charged per geofence evaluation request (see pricing below), not per stored geofence. A single collection can hold thousands of geofences.

Defining geofences

Circle geofences

A circle geofence is defined by a center point and a radius in meters — the most common shape for delivery, proximity, or point-of-interest triggers:

import { PutGeofenceCommand } from "@aws-sdk/client-location";

await location.send(new PutGeofenceCommand({
  CollectionName: "my-mcp-geofences",
  GeofenceId: "warehouse-seattle",          // unique string ID within the collection
  Geometry: {
    Circle: {
      Center: [-122.3321, 47.6062],  // [longitude, latitude]
      Radius: 200,                   // meters
    },
  },
  GeofenceProperties: {              // optional key-value metadata
    "type": "warehouse",
    "region": "pacific-northwest",
  },
}));

Polygon geofences

Polygon geofences use GeoJSON linear ring syntax — a closed array of [longitude, latitude] positions where the first and last position must be identical:

await location.send(new PutGeofenceCommand({
  CollectionName: "my-mcp-geofences",
  GeofenceId: "downtown-seattle",
  Geometry: {
    Polygon: [
      [   // outer ring (must be counter-clockwise for exterior)
        [-122.3600, 47.6000],
        [-122.3200, 47.6000],
        [-122.3200, 47.6200],
        [-122.3600, 47.6200],
        [-122.3600, 47.6000],  // closes the ring (same as first point)
      ],
    ],
  },
}));

Amazon Location Service uses the right-hand rule for polygon orientation: the outer ring must be counter-clockwise, holes must be clockwise. If you submit a polygon with the wrong orientation, the service either corrects it silently or returns a validation error depending on the data complexity — test with a known point inside the polygon to verify the geofence is behaving as expected.

Upserting geofences

PutGeofenceCommand is an upsert — if the GeofenceId already exists, it replaces the geometry. No separate update command needed. This makes bulk geofence management idempotent:

async function upsertGeofences(
  client: LocationClient,
  collection: string,
  fences: Array<{ id: string; lat: number; lon: number; radiusM: number }>
): Promise<void> {
  for (const fence of fences) {
    await client.send(new PutGeofenceCommand({
      CollectionName: collection,
      GeofenceId: fence.id,
      Geometry: {
        Circle: {
          Center: [fence.lon, fence.lat],  // longitude first
          Radius: fence.radiusM,
        },
      },
    }));
  }
}

Listing geofences

Use ListGeofencesCommand to enumerate geofences in a collection (paginated):

import { ListGeofencesCommand, GetGeofenceCommand } from "@aws-sdk/client-location";

async function* allGeofences(client: LocationClient, collection: string) {
  let nextToken: string | undefined;
  do {
    const resp = await client.send(new ListGeofencesCommand({
      CollectionName: collection,
      NextToken: nextToken,
    }));
    yield* resp.Entries ?? [];
    nextToken = resp.NextToken;
  } while (nextToken);
}

for await (const fence of allGeofences(location, "my-mcp-geofences")) {
  console.log(fence.GeofenceId, fence.Status);  // "ACTIVE" | "PENDING" | "FAILED"
}

Get a specific geofence by ID with GetGeofenceCommand:

const fence = await location.send(new GetGeofenceCommand({
  CollectionName: "my-mcp-geofences",
  GeofenceId: "warehouse-seattle",
}));
console.log(fence.Status, fence.Geometry?.Circle);

Synchronous position evaluation

BatchEvaluateGeofencesCommand immediately tests whether submitted positions are inside or outside any geofence in the collection. It is synchronous — no polling needed — and returns entry/exit events for each position:

import {
  BatchEvaluateGeofencesCommand,
  type DevicePositionUpdate,
} from "@aws-sdk/client-location";

const positions: DevicePositionUpdate[] = [
  {
    DeviceId: "device-001",
    Position: [-122.3321, 47.6062],  // [longitude, latitude]
    SampleTime: new Date(),
  },
  {
    DeviceId: "device-002",
    Position: [-122.5000, 47.5500],
    SampleTime: new Date(),
  },
];

const evalResult = await location.send(new BatchEvaluateGeofencesCommand({
  CollectionName: "my-mcp-geofences",
  DevicePositionUpdates: positions,
}));

// Check for errors
for (const error of evalResult.Errors ?? []) {
  console.error("Eval error for device:", error.DeviceId, error.Error?.Code);
}

// Note: BatchEvaluateGeofencesCommand does NOT return the entry/exit events
// in the response body — it only returns errors. Events are emitted via
// EventBridge (amazon.location source) if you have a tracker association.
// For synchronous position-in-polygon testing without EventBridge, see the
// tracker approach below.

Important behavior note: BatchEvaluateGeofencesCommand stores the position in the geofence collection's internal history and emits EventBridge events for entries and exits — but it does NOT return the entry/exit results directly in the API response body. Only errors are returned synchronously. If you need synchronous inside/outside determination without EventBridge, use the tracker-collection association pattern and poll GetDevicePositionCommand.

EventBridge integration for entry/exit events

When a tracker is associated with a geofence collection, any device position update (via BatchUpdateDevicePositionCommand) automatically triggers EventBridge ENTER and EXIT events when the device crosses a geofence boundary. No explicit call to BatchEvaluateGeofencesCommand needed — the association handles evaluation automatically.

Associate a tracker with a geofence collection:

import { AssociateTrackerConsumerCommand } from "@aws-sdk/client-location";

await location.send(new AssociateTrackerConsumerCommand({
  TrackerName: "my-mcp-tracker",
  ConsumerArn: "arn:aws:geo:us-east-1:123456789012:geofence-collection/my-mcp-geofences",
}));

Now, every BatchUpdateDevicePositionCommand call triggers automatic geofence evaluation against all associated collections. EventBridge events have this structure:

{
  "source": "aws.geo",
  "detail-type": "Location Geofence Event",
  "detail": {
    "EventType": "ENTER",         // "ENTER" | "EXIT"
    "GeofenceId": "warehouse-seattle",
    "DeviceId": "device-001",
    "TrackerName": "my-mcp-tracker",
    "Position": [-122.3321, 47.6062],
    "SampleTime": "2026-11-15T10:30:00.000Z"
  }
}

Create an EventBridge rule to route these events to Lambda, SQS, or any other target:

// EventBridge rule pattern for Location geofence ENTER events
{
  "source": ["aws.geo"],
  "detail-type": ["Location Geofence Event"],
  "detail": {
    "EventType": ["ENTER"],
    "TrackerName": ["my-mcp-tracker"]
  }
}

IAM policy for geofencing

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "geo:PutGeofence",
        "geo:GetGeofence",
        "geo:ListGeofences",
        "geo:BatchEvaluateGeofences",
        "geo:AssociateTrackerConsumer"
      ],
      "Resource": [
        "arn:aws:geo:us-east-1:123456789012:geofence-collection/my-mcp-geofences",
        "arn:aws:geo:us-east-1:123456789012:tracker/my-mcp-tracker"
      ]
    }
  ]
}

Use the geo: IAM prefix. For read-only MCP servers that only check whether positions are inside geofences, restrict to geo:BatchEvaluateGeofences and geo:GetGeofence. Reserve geo:PutGeofence for administrative tools or the system component responsible for maintaining the geofence definitions.

Pricing