forcedotcom / forcedotcom/mcp-hosted

[Question]: Unable to use Blob.toPDF() or Visualforce `renderAs=pdf` in MCP synchronously

Open
#56 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
No language data
Stars
135
Forks
20
PR merge metrics
No merged PRs in 30d

Description

### Your question

We are generating PDFs in apex via `Blob.toPdf()` or Visualforce `renderAs=pdf` and those refer to images that are relative image links .. if they are logged in users this all works fine in the lightning experience via apex (no browser required) but they don't work in an MCP Invocable class synchronously. We have to make them async as an Apex queuable class do the same thing and it works. The queueable adds overhead of fetching the status of that job etc. which isn't a good user experience.

The error we see in the debug log when trying to generate synchronously is below:

```
19:11:28.261 (2366175194)|METHOD_EXIT|[186]|01pDn00000ZIFtO|SDOC.DocumentSDK.generateDoc(Id, Id)
19:11:28.261 (2366267419)|VARIABLE_SCOPE_BEGIN|[210]|e|Exception|true|false
19:11:28.261 (2366378295)|VARIABLE_ASSIGNMENT|[210]|e|"common.apex.runtime.impl.ExecutionException: system.security.session.UnsupportedMockSessionOperationException"|0xa6dbf87
19:11:28.261 (2366386910)|STATEMENT_EXECUTE|[210]
19:11:28.261 (2366388726)|STATEMENT_EXECUTE|[211]
19:11:28.261 (2366396237)|HEAP_ALLOCATE|[211]|Bytes:27
19:11:28.261 (2366440523)|HEAP_ALLOCATE|[211]|Bytes:16
19:11:28.261 (2366721317)|HEAP_ALLOCATE|[211]|Bytes:193
19:11:28.261 (2366815521)|USER_DEBUG|[211]|ERROR|Error generating document: system.security.session.UnsupportedMockSessionOperationException | Stack Trace: (SDOC)
Class.SDocsMCPGenerateDocSyncInvocable.generateDocumentSync: line 186, column 1
```

### Context

_No response_

### Environment

sandbox

Contributor guide

Open the contributing guide

Research direction

Start with SDocsMCPGenerateDocSyncInvocable.generateDocumentSync at line 186 and the logged UnsupportedMockSessionOperationException. Compare the synchronous invocable path with the working queueable path to determine whether synchronous PDF generation is supported; done means documenting a confirmed limitation or an identified supported approach.

Written by the indexing model from the issue text.

Assessment

Domain
backend-api-design
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.