create_doc
Generate a new Google Doc with a specified title and optional initial content. Returns a confirmation message including the document ID and link for easy 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 | ||
| title | Yes | ||
| user_google_email | Yes |
Implementation Reference
- gdocs/docs_tools.py:278-303 (handler)The primary handler function for the 'create_doc' MCP tool. It creates a new Google Document using the Docs API with the given title and optional initial content, then returns the document ID and edit link.@server.tool() @handle_http_errors("create_doc", service_type="docs") @require_google_service("docs", "docs_write") async def create_doc( service, 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:278-278 (registration)The @server.tool() decorator registers the create_doc function as an MCP tool.@server.tool()