ofp-ai-bootcamp2025-trtran

Azure/ofp-ai-bootcamp2025-trtran

3.2

If you are the rightful owner of ofp-ai-bootcamp2025-trtran and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This project implements a Model Context Protocol (MCP) Server using FastMCP to search for person information via Microsoft Graph API with Azure CLI authentication.

Tools
1
Resources
0
Prompts
0

Microsoft WhoIs MCP Server

This project implements a Model Context Protocol (MCP) Server in Python using the FastMCP library. The server exposes tools for searching person information using the Microsoft Graph API with Azure CLI authentication.

Features

  • šŸ” Person Search: Search for people by name using Microsoft Graph API
  • šŸ“§ Contact Information: Retrieve email addresses, phone numbers, job titles, and aliases
  • šŸ¢ Organization Details: Get company, department, and office location information
  • šŸ” Azure CLI Authentication: Seamless authentication using Azure CLI credentials
  • šŸ›”ļø Error Handling: Comprehensive error handling and validation
  • šŸš€ FastMCP Integration: Built with the latest FastMCP library for optimal performance

API Endpoint

The server queries the Microsoft Graph API endpoint:

GET https://graph.microsoft.com/v1.0/users

Installation

Prerequisites

  • Python 3.12
  • Azure CLI installed and authenticated (az login)
  • Conda (recommended) or pip

Using Conda (Recommended)

  1. Clone the repository:

    git clone <repository-url>
    cd ofp-ai-bootcamp2025-trtran
    
  2. Create and activate the conda environment:

    conda env create -f environment.yml
    conda activate mcp_server_env
    

Using pip

  1. Install dependencies:
    pip install -r requirements.txt
    

Configuration

Authentication Setup

The server uses Azure CLI authentication. No manual token configuration is required.

  1. Install Azure CLI if not already installed:

  2. Authenticate with Azure:

    az login
    
  3. Verify authentication:

    az account show
    

The server will automatically obtain and cache access tokens using your Azure CLI credentials.

Usage

Running the MCP Server

Method 1: Direct Python execution
python mcp_server.py
Method 2: Using the provided batch script (Windows)
start_server.bat

Testing the Server

Run the test suite to verify everything is working:

python test_server.py

Available Tools

1. search_person

Search for people by name using Microsoft Graph API.

Parameters:

  • name (string): The name of the person to search for

Example:

{
  "name": "Tri Tran"
}

Response:

{
  "results": [
    {
      "display_name": "Tri Tran",
      "email": "trtran@microsoft.com",
      "alias": "trtran",
      "job_title": "PRINCIPAL SOFTWARE ENGINEER",
      "office_location": "STUDIO X/1310",
      "phone": "+1 (425) 5382112"
    }
  ],
  "count": 1,
  "total_count": 1,
  "error": null
}
2. Person Information Fields

Each person result includes:

  • display_name: Full name as it appears in Microsoft's directory
  • email: Primary email address
  • alias: Microsoft alias (username without @microsoft.com)
  • job_title: Current job title
  • office_location: Office location/building information
  • phone: Business phone number (if available)

Using with MCP Clients

This server is compatible with any MCP client. Here are some examples:

Claude Desktop (Anthropic)

Add to your Claude Desktop configuration:

{
  "mcpServers": {
    "microsoft-whois": {
      "command": "python",
      "args": ["path/to/mcp_server.py"]
    }
  }
}

Custom Client

import asyncio
from fastmcp import Client

async def search_example():
    client = Client("mcp_server.py")
    
    async with client:
        result = await client.call_tool("search_person", {"name": "Tri Tran"})
        print(result)

asyncio.run(search_example())

Architecture

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”    ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”    ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│   MCP Client    │◄──►│  FastMCP Server │◄──►│ Microsoft Graph  │
│  (Claude, etc.) │    │   (mcp_server)  │    │    API + Azure   │
│                 │    │                 │    │  CLI Credentials │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜    ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜    ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Project Structure

ofp-ai-bootcamp2025-trtran/
ā”œā”€ā”€ mcp_server.py          # Main MCP server implementation
ā”œā”€ā”€ test_server.py         # Test suite for the server
ā”œā”€ā”€ start_server.bat       # Windows batch script to start server
ā”œā”€ā”€ setup.bat              # Windows batch script for setup
ā”œā”€ā”€ requirements.txt       # Python dependencies
ā”œā”€ā”€ environment.yml        # Conda environment configuration
ā”œā”€ā”€ server_config.json     # Server configuration
ā”œā”€ā”€ README.md             # This file
└── LICENSE               # License file

Dependencies

  • fastmcp: Latest MCP server framework
  • httpx: Modern HTTP client for API requests
  • azure-identity: Azure authentication library for CLI credentials

Error Handling

The server includes comprehensive error handling for:

  • Missing or invalid Azure CLI authentication
  • Network timeouts and connectivity issues
  • API rate limiting and quota errors
  • Invalid input parameters
  • Unexpected API responses

Security Considerations

  • ļæ½ Uses Azure CLI credentials (no hardcoded tokens)
  • šŸ›”ļø Input validation prevents injection attacks
  • ā° Request timeouts prevent hanging connections
  • šŸ“ Detailed error logging without exposing sensitive information
  • šŸ”’ Token caching for efficient authentication

Development

Running Tests

python test_server.py

Code Structure

  • GraphAPIClient: Handles Microsoft Graph API interactions with Azure CLI authentication
  • search_person: Main tool for person search functionality
  • Token caching mechanism for improved performance

Troubleshooting

Common Issues

  1. "No access token available. Run 'az login' to authenticate"

    • Run az login to authenticate with Azure CLI
    • Verify authentication with az account show
  2. "Import 'fastmcp' could not be resolved"

    • Install dependencies: pip install -r requirements.txt
  3. "Unauthorized" (401 error)

    • Re-authenticate with Azure CLI: az login
    • Ensure you have access to Microsoft Graph API
  4. "Request timeout"

    • Check your internet connection
    • Verify Microsoft Graph API endpoint is accessible

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

License

See the file for details.

Support

For issues and questions:

  1. Check the troubleshooting section above
  2. Review Microsoft Graph API documentation
  3. Check FastMCP documentation at gofastmcp.com
  4. Open an issue in this repository