Skip to content

Return a PDF as a Tool result #162

@gyger

Description

@gyger

Is your feature request related to a problem? Please describe.
I want to return a PDF instead of an Image during a Tool results using the Python SDK.

I thought the way to do it is probably like this:

@mcp.tool(description="Retrieve PDF for item in the library")
def get_item_pdf(item_key: str, attachment_index: int = 0, *, ctx: Context) -> EmbeddedResource | str:
            [......]
            with pdf_path.open('rb') as fp:
                pdf_content = fp.read()
                pdf_resource = BlobResourceContents(
                      uri=f"zotero://items/{item_key}/pdf", 
                      mimeType="application/pdf", 
                     blob=base64.b64encode(pdf_content).decode())
                return EmbeddedResource(type='resource', resource=pdf_resource)

but I only get the error

Error
too much recursion in the MCP inspector.

And Claude desktop does not like it, so I am guessing it does not work yet, or it would be great if there is an alternative version of returning things that are not images.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions