MCP ExplorerExplorer

Mcp Server With Google Auth

@Nvillaluengaon a month ago
1 Apache-2.0
FreeCommunity
AI Systems
MCP Server with Google Auth integrates Google Drive for client interaction.

Overview

What is Mcp Server With Google Auth

The mcp-server-with-google-auth is a project that implements an MCP (Model Context Protocol) server integrated with Google Drive, allowing clients to interact with it using the Gemini framework.

Use cases

Use cases include building applications that require user authentication via Google, leveraging Google Drive for file storage, and utilizing AI models for data processing and analysis.

How to use

To use mcp-server-with-google-auth, clone the repository, set up a virtual environment, install dependencies, configure Google OAuth credentials, and set environment variables as specified in the README.

Key features

Key features include integration with Google Drive, support for OAuth 2.0 authentication, a web framework built with FastAPI, and the ability to utilize Google Generative AI through the Google API client.

Where to use

This server can be used in fields such as cloud computing, AI development, and web applications that require secure authentication and interaction with Google services.

Content

MCP Server Google Auth Project

This project demonstrates an MCP (Model Context Protocol) server with Google Drive integration and a client to interact with it using Gemini.

Prerequisites

  • Python 3.12+
  • uv (Python package installer and virtual environment manager)
  • Google Cloud Project with Vertex AI API enabled.
  • OAuth 2.0 credentials.json file from Google Cloud Console.

Setup

  1. Clone the repository:

    git clone https://github.com/Nvillaluenga/mcp-server-with-google-auth.git
    cd mcp-server-with-google-auth
    
  2. Create and activate a virtual environment with uv:

    uv venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install dependencies with uv sync from pyproject.toml:

    uv sync
    

    The dependencies are defined in pyproject.toml and include:

    • fastapi - Web framework for the MCP server
    • fastmcp - MCP server implementation
    • google-api-python-client - Google API client
    • google-auth and google-auth-oauthlib - Google authentication
    • google-genai - Google Generative AI interface
  4. Set up Google OAuth Credentials:

    • Go to the Google Cloud Console
    • Navigate to “APIs & Services” > “Credentials”
    • Create OAuth 2.0 Client IDs (Web application)
    • Add http://localhost:8081 to “Authorized JavaScript origins”
    • Add http://localhost:8081/oauth2callback to “Authorized redirect URIs”
    • Download and rename the credentials file to credentials.json and place it in the project root
  5. Configure Environment Variables:

    • Create .env from the template:
      cp .env.template .env
      
    • Edit .env with your configuration:
      • PROJECT: Your Google Cloud Project ID
      • LOCATION: Your GCP region (e.g., us-central1)
      • DEFAULT_MODEL: Gemini model name (e.g., gemini-2.0-flash-001)
      • HOST: Server host (default: localhost)
      • PORT: Server port (default: 8081)

Running the Application

You’ll need two terminals with active uv environments:

1. Start the MCP Server:

python drive_web_mcp_server.py

2. Run the Client:

python main.py

Or specify a server URL:

python main.py http://your-server-address:port

The client will prompt you to authenticate with Google Drive:

  • Open the displayed URL in your browser
  • Complete the Google authentication flow
  • Return to the terminal and start querying Gemini with access to Google Drive

How it Works

  • drive_web_mcp_server.py: FastAPI-based MCP server that:

    • Handles OAuth 2.0 authentication with Google
    • Exposes tools for the LLM to call
    • Stores client credentials in memory by client_id
  • mcp_client.py: Contains MCPClient and GeminiMCPClient classes:

    • Manages connections to MCP servers
    • Handles authentication flow
    • Interfaces with Gemini models
    • Translates between MCP tools and Gemini function calls
  • main.py: CLI to interact with GeminiMCPClient

  • .env and .env.template: Environment configuration

  • credentials.json: Google OAuth 2.0 client secrets (never commit this)

Authentication Flow Diagram

The following diagram illustrates the authentication process between the MCP client, MCP server and Google OAuth:

Authentication Flow Diagram

Available Tools

  • search_drive_files(query: str): Search files in Google Drive
  • check_authentication_status(): Check client authentication status

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers