Abstract
This project simplifies Google Workspace automation by using a Gemini CLI Extension. It installs a local Model Context Protocol (MCP) server that communicates with a powerful, securely authorized backend built on Google Apps Script Web Apps, overcoming previous complex setup and performance bottlenecks.
Introduction
In order to achieve Google Workspace Automation with seamless authorization and safety, I have published a Model Context Protocol (MCP) server built by Google Apps Script Web Apps. Ref This is very useful because Google Apps Script provides native, secure authorization for Google Workspace APIs like Gmail, Drive, and Calendar. However, there was a bottleneck in the complex installation and a long loading time of the MCP server. Recently, Gemini Extensions have been released. Ref By this, tools and MCP servers can be directly and easily installed from sources like GitHub repositories using a simple command. From this situation, I attempted to implement this simplified installation method on the MCP server built by Google Apps Script Web Apps.
Repository
https://github.com/tanaikech/ToolsForMCPServer-extension
Workflow
- A user inputs a prompt into the Gemini CLI.
- The local MCP server (running on Node.js) accepts the prompt.
- The AI agent selects a tool and provides the necessary arguments.
- The local server calls the corresponding tool on the GAS MCP server via an HTTP request.
- The tool executes with your permissions on Google Apps Script and returns the result.
- The result is passed back from the local server to the AI agent.
- The AI agent processes the result and displays the final response to the user.
Mermaid Chart Playground
This solution uses a local MCP server that acts as a fast-loading proxy for the more powerful Google Apps Script (GAS) MCP server. This architecture significantly reduces the startup time for the Gemini CLI while retaining the secure, native authorization of Google Apps Script for all Workspace API calls.
Installation and Configuration
Follow these steps to set up the environment.
1. Install Gemini CLI and default settings
1. Install Gemini CLI
npm install -g @google/gemini-cli
2. Authorization
Follow the official instructions to authenticate the CLI with your Google account: Gemini CLI Authentication Options.
2. Copy a Google Apps Script project
After you log in to your Google account, access the following URL using your browser. And, copy the project by clicking the copy button at the top right.
https://script.google.com/home/projects/1Qm9LgtuQLxDzdLUoJPrOEpmyTBivZZsCLiSUC7q-D3Gi4fISvxgcITWb
By this, the copied Google Apps Script project is automatically opened.
3. Deploy Web Apps
To allow the Gemini CLI to communicate with our script, we must deploy it as a Web App. This creates a unique URL that acts as our MCP server endpoint.
You can find detailed information in the official documentation.
Please follow these steps to deploy the Web App in the script editor:
- In the script editor, at the top right, click Deploy -> New deployment.
- Click Select type -> Web App.
- Enter a description for the Web App in the fields under Deployment configuration.
- Select “Me” for “Execute as”. This is crucial, as it allows the script to run with your permissions to access your Google services.
- Select “Anyone” for “Who has access”. This makes the URL callable from the internet. Access is controlled by the unguessable URL and the
accessKeydefined in the script. - Click Deploy.
- After authorizing the necessary scopes, copy the Web app URL. It will look similar to
https://script.google.com/macros/s/###/exec. This is your MCP server endpoint.
Important: If you modify the Apps Script code, you must redeploy the project to apply the changes. Go to Deploy > Manage deployments, edit your active deployment, and select “New version”. More info here.
4. Environmental variables
This MCP server uses the following 2 environmental variables. Please set them.
API key for using Gemini API. (This variable might have already been set for using Gemini CLI and Gemini API, depending on the environment.)
export GEMINI_API_KEY="{Your API key}"
Web Apps URL retrieved from the above section.
export MCP_WEB_APPS_URL="https://script.google.com/macros/s/###/exec?accessKey=sample"
Note: The value
sampleinaccessKey=samplemust match the key defined in your Google Apps Script project (new MCPApp.mcpApp({ accessKey: "sample" })). If you change the key in the script, you must update it here and redeploy the Web App.
For persistence, add the export commands for GEMINI_API_KEY and MCP_WEB_APPS_URL to your shell’s startup file (e.g., .bashrc or .zshrc).
5. Install Gemini extension
Finally, install the extension using the following command. This will download the local MCP server and configure the tools.
gemini extensions install https://github.com/tanaikech/ToolsForMCPServer-extension
6. Testing
To confirm that the setup is working correctly:
- Run the Gemini CLI:
gemini
- Once the CLI is open, check the available MCP tools:
/mcp
If you see a list of tools from your Google Apps Script project, the installation was successful.
Summary
- One-Command Installation: The Gemini Extension simplifies setup to a single
gemini extensions installcommand after initial configuration. - Secure Workspace Access: It leverages Google Apps Script for native, secure authorization to Google Workspace APIs like Gmail, Drive, and Calendar.
- Improved Performance: A local proxy MCP server dramatically reduces the CLI loading time compared to a direct Web App implementation.
- Powerful Automation Backend: Provides a robust foundation for creating custom tools that automate complex workflows within your Google Workspace environment.
- User-Controlled Security: Your project remains secure through your private access key and Google’s established Web App infrastructure.
Source Credit: https://medium.com/google-cloud/simplified-google-workspace-automation-with-gemini-cli-extensions-cbd86bcd7948?source=rss—-e52cf94d98af—4
