Skip to content

MindForgeCollective/MCP_server_GraphAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple MCP Server with Microsoft OAuth Authentication

An example of an MCP server using Microsoft OAuth (v2.0) for user authentication. It demonstrates the essential components for OAuth integration, with various tools based on Microsoft Graph APIs.

Overview

This demo guides you through setting up a server with:

  • OAuth2 authorization flow against Microsoft Azure AD (v2.0 endpoint)

  • Tools for:

    • Retrieving the authenticated user's Microsoft Graph profile
    • Reading and sending emails
    • Creating, reading, updating, and deleting calendar events
    • Checking team availability (free/busy)

Prerequisites

  1. Register an app in Azure AD:

    • Log in to the Azure portal: https://portal.azure.com

    • Navigate to Azure Active Directory > App registrations > New registration

      • Name: e.g., "Simple MCP Microsoft Auth"
      • Supported account types: Accounts in any organizational directory ("Multitenant") + personal Microsoft accounts
      • Redirect URI (Web): http://localhost:8000/microsoft/callback
    • Click Register and note down:

      • Application (client) ID
      • Directory (tenant) ID
    • Go to Certificates & secrets, create a New client secret, and note its value.

  2. Ensure you have Python 3.9+ and either poetry or pip installed.

Required Environment Variables

Before running the server, set the following environment variables:

export MCP_MICROSOFT_MICROSOFT_CLIENT_ID="your-application-client-id"
export MCP_MICROSOFT_MICROSOFT_CLIENT_SECRET="your-client-secret"
export MCP_MICROSOFT_MICROSOFT_CALLBACK_PATH="http://localhost:8000/microsoft/callback"

Installation & Running

  1. Install dependencies:
uv pip install .
  1. Start the server:
uv run mcp_microsoft_auth --host localhost --port 8000 --transport streamable-http

If --transport is not specified, sse will be used as default

Endpoints

- SSE endpoint: `/sse`
- Streamable HTTP endpoint: `/mcp`

Available Tools

Tool Description Required Scope
get_user_profile Returns the authenticated user's Microsoft Graph profile user
list_emails Reads the latest emails from the inbox (count parameter) mail.read
send_email Sends an email (to, subject, body) mail.send
create_meeting Creates a calendar event (subject, attendees, start, duration) calendars.readwrite
list_events Lists upcoming events (from_now_minutes, next_hours, max_results) calendars.read
get_user_schedule Retrieves another user's calendar (user_email, start_datetime, end_datetime) calendars.read.shared
get_team_availability Returns free/busy availability for a list of attendees calendars.read
update_event Updates an existing event (event_id, updates) calendars.readwrite
delete_event Deletes an event (event_id) calendars.readwrite

Troubleshooting

  1. Verify the environment variables:
    • MCP_MICROSOFT_MICROSOFT_CLIENT_ID
    • MCP_MICROSOFT_MICROSOFT_CLIENT_SECRET
    • MCP_MICROSOFT_MICROSOFT_CALLBACK_PATH
  2. Ensure the callback URL in Azure AD exactly matches the one configured.
  3. Confirm no other service is using port 8000.
  4. Check that the transport (sse or streamable-http) is valid.
  5. Inspect console logs for any errors from Microsoft Graph API responses.

To test the server, you can use Inspector or tools like curl / Postman.

About

An MCP server that interacts with GraphAPI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages