UNPKG

@bdmarvin/mcp-server-gbp

Version:

MCP server for Google Business Profile Performance API.

50 lines (49 loc) 2.29 kB
import { google } from 'googleapis'; // Verify exact service name export class GbpPerformanceService { constructor() { // Constructor can be empty if no setup is needed at instantiation } getOAuth2Client(accessToken) { const oauth2Client = new google.auth.OAuth2(); oauth2Client.setCredentials({ access_token: accessToken }); return oauth2Client; } getBusinessProfilePerformanceApi(accessToken) { const authClient = this.getOAuth2Client(accessToken); // Ensure 'businessprofileperformance' is the correct service name and 'v1' is the version return google.businessprofileperformance({ version: 'v1', auth: authClient, }); // Cast to specific options type if available/needed } async getDailyPerformanceMetrics(accessToken, params) { const gbpApi = this.getBusinessProfilePerformanceApi(accessToken); const { locationName, dailyMetrics, startDate, endDate } = params; // Construct request parameters for the API const requestParams = { location: locationName, dailyMetrics: dailyMetrics, 'dailyRange.startDate.year': startDate.year, 'dailyRange.startDate.month': startDate.month, 'dailyRange.startDate.day': startDate.day, 'dailyRange.endDate.year': endDate.year, 'dailyRange.endDate.month': endDate.month, 'dailyRange.endDate.day': endDate.day, }; return gbpApi.locations.fetchMultiDailyMetricsTimeSeries(requestParams); } async getMonthlySearchKeywords(accessToken, params) { const gbpApi = this.getBusinessProfilePerformanceApi(accessToken); const { parentLocationName, startMonth, endMonth, pageSize, pageToken } = params; const requestParams = { parent: parentLocationName, 'monthlyRange.startMonth.year': startMonth.year, 'monthlyRange.startMonth.month': startMonth.month, 'monthlyRange.endMonth.year': endMonth.year, 'monthlyRange.endMonth.month': endMonth.month, pageSize: pageSize, pageToken: pageToken, }; return gbpApi.locations.searchkeywords.impressions.monthly.list(requestParams); } }