docs_update_content
Modify text in Google Docs by replacing existing content with new text using the document ID.
Instructions
Update the content of a Google Doc
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document_id | Yes | ID of the document | |
| content | Yes | New content |
Implementation Reference
- src/mcp_google_suite/server.py:339-354 (handler)The tool handler function _handle_docs_update_content that extracts arguments, performs basic validation, logs the operation, calls the DocsService to update the document, and returns the result.async def _handle_docs_update_content( self, context: GoogleWorkspaceContext, arguments: dict ) -> Dict[str, Any]: """Handle docs update content requests.""" document_id = arguments.get("document_id") content = arguments.get("content") if not document_id or content is None: raise ValueError("Both document_id and content are required") logger.debug(f"Updating document - ID: {document_id}, Content length: {len(content)}") result = await context.docs.update_document_content( document_id=document_id, content=content ) logger.debug("Document content updated successfully") return result
- The input schema definition for the docs_update_content tool, specifying required parameters document_id and content.types.Tool( name="docs_update_content", description="Update the content of a Google Doc", inputSchema={ "type": "object", "properties": { "document_id": {"type": "string", "description": "ID of the document"}, "content": {"type": "string", "description": "New content"}, }, "required": ["document_id", "content"], }, ),
- The DocsService.update_document_content method that implements the core logic using Google Docs API batchUpdate to insert the new content at document index 1, effectively updating the content.async def update_document_content(self, document_id: str, content: str) -> Dict[str, Any]: """Update the content of a Google Doc.""" try: service = await self.get_service() requests = [{"insertText": {"location": {"index": 1}, "text": content}}] result = await asyncio.to_thread( service.documents() .batchUpdate(documentId=document_id, body={"requests": requests}) .execute ) return {"success": True, "result": result} except HttpError as error: return {"success": False, **self.handle_error(error)}
- src/mcp_google_suite/server.py:177-182 (registration)Dynamic registration of tool handlers into the _tool_registry based on _handle_{tool.name} methods.for tool in self._get_tools_list(): handler_name = f"_handle_{tool.name}" if hasattr(self, handler_name): handler = getattr(self, handler_name) self._tool_registry[tool.name] = handler logger.debug(f"Registered handler for {tool.name}")