Labsco
bighadj22 logo

MCP Server with Google OAuth & Analytics

β˜… 3

from bighadj22

A remote MCP server with built-in Google OAuth authentication and analytics tracking.

πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

Model Context Protocol (MCP) Server + Google OAuth + Analytics

This is a Model Context Protocol (MCP) server that supports remote MCP connections, with Google OAuth built-in and comprehensive analytics tracking.

You can deploy it to your own Cloudflare account, and after you create your own Google Cloud OAuth client app, you'll have a fully functional remote MCP server with automatic analytics tracking that you can build off. Users will be able to connect to your MCP server by signing in with their Google account, while you get detailed insights into tool usage, performance, and user behavior.

You can use this as a reference example for how to integrate other OAuth providers with an MCP server deployed to Cloudflare, using the workers-oauth-provider library and mcp-analytics for comprehensive tracking.

The MCP server (powered by Cloudflare Workers):

  • Acts as OAuth Server to your MCP clients
  • Acts as OAuth Client to your real OAuth server (in this case, Google)
  • Automatically tracks tool usage, performance metrics, and user behavior

Analytics Features

This server includes automatic analytics tracking via the mcp-analytics SDK:

βœ… Tool execution time - How long each tool takes to run
βœ… Success/failure status - Which tools succeed or fail
βœ… Input parameters - What data users provide (sensitive data auto-redacted)
βœ… Tool results - Output data from tool executions (automatically sanitized)
βœ… Error details - Full error information when tools fail
βœ… User information - Automatic user identification from OAuth props
βœ… Session tracking - Group tool calls by user session
βœ… Server metadata - Server name and version automatically detected

How does it work?

OAuth Provider

The OAuth Provider library serves as a complete OAuth 2.1 server implementation for Cloudflare Workers. It handles the complexities of the OAuth flow, including token issuance, validation, and management. In this project, it plays the dual role of:

  • Authenticating MCP clients that connect to your server
  • Managing the connection to Google Cloud's OAuth services
  • Securely storing tokens and authentication state in KV storage

Durable MCP with Analytics

Durable MCP extends the base MCP functionality with Cloudflare's Durable Objects and analytics tracking, providing:

  • Persistent state management for your MCP server
  • Secure storage of authentication context between requests
  • Access to authenticated user information via this.props
  • Support for conditional tool availability based on user identity
  • Automatic analytics tracking of all tool usage with user context
  • Performance metrics and error monitoring
  • Comprehensive insights into user behavior and tool effectiveness

MCP Remote

The MCP Remote library enables your server to expose tools that can be invoked by MCP clients like the Inspector. It:

  • Defines the protocol for communication between clients and your server
  • Provides a structured way to define tools
  • Handles serialization and deserialization of requests and responses
  • Maintains the Server-Sent Events (SSE) connection between clients and your server

Analytics Dashboard

Visit mcpanalytics.dev to view your analytics dashboard and gain insights into:

  • Tool usage patterns and popularity
  • User engagement and session analytics
  • Performance metrics and bottlenecks
  • Error rates and failure analysis
  • Success/failure trends over time