firebase-tools-with-isolate 14.10.1 → 14.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api.js +5 -1
- package/lib/apphosting/backend.js +40 -15
- package/lib/apptesting/ensureProjectConfigured.js +56 -0
- package/lib/apptesting/invokeTests.js +40 -0
- package/lib/apptesting/parseTestFiles.js +75 -0
- package/lib/apptesting/types.js +18 -0
- package/lib/auth.js +37 -2
- package/lib/command.js +24 -5
- package/lib/commands/apphosting-backends-create.js +8 -5
- package/lib/commands/apptesting-execute.js +101 -0
- package/lib/commands/dataconnect-sdk-generate.js +28 -26
- package/lib/commands/dataconnect-services-list.js +1 -1
- package/lib/commands/dataconnect-sql-diff.js +2 -2
- package/lib/commands/dataconnect-sql-grant.js +7 -2
- package/lib/commands/dataconnect-sql-migrate.js +2 -2
- package/lib/commands/dataconnect-sql-setup.js +3 -5
- package/lib/commands/dataconnect-sql-shell.js +2 -2
- package/lib/commands/ext-export.js +1 -1
- package/lib/commands/firestore-bulkdelete.js +73 -0
- package/lib/commands/firestore-databases-create.js +11 -0
- package/lib/commands/firestore-operations-cancel.js +44 -0
- package/lib/commands/firestore-operations-describe.js +29 -0
- package/lib/commands/firestore-operations-list.js +29 -0
- package/lib/commands/firestore-utils.js +15 -0
- package/lib/commands/functions-config-clone.js +2 -0
- package/lib/commands/functions-config-export.js +5 -2
- package/lib/commands/functions-config-get.js +2 -0
- package/lib/commands/functions-config-set.js +2 -0
- package/lib/commands/functions-config-unset.js +2 -0
- package/lib/commands/index.js +9 -0
- package/lib/commands/init.js +24 -4
- package/lib/commands/internaltesting-functions-discover.js +20 -5
- package/lib/commands/login.js +13 -9
- package/lib/commands/use.js +5 -0
- package/lib/config.js +16 -4
- package/lib/crashlytics/addNote.js +27 -0
- package/lib/crashlytics/buildToolsJarHelper.js +1 -2
- package/lib/crashlytics/deleteNote.js +23 -0
- package/lib/crashlytics/getIssueDetails.js +26 -0
- package/lib/crashlytics/getSampleCrash.js +34 -0
- package/lib/crashlytics/listNotes.js +29 -0
- package/lib/crashlytics/listTopDevices.js +33 -0
- package/lib/crashlytics/listTopIssues.js +8 -23
- package/lib/crashlytics/listTopOperatingSystems.js +32 -0
- package/lib/crashlytics/listTopVersions.js +32 -0
- package/lib/crashlytics/updateIssue.js +35 -0
- package/lib/crashlytics/utils.js +38 -0
- package/lib/dataconnect/appFinder.js +102 -0
- package/lib/dataconnect/client.js +23 -15
- package/lib/dataconnect/ensureApis.js +6 -9
- package/lib/dataconnect/errors.js +7 -1
- package/lib/dataconnect/freeTrial.js +16 -38
- package/lib/dataconnect/load.js +105 -6
- package/lib/dataconnect/provisionCloudSql.js +67 -70
- package/lib/dataconnect/schemaMigration.js +219 -169
- package/lib/deploy/dataconnect/deploy.js +7 -9
- package/lib/deploy/dataconnect/prepare.js +7 -12
- package/lib/deploy/dataconnect/release.js +43 -31
- package/lib/deploy/firestore/deploy.js +10 -0
- package/lib/deploy/functions/backend.js +7 -1
- package/lib/deploy/functions/build.js +28 -14
- package/lib/deploy/functions/deploy.js +3 -2
- package/lib/deploy/functions/ensure.js +1 -1
- package/lib/deploy/functions/functionsDeployHelper.js +8 -1
- package/lib/deploy/functions/params.js +4 -0
- package/lib/deploy/functions/prepare.js +25 -13
- package/lib/deploy/functions/pricing.js +12 -5
- package/lib/deploy/functions/release/fabricator.js +25 -3
- package/lib/deploy/functions/release/reporter.js +1 -0
- package/lib/deploy/functions/runtimes/discovery/index.js +52 -5
- package/lib/deploy/functions/runtimes/node/index.js +83 -51
- package/lib/emulator/auth/operations.js +10 -1
- package/lib/emulator/commandUtils.js +7 -1
- package/lib/emulator/controller.js +22 -34
- package/lib/emulator/dataconnectEmulator.js +27 -24
- package/lib/emulator/downloadableEmulatorInfo.json +18 -18
- package/lib/emulator/env.js +2 -1
- package/lib/emulator/functionsEmulator.js +12 -2
- package/lib/emulator/hub.js +11 -8
- package/lib/emulator/tasksEmulator.js +1 -1
- package/lib/emulator/ui.js +3 -1
- package/lib/env.js +18 -0
- package/lib/experiments.js +20 -0
- package/lib/extensions/extensionsHelper.js +4 -15
- package/lib/extensions/runtimes/common.js +3 -2
- package/lib/extensions/utils.js +1 -12
- package/lib/firestore/api-sort.js +96 -3
- package/lib/firestore/api-types.js +20 -1
- package/lib/firestore/api.js +144 -15
- package/lib/firestore/pretty-print.js +35 -1
- package/lib/firestore/validator.js +1 -1
- package/lib/functional.js +7 -1
- package/lib/functions/deprecationWarnings.js +21 -0
- package/lib/functions/env.js +31 -16
- package/lib/functions/projectConfig.js +87 -8
- package/lib/functions/secrets.js +3 -0
- package/lib/gcp/cloudfunctions.js +1 -6
- package/lib/gcp/cloudfunctionsv2.js +3 -39
- package/lib/gcp/cloudscheduler.js +1 -1
- package/lib/gcp/cloudsql/cloudsqladmin.js +4 -16
- package/lib/gcp/cloudsql/connect.js +4 -3
- package/lib/gcp/cloudsql/permissionsSetup.js +23 -16
- package/lib/gcp/k8s.js +32 -0
- package/lib/gcp/runv2.js +181 -0
- package/lib/gemini/fdcExperience.js +5 -3
- package/lib/init/features/aitools/claude.js +43 -0
- package/lib/init/features/aitools/cursor.js +61 -0
- package/lib/init/features/aitools/gemini.js +58 -0
- package/lib/init/features/aitools/index.js +28 -0
- package/lib/init/features/aitools/promptUpdater.js +111 -0
- package/lib/init/features/aitools/studio.js +17 -0
- package/lib/init/features/aitools/types.js +2 -0
- package/lib/init/features/aitools.js +83 -0
- package/lib/init/features/apptesting/index.js +34 -0
- package/lib/init/features/dataconnect/create_app.js +53 -0
- package/lib/init/features/dataconnect/index.js +280 -186
- package/lib/init/features/dataconnect/sdk.js +232 -144
- package/lib/init/features/index.js +8 -3
- package/lib/init/features/project.js +4 -0
- package/lib/init/index.js +18 -2
- package/lib/management/apps.js +3 -3
- package/lib/management/studio.js +120 -0
- package/lib/mcp/errors.js +5 -7
- package/lib/mcp/index.js +179 -61
- package/lib/mcp/logging-transport.js +23 -0
- package/lib/mcp/prompt.js +10 -0
- package/lib/mcp/prompts/core/deploy.js +101 -0
- package/lib/mcp/prompts/core/index.js +5 -0
- package/lib/mcp/prompts/crashlytics/connect.js +114 -0
- package/lib/mcp/prompts/crashlytics/index.js +5 -0
- package/lib/mcp/prompts/dataconnect/index.js +9 -0
- package/lib/mcp/prompts/dataconnect/schema.js +67 -0
- package/lib/mcp/prompts/index.js +47 -0
- package/lib/mcp/tools/apphosting/fetch_logs.js +22 -22
- package/lib/mcp/tools/apphosting/list_backends.js +10 -10
- package/lib/mcp/tools/auth/disable_user.js +7 -7
- package/lib/mcp/tools/auth/get_user.js +13 -6
- package/lib/mcp/tools/auth/index.js +10 -10
- package/lib/mcp/tools/auth/list_users.js +6 -6
- package/lib/mcp/tools/auth/set_claims.js +7 -7
- package/lib/mcp/tools/auth/set_sms_region_policy.js +6 -6
- package/lib/mcp/tools/core/consult_assistant.js +13 -8
- package/lib/mcp/tools/core/create_android_sha.js +9 -9
- package/lib/mcp/tools/core/create_app.js +7 -7
- package/lib/mcp/tools/core/create_project.js +13 -13
- package/lib/mcp/tools/core/get_admin_sdk_config.js +7 -7
- package/lib/mcp/tools/core/get_environment.js +8 -8
- package/lib/mcp/tools/core/get_project.js +5 -5
- package/lib/mcp/tools/core/get_sdk_config.js +19 -9
- package/lib/mcp/tools/core/index.js +28 -24
- package/lib/mcp/tools/core/init.js +39 -16
- package/lib/mcp/tools/core/list_apps.js +6 -6
- package/lib/mcp/tools/core/list_projects.js +6 -6
- package/lib/mcp/tools/core/login.js +46 -0
- package/lib/mcp/tools/core/logout.js +62 -0
- package/lib/mcp/tools/core/update_environment.js +10 -10
- package/lib/mcp/tools/crashlytics/add_note.js +32 -0
- package/lib/mcp/tools/crashlytics/constants.js +11 -0
- package/lib/mcp/tools/crashlytics/delete_note.js +35 -0
- package/lib/mcp/tools/crashlytics/get_issue_details.js +31 -0
- package/lib/mcp/tools/crashlytics/get_sample_crash.js +43 -0
- package/lib/mcp/tools/crashlytics/index.js +22 -2
- package/lib/mcp/tools/crashlytics/list_notes.js +37 -0
- package/lib/mcp/tools/crashlytics/list_top_devices.js +33 -0
- package/lib/mcp/tools/crashlytics/list_top_issues.js +12 -13
- package/lib/mcp/tools/crashlytics/list_top_operating_systems.js +33 -0
- package/lib/mcp/tools/crashlytics/list_top_versions.js +33 -0
- package/lib/mcp/tools/crashlytics/update_issue.js +37 -0
- package/lib/mcp/tools/database/get_data.js +49 -0
- package/lib/mcp/tools/database/get_rules.js +39 -0
- package/lib/mcp/tools/database/index.js +8 -0
- package/lib/mcp/tools/database/set_data.js +57 -0
- package/lib/mcp/tools/database/validate_rules.js +41 -0
- package/lib/mcp/tools/dataconnect/compile.js +43 -0
- package/lib/mcp/tools/dataconnect/execute.js +71 -0
- package/lib/mcp/tools/dataconnect/generate_operation.js +8 -8
- package/lib/mcp/tools/dataconnect/generate_schema.js +6 -6
- package/lib/mcp/tools/dataconnect/index.js +10 -18
- package/lib/mcp/tools/dataconnect/list_services.js +107 -11
- package/lib/mcp/tools/firestore/delete_document.js +13 -13
- package/lib/mcp/tools/firestore/get_documents.js +13 -13
- package/lib/mcp/tools/firestore/list_collections.js +7 -10
- package/lib/mcp/tools/firestore/query_collection.js +13 -13
- package/lib/mcp/tools/index.js +24 -18
- package/lib/mcp/tools/messaging/index.js +2 -2
- package/lib/mcp/tools/messaging/send_message.js +7 -7
- package/lib/mcp/tools/remoteconfig/get_template.js +5 -5
- package/lib/mcp/tools/remoteconfig/index.js +4 -4
- package/lib/mcp/tools/remoteconfig/publish_template.js +7 -7
- package/lib/mcp/tools/remoteconfig/rollback_template.js +6 -6
- package/lib/mcp/tools/rules/get_rules.js +8 -8
- package/lib/mcp/tools/rules/validate_rules.js +10 -10
- package/lib/mcp/tools/storage/get_download_url.js +8 -8
- package/lib/mcp/tools/storage/get_rules.js +8 -8
- package/lib/mcp/types.js +2 -0
- package/lib/mcp/util/dataconnect/compile.js +20 -0
- package/lib/mcp/util/dataconnect/content.js +655 -0
- package/lib/mcp/util/dataconnect/emulator.js +16 -0
- package/lib/mcp/util.js +5 -18
- package/lib/requireAuth.js +14 -4
- package/lib/rtdb.js +10 -6
- package/lib/scopes.js +2 -1
- package/lib/serve/functions.js +4 -3
- package/lib/timeout.js +21 -0
- package/lib/track.js +18 -1
- package/lib/unzip.js +13 -0
- package/lib/utils.js +76 -2
- package/package.json +5 -3
- package/prompts/FIREBASE.md +121 -0
- package/prompts/FIREBASE_FUNCTIONS.md +221 -0
- package/schema/apptesting-yaml.json +64 -0
- package/schema/firebase-config.json +163 -53
- package/templates/init/aitools/cursor-rules-header.txt +8 -0
- package/templates/init/aitools/gemini-extension.json +11 -0
- package/templates/init/apptesting/smoke_test.yaml +6 -0
- package/templates/init/dataconnect/connector.yaml +0 -16
- package/templates/init/dataconnect/dataconnect.yaml +2 -1
- package/templates/init/dataconnect/mutations.gql +29 -29
- package/templates/init/dataconnect/queries.gql +73 -73
- package/templates/init/dataconnect/schema.gql +48 -48
- package/templates/init/firestore/firestore.indexes.json +26 -1
- package/lib/dataconnect/fileUtils.js +0 -168
- package/lib/emulator/adminSdkConfig.test.js +0 -16
- package/lib/extensions/resolveSource.js +0 -23
- package/lib/firestore/api-sort.test.js +0 -74
- package/lib/firestore/backupUtils.test.js +0 -18
- package/lib/firestore/pretty-print.test.js +0 -61
- package/lib/firestore/util.test.js +0 -42
- package/lib/mcp/tools/dataconnect/emulator.js +0 -16
- package/lib/mcp/tools/dataconnect/execute_graphql.js +0 -48
- package/lib/mcp/tools/dataconnect/execute_graphql_read.js +0 -48
- package/lib/mcp/tools/dataconnect/execute_mutation.js +0 -62
- package/lib/mcp/tools/dataconnect/execute_query.js +0 -62
- package/lib/mcp/tools/dataconnect/get_connector.js +0 -31
- package/lib/mcp/tools/dataconnect/get_schema.js +0 -31
- /package/lib/mcp/{tools → util}/dataconnect/converter.js +0 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateStudioFirebaseProject = exports.reconcileStudioFirebaseProject = void 0;
|
|
4
|
+
const apiv2_1 = require("../apiv2");
|
|
5
|
+
const prompt = require("../prompt");
|
|
6
|
+
const api = require("../api");
|
|
7
|
+
const logger_1 = require("../logger");
|
|
8
|
+
const utils = require("../utils");
|
|
9
|
+
const configstore_1 = require("../configstore");
|
|
10
|
+
const TIMEOUT_MILLIS = 30000;
|
|
11
|
+
const studioClient = new apiv2_1.Client({
|
|
12
|
+
urlPrefix: api.studioApiOrigin(),
|
|
13
|
+
apiVersion: "v1",
|
|
14
|
+
});
|
|
15
|
+
async function reconcileStudioFirebaseProject(options, activeProjectFromConfig) {
|
|
16
|
+
const studioWorkspace = await getStudioWorkspace();
|
|
17
|
+
if (!studioWorkspace) {
|
|
18
|
+
return activeProjectFromConfig;
|
|
19
|
+
}
|
|
20
|
+
if (!studioWorkspace.firebaseProjectId) {
|
|
21
|
+
if (activeProjectFromConfig) {
|
|
22
|
+
await updateStudioFirebaseProject(activeProjectFromConfig);
|
|
23
|
+
}
|
|
24
|
+
return activeProjectFromConfig;
|
|
25
|
+
}
|
|
26
|
+
if (!activeProjectFromConfig) {
|
|
27
|
+
await writeStudioProjectToConfigStore(options, studioWorkspace.firebaseProjectId);
|
|
28
|
+
return studioWorkspace.firebaseProjectId;
|
|
29
|
+
}
|
|
30
|
+
if (studioWorkspace.firebaseProjectId !== activeProjectFromConfig && !options.nonInteractive) {
|
|
31
|
+
const choices = [
|
|
32
|
+
{
|
|
33
|
+
name: `Set ${studioWorkspace.firebaseProjectId} from Firebase Studio as my active project in both places`,
|
|
34
|
+
value: false,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: `Set ${activeProjectFromConfig} from Firebase CLI as my active project in both places`,
|
|
38
|
+
value: true,
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
const useCliProject = await prompt.select({
|
|
42
|
+
message: "Found different active Firebase Projects in the Firebase CLI and your Firebase Studio Workspace. Which project would you like to set as your active project?",
|
|
43
|
+
choices,
|
|
44
|
+
});
|
|
45
|
+
if (useCliProject) {
|
|
46
|
+
await updateStudioFirebaseProject(activeProjectFromConfig);
|
|
47
|
+
return activeProjectFromConfig;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
await writeStudioProjectToConfigStore(options, studioWorkspace.firebaseProjectId);
|
|
51
|
+
return studioWorkspace.firebaseProjectId;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return studioWorkspace.firebaseProjectId;
|
|
55
|
+
}
|
|
56
|
+
exports.reconcileStudioFirebaseProject = reconcileStudioFirebaseProject;
|
|
57
|
+
async function getStudioWorkspace() {
|
|
58
|
+
const workspaceId = process.env.WORKSPACE_SLUG;
|
|
59
|
+
if (!workspaceId) {
|
|
60
|
+
logger_1.logger.error(`Failed to fetch Firebase Project from Studio Workspace because WORKSPACE_SLUG environment variable is empty`);
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const res = await studioClient.request({
|
|
65
|
+
method: "GET",
|
|
66
|
+
path: `/workspaces/${workspaceId}`,
|
|
67
|
+
timeout: TIMEOUT_MILLIS,
|
|
68
|
+
});
|
|
69
|
+
return res.body;
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
let message = err.message;
|
|
73
|
+
if (err.original) {
|
|
74
|
+
message += ` (original: ${err.original.message})`;
|
|
75
|
+
}
|
|
76
|
+
logger_1.logger.error(`Failed to fetch Firebase Project from current Studio Workspace: ${message}`);
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function writeStudioProjectToConfigStore(options, studioProjectId) {
|
|
81
|
+
if (options.projectRoot) {
|
|
82
|
+
logger_1.logger.info(`Updating Firebase CLI active project to match Studio Workspace '${studioProjectId}'`);
|
|
83
|
+
utils.makeActiveProject(options.projectRoot, studioProjectId);
|
|
84
|
+
recordStudioProjectSyncTime();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function updateStudioFirebaseProject(projectId) {
|
|
88
|
+
logger_1.logger.info(`Updating Studio Workspace active project to match Firebase CLI '${projectId}'`);
|
|
89
|
+
const workspaceId = process.env.WORKSPACE_SLUG;
|
|
90
|
+
if (!workspaceId) {
|
|
91
|
+
logger_1.logger.error(`Failed to update Firebase Project for Studio Workspace because WORKSPACE_SLUG environment variable is empty`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
await studioClient.request({
|
|
96
|
+
method: "PATCH",
|
|
97
|
+
path: `/workspaces/${workspaceId}`,
|
|
98
|
+
responseType: "json",
|
|
99
|
+
body: {
|
|
100
|
+
firebaseProjectId: projectId,
|
|
101
|
+
},
|
|
102
|
+
queryParams: {
|
|
103
|
+
updateMask: "workspace.firebaseProjectId",
|
|
104
|
+
},
|
|
105
|
+
timeout: TIMEOUT_MILLIS,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
let message = err.message;
|
|
110
|
+
if (err.original) {
|
|
111
|
+
message += ` (original: ${err.original.message})`;
|
|
112
|
+
}
|
|
113
|
+
logger_1.logger.debug(`Failed to update active Firebase Project for current Studio Workspace: ${message}`);
|
|
114
|
+
}
|
|
115
|
+
recordStudioProjectSyncTime();
|
|
116
|
+
}
|
|
117
|
+
exports.updateStudioFirebaseProject = updateStudioFirebaseProject;
|
|
118
|
+
function recordStudioProjectSyncTime() {
|
|
119
|
+
configstore_1.configstore.set("firebaseStudioProjectLastSynced", Date.now());
|
|
120
|
+
}
|
package/lib/mcp/errors.js
CHANGED
|
@@ -3,13 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mcpGeminiError = exports.mcpAuthError = exports.NO_PROJECT_ERROR = void 0;
|
|
4
4
|
const util_1 = require("./util");
|
|
5
5
|
exports.NO_PROJECT_ERROR = (0, util_1.mcpError)('No active project was found. Use the `firebase_update_environment` tool to set the project directory to an absolute folder location containing a firebase.json config file. Alternatively, change the MCP server config to add [...,"--dir","/absolute/path/to/project/directory"] in its command-line arguments.', "PRECONDITION_FAILED");
|
|
6
|
-
function mcpAuthError() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
\`\`\`
|
|
12
|
-
|
|
6
|
+
function mcpAuthError(skipADC) {
|
|
7
|
+
if (skipADC) {
|
|
8
|
+
return (0, util_1.mcpError)(`The user is not currently logged into the Firebase CLI, which is required to use this tool. Please run the 'firebase_login' tool to log in.`);
|
|
9
|
+
}
|
|
10
|
+
return (0, util_1.mcpError)(`The user is not currently logged into the Firebase CLI, which is required to use this tool. Please run the 'firebase_login' tool to log in, or instruct the user to configure [Application Default Credentials][ADC] on their machine.
|
|
13
11
|
[ADC]: https://cloud.google.com/docs/authentication/application-default-credentials`);
|
|
14
12
|
}
|
|
15
13
|
exports.mcpAuthError = mcpAuthError;
|
package/lib/mcp/index.js
CHANGED
|
@@ -4,41 +4,72 @@ exports.FirebaseMcpServer = void 0;
|
|
|
4
4
|
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
5
5
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
6
6
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
7
|
+
const util_1 = require("./util");
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
const index_1 = require("./tools/index");
|
|
10
|
+
const index_2 = require("./prompts/index");
|
|
11
|
+
const configstore_1 = require("../configstore");
|
|
12
|
+
const command_1 = require("../command");
|
|
13
|
+
const requireAuth_1 = require("../requireAuth");
|
|
14
|
+
const projectUtils_1 = require("../projectUtils");
|
|
15
|
+
const errors_1 = require("./errors");
|
|
16
|
+
const track_1 = require("../track");
|
|
17
|
+
const config_1 = require("../config");
|
|
18
|
+
const rc_1 = require("../rc");
|
|
19
|
+
const hubClient_1 = require("../emulator/hubClient");
|
|
19
20
|
const node_fs_1 = require("node:fs");
|
|
20
|
-
const
|
|
21
|
-
const api = require("../api
|
|
22
|
-
const
|
|
23
|
-
const
|
|
21
|
+
const ensureApiEnabled_1 = require("../ensureApiEnabled");
|
|
22
|
+
const api = require("../api");
|
|
23
|
+
const logging_transport_1 = require("./logging-transport");
|
|
24
|
+
const env_1 = require("../env");
|
|
25
|
+
const timeout_1 = require("../timeout");
|
|
26
|
+
const SERVER_VERSION = "0.3.0";
|
|
27
|
+
const cmd = new command_1.Command("experimental:mcp");
|
|
28
|
+
const orderedLogLevels = [
|
|
29
|
+
"debug",
|
|
30
|
+
"info",
|
|
31
|
+
"notice",
|
|
32
|
+
"warning",
|
|
33
|
+
"error",
|
|
34
|
+
"critical",
|
|
35
|
+
"alert",
|
|
36
|
+
"emergency",
|
|
37
|
+
];
|
|
24
38
|
class FirebaseMcpServer {
|
|
39
|
+
async trackGA4(event, params = {}) {
|
|
40
|
+
if (!this.clientInfo)
|
|
41
|
+
await (0, timeout_1.timeoutFallback)(this.ready(), null, 2000);
|
|
42
|
+
const clientInfoParams = {
|
|
43
|
+
mcp_client_name: this.clientInfo?.name || "<unknown-client>",
|
|
44
|
+
mcp_client_version: this.clientInfo?.version || "<unknown-version>",
|
|
45
|
+
};
|
|
46
|
+
(0, track_1.trackGA4)(event, { ...params, ...clientInfoParams });
|
|
47
|
+
}
|
|
25
48
|
constructor(options) {
|
|
26
49
|
this._ready = false;
|
|
27
50
|
this._readyPromises = [];
|
|
51
|
+
this.currentLogLevel = process.env.FIREBASE_MCP_DEBUG_LOG ? "debug" : undefined;
|
|
52
|
+
this.logger = Object.fromEntries(orderedLogLevels.map((logLevel) => [
|
|
53
|
+
logLevel,
|
|
54
|
+
(message) => this.log(logLevel, message),
|
|
55
|
+
]));
|
|
28
56
|
this.activeFeatures = options.activeFeatures;
|
|
29
57
|
this.startupRoot = options.projectRoot || process.env.PROJECT_ROOT;
|
|
30
58
|
this.server = new index_js_1.Server({ name: "firebase", version: SERVER_VERSION });
|
|
31
|
-
this.server.registerCapabilities({
|
|
59
|
+
this.server.registerCapabilities({
|
|
60
|
+
tools: { listChanged: true },
|
|
61
|
+
logging: {},
|
|
62
|
+
prompts: { listChanged: true },
|
|
63
|
+
});
|
|
32
64
|
this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, this.mcpListTools.bind(this));
|
|
33
65
|
this.server.setRequestHandler(types_js_1.CallToolRequestSchema, this.mcpCallTool.bind(this));
|
|
66
|
+
this.server.setRequestHandler(types_js_1.ListPromptsRequestSchema, this.mcpListPrompts.bind(this));
|
|
67
|
+
this.server.setRequestHandler(types_js_1.GetPromptRequestSchema, this.mcpGetPrompt.bind(this));
|
|
34
68
|
this.server.oninitialized = async () => {
|
|
35
69
|
const clientInfo = this.server.getClientVersion();
|
|
36
70
|
this.clientInfo = clientInfo;
|
|
37
71
|
if (clientInfo?.name) {
|
|
38
|
-
|
|
39
|
-
mcp_client_name: clientInfo.name,
|
|
40
|
-
mcp_client_version: clientInfo.version,
|
|
41
|
-
});
|
|
72
|
+
this.trackGA4("mcp_client_connected");
|
|
42
73
|
}
|
|
43
74
|
if (!this.clientInfo?.name)
|
|
44
75
|
this.clientInfo = { name: "<unknown-client>" };
|
|
@@ -47,6 +78,10 @@ class FirebaseMcpServer {
|
|
|
47
78
|
this._readyPromises.pop()?.resolve();
|
|
48
79
|
}
|
|
49
80
|
};
|
|
81
|
+
this.server.setRequestHandler(types_js_1.SetLevelRequestSchema, async ({ params }) => {
|
|
82
|
+
this.currentLogLevel = params.level;
|
|
83
|
+
return {};
|
|
84
|
+
});
|
|
50
85
|
this.detectProjectRoot();
|
|
51
86
|
this.detectActiveFeatures();
|
|
52
87
|
}
|
|
@@ -57,37 +92,43 @@ class FirebaseMcpServer {
|
|
|
57
92
|
this._readyPromises.push({ resolve: resolve, reject });
|
|
58
93
|
});
|
|
59
94
|
}
|
|
95
|
+
get clientName() {
|
|
96
|
+
return this.clientInfo?.name ?? ((0, env_1.isFirebaseStudio)() ? "Firebase Studio" : "<unknown-client>");
|
|
97
|
+
}
|
|
60
98
|
get clientConfigKey() {
|
|
61
|
-
return `mcp.clientConfigs.${this.
|
|
99
|
+
return `mcp.clientConfigs.${this.clientName}:${this.startupRoot || process.cwd()}`;
|
|
62
100
|
}
|
|
63
101
|
getStoredClientConfig() {
|
|
64
|
-
return
|
|
102
|
+
return configstore_1.configstore.get(this.clientConfigKey) || {};
|
|
65
103
|
}
|
|
66
104
|
updateStoredClientConfig(update) {
|
|
67
|
-
const config =
|
|
105
|
+
const config = configstore_1.configstore.get(this.clientConfigKey) || {};
|
|
68
106
|
const newConfig = { ...config, ...update };
|
|
69
|
-
|
|
107
|
+
configstore_1.configstore.set(this.clientConfigKey, newConfig);
|
|
70
108
|
return newConfig;
|
|
71
109
|
}
|
|
72
110
|
async detectProjectRoot() {
|
|
73
|
-
await this.ready();
|
|
111
|
+
await (0, timeout_1.timeoutFallback)(this.ready(), null, 2000);
|
|
74
112
|
if (this.cachedProjectRoot)
|
|
75
113
|
return this.cachedProjectRoot;
|
|
76
114
|
const storedRoot = this.getStoredClientConfig().projectRoot;
|
|
77
115
|
this.cachedProjectRoot = storedRoot || this.startupRoot || process.cwd();
|
|
116
|
+
this.log("debug", "detected and cached project root: " + this.cachedProjectRoot);
|
|
78
117
|
return this.cachedProjectRoot;
|
|
79
118
|
}
|
|
80
119
|
async detectActiveFeatures() {
|
|
81
120
|
if (this.detectedFeatures?.length)
|
|
82
121
|
return this.detectedFeatures;
|
|
122
|
+
this.log("debug", "detecting active features of Firebase MCP server...");
|
|
83
123
|
const options = await this.resolveOptions();
|
|
84
124
|
const projectId = await this.getProjectId();
|
|
85
|
-
const detected = await Promise.all(
|
|
86
|
-
if (await (0,
|
|
125
|
+
const detected = await Promise.all(types_1.SERVER_FEATURES.map(async (f) => {
|
|
126
|
+
if (await (0, util_1.checkFeatureActive)(f, projectId, options))
|
|
87
127
|
return f;
|
|
88
128
|
return null;
|
|
89
129
|
}));
|
|
90
130
|
this.detectedFeatures = detected.filter((f) => !!f);
|
|
131
|
+
this.log("debug", "detected features of Firebase MCP server: " + (this.detectedFeatures.join(", ") || "<none>"));
|
|
91
132
|
return this.detectedFeatures;
|
|
92
133
|
}
|
|
93
134
|
async getEmulatorHubClient() {
|
|
@@ -95,10 +136,7 @@ class FirebaseMcpServer {
|
|
|
95
136
|
return this.emulatorHubClient;
|
|
96
137
|
}
|
|
97
138
|
const projectId = await this.getProjectId();
|
|
98
|
-
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
this.emulatorHubClient = new hubClient_js_1.EmulatorHubClient(projectId);
|
|
139
|
+
this.emulatorHubClient = new hubClient_1.EmulatorHubClient(projectId);
|
|
102
140
|
return this.emulatorHubClient;
|
|
103
141
|
}
|
|
104
142
|
async getEmulatorUrl(emulatorType) {
|
|
@@ -109,22 +147,29 @@ class FirebaseMcpServer {
|
|
|
109
147
|
const emulators = await hubClient.getEmulators();
|
|
110
148
|
const emulatorInfo = emulators[emulatorType];
|
|
111
149
|
if (!emulatorInfo) {
|
|
112
|
-
throw Error(
|
|
150
|
+
throw Error(`No ${emulatorType} Emulator found running. Make sure your project firebase.json file includes ${emulatorType} and then rerun emulator using \`firebase emulators:start\` from your project directory.`);
|
|
113
151
|
}
|
|
114
152
|
const host = emulatorInfo.host.includes(":") ? `[${emulatorInfo.host}]` : emulatorInfo.host;
|
|
115
153
|
return `http://${host}:${emulatorInfo.port}`;
|
|
116
154
|
}
|
|
117
155
|
get availableTools() {
|
|
118
|
-
return (0,
|
|
156
|
+
return (0, index_1.availableTools)(this.activeFeatures?.length ? this.activeFeatures : this.detectedFeatures);
|
|
119
157
|
}
|
|
120
158
|
getTool(name) {
|
|
121
159
|
return this.availableTools.find((t) => t.mcp.name === name) || null;
|
|
122
160
|
}
|
|
161
|
+
get availablePrompts() {
|
|
162
|
+
return (0, index_2.availablePrompts)(this.activeFeatures?.length ? this.activeFeatures : this.detectedFeatures);
|
|
163
|
+
}
|
|
164
|
+
getPrompt(name) {
|
|
165
|
+
return this.availablePrompts.find((p) => p.mcp.name === name) || null;
|
|
166
|
+
}
|
|
123
167
|
setProjectRoot(newRoot) {
|
|
124
168
|
this.updateStoredClientConfig({ projectRoot: newRoot });
|
|
125
169
|
this.cachedProjectRoot = newRoot || undefined;
|
|
126
170
|
this.detectedFeatures = undefined;
|
|
127
171
|
void this.server.sendToolListChanged();
|
|
172
|
+
void this.server.sendPromptListChanged();
|
|
128
173
|
}
|
|
129
174
|
async resolveOptions() {
|
|
130
175
|
const options = { cwd: this.cachedProjectRoot, isMCP: true };
|
|
@@ -132,30 +177,32 @@ class FirebaseMcpServer {
|
|
|
132
177
|
return options;
|
|
133
178
|
}
|
|
134
179
|
async getProjectId() {
|
|
135
|
-
return (0,
|
|
180
|
+
return (0, projectUtils_1.getProjectId)(await this.resolveOptions());
|
|
136
181
|
}
|
|
137
|
-
async getAuthenticatedUser() {
|
|
182
|
+
async getAuthenticatedUser(skipAutoAuth = false) {
|
|
138
183
|
try {
|
|
139
|
-
|
|
140
|
-
|
|
184
|
+
this.log("debug", `calling requireAuth`);
|
|
185
|
+
const email = await (0, requireAuth_1.requireAuth)(await this.resolveOptions(), skipAutoAuth);
|
|
186
|
+
this.log("debug", `detected authenticated account: ${email || "<none>"}`);
|
|
187
|
+
return email ?? (skipAutoAuth ? null : "Application Default Credentials");
|
|
141
188
|
}
|
|
142
189
|
catch (e) {
|
|
190
|
+
this.log("debug", `error in requireAuth: ${e}`);
|
|
143
191
|
return null;
|
|
144
192
|
}
|
|
145
193
|
}
|
|
146
194
|
async mcpListTools() {
|
|
147
195
|
await Promise.all([this.detectActiveFeatures(), this.detectProjectRoot()]);
|
|
148
196
|
const hasActiveProject = !!(await this.getProjectId());
|
|
149
|
-
await
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
});
|
|
197
|
+
await this.trackGA4("mcp_list_tools");
|
|
198
|
+
const skipAutoAuthForStudio = (0, env_1.isFirebaseStudio)();
|
|
199
|
+
this.log("debug", `skip auto-auth in studio environment: ${skipAutoAuthForStudio}`);
|
|
153
200
|
return {
|
|
154
201
|
tools: this.availableTools.map((t) => t.mcp),
|
|
155
202
|
_meta: {
|
|
156
203
|
projectRoot: this.cachedProjectRoot,
|
|
157
204
|
projectDetected: hasActiveProject,
|
|
158
|
-
authenticatedUser: await this.getAuthenticatedUser(),
|
|
205
|
+
authenticatedUser: await this.getAuthenticatedUser(skipAutoAuthForStudio),
|
|
159
206
|
activeFeatures: this.activeFeatures,
|
|
160
207
|
detectedFeatures: this.detectedFeatures,
|
|
161
208
|
},
|
|
@@ -170,24 +217,25 @@ class FirebaseMcpServer {
|
|
|
170
217
|
throw new Error(`Tool '${toolName}' could not be found.`);
|
|
171
218
|
if (tool.mcp.name !== "firebase_update_environment" &&
|
|
172
219
|
(!this.cachedProjectRoot || !(0, node_fs_1.existsSync)(this.cachedProjectRoot))) {
|
|
173
|
-
return (0,
|
|
220
|
+
return (0, util_1.mcpError)(`The current project directory '${this.cachedProjectRoot || "<NO PROJECT DIRECTORY FOUND>"}' does not exist. Please use the 'update_firebase_environment' tool to target a different project directory.`);
|
|
174
221
|
}
|
|
175
222
|
let projectId = await this.getProjectId();
|
|
176
223
|
if (tool.mcp._meta?.requiresProject && !projectId) {
|
|
177
|
-
return
|
|
224
|
+
return errors_1.NO_PROJECT_ERROR;
|
|
178
225
|
}
|
|
179
226
|
projectId = projectId || "";
|
|
180
|
-
const
|
|
227
|
+
const skipAutoAuthForStudio = (0, env_1.isFirebaseStudio)();
|
|
228
|
+
const accountEmail = await this.getAuthenticatedUser(skipAutoAuthForStudio);
|
|
181
229
|
if (tool.mcp._meta?.requiresAuth && !accountEmail) {
|
|
182
|
-
return (0,
|
|
230
|
+
return (0, errors_1.mcpAuthError)(skipAutoAuthForStudio);
|
|
183
231
|
}
|
|
184
232
|
if (tool.mcp._meta?.requiresGemini) {
|
|
185
|
-
if (
|
|
186
|
-
await (0,
|
|
233
|
+
if (configstore_1.configstore.get("gemini")) {
|
|
234
|
+
await (0, ensureApiEnabled_1.ensure)(projectId, api.cloudAiCompanionOrigin(), "");
|
|
187
235
|
}
|
|
188
236
|
else {
|
|
189
|
-
if (!(await (0,
|
|
190
|
-
return (0,
|
|
237
|
+
if (!(await (0, ensureApiEnabled_1.check)(projectId, api.cloudAiCompanionOrigin(), ""))) {
|
|
238
|
+
return (0, errors_1.mcpGeminiError)(projectId);
|
|
191
239
|
}
|
|
192
240
|
}
|
|
193
241
|
}
|
|
@@ -195,33 +243,103 @@ class FirebaseMcpServer {
|
|
|
195
243
|
const toolsCtx = {
|
|
196
244
|
projectId: projectId,
|
|
197
245
|
host: this,
|
|
198
|
-
config:
|
|
199
|
-
rc: (0,
|
|
246
|
+
config: config_1.Config.load(options, true) || new config_1.Config({}, options),
|
|
247
|
+
rc: (0, rc_1.loadRC)(options),
|
|
200
248
|
accountEmail,
|
|
201
249
|
};
|
|
202
250
|
try {
|
|
203
251
|
const res = await tool.fn(toolArgs, toolsCtx);
|
|
204
|
-
await
|
|
252
|
+
await this.trackGA4("mcp_tool_call", {
|
|
205
253
|
tool_name: toolName,
|
|
206
254
|
error: res.isError ? 1 : 0,
|
|
207
|
-
mcp_client_name: this.clientInfo?.name,
|
|
208
|
-
mcp_client_version: this.clientInfo?.version,
|
|
209
255
|
});
|
|
210
256
|
return res;
|
|
211
257
|
}
|
|
212
258
|
catch (err) {
|
|
213
|
-
await
|
|
259
|
+
await this.trackGA4("mcp_tool_call", {
|
|
214
260
|
tool_name: toolName,
|
|
215
261
|
error: 1,
|
|
216
|
-
mcp_client_name: this.clientInfo?.name,
|
|
217
|
-
mcp_client_version: this.clientInfo?.version,
|
|
218
262
|
});
|
|
219
|
-
return (0,
|
|
263
|
+
return (0, util_1.mcpError)(err);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async mcpListPrompts() {
|
|
267
|
+
await Promise.all([this.detectActiveFeatures(), this.detectProjectRoot()]);
|
|
268
|
+
const hasActiveProject = !!(await this.getProjectId());
|
|
269
|
+
await this.trackGA4("mcp_list_prompts");
|
|
270
|
+
const skipAutoAuthForStudio = (0, env_1.isFirebaseStudio)();
|
|
271
|
+
return {
|
|
272
|
+
prompts: this.availablePrompts.map((p) => ({
|
|
273
|
+
name: p.mcp.name,
|
|
274
|
+
description: p.mcp.description,
|
|
275
|
+
annotations: p.mcp.annotations,
|
|
276
|
+
arguments: p.mcp.arguments,
|
|
277
|
+
})),
|
|
278
|
+
_meta: {
|
|
279
|
+
projectRoot: this.cachedProjectRoot,
|
|
280
|
+
projectDetected: hasActiveProject,
|
|
281
|
+
authenticatedUser: await this.getAuthenticatedUser(skipAutoAuthForStudio),
|
|
282
|
+
activeFeatures: this.activeFeatures,
|
|
283
|
+
detectedFeatures: this.detectedFeatures,
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
async mcpGetPrompt(req) {
|
|
288
|
+
await this.detectProjectRoot();
|
|
289
|
+
const promptName = req.params.name;
|
|
290
|
+
const promptArgs = req.params.arguments || {};
|
|
291
|
+
const prompt = this.getPrompt(promptName);
|
|
292
|
+
if (!prompt) {
|
|
293
|
+
throw new Error(`Prompt '${promptName}' could not be found.`);
|
|
294
|
+
}
|
|
295
|
+
let projectId = await this.getProjectId();
|
|
296
|
+
projectId = projectId || "";
|
|
297
|
+
const skipAutoAuthForStudio = (0, env_1.isFirebaseStudio)();
|
|
298
|
+
const accountEmail = await this.getAuthenticatedUser(skipAutoAuthForStudio);
|
|
299
|
+
const options = { projectDir: this.cachedProjectRoot, cwd: this.cachedProjectRoot };
|
|
300
|
+
const promptsCtx = {
|
|
301
|
+
projectId: projectId,
|
|
302
|
+
host: this,
|
|
303
|
+
config: config_1.Config.load(options, true) || new config_1.Config({}, options),
|
|
304
|
+
rc: (0, rc_1.loadRC)(options),
|
|
305
|
+
accountEmail,
|
|
306
|
+
};
|
|
307
|
+
try {
|
|
308
|
+
const messages = await prompt.fn(promptArgs, promptsCtx);
|
|
309
|
+
await this.trackGA4("mcp_get_prompt", {
|
|
310
|
+
tool_name: promptName,
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
messages,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
await this.trackGA4("mcp_get_prompt", {
|
|
318
|
+
tool_name: promptName,
|
|
319
|
+
error: 1,
|
|
320
|
+
});
|
|
321
|
+
throw err;
|
|
220
322
|
}
|
|
221
323
|
}
|
|
222
324
|
async start() {
|
|
223
|
-
const transport =
|
|
325
|
+
const transport = process.env.FIREBASE_MCP_DEBUG_LOG
|
|
326
|
+
? new logging_transport_1.LoggingStdioServerTransport(process.env.FIREBASE_MCP_DEBUG_LOG)
|
|
327
|
+
: new stdio_js_1.StdioServerTransport();
|
|
224
328
|
await this.server.connect(transport);
|
|
225
329
|
}
|
|
330
|
+
async log(level, message) {
|
|
331
|
+
let data = message;
|
|
332
|
+
if (typeof message === "string") {
|
|
333
|
+
data = { message };
|
|
334
|
+
}
|
|
335
|
+
if (!this.currentLogLevel) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (orderedLogLevels.indexOf(this.currentLogLevel) > orderedLogLevels.indexOf(level)) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (this._ready)
|
|
342
|
+
await this.server.sendLoggingMessage({ level, data });
|
|
343
|
+
}
|
|
226
344
|
}
|
|
227
345
|
exports.FirebaseMcpServer = FirebaseMcpServer;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggingStdioServerTransport = void 0;
|
|
4
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const promises_1 = require("fs/promises");
|
|
7
|
+
class LoggingStdioServerTransport extends stdio_js_1.StdioServerTransport {
|
|
8
|
+
constructor(path) {
|
|
9
|
+
super();
|
|
10
|
+
this.path = path;
|
|
11
|
+
(0, fs_1.appendFileSync)(path, "--- new process start ---\n");
|
|
12
|
+
const origOnData = this._ondata;
|
|
13
|
+
this._ondata = (chunk) => {
|
|
14
|
+
origOnData(chunk);
|
|
15
|
+
(0, fs_1.appendFileSync)(path, chunk.toString(), { encoding: "utf8" });
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async send(message) {
|
|
19
|
+
await super.send(message);
|
|
20
|
+
await (0, promises_1.appendFile)(this.path, JSON.stringify(message) + "\n");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.LoggingStdioServerTransport = LoggingStdioServerTransport;
|