create_doc
Generate and customize Google Docs by specifying a title and optional content using the Google Workspace MCP Server, returning a document ID and link for immediate access.
Instructions
Creates a new Google Doc and optionally inserts initial content.
Returns:
str: Confirmation message with document ID and link.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | ||
| service | Yes | ||
| title | Yes | ||
| user_google_email | Yes |
Implementation Reference
- gdocs/docs_tools.py:287-309 (handler)The core handler function for the 'create_doc' tool. It creates a new Google Document using the Google Docs API, optionally inserts initial content at index 1, generates a shareable link, and returns a confirmation message with the document ID.async def create_doc( service: Any, user_google_email: str, title: str, content: str = '', ) -> str: """ Creates a new Google Doc and optionally inserts initial content. Returns: str: Confirmation message with document ID and link. """ logger.info(f"[create_doc] Invoked. Email: '{user_google_email}', Title='{title}'") doc = await asyncio.to_thread(service.documents().create(body={'title': title}).execute) doc_id = doc.get('documentId') if content: requests = [{'insertText': {'location': {'index': 1}, 'text': content}}] await asyncio.to_thread(service.documents().batchUpdate(documentId=doc_id, body={'requests': requests}).execute) link = f"https://docs.google.com/document/d/{doc_id}/edit" msg = f"Created Google Doc '{title}' (ID: {doc_id}) for {user_google_email}. Link: {link}" logger.info(f"Successfully created Google Doc '{title}' (ID: {doc_id}) for {user_google_email}. Link: {link}") return msg
- gdocs/docs_tools.py:284-284 (registration)The @server.tool() decorator registers the create_doc function as an MCP tool.@server.tool()
- gdocs/docs_tools.py:285-286 (handler)Decorators for error handling specific to 'create_doc' tool and required auth scopes for Docs API write access.@handle_http_errors("create_doc", service_type="docs") @require_google_service("docs", "docs_write")