Skip to main content
Glama
shaynemeyer

Google Calendar MCP Server

by shaynemeyer

getMyCalendarDataByDate

Retrieve Google Calendar events for a specific date using the Google Calendar API. Query calendar data with date validation and error handling.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • server.js:65-74 (handler)
    The MCP tool handler function that processes the input date, calls the helper function, and returns the result as JSON-formatted text content.
    async ({ date }) => {
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(await getMyCalendarDataByDate(date)),
          },
        ],
      };
    }
  • Helper function implementing the core logic: fetches calendar events for the specified date using Google Calendar API, formats meetings, handles errors.
    async function getMyCalendarDataByDate(date) {
      const calendar = google.calendar({
        version: 'v3',
        auth: process.env.GOOGLE_PUBLIC_API_KEY,
      });
    
      // Calculate the start and end of the given date (UTC)
      const start = new Date(date);
      start.setUTCHours(0, 0, 0, 0);
      const end = new Date(start);
      end.setUTCDate(end.getUTCDate() + 1);
    
      try {
        const res = await calendar.events.list({
          calendarId: process.env.CALENDAR_ID,
          timeMin: start.toISOString(),
          timeMax: end.toISOString(),
          maxResults: 10,
          singleEvents: true,
          orderBy: 'startTime',
        });
    
        const events = res.data.items || [];
        const meetings = events.map((event) => {
          const start = event.start.dateTime || event.start.date;
          return `${event.summary} at ${start}`;
        });
    
        if (meetings.length > 0) {
          return {
            meetings,
          };
        } else {
          return {
            meetings: [],
          };
        }
      } catch (err) {
        return {
          error: err.message,
        };
      }
    }
  • Zod schema for the 'date' input parameter with refinement to validate it as a parsable date string.
    date: z.string().refine(
      (val) => !isNaN(Date.parse(val)),
      {
        message: 'Invalid date format. Please provide a valid date string.',
      },
  • server.js:59-76 (registration)
    Registration of the 'getMyCalendarDataByDate' tool with the MCP server, including schema and handler.
    server.tool('getMyCalendarDataByDate', {
      date: z.string().refine(
        (val) => !isNaN(Date.parse(val)),
        {
          message: 'Invalid date format. Please provide a valid date string.',
        },
        async ({ date }) => {
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(await getMyCalendarDataByDate(date)),
              },
            ],
          };
        }
      ),
    });

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/shaynemeyer/gcal-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server