Outlook Calendar MCP
by merajmehrabi
#!/usr/bin/env node
/**
* index.js - Entry point for the Outlook Calendar MCP server
*/
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
CallToolRequestSchema,
ErrorCode,
ListToolsRequestSchema,
McpError
} from '@modelcontextprotocol/sdk/types.js';
import { defineOutlookTools } from './outlookTools.js';
/**
* Main class for the Outlook Calendar MCP server
*/
class OutlookCalendarServer {
constructor() {
// Initialize the MCP server
this.server = new Server(
{
name: 'outlook-calendar-server',
version: '1.0.0',
},
{
capabilities: {
tools: {},
},
}
);
// Define the tools
this.tools = defineOutlookTools();
// Set up request handlers
this.setupToolHandlers();
// Error handling
this.server.onerror = (error) => console.error('[MCP Error]', error);
process.on('SIGINT', async () => {
await this.server.close();
process.exit(0);
});
}
/**
* Sets up the tool request handlers
*/
setupToolHandlers() {
// List available tools
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
const toolsList = Object.values(this.tools).map(tool => ({
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema,
}));
return {
tools: toolsList,
};
});
// Handle tool calls
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,
};
}
});
}
/**
* Starts the MCP server
*/
async run() {
try {
const transport = new StdioServerTransport();
await this.server.connect(transport);
console.error('Outlook Calendar MCP server running on stdio');
} catch (error) {
console.error('Failed to start MCP server:', error);
process.exit(1);
}
}
}
// Create and run the server
const server = new OutlookCalendarServer();
server.run().catch(console.error);