get_stop_searches_by_area
Retrieve stop and search incidents within a 1-mile radius or custom polygon area by specifying coordinates. Filter results by month to analyze patterns in UK police stop-and-search data.
Instructions
Retrieve stop and searches within a 1-mile radius or custom area
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lat | No | Latitude of the centre point | |
| lng | No | Longitude of the centre point | |
| poly | No | Lat/lng pairs defining a polygon | |
| date | No | Specific month (YYYY-MM) |
Implementation Reference
- src/index.ts:408-423 (handler)The handler function for getStopSearchesByArea. Accepts lat, lng, poly, and date arguments. Builds query params and calls the police.uk API endpoint 'stops-street'.
async function getStopSearchesByArea(args: any) { const { lat, lng, poly, date } = args; const params: Record<string, any> = {}; if (date) params.date = date; if (lat !== undefined && lng !== undefined) { params.lat = lat; params.lng = lng; } else if (poly) { params.poly = poly; } else { return []; } return await makeApiRequest('stops-street', params) || []; } - src/index.ts:220-232 (schema)Input schema for get_stop_searches_by_area tool. Defines optional properties: lat (number), lng (number), poly (string), and date (string).
{ name: 'get_stop_searches_by_area', description: 'Retrieve stop and searches within a 1-mile radius or custom area', inputSchema: { type: 'object', properties: { lat: { type: 'number', description: 'Latitude of the centre point' }, lng: { type: 'number', description: 'Longitude of the centre point' }, poly: { type: 'string', description: 'Lat/lng pairs defining a polygon' }, date: { type: 'string', description: 'Specific month (YYYY-MM)' } } } }, - src/index.ts:446-469 (registration)Tool function mapping that registers get_stop_searches_by_area to the getStopSearchesByArea handler function.
// Tool function mapping 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:487-517 (registration)The CallToolRequestSchema handler that dispatches tool calls by name to the corresponding tool function.
// Handle tool calls server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { const toolFunction = toolFunctions[name as keyof typeof toolFunctions]; if (!toolFunction) { throw new Error(`Unknown tool: ${name}`); } const result = await toolFunction(args); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }); - src/index.ts:8-20 (helper)The makeApiRequest helper function used by getStopSearchesByArea 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; } }