Sponsored by Deepsite.site

Google Docs MCP Server

Created By
Meerkats-Ai8 months ago
google-docs-mcp-server
Content

Google Docs MCP Server

A powerful Model Context Protocol (MCP) server implementation for seamless Google Docs API integration, enabling AI assistants to create, read, update, and manage Google Docs.

Features

  • Create new Google Docs with custom titles and content
  • Retrieve document content and metadata
  • Update existing documents with new content
  • List all accessible documents
  • Delete documents
  • Export documents to different formats (PDF, plain text, etc.)
  • Share documents with specific users
  • Search for documents by title or content
  • Verify connection and credentials

Prerequisites

  • Node.js 18 or higher
  • A Google Cloud project with the Google Docs API enabled
  • Authentication credentials (API key, service account, or OAuth2)

Installation

  1. Clone this repository:

    git clone https://github.com/lkm1developer/google-docs-mcp-server.git
    cd google-docs-mcp-server
    
  2. Install dependencies:

    npm install
    
  3. Create a .env file with your Google Cloud credentials:

    # Required
    GOOGLE_CLOUD_PROJECT_ID=your-project-id
    
    # Choose one authentication method:
    
    # Option 1A: Service Account with file path (recommended for production)
    GOOGLE_APPLICATION_CREDENTIALS=path/to/your-service-account-key.json
    
    # Option 1B: Service Account with JSON content directly
    # Useful for environments where you can't create files
    GOOGLE_APPLICATION_CREDENTIALS_JSON={"type":"service_account","project_id":"...","private_key":"...","client_email":"..."}
    
    # Option 2: API Key (simpler for development)
    GOOGLE_API_KEY=your-api-key
    
    # Option 3: OAuth2 (required for user-specific operations)
    client_id=your-oauth-client-id
    client_secret=your-oauth-client-secret
    refresh_token=your-oauth-refresh-token
    

Authentication Setup

Service Account Authentication

  1. Go to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Google Docs API and Google Drive API
  4. Go to "IAM & Admin" > "Service Accounts"
  5. Create a new service account
  6. Grant it the necessary roles (e.g., "Docs API User", "Drive API User")
  7. Create and download a JSON key for the service account
  8. Set the path to this JSON file in your .env file

OAuth2 Authentication

For operations that require user consent (like creating/editing documents):

  1. Go to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Google Docs API and Google Drive API
  4. Go to "APIs & Services" > "Credentials"
  5. Create OAuth client ID credentials (Web application type)
  6. Add authorized redirect URIs (e.g., http://localhost:3000/oauth2callback)
  7. Note your Client ID and Client Secret
  8. Use the following script to get a refresh token:
// get-refresh-token.js
const { google } = require('googleapis');
const http = require('http');
const url = require('url');
const open = require('open');
const destroyer = require('server-destroy');

async function getRefreshToken() {
  const oauth2Client = new google.auth.OAuth2(
    'YOUR_CLIENT_ID',
    'YOUR_CLIENT_SECRET',
    'http://localhost:3000/oauth2callback'
  );

  const scopes = [
    'https://www.googleapis.com/auth/documents',
    'https://www.googleapis.com/auth/drive'
  ];

  const authorizeUrl = oauth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: scopes,
    prompt: 'consent'
  });

  console.log('Opening browser for authorization...');
  open(authorizeUrl);

  return new Promise((resolve, reject) => {
    const server = http.createServer(async (req, res) => {
      try {
        const queryParams = url.parse(req.url, true).query;
        
        if (queryParams.code) {
          res.end('Authentication successful! You can close this window.');
          server.destroy();
          
          const { tokens } = await oauth2Client.getToken(queryParams.code);
          console.log('\nRefresh Token:', tokens.refresh_token);
          console.log('\nAdd this refresh token to your .env file as refresh_token');
          
          resolve(tokens.refresh_token);
        }
      } catch (e) {
        reject(e);
      }
    }).listen(3000);
    
    destroyer(server);
  });
}

getRefreshToken().catch(console.error);

Run this script with:

npm install googleapis open server-destroy
node get-refresh-token.js

Building and Running

  1. Build the project:

    npm run build
    
  2. Test your connection:

    npx tsx src/test-connection.ts
    
  3. Run the server:

    npm start
    

    Or with specific credentials:

    npm start -- --GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json --GOOGLE_CLOUD_PROJECT_ID=your-project-id
    
    # Or with JSON content directly:
    npm start -- --GOOGLE_APPLICATION_CREDENTIALS_JSON='{"type":"service_account","project_id":"..."}' --GOOGLE_CLOUD_PROJECT_ID=your-project-id
    
  4. Run the SSE server with authentication:

    npx mcp-proxy-auth node dist/index.js
    

Implementing Authentication in SSE Server

The SSE server uses the mcp-proxy-auth package for authentication. To implement authentication:

  1. Install the package:

    npm install mcp-proxy-auth
    
  2. Set the AUTH_SERVER_URL environment variable to point to your API key verification endpoint:

    export AUTH_SERVER_URL=https://your-auth-server.com/verify
    
  3. Run the SSE server with authentication:

    npx mcp-proxy-auth node dist/index.js
    
  4. The SSE URL will be available at:

    localhost:8080/sse?apiKey=apikey
    

    Replace apikey with your actual API key for authentication.

The mcp-proxy-auth package acts as a proxy that:

  • Intercepts requests to your SSE server
  • Verifies API keys against your authentication server
  • Only allows authenticated requests to reach your SSE endpoint

Docker Support

You can also run the server using Docker:

  1. Build the Docker image:

    docker build -t google-docs-mcp-server .
    
  2. Run the container:

    docker run -p 8080:8080 \
      -e GOOGLE_CLOUD_PROJECT_ID=your-project-id \
      -e GOOGLE_APPLICATION_CREDENTIALS_JSON='{"type":"service_account","project_id":"..."}' \
      -e client_id=your-client-id \
      -e client_secret=your-client-secret \
      -e refresh_token=your-refresh-token \
      -e AUTH_SERVER_URL=https://your-auth-server.com/verify \
      google-docs-mcp-server
    

MCP Integration

To use this server with Claude or other MCP-compatible assistants, add it to your MCP settings:

{
  "mcpServers": {
    "google-docs": {
      "command": "node",
      "args": ["/path/to/google-docs-mcp-server/dist/index.js"],
      "env": {
        "GOOGLE_CLOUD_PROJECT_ID": "your-project-id",
        "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your-service-account-key.json",
        "GOOGLE_APPLICATION_CREDENTIALS_JSON": "{\"type\":\"service_account\",\"project_id\":\"...\"}",
        "GOOGLE_API_KEY": "your-api-key",
        "client_id": "your-oauth-client-id",
        "client_secret": "your-oauth-client-secret",
        "refresh_token": "your-oauth-refresh-token"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

Available Tools

Tool NameDescriptionRequired Parameters
google_docs_createCreate a new Google Doctitle, content (optional)
google_docs_getGet a Google Doc by IDdocumentId
google_docs_updateUpdate a Google Doc with new contentdocumentId, content, replaceAll (optional)
google_docs_listList Google Docs accessible to the authenticated userpageSize (optional), pageToken (optional)
google_docs_deleteDelete a Google DocdocumentId
google_docs_exportExport a Google Doc to different formatsdocumentId, mimeType (optional)
google_docs_shareShare a Google Doc with specific usersdocumentId, emailAddress, role (optional)
google_docs_searchSearch for Google Docs by title or contentquery, pageSize (optional), pageToken (optional)
google_docs_verify_connectionVerify connection with Google Docs APINone

Example Usage

Here are some examples of how to use the tools:

Create a new document

{
  "name": "google_docs_create",
  "arguments": {
    "title": "My New Document",
    "content": "This is the content of my new document."
  }
}

Get a document

{
  "name": "google_docs_get",
  "arguments": {
    "documentId": "1Ax7vsdg3_YhKjkl2P0TZ5XYZ123456"
  }
}

Update a document

{
  "name": "google_docs_update",
  "arguments": {
    "documentId": "1Ax7vsdg3_YhKjkl2P0TZ5XYZ123456",
    "content": "This is the new content.",
    "replaceAll": true
  }
}

Search for documents

{
  "name": "google_docs_search",
  "arguments": {
    "query": "meeting notes",
    "pageSize": 5
  }
}

License

MIT

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Serper MCP ServerA Serper MCP Server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Amap Maps高德地图官方 MCP Server
CursorThe AI Code Editor
ChatWiseThe second fastest AI chatbot™
DeepChatYour AI Partner on Desktop
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Playwright McpPlaywright MCP server
Tavily Mcp
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
WindsurfThe new purpose-built IDE to harness magic