An AI agent should ask a document three things before it renders a single page: how many pages it has, how big each page is, and whether it needs a password. The GroupDocs.Viewer.Mcp server answers the first two with one cheap call (get_view_info), run locally on your machine, and the password question is settled in the prompt. The agent then renders only the pages that matter:

What is contract.docx — how many pages, and what page size?

The step-by-step version with config and troubleshooting is in the documentation: How to check a document’s pages before rendering them.

Why inspect first?

Every page the render_page tool produces comes back to the agent as an inline PNG, often a few hundred kilobytes. An agent that renders a 60-page file to find one table pays for 59 images it did not need, in time and in context window. The inspection tool, get_view_info, renders nothing. It returns a small JSON object, so the decision about what to render is made on facts rather than guesses.

The pattern is reusable in any client: Claude Desktop, Claude Code, Cursor, VS Code with GitHub Copilot or Windsurf. It is a habit you put in a prompt, not a feature you configure.

Question 1: How many pages are there?

get_view_info returns pageCount. This is the only guard against a documented sharp edge: render_page does not check the page number against the document. Ask for page 40 of a 12-page file and you still receive an image, saved as <name>_page40.png, of a page that is not page 40.

A prompt that builds the guard in:

How many pages does the report have? Then show me the last one.

For spreadsheets the count matters even more. The engine splits a sheet into pages, and the number can be far larger than the sheet looks. Knowing it first keeps the agent from rendering all of them.

Question 2: What size is each page?

What size are the pages in this PDF — Letter or A4?

The response lists number, width and height for every page, in points. 612 by 792 is US Letter; about 595 by 842 is A4. A document with one landscape page among portrait pages shows it in the sizes, and that page is often the table or the drawing someone is asking about.

Two other fields, name and visible, are filled where the format has them, for example worksheet names and hidden slides or sheets. They are null and true otherwise.

Question 3: Does the file need a password?

get_view_info has no protection field, so the file type and page count do not tell you whether a password is needed. A password-protected file needs its password on every call, to either tool. Give it up front in the prompt:

The password for contract.pdf is in my message. Check how many pages it has, then show me page 2.

Without the password the call fails, and the agent can ask you for it instead of guessing. If the call fails, get_view_info returns text starting View-info lookup failed for followed by the exception type and message, so the agent can read the reason and ask for the password or the right file name.

A reusable inspect-then-render prompt

Before rendering anything from the file named below, check its file type, page count and page sizes. Tell me what you found, then render only the pages needed to answer my question. File: contract.docx. Question: where is the termination clause?

The agent calls get_view_info, reports the file type and page count, picks pages, and calls render_page for each. The get_license_status tool is the third tool on the server; use it when you need to know whether rendered pages will be watermarked.

Example session

An illustration based on the documented response shape, not a captured screenshot.

You:   Inspect report.pdf before rendering anything.

Agent: [calls get_view_info on report.pdf]
       report.pdf: Portable Document Format File (.pdf), 2 pages.
       Page 1: 612 x 792 points (US Letter). Page 2: 612 x 792 points.
       Which page would you like me to render?

What does the agent decide, and what does the engine do?

Step Agent Engine
Choose the file Takes the file name from your prompt Resolves it in the storage folder, lists available files if the name does not match
Inspect Decides which questions matter Returns file type, page count and page sizes
Select pages Maps your question to page numbers Nothing
Render Calls render_page for each chosen page Produces the PNG

Honest limits

  • Evaluation mode. Rendered pages carry an evaluation watermark and a server process opens at most 15 documents. Ask “Is the viewer server licensed?” so the agent calls get_license_status before you rely on the output.
  • The page count does not choose pages for you. get_view_info says which pages exist, not which one holds the answer. For that, render a contents page or a few candidates.
  • PNG only. There is no format option on render_page.

FAQ

How can an AI agent get the page count of a PDF? If the Viewer server is connected, Claude can call get_view_info and read pageCount without rendering anything. The answer comes from the document, not from a guess.

Can a document info MCP tool tell the agent which pages to render? Yes. Give it the page count and sizes first, then tell it what you are looking for. It renders the pages that answer the question.

Does inspecting a document upload it anywhere? No. The server reads the file from the folder you configure and returns a small JSON object to your client.

Go deeper