get_crimes_at_location
Retrieve street-level crimes at a location using latitude/longitude or location ID, with optional filter by month (YYYY-MM).
Instructions
Retrieve crimes at a specific location by ID or nearest to lat/lng
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lat | No | Latitude of the requested crime area | |
| lng | No | Longitude of the requested crime area | |
| location_id | No | The ID of the location | |
| date | No | Limit results to a specific month (YYYY-MM) |
Implementation Reference
- src/index.ts:309-324 (handler)The handler function getCrimesAtLocation that executes the tool logic. It accepts lat/lng or location_id and date params, builds the API request, and calls the police.uk 'crimes-at-location' endpoint.
async function getCrimesAtLocation(args: any) { const { lat, lng, location_id, date } = args; const params: Record<string, any> = {}; if (date) params.date = date; if (location_id) { params.location_id = location_id; } else if (lat && lng) { params.lat = lat; params.lng = lng; } else { return []; } return await makeApiRequest('crimes-at-location', params) || []; } - src/index.ts:52-64 (schema)Input schema definition for the get_crimes_at_location tool, defining properties: lat (number), lng (number), location_id (number), date (string).
{ name: 'get_crimes_at_location', description: 'Retrieve crimes at a specific location by ID or nearest to lat/lng', inputSchema: { type: 'object', properties: { lat: { type: 'number', description: 'Latitude of the requested crime area' }, lng: { type: 'number', description: 'Longitude of the requested crime area' }, location_id: { type: 'number', description: 'The ID of the location' }, date: { type: 'string', description: 'Limit results to a specific month (YYYY-MM)' } } } }, - src/index.ts:447-469 (registration)Registration of the tool function mapping, where get_crimes_at_location is mapped to the getCrimesAtLocation handler function.
const toolFunctions = { get_street_level_crimes: getStreetLevelCrimes, get_street_level_outcomes: getStreetLevelOutcomes, get_crimes_at_location: getCrimesAtLocation, get_crimes_no_location: getCrimesNoLocation, get_crime_categories: getCrimeCategories, get_last_updated: getLastUpdated, get_outcomes_for_crime: getOutcomesForCrime, get_list_of_forces: getListOfForces, get_force_details: getForceDetails, get_senior_officers: getSeniorOfficers, get_neighbourhoods: getNeighbourhoods, get_neighbourhood_details: getNeighbourhoodDetails, get_neighbourhood_boundary: getNeighbourhoodBoundary, get_neighbourhood_team: getNeighbourhoodTeam, get_neighbourhood_events: getNeighbourhoodEvents, get_neighbourhood_priorities: getNeighbourhoodPriorities, locate_neighbourhood: locateNeighbourhood, get_stop_searches_by_area: getStopSearchesByArea, get_stop_searches_by_location: getStopSearchesByLocation, get_stop_searches_no_location: getStopSearchesNoLocation, get_stop_searches_by_force: getStopSearchesByForce }; - src/index.ts:8-20 (helper)The makeApiRequest helper function used by getCrimesAtLocation to make HTTP requests to the police.uk API.
// Helper function to make API requests to police.uk async function makeApiRequest(endpoint: string, params?: Record<string, any>) { const baseUrl = 'https://data.police.uk/api'; const url = `${baseUrl}/${endpoint}`; try { const response = await axios.get(url, { params, timeout: 10000 }); return response.data; } catch (error) { console.error(`API request failed: ${error}`); return null; } }