UNPKG

firebase-tools

Version:
63 lines (62 loc) 3.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execute_mutation = void 0; const zod_1 = require("zod"); const tool_js_1 = require("../../tool.js"); const util_js_1 = require("../../util.js"); const dataplane = require("../../../dataconnect/dataplaneClient.js"); const fileUtils_js_1 = require("../../../dataconnect/fileUtils.js"); const converter_js_1 = require("./converter.js"); const emulator_js_1 = require("./emulator.js"); exports.execute_mutation = (0, tool_js_1.tool)({ name: "execute_mutation", description: "Executes a deployed Data Connect mutation against a service or its emulator. Can read and write 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: "Execute Data Connect Connector Mutation", readOnlyHint: false, }, _meta: { requiresProject: true, requiresAuth: true, }, }, async ({ operationName, service_id, connector_id, variables: unparsedVariables, use_emulator }, { projectId, config, host }) => { const serviceInfo = await (0, fileUtils_js_1.pickService)(projectId, config, service_id || undefined); let apiClient; if (!connector_id) { if (serviceInfo.connectorInfo.length === 0) { return (0, util_js_1.mcpError)(`Service ${serviceInfo.serviceName} has no connectors`, "NO_CONNECTORS_FOUND"); } if (serviceInfo.connectorInfo.length > 1) { return (0, util_js_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_js_1.getDataConnectEmulatorClient)(host); } else { apiClient = dataplane.dataconnectDataplaneClient(); } const response = await dataplane.executeGraphQLMutation(apiClient, connectorPath, { operationName, variables: (0, converter_js_1.parseVariables)(unparsedVariables), }); return (0, converter_js_1.graphqlResponseToToolResponse)(response.body); });