Files
gods-eye-view/server/mcp/services.js
T
Sameh Khamis e680a59bf5 feat: add place search and routing tools
Add search_places and places_nearby over the app's Google Places routes,
and plan_route over its OpenStreetMap routing. The place search service
reports when no search key is configured, so an unconfigured server is
not mistaken for an empty result, and rate limits become retry_later.
Route endpoints accept a place name or coordinates.
2026-10-01 12:16:01 -07:00

58 lines
2.1 KiB
JavaScript

/**
* Local composition of tool services: the portable source factories, pointed
* at a running God's Eye View server's `/api` routes.
*/
import { createCctvSource } from '../../src/layers/cctv/source.js';
import { createUsgsEarthquakeSource } from '../../src/layers/earthquakes/source.js';
import { createFirmsSource } from '../../src/layers/firms/source.js';
import { createLaunchSource } from '../../src/layers/launches/source.js';
import { createRadioSource } from '../../src/layers/radio/source.js';
import { createSatelliteSource } from '../../src/layers/satellites/source.js';
import {
createAdsbLolSource,
createOpenSkySource,
} from '../../src/sources/live/standalone.js';
import {
createGeocodePlaceService,
createPlaceSearchService,
createRouteService,
} from '../../src/tools/places.js';
export const DEFAULT_API_BASE = 'http://localhost:4173';
/** Resolve the sources' relative `/api/...` requests against `apiBase`. */
export function createApiFetch({
apiBase = DEFAULT_API_BASE,
fetchImpl = (...args) => globalThis.fetch(...args),
} = {}) {
const base = new URL(apiBase);
if (!['http:', 'https:'].includes(base.protocol))
throw new TypeError(`apiBase must be an http(s) URL: ${apiBase}`);
return (input, init) =>
fetchImpl(
typeof input === 'string' && input.startsWith('/')
? new URL(input, base)
: input,
init,
);
}
/** Construct every service Core's tools read, backed by the local server. */
export function createLocalToolServices(options = {}) {
const fetchImpl = createApiFetch(options);
return {
earthquakes: createUsgsEarthquakeSource({ fetchImpl }),
fires: createFirmsSource({ fetchImpl }),
launches: createLaunchSource({ fetchImpl }),
aircraft: createOpenSkySource({ fetchImpl }),
military: createAdsbLolSource({ fetchImpl }),
satellites: createSatelliteSource({ fetchImpl }),
cctv: createCctvSource({ fetchImpl }),
radio: createRadioSource({ fetchImpl }),
placeSearch: createPlaceSearchService({ fetchImpl }),
routing: createRouteService({ fetchImpl }),
places: createGeocodePlaceService({ fetchImpl }),
};
}