Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/apiv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@

// Using import would require resolveJsonModule, which seems to break the
// build/output format.
const pkg = require("../package.json");

Check warning on line 19 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

Check warning on line 19 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
const CLI_VERSION: string = pkg.version;

Check warning on line 20 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .version on an `any` value

Check warning on line 20 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

const agent = detectAIAgent();
const agentStr = agent === "unknown" ? "" : ` agent-name/${agent}`;
const platform = isFirebaseMcp() ? "FirebaseMCP" : "FirebaseCLI";
const clientVersion = `${platform}/${CLI_VERSION}${agentStr}`;

export const STANDARD_HEADERS: Record<string, string> = {
Connection: "keep-alive",
"User-Agent": clientVersion,
"X-Client-Version": clientVersion,
export const standardHeaders: () => Record<string, string> = () => {
const agent = detectAIAgent();
const agentStr = agent === "unknown" ? "" : ` agent-name/${agent}`;
const platform = isFirebaseMcp() ? "FirebaseMCP" : "FirebaseCLI";
const clientVersion = `${platform}/${CLI_VERSION}${agentStr}`;
return {
Connection: "keep-alive",
"User-Agent": clientVersion,
"X-Client-Version": clientVersion,
};
};

// Don't use this one.
Expand Down Expand Up @@ -133,7 +134,7 @@

/**
* Gets a singleton access token
* @returns An access token

Check warning on line 137 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid JSDoc tag (preference). Replace "returns" JSDoc tag with "return"
*/
export async function getAccessToken(): Promise<string> {
const valid = auth.haveValidTokens(refreshToken, []);
Expand Down Expand Up @@ -238,7 +239,7 @@
* Makes a request as specified by the options.
* By default, this will:
* - use content-type: application/json
* - assume the HTTP GET method

Check warning on line 242 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected only 0 line after block description
*
* @example
* const res = apiv2.request<ResourceType>({
Expand Down Expand Up @@ -277,8 +278,8 @@
}
try {
return await this.doRequest<ReqT, ResT>(internalReqOptions);
} catch (thrown: any) {

Check warning on line 281 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
const originalErrorMessage = thrown.original?.message || thrown.message || "";

Check warning on line 282 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .message on an `any` value

Check warning on line 282 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .original on an `any` value

Check warning on line 282 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
if (originalErrorMessage.includes(CLI_OAUTH_PROJECT_NUMBER)) {
// Error messages mentioning the CLI's OAuth project number should not be shared with end users,
// since they will never be actionable for them. If we do display them, support gets a bunch of tickets asking for quota
Expand Down Expand Up @@ -309,7 +310,7 @@
if (!reqOptions.headers) {
reqOptions.headers = new Headers();
}
for (const [h, v] of Object.entries(STANDARD_HEADERS)) {
for (const [h, v] of Object.entries(standardHeaders())) {
if (!reqOptions.headers.has(h)) {
reqOptions.headers.set(h, v);
}
Expand Down
3 changes: 2 additions & 1 deletion src/bin/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { resolve } from "path";
import { parseArgs } from "util";
import { useFileLogger } from "../logger";
import { FirebaseMcpServer } from "../mcp/index";
import { setFirebaseMcp } from "../env";
import { markdownDocsOfPrompts } from "../mcp/prompts/index.js";
import { markdownDocsOfResources } from "../mcp/resources/index.js";
import { markdownDocsOfTools } from "../mcp/tools/index.js";
Expand Down Expand Up @@ -82,7 +83,7 @@ export async function mcp(): Promise<void> {
}
if (earlyExit) return;

process.env.IS_FIREBASE_MCP = "true";
setFirebaseMcp(true);
useFileLogger();
const activeFeatures = (values.only || "")
.split(",")
Expand Down
7 changes: 6 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ export function isFirebaseStudio() {
return googleIdxFolderExists;
}

let isFirebaseMcpFlag = false;
export function isFirebaseMcp() {
return !!process.env.IS_FIREBASE_MCP;
return isFirebaseMcpFlag;
}

export function setFirebaseMcp(value: boolean) {
isFirebaseMcpFlag = value;
}

// Detect if the CLI was invoked by a coding agent, based on well-known env vars.
Expand Down
2 changes: 1 addition & 1 deletion src/gcp/cloudsql/fbToolsAuthClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class FBToolsAuthClient extends AuthClient {
public async getRequestHeaders(): Promise<Record<string, string>> {
const token = await this.getAccessToken();
return {
...apiv2.STANDARD_HEADERS,
...apiv2.standardHeaders(),
Authorization: `Bearer ${token.token}`,
};
}
Expand Down
Loading