This guide demonstrates how to set up and use a Model Context Protocol (MCP) server with Google Apps Script to enhance Gemini CLI capabilities. The integration allows Gemini to interact directly with Google Workspace services like Gmail, Drive, Calendar, and more.
First, create a standalone Google Apps Script project by visiting script.google.com.
Install these libraries to your project:
MCPApp
ToolsForMCPServer
Copy this script to your project:
const apiKey = "###"; // API key for Gemini API
/**
* This function is automatically run when the MCP client accesses Web Apps.
*/
const doPost = e => main(e);
function main(eventObject) {
const m = ToolsForMCPServer;
m.apiKey = apiKey;
const object = { eventObject, items: m.getServer() };
return new MCPApp
.mcpApp({ accessKey: "sample" })
.setServices({ lock: LockService.getScriptLock() })
.server(object);
}
Note: If you plan to use the generate_presentation_with_google_slides tool, uncomment the apiKey line and add a valid Gemini API key.
Follow the instructions at the official Gemini CLI repository.
Locate your settings file (~/.gemini/settings.json on macOS/Linux or %USERPROFILE%.gemini\settings.json on Windows) and add:
{
"theme": "Default",
"selectedAuthType": "###",
"mcpServers": {
"gas_web_apps": {
"command": "npx",
"args": [
"mcp-remote",
"https://script.google.com/macros/s/###/exec?accessKey=sample"
],
"env": {}
}
}
}
Replace the URL with your Web App URL. If you haven't installed mcp-remote, install it with npm.
Type /mcp
in the Gemini CLI to see all available tools. You should see 23 tools including:
Ask: "Search for files with the filename of 'sample file' from Google Drive."
Ask: "Tell me my today's schedule."
Ask: "Tell me my today's emails from [email address]."
Ask: "Create an email to thank [name] for [something]. Their email address is [email]."
Ask: "Create a new Google Document and put the following text into it: [text]"
Ask: "Please create a presentation about [topic]. My name is [name]."
Ask: "Generate a survey about [topic] using Google Forms and send the URL to [email]."
If you want to extend the MCP server with your own tools, use this template:
function getCustomTools() {
const functions = {
params_: {
function_name1: {
description: "###",
parameters: {}
},
function_name2: {
description: "###",
parameters: {}
}
},
function_name1: (object) => { },
function_name2: (object) => { },
};
// for MCP
const itemsForMCP = [
{
"type": "initialize",
"value": {
"protocolVersion": "2024-11-05", // or "2025-03-26"
"capabilities": { "tools": { "listChanged": false } },
"serverInfo": { "name": "gas_web_apps", "version": "1.0.0" }
}
},
...Object.keys(functions.params_).map(f => (
{
"type": "tools/list",
"function": functions[f],
"value": {
name: f,
description: functions.params_[f].description,
inputSchema: functions.params_[f].parameters,
}
}))
];
return itemsForMCP;
}
Then modify your main function to include both the built-in and custom tools:
function main(eventObject) {
const m = ToolsForMCPServer;
m.apiKey = apiKey;
const object = { eventObject, items: [...m.getServer(), ...getCustomTools()] };
return new MCPApp
.mcpApp({ accessKey: "sample" })
.setServices({ lock: LockService.getScriptLock() })
.server(object);
}
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "gas_web_apps" '{"command":"npx","args":["mcp-remote","https://script.google.com/macros/s/###/exec?accessKey=sample"],"env":[]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"gas_web_apps": {
"command": "npx",
"args": [
"mcp-remote",
"https://script.google.com/macros/s/###/exec?accessKey=sample"
],
"env": []
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"gas_web_apps": {
"command": "npx",
"args": [
"mcp-remote",
"https://script.google.com/macros/s/###/exec?accessKey=sample"
],
"env": []
}
}
}
3. Restart Claude Desktop for the changes to take effect