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.

4 min readSume
All posts

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()?

Job behavior from the Sume docs, read 2026-09-30: https://docs.sume.com/workflows/jobs-and-results
ThingBehavior in the docs
Submitted paid jobKeeps running and billing until terminal or canceled
Local process timeoutDo not resubmit the paid request because of it
wait_for: "any"Remaining jobs continue and still bill
Canceljobs_cancel (write, needs idempotency_key)
Read laterjobs_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

All Developers posts

Written by Sume