UNPKG

firebase-tools

Version:
63 lines (62 loc) 3.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execute_query = void 0; const zod_1 = require("zod"); const tool_1 = require("../../tool"); const util_1 = require("../../util"); const dataplane = require("../../../dataconnect/dataplaneClient"); const fileUtils_1 = require("../../../dataconnect/fileUtils"); const converter_1 = require("./converter"); const emulator_1 = require("./emulator"); exports.execute_query = (0, tool_1.tool)({ name: "execute_query", description: "Executes a deployed Data Connect query against a service or its emulator. Cannot write any data.", inputSchema: zod_1.z.object({ operationName: zod_1.z.string().describe("The name of the deployed operation you want to execute"), service_id: zod_1.z .string() .nullable() .describe("The Firebase Data Connect service ID to look for. If there is only one service defined in firebase.json, this can be omitted and that will be used."), connector_id: zod_1.z .string() .nullable() .describe("The Firebase Data Connect connector ID to look for. If there is only one connector defined in dataconnect.yaml, this can be omitted and that will be used."), variables: zod_1.z .string() .optional() .describe("A stringified JSON object containing the variables needed to execute the operation. The value MUST be able to be parsed as a JSON object."), use_emulator: zod_1.z.boolean().default(false).describe("Target the DataConnect emulator if true."), }), annotations: { title: "Executes a deployed Data Connect query.", readOnlyHint: true, }, _meta: { requiresProject: true, requiresAuth: true, }, }, async ({ operationName, service_id, connector_id, variables: unparsedVariables, use_emulator }, { projectId, config, host }) => { const serviceInfo = await (0, fileUtils_1.pickService)(projectId, config, service_id || undefined); let apiClient; if (!connector_id) { if (serviceInfo.connectorInfo.length === 0) { return (0, util_1.mcpError)(`Service ${serviceInfo.serviceName} has no connectors`, "NO_CONNECTORS_FOUND"); } if (serviceInfo.connectorInfo.length > 1) { return (0, util_1.mcpError)(`Service ${serviceInfo.serviceName} has more than one connector. Please use the connector_id argument to specify which connector this operation is part of.`, "MULTIPLE_CONNECTORS_FOUND"); } connector_id = serviceInfo.connectorInfo[0].connectorYaml.connectorId; } const connectorPath = `${serviceInfo.serviceName}/connectors/${connector_id}`; if (use_emulator) { apiClient = await (0, emulator_1.getDataConnectEmulatorClient)(host); } else { apiClient = dataplane.dataconnectDataplaneClient(); } const response = await dataplane.executeGraphQLQuery(apiClient, connectorPath, { operationName, variables: (0, converter_1.parseVariables)(unparsedVariables), }); return (0, converter_1.graphqlResponseToToolResponse)(response.body); });