@@ -47,6 +47,7 @@ import { timeoutFallback } from "../timeout";
4747import { resolveResource , resources , resourceTemplates } from "./resources" ;
4848import * as crossSpawn from "cross-spawn" ;
4949import { getDefaultFeatureAvailabilityCheck } from "./util/availability" ;
50+ import { checkBillingEnabled } from "../gcp/cloudbilling" ;
5051
5152const SERVER_VERSION = "0.3.0" ;
5253
@@ -193,7 +194,8 @@ export class FirebaseMcpServer {
193194 this . logger . debug ( "detecting active features of Firebase MCP server..." ) ;
194195 const projectId = ( await this . getProjectId ( ) ) || "" ;
195196 const accountEmail = await this . getAuthenticatedUser ( ) ;
196- const ctx = this . _createMcpContext ( projectId , accountEmail ) ;
197+ const isBillingEnabled = projectId ? await checkBillingEnabled ( projectId ) : false ;
198+ const ctx = this . _createMcpContext ( projectId , accountEmail , isBillingEnabled ) ;
197199 const detected = await Promise . all (
198200 SERVER_FEATURES . map ( async ( f ) => {
199201 const availabilityCheck = getDefaultFeatureAvailabilityCheck ( f ) ;
@@ -244,7 +246,8 @@ export class FirebaseMcpServer {
244246 // We need a project ID and user for the context, but it's ok if they're empty.
245247 const projectId = ( await this . getProjectId ( ) ) || "" ;
246248 const accountEmail = await this . getAuthenticatedUser ( ) ;
247- const ctx = this . _createMcpContext ( projectId , accountEmail ) ;
249+ const isBillingEnabled = projectId ? await checkBillingEnabled ( projectId ) : false ;
250+ const ctx = this . _createMcpContext ( projectId , accountEmail , isBillingEnabled ) ;
248251 return availableTools ( ctx , features ) ;
249252 }
250253
@@ -258,7 +261,8 @@ export class FirebaseMcpServer {
258261 // We need a project ID and user for the context, but it's ok if they're empty.
259262 const projectId = ( await this . getProjectId ( ) ) || "" ;
260263 const accountEmail = await this . getAuthenticatedUser ( ) ;
261- const ctx = this . _createMcpContext ( projectId , accountEmail ) ;
264+ const isBillingEnabled = projectId ? await checkBillingEnabled ( projectId ) : false ;
265+ const ctx = this . _createMcpContext ( projectId , accountEmail , isBillingEnabled ) ;
262266 return availablePrompts ( ctx , features ) ;
263267 }
264268
@@ -297,7 +301,11 @@ export class FirebaseMcpServer {
297301 }
298302 }
299303
300- private _createMcpContext ( projectId : string , accountEmail : string | null ) : McpContext {
304+ private _createMcpContext (
305+ projectId : string ,
306+ accountEmail : string | null ,
307+ isBillingEnabled : boolean ,
308+ ) : McpContext {
301309 const options = { projectDir : this . cachedProjectDir , cwd : this . cachedProjectDir } ;
302310 return {
303311 projectId : projectId ,
@@ -306,6 +314,7 @@ export class FirebaseMcpServer {
306314 rc : loadRC ( options ) ,
307315 accountEmail,
308316 firebaseCliCommand : this . _getFirebaseCliCommand ( ) ,
317+ isBillingEnabled,
309318 } ;
310319 }
311320
@@ -370,7 +379,8 @@ export class FirebaseMcpServer {
370379 if ( err ) return err ;
371380 }
372381
373- const toolsCtx = this . _createMcpContext ( projectId , accountEmail ) ;
382+ const isBillingEnabled = projectId ? await checkBillingEnabled ( projectId ) : false ;
383+ const toolsCtx = this . _createMcpContext ( projectId , accountEmail , isBillingEnabled ) ;
374384 try {
375385 const res = await tool . fn ( toolArgs , toolsCtx ) ;
376386 await this . trackGA4 ( "mcp_tool_call" , {
@@ -424,7 +434,8 @@ export class FirebaseMcpServer {
424434 const skipAutoAuthForStudio = isFirebaseStudio ( ) ;
425435 const accountEmail = await this . getAuthenticatedUser ( skipAutoAuthForStudio ) ;
426436
427- const promptsCtx = this . _createMcpContext ( projectId , accountEmail ) ;
437+ const isBillingEnabled = projectId ? await checkBillingEnabled ( projectId ) : false ;
438+ const promptsCtx = this . _createMcpContext ( projectId , accountEmail , isBillingEnabled ) ;
428439
429440 try {
430441 const messages = await prompt . fn ( promptArgs , promptsCtx ) ;
@@ -464,7 +475,8 @@ export class FirebaseMcpServer {
464475 const skipAutoAuthForStudio = isFirebaseStudio ( ) ;
465476 const accountEmail = await this . getAuthenticatedUser ( skipAutoAuthForStudio ) ;
466477
467- const resourceCtx = this . _createMcpContext ( projectId , accountEmail ) ;
478+ const isBillingEnabled = projectId ? await checkBillingEnabled ( projectId ) : false ;
479+ const resourceCtx = this . _createMcpContext ( projectId , accountEmail , isBillingEnabled ) ;
468480
469481 const resolved = await resolveResource ( req . params . uri , resourceCtx ) ;
470482 if ( ! resolved ) {
0 commit comments