Skip to main content
Glama
merajmehrabi

Outlook Calendar MCP

by merajmehrabi

list_events

Retrieve calendar events within a specified date range from Microsoft Outlook using a local, privacy-focused solution. Input start date, optional end date, and calendar name to view event details.

Instructions

List calendar events within a specified date range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
calendarNoCalendar name (optional)
endDateNoEnd date in MM/DD/YYYY format (optional)
startDateYesStart date in MM/DD/YYYY format

Implementation Reference

  • Handler for the list_events MCP tool. Calls listEvents wrapper and formats the output as MCP content with error handling.
    handler: async ({ startDate, endDate, calendar }) => {
      try {
        const events = await listEvents(startDate, endDate, calendar);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(events, null, 2)
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error listing events: ${error.message}`
            }
          ],
          isError: true
        };
      }
    }
  • Input schema for the list_events tool defining required startDate/endDate and optional calendar.
    inputSchema: {
      type: 'object',
      properties: {
        startDate: {
          type: 'string',
          description: 'Start date in MM/DD/YYYY format'
        },
        endDate: {
          type: 'string',
          description: 'End date in MM/DD/YYYY format'
        },
        calendar: {
          type: 'string',
          description: 'Calendar name (optional)'
        }
      },
      required: ['startDate', 'endDate']
    },
  • src/index.js:66-96 (registration)
    Registration of tool call handler in MCP server. Dispatches to specific tool handler based on name, including the list_events tool.
      this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
        const { name, arguments: args } = request.params;
        
        // Find the requested tool
        const tool = this.tools[name];
        
        if (!tool) {
          throw new McpError(
            ErrorCode.MethodNotFound,
            `Tool not found: ${name}`
          );
        }
        
        try {
          // Call the tool handler
          return await tool.handler(args);
        } catch (error) {
          console.error(`Error executing tool ${name}:`, error);
          
          return {
            content: [
              {
                type: 'text',
                text: `Error executing tool ${name}: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
      });
    }
  • Helper wrapper function listEvents that invokes executeScript on the listEvents.vbs script.
    export async function listEvents(startDate, endDate, calendar) {
      return executeScript('listEvents', { startDate, endDate, calendar });
    }
  • Core helper function executeScript that runs VBScript files via child_process.exec and parses JSON output.
    export async function executeScript(scriptName, params = {}) {
      return new Promise((resolve, reject) => {
        // Build the command with UTF-8 support
        const scriptPath = path.join(SCRIPTS_DIR, `${scriptName}.vbs`);
        let command = `chcp 65001 >nul 2>&1 && cscript //NoLogo "${scriptPath}"`;
        
        // Add parameters
        for (const [key, value] of Object.entries(params)) {
          if (value !== undefined && value !== null && value !== '') {
            // Handle special characters in values
            const escapedValue = value.toString().replace(/"/g, '\\"');
            command += ` /${key}:"${escapedValue}"`;
          }
        }
        
        // Execute the command with UTF-8 encoding
        exec(command, { encoding: 'utf8' }, (error, stdout, stderr) => {
          // Check for execution errors
          if (error && !stdout.includes(SUCCESS_PREFIX)) {
            return reject(new Error(`Script execution failed: ${error.message}`));
          }
          
          // Check for script errors
          if (stdout.includes(ERROR_PREFIX)) {
            const errorMessage = stdout.substring(stdout.indexOf(ERROR_PREFIX) + ERROR_PREFIX.length).trim();
            return reject(new Error(`Script error: ${errorMessage}`));
          }
          
          // Process successful output
          if (stdout.includes(SUCCESS_PREFIX)) {
            try {
              const jsonStr = stdout.substring(stdout.indexOf(SUCCESS_PREFIX) + SUCCESS_PREFIX.length).trim();
              const result = JSON.parse(jsonStr);
              return resolve(result);
            } catch (parseError) {
              return reject(new Error(`Failed to parse script output: ${parseError.message}`));
            }
          }
          
          // If we get here, something unexpected happened
          reject(new Error(`Unexpected script output: ${stdout}`));
        });
      });
    }
Install Server

Other Tools

Related 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/merajmehrabi/Outlook_Calendar_MCP'

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