upload_media
Upload an image or video from a public URL to Sprout Social and obtain a media ID for use in publishing posts.
Instructions
Upload media (image/video) to Sprout Social for use in publishing posts. Provide either a public URL to the media file. Returns a media ID to use with create_publishing_post.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| media_url | Yes | A public HTTP/HTTPS URL of the media file to upload. |
Implementation Reference
- src/index.ts:476-512 (registration)Registration of the 'upload_media' tool via server.tool(), including its description, schema, and handler function.
// ─── Media Upload Tool ────────────────────────────────────────────────────── server.tool( "upload_media", "Upload media (image/video) to Sprout Social for use in publishing posts. " + "Provide either a public URL to the media file. Returns a media ID to use with create_publishing_post.", { media_url: z .string() .describe("A public HTTP/HTTPS URL of the media file to upload."), }, async ({ media_url }) => { const { apiKey, customerId } = getConfig(); const url = `${SPROUT_API_BASE}/v1/${customerId}/media`; const formData = new FormData(); formData.append("media_url", media_url); const response = await fetch(url, { method: "POST", headers: { Authorization: `Bearer ${apiKey}`, }, body: formData, }); if (!response.ok) { const errorText = await response.text(); throw new Error( `Sprout Social media upload error (${response.status}): ${errorText}` ); } const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:482-486 (schema)Input schema for upload_media: requires a single string parameter 'media_url' (a public HTTP/HTTPS URL).
{ media_url: z .string() .describe("A public HTTP/HTTPS URL of the media file to upload."), }, - src/index.ts:487-511 (handler)Handler function for upload_media that constructs a FormData payload with the media_url, POSTs it to Sprout Social's /v1/{customerId}/media endpoint, and returns the JSON response containing the media ID.
async ({ media_url }) => { const { apiKey, customerId } = getConfig(); const url = `${SPROUT_API_BASE}/v1/${customerId}/media`; const formData = new FormData(); formData.append("media_url", media_url); const response = await fetch(url, { method: "POST", headers: { Authorization: `Bearer ${apiKey}`, }, body: formData, }); if (!response.ok) { const errorText = await response.text(); throw new Error( `Sprout Social media upload error (${response.status}): ${errorText}` ); } const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } - src/index.ts:420-425 (helper)The media_ids parameter on create_publishing_post references upload_media output, showing how the media ID returned by upload_media is consumed.
media_ids: z .array(z.string()) .optional() .describe( "Array of media IDs (from upload_media) to attach to the post." ),