> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

# Use Media Library with AI agents

Connect an AI agent to upload, find, edit, organize, and link assets in your organization's Media Library.

The Sanity MCP server includes tools for working with Media Library. An agent connected through Claude Code, Cursor, or any other MCP-compatible client can upload, find, edit, organize, and link assets in your organization's Media Library.

This guide explains how to connect an agent, what you can ask it to do with your Media Library, and how changes are kept safe.

## Requirements

- Media Library enabled for your organization. See the [Media Library introduction](https://www.sanity.io/docs/media-library/introduction).
- An MCP-compatible client, such as Claude Code or Cursor.
- An account in the organization with access to the library, or an API token for one.

## Connect your agent

The Media Library tools are part of the hosted Sanity MCP server, so there is nothing else to install. See the [Sanity MCP server](https://www.sanity.io/docs/ai/mcp-server) guide to configure your client and authenticate.

The tools run as the authenticated account. The agent can only see or change resources that the account can see or change in the Media Library app. Media Library belongs to an organization rather than a project, so the account must be a member of the organization and have access to the library. If you use a token instead, the account behind that token needs the same access.

The agent finds your libraries itself, so you do not need to supply a library ID. If the agent reports that the organization has no Media Library, see the [Media Library introduction](https://www.sanity.io/docs/media-library/introduction).

## What you can ask the agent to do

Once connected and authenticated, you can use natural language to ask the agent to work with your Media Library.

### Understand your library's aspects

The agent can read the custom asset aspects defined by your organization and the values they allow.

- Show me the aspects available for images in my Media Library.
- What values can I use for the copyright aspect?
- Explain which aspects apply to video assets.

### Find and inspect assets

The agent can search assets by aspect values, asset type, folder, and title, and find collections and folders by name. It can open a specific asset and read everything stored on it, including its aspects.

- Find assets in my Media Library where the copyright aspect is Sanity.
- Show me all video assets in the Campaigns folder.
- Find collections with campaign in the title.
- Which aspects are set on this asset?

### Edit asset aspects

Changes to an asset's title or aspect values are saved to a draft, never directly to the published asset. You can review the draft in the Media Library app, ask the agent to publish it, or ask the agent to discard it. 

- Change this asset's title to Product launch hero.
- Set the copyright holder for these assets to Sanity.
- Publish the draft changes for this asset.
- Discard the draft changes on this asset.
- Make this asset private.

> [!WARNING]
> Gotcha
> Changes to an asset's visibility (public or private) apply immediately and don't create a draft.

### Organize assets into collections

The agent can create collections and change their title, description, and included assets. Collection changes apply immediately and do not create drafts.

- Create a collection named Product launch campaign.
- Add these three assets to the Product launch campaign collection.
- Rename this collection and update its description.
- Remove the outdated logo from this collection.

### See where an asset is used

The agent can list documents across your organization's Sanity projects that use an asset. Check these references before replacing an asset.

- Which documents use this image?
- Find every project and document that references this asset.
- Check whether this video is in use before I replace it.

### Link assets to documents

The agent can link Media Library assets to image, file, and video fields on documents in your projects, including documents your team edits in Sanity Studio.

- Link an asset from my Media Library to the image field on this document.
- Use the approved press kit PDF for this document's download field.
- Put the latest product demo video in this page's video field.

### Upload assets

The agent can upload images, videos, and files to your Media Library from your computer or a public URL. When you create a new asset, tell the agent what title and aspect values to use and whether the asset should be public or private. For an image, you can ask the agent to generate the title from its content.

#### Upload from a URL

The agent can upload an asset from a public HTTPS URL. Sanity retrieves the file directly and does not send your credentials to the source. The agent waits for the upload to finish, which can take a few minutes for large files.

- Upload the image from this URL to my Media Library and generate a title from its content.
- Upload the video from this URL to my Media Library as a private asset titled Campaign preview.
- Upload the PDF from this URL as a new version of the existing product brochure asset, then update every document that uses the asset.

#### Upload from your computer

The agent can upload a file from your computer or use a file it generated for you. Files can be up to 50 MiB. Uploading from your computer works in MCP clients that can read local files, such as Claude Code and Cursor.

- Upload ~/Desktop/product-diagram.png to my Media Library with the title Product diagram.
- Upload ~/Downloads/campaign-hero.png to my Media Library as a public asset and set its approval status aspect to Approved.
- Upload the image you generated to my Media Library as a private asset titled Homepage concept.

## Safeguards on every change

Every change is validated against your library's schema, including its aspect definitions, before anything is written. The tools use the same validation engine as the Media Library app. If a change is invalid, the tools reject it, the agent passes the reason on, and nothing is written.

The agent cannot change information that Media Library manages itself, such as version history or asset type, and it cannot place assets in folders. It also cannot change read-only aspects, add aspects to asset types they do not apply to, or reference missing or draft-only documents in the library.

The agent cannot delete assets or collections, or change aspect definitions. Other ways to upload, such as the CLI and the HTTP API, are covered by [Upload assets programmatically](https://www.sanity.io/docs/media-library/upload-assets). To deploy aspect definitions, see [Create an aspect](https://www.sanity.io/docs/media-library/create-aspect).

For the full list of Media Library tools and what each does, see the [Sanity MCP server](https://www.sanity.io/docs/ai/mcp-server) page.

#### Related articles

[Sanity MCP server](https://www.sanity.io/docs/ai/mcp-server)
Enable AI agents to interact with your Sanity workspace through the Model Context Protocol (MCP).

[Upload assets programmatically](https://www.sanity.io/docs/media-library/upload-assets)
Programmatically upload assets to your Media Library.

[Create an aspect](https://www.sanity.io/docs/media-library/create-aspect)
Create and deploy aspects for Media Library.

[Media Library introduction](https://www.sanity.io/docs/media-library/introduction)
Learn about Media Library, how to incorporate it into your workflow, and how to get started.

