Skip to main content
Google Docs

Google Docs

The GoogleDocs molecule provides MCP (Model Context Protocol) tools for creating and displaying Google Docs in the SixDegree discovery service.

  • Create Google Docs: Create new Google Documents from text, Markdown, or HTML content
  • Display Docs: Embed Google Docs with view/edit controls in widgets
  • OAuth Authentication: Uses Google OAuth tokens for secure API access
  • Widget Support: Renders embedded Google Doc iframes with interactive controls
  • MCP Tools: Exposes Google Docs creation capabilities via the MCP protocol

This molecule is MCP-only - it does not provide entity or relation discovery. It focuses on providing tools for document creation and display through the Model Context Protocol.

  • MCP: Full support for MCP tools (create_doc, show_doc, create_doc_with_markdown)

  • Discovery: Not supported (no entity/relation discovery)

  • Widgets: Display widget for embedding Google Docs

  • Go 1.25+

  • Google Docs and Drive API access

  • OAuth token with required scopes

cd molecules
make dev

Output: ./bin/googledocs

make build

Create a config.yaml file:

mcp:
enabled: true
settings:
oauth_token: "YOUR_GOOGLE_OAUTH_TOKEN_HERE"
  1. Via Google OAuth 2.0 Playground (easiest for testing):

  2. Via your own OAuth flow:

    • Configure a Google Cloud project with Docs and Drive APIs enabled
    • Implement OAuth 2.0 authentication
    • Obtain an access token with required scopes
https://www.googleapis.com/auth/documents      # Google Docs API
https://www.googleapis.com/auth/drive.file # Google Drive API (file creation)

Run the molecule as an MCP server:

./bin/googledocs -mcp --config example-config.yaml

The server accepts JSON-RPC 2.0 requests over stdin and outputs responses to stdout.

Create a new Google Doc from content.

Request:

{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "create_doc",
"arguments": {
"title": "My Document",
"content": "Document content here",
"content_type": "text/plain"
}
}
}

Parameters:

  • title (string, required): Document title
  • content (string, required): Document content
  • content_type (string, optional): "text/plain" (default), "text/markdown", or "text/html"

Response:

{
"jsonrpc": "2.0",
"id": 1,
"result": {
"success": true,
"result": {
"created": true,
"doc_id": "1BxiMVs0XRA5nFMwSqWObJJW6IH-QyWsF1479kxQaPAU",
"title": "My Document",
"view_link": "https://docs.google.com/document/d/1BxiMVs0.../view",
"edit_link": "https://docs.google.com/document/d/1BxiMVs0.../edit",
"embed_url": "https://docs.google.com/document/d/1BxiMVs0.../preview?embedded=true&rm=minimal",
"_meta": {
"type": "googledoc-embed",
"data": { ... }
}
}
}
}

Display an embedded Google Doc widget.

Request:

{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "show_doc",
"arguments": {
"document_id": "1BxiMVs0XRA5nFMwSqWObJJW6IH-QyWsF1479kxQaPAU",
"title": "My Presentation",
"mode": "view",
"width": "100%",
"height": "600px"
}
}
}

Parameters:

  • document_id (string, required): Google Doc document ID
  • title (string, optional): Display title
  • mode (string, optional): "view" (default) or "edit"
  • width (string, optional): Widget width (default: "100%")
  • height (string, optional): Widget height (default: "600px")

Response:

{
"jsonrpc": "2.0",
"id": 2,
"result": {
"success": true,
"result": {
"document_id": "1BxiMVs0XRA5nFMwSqWObJJW6IH-QyWsF1479kxQaPAU",
"title": "My Presentation",
"embed_url": "https://docs.google.com/document/d/1BxiMVs0.../preview?embedded=true&rm=minimal",
"view_link": "https://docs.google.com/document/d/1BxiMVs0.../view",
"edit_link": "https://docs.google.com/document/d/1BxiMVs0.../edit",
"mode": "view",
"width": "100%",
"height": "600px",
"_meta": { ... }
}
}
}

Create a Google Doc from Markdown content.

Request:

{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "create_doc_with_markdown",
"arguments": {
"title": "My Markdown Doc",
"markdown_content": "# Heading\n\nSome **bold** text"
}
}
}

Parameters:

  • title (string, required): Document title
  • markdown_content (string, required): Markdown formatted content

Response: Same format as create_doc

The molecule returns widget data in the _meta field with the following structure:

{
"_meta": {
"type": "googledoc-embed",
"data": {
"document_id": "...",
"title": "...",
"embed_url": "...",
"view_link": "...",
"edit_link": "...",
"mode": "view",
"width": "100%",
"height": "600px"
}
}
}

The dashboard renders this using the JavaScript widget in static/googledoc.js, which:

  • Displays an iframe with the embedded Google Doc
  • Shows a header with the document title and Google Docs logo
  • Provides "View" and "Edit" buttons to open the document
  • Supports custom width and height
  1. initialize: Client initializes the MCP server
  2. tools/list: Client requests available tools
  3. tools/call: Client calls a tool with arguments
  4. Configure: Molecule loads OAuth token from config
  5. API Call: Molecule calls Google Docs/Drive API
  6. Return Result: Molecule returns formatted response
  • Plain Text: Inserted as-is
  • Markdown: Markdown syntax stripped, text inserted
  • HTML: HTML tags removed, text inserted

Tokens are provided via MCP config and stored in memory. The molecule creates an OAuth HTTP client that automatically includes the token in API requests.

Common errors and their meanings:

  • "oauth_token is required": OAuth token not provided in config

  • "molecule not configured": Configure() hasn't been called yet

  • "failed to create file": Drive API error (quota, permissions, etc.)

  • "failed to update document": Docs API error

  • ✅ OAuth tokens are treated as secrets (marked with x-sixdegree: {widget: secret})

  • ✅ No tokens are logged to stdout/stderr

  • ✅ All API communication uses HTTPS

  • ✅ OAuth tokens should have minimal scopes (documents, drive.file only)

  • main.go: Main molecule implementation

  • molecule.yaml: Metadata and capability definitions

  • example-config.yaml: Example configuration

  • static/googledoc.js: Widget JavaScript renderer

  • README.md: This file


echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}
{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | ./bin/googledocs -mcp


echo '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"show_doc","arguments":{"document_id":"1BxiMVs0XRA5nFMwSqWObJJW6IH-QyWsF1479kxQaPAU"}}}' | ./bin/googledocs -mcp --config example-config.yaml

MIT - See LICENSE file in molecules directory