mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
Move the composition of the default tool services from the Node MCP server into gods-eye-view/tools/services, a portable export. Given a fetch that resolves the sources' /api paths, it builds the same services in a browser as on the local MCP server, so other surfaces can compose the same catalog. Queries still read only their services.
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
/**
|
|
* Local composition of tool services: Core's default services, pointed at a
|
|
* running God's Eye View server's `/api` routes.
|
|
*/
|
|
|
|
import { createToolServices } from '../../src/tools/services.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 = {}) {
|
|
return createToolServices({
|
|
fetchImpl: createApiFetch(options),
|
|
appUrl: options.apiBase ?? DEFAULT_API_BASE,
|
|
});
|
|
}
|