docs_create
Create a new Google Doc with a title and optional initial content through Google Workspace integration.
Instructions
Create a new Google Doc
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | Title of the document | |
| content | No | Initial content |
Implementation Reference
- src/mcp_google_suite/server.py:310-323 (handler)The primary MCP tool handler for 'docs_create'. Extracts title and optional content from input arguments, validates title, logs the action, calls DocsService.create_document, and returns the result.async def _handle_docs_create( self, context: GoogleWorkspaceContext, arguments: dict ) -> Dict[str, Any]: """Handle docs create requests.""" title = arguments.get("title") content = arguments.get("content") if not title: raise ValueError("Document title is required") logger.debug(f"Creating document - Title: {title}, Content length: {len(content or '')}") result = await context.docs.create_document(title=title, content=content) logger.debug(f"Document created - ID: {result.get('documentId')}") return result
- src/mcp_google_suite/server.py:85-96 (schema)Input schema definition for the 'docs_create' tool, specifying title as required string and content as optional string.types.Tool( name="docs_create", description="Create a new Google Doc", inputSchema={ "type": "object", "properties": { "title": {"type": "string", "description": "Title of the document"}, "content": {"type": "string", "description": "Initial content"}, }, "required": ["title"], }, ),
- src/mcp_google_suite/server.py:178-183 (registration)Dynamic registration code that maps the 'docs_create' tool name to its handler '_handle_docs_create' in the tool registry.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}")
- Helper method in DocsService that performs the actual Google Docs API call to create a new document and optionally updates it with initial content.async def create_document(self, title: str, content: Optional[str] = None) -> Dict[str, Any]: """Create a new Google Doc with optional initial content.""" try: service = await self.get_service() doc = await asyncio.to_thread(service.documents().create(body={"title": title}).execute) if content: await self.update_document_content(doc["documentId"], content) return {"success": True, "document": doc} except HttpError as error: return {"success": False, **self.handle_error(error)}