MCP Server with Google OAuth & Analytics

by bighadj22

Not rated
GitHub

About

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

Details

Author
bighadj22
Categories
Developer Tools, Other

Setup

Install MCP Server with Google OAuth & Analytics in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/bighadj22/cloudflare-mcp-google-oauth-analytics

Follow the installation instructions in the repository README, then restart your MCP client.

MCP Server with Google OAuth & Analytics

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

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

This is aModel 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 theworkers-oauth-providerlibraryandmcp-analyticsfor comprehensive tracking.

The MCP server (powered byCloudflare Workers):

- Acts as OAuthServerto your MCP clients
- Acts as OAuthClientto yourrealOAuth server (in this case, Google)
- Automatically tracks tool usage, performance metrics, and user behavior

This server includes automatic analytics tracking via themcp-analyticsSDK:

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

Clone the repo & install dependencies:npm install

- For the Homepage URL, specifyhttps://mcp-google-oauth.<your-subdomain>.workers.dev
- For the Authorization callback URL, specifyhttps://mcp-google-oauth.<your-subdomain>.workers.dev/callback
- Note your Client ID and generate a Client secret.
- Set secrets via Wrangler

- Create the KV namespace:wrangler kv:namespace create "OAUTH_KV"
- Update the Wrangler file with the KV ID

Deploy the MCP server to make it available on your workers.dev domainwrangler deploy

Test the remote server usingMCP Playground:
- Visit
mcpsplayground.com
- Enter your server URL:https://mcp-google-oauth.<your-subdomain>.workers.dev/sse
- Click "Connect" and complete the Google OAuth authentication flow
- Once authenticated, you'll see your tools available in the playground interface
- Test the "add" tool by providing two numbers and see the results with automatic analytics tracking

Alternatively, you can also test using the traditionalInspector:

npx @modelcontextprotocol/inspector@latest

You now have a remote MCP server deployed with comprehensive analytics!

This MCP server uses Google Cloud OAuth for authentication. All authenticated Google users can access basic tools like "add". When you restrict users with hosted domain, setHOSTED_DOMAINenv.

Access the remote MCP server from Claude Desktop

Open Claude Desktop and navigate to Settings -> Developer -> Edit Config. This opens the configuration file that controls which MCP servers Claude can access.

Replace the content with the following configuration. Once you restart Claude Desktop, a browser window will open showing your OAuth login page. Complete the authentication flow to grant Claude access to your MCP server. After you grant access, the tools will become available for you to use.

{ "mcpServers": { "math": { "command": "npx", "args": [ "mcp-remote", "https://mcp-google-oauth.<your-subdomain>.workers.dev/sse" ] } } }

Once the Tools (under 🔨) show up in the interface, you can ask Claude to use them. For example: "Could you use the math tool to add 23 and 19?". Claude should invoke the tool and show the result generated by the MCP server, with all interactions automatically tracked in your analytics dashboard.

If you'd like to iterate and test your MCP server, you can do so in local development. This will require you to create another OAuth App on Google Cloud:

- For the Homepage URL, specifyhttp://localhost:8788
- For the Authorization callback URL, specifyhttp://localhost:8788/callback
- Note your Client ID and generate a Client secret.
- Create a.dev.varsfile in your project root with:

GOOGLE_CLIENT_ID=your_development_google_cloud_oauth_client_id GOOGLE_CLIENT_SECRET=your_development_google_cloud_oauth_client_secret MCP_ANALYTICS_API_KEY=your_analytics_api_key

Run the server locally to make it available athttp://localhost:8788wrangler dev

To test the local server, enterhttp://localhost:8788/sseinto Inspector and hit connect. Once you follow the prompts, you'll be able to "List Tools" with analytics tracking enabled.

When using Claude to connect to your remote MCP server, you may see some error messages. This is because Claude Desktop doesn't yet support remote MCP servers, so it sometimes gets confused. To verify whether the MCP server is connected, hover over the 🔨 icon in the bottom right corner of Claude's interface. You should see your tools available there.

To connect Cursor with your MCP server, chooseType: "Command" and in theCommandfield, combine the command and args fields into one (e.g.npx mcp-remote https://<your-worker-name>.<your-subdomain>.workers.dev/sse).

Note that while Cursor supports HTTP+SSE servers, it doesn't support authentication, so you still need to usemcp-remote(and to use a STDIO server, not an HTTP one).

You can connect your MCP server to other MCP clients like Windsurf by opening the client's configuration file, adding the same JSON that was used for the Claude setup, and restarting the MCP client.

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 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 viathis.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

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

Visitmcpanalytics.devto 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

This is a web browser that enables your coding agent, such as Claude Code, to visit websites on your behalf and assist you in identifying bugs or creating UI test cases.

Integrates Google Tag Manager to automate GTM configuration and component creation through natural language prompts.

A collection of MCP servers for growth and analytics, including a server for Google Analytics.

A managed AI marketing agent that plugs into all your AI tools. Ask about your marketing in natural language — get synthesized insights from GA4, Google Ads, Search Console, WooCommerce, and more.

Read-only, multi-tenant access to Google Analytics 4, Google Ads, Search Console and Meta Ads: one connector per client plus a master connector spanning every client of an agency.

GA4 conversion analyst inside Claude. Ask where your funnel is leaking, get numbers back.

Access Google Analytics 4 (GA4) data using the Model Context Protocol.

Connect GA4 to Claude or ChatGPT via Two Minute Reports MCP. Track New Users, Sessions, and Signups to improve website performance.

Access the Google Analytics Data API to retrieve and analyze website traffic data.

MCP server for Google Analytics 4 — reports, realtime, and admin (Rust)

A structured interface for interacting with Google Analytics APIs, simplifying tasks like querying reports and managing properties.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.