Skip to main content
Glama

prismic_upsert_documents

Batch create or update documents in Prismic's Migration API workflow for content management. Use dry runs and fail-fast options for controlled execution before publishing.

Instructions

Batch create/update documents in the Prismic Migration API.

Important behavior:

  • This writes to the Migration workflow (Migration UI/release flow).

  • Batch-created/updated documents may not be visible via Content API master reads until release/publish workflow makes them readable.

  • For read-back before publish, use a release ref with read tools (ref parameter), plus PRISMIC_CONTENT_API_TOKEN if repo settings require authenticated reads.

  • Supports dry_run and fail_fast for safer execution.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
documentsYes
fail_fastNo
dry_runNo

Implementation Reference

  • The implementation of the `handle_prismic_upsert_documents` handler which performs the batch upsert operations.
    async def handle_prismic_upsert_documents(
        *,
        documents: list[DocumentWrite],
        fail_fast: bool = False,
        dry_run: bool = False,
        service_factory: ServiceFactory = _build_service,
    ) -> dict[str, Any]:
        """Batch create/update documents in the Migration API."""
    
        created = 0
        updated = 0
        failed = 0
        results: list[dict[str, Any]] = []
    
        async with service_factory(require_write_credentials=True) as service:
            service.validate_batch_size(len(documents))
            for index, document in enumerate(documents):
                input_ref = _document_reference(document, index)
                try:
                    if dry_run:
                        plan = service.plan_upsert(document)
                        status = plan["status"]
                        resolved_id = plan["id"]
                    else:
                        response = await service.upsert_document(document)
                        status = response["status"]
                        resolved_id = response["id"]
    
                    if status == "created":
                        created += 1
                    else:
                        updated += 1
                    results.append(
                        {
                            "input_ref": input_ref,
                            "ok": True,
                            "id": resolved_id,
                            "error": None,
                            "dry_run": dry_run,
                        }
                    )
                except RECOVERABLE_BATCH_EXCEPTIONS as exc:
                    failed += 1
                    results.append(
                        {
                            "input_ref": input_ref,
                            "ok": False,
                            "id": None,
                            "error": _safe_batch_error(exc),
                            "dry_run": dry_run,
                        }
                    )
                    if fail_fast:
                        raise
    
        return {
            "results": results,
            "summary": {
                "created": created,
                "updated": updated,
                "failed": failed,
            },
        }
  • The registration of the `prismic_upsert_documents` tool using the @server.tool decorator.
    @server.tool(name="prismic_upsert_documents")
    async def prismic_upsert_documents(
        documents: list[DocumentWrite],
        fail_fast: bool = False,
        dry_run: bool = False,
    ) -> dict[str, Any]:
        """Batch create/update documents in the Prismic Migration API.
    
        Important behavior:
        - This writes to the Migration workflow (Migration UI/release flow).
        - Batch-created/updated documents may not be visible via Content API
          master reads until release/publish workflow makes them readable.
        - For read-back before publish, use a release ref with read tools
          (`ref` parameter), plus `PRISMIC_CONTENT_API_TOKEN` if repo settings
          require authenticated reads.
        - Supports `dry_run` and `fail_fast` for safer execution.
        """
    
        return await handle_prismic_upsert_documents(
            documents=documents,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rahulpowar/prismic-content-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server