AI SDK MCP client close() in onEnd: Sume jobs keep running
Closing the AI SDK MCP client in onEnd ends the tool connection, not the Sume jobs already submitted. Track job ids, then read or cancel them.

Closing the MCP client in onEnd only ends your connection to Sume. A video job submitted through a tool call is a Sume job with its own id, so keep the job_id and read it later with jobs_status, or cancel it with jobs_cancel.
Client facts are from the AI SDK MCP page; job behavior from Sume's Jobs and results and MCP tools and gates, read 2026-09-30.
When does the AI SDK say to close the client?
The page says to close based on your usage pattern: for short-lived use, close in the onEnd callback of a streaming call; for long-running use, close when the application terminates.
import { createMCPClient } from "@ai-sdk/mcp";
const mcpClient = await createMCPClient({
transport: {
type: "http",
url: "https://mcp.sume.com/mcp",
headers: { Authorization: `Bearer ${process.env.SUME_API_KEY}` },
},
});
const tools = await mcpClient.tools();
// ... streamText({ tools, onEnd: async () => { await mcpClient.close(); } })What survives after close()?
| Thing | Behavior in the docs |
|---|---|
| Submitted paid job | Keeps running and billing until terminal or canceled |
| Local process timeout | Do not resubmit the paid request because of it |
wait_for: "any" | Remaining jobs continue and still bill |
| Cancel | jobs_cancel (write, needs idempotency_key) |
| Read later | jobs_status, jobs_result, or batch with job_ids |
What should I store before closing?
Store the job ids returned by the create tool. The docs' guidance is to re-read with the same ids, never to resubmit the create.
Should I use a long-lived client instead?
For a server that handles many requests, the page's long-running pattern applies: open the client once and close it when the app ends. The same rule holds either way: job state lives on Sume, not in the client.
What do I do with a job I no longer want?
Cancel it. jobs_cancel is a write tool and needs an idempotency_key, so the session must have mcp:write or an API key. Cancellation succeeds only before generation work starts; after that the job runs to completion. If the render is already done, jobs_result returns the artifacts, and the docs recommend reporting Sume public ids and media.sume.com URLs rather than pasting signed URLs, tokens or keys into chat logs.
Sources
Related posts
More in Developers
- Airtable script 50-fetch limit: send 100 records as one bulk run
An Airtable automation script gets 50 fetches and a 30-second timeout. One Sume bulk-run request carries up to 100 items, so one fetch beats a per-record loop.
- Airtable has no webhook signature check: verify Sume first
Airtable's When webhook received trigger cannot verify signatures and caps payloads at 100kb. Verify the Sume signature in a relay and forward a small object.
- AI Act Article 50 in force: what to log per generated file
Article 50 applies from 2 August 2026. Keep a per-file record of job id, request id and artifact URL from Sume, and know what the docs leave unsaid on marking.
- Why Sume Agent Completions rejects assistant messages
An assistant turn in messages[] returns 400 invalid_request on Sume Agent Completions. Only system and user turns work; each call runs in a fresh thread.
Written by Sume