Authorization, tasks and request tracing
medium 6 minA protocol request and a long-running job have different lifetimes.
Video lesson · Chapter 1 of 4
An export running after the connection closes
Theory
Read or listen first. About 2 min.
What it is
A protocol request and a long-running job have different lifetimes. A JSON-RPC ID connects a response to a request. The July tasks extension adds a separately identified task whose status can be consulted later. Check extension support and retain access checks on status, artifacts and cancellation where applicable. Ending an HTTP exchange does not itself establish the business outcome.
Why it exists
An operator needs separate signals for access denial, application failure, queue time and successful completion. Correlate attempts under a business identifier without recording credentials or sensitive documents. The July release hardens authorization and moves toward Client ID Metadata Documents. Bind credentials to the appropriate issuer and resource, and validate issuer information in the authorization flow.
Track a long export across independent requests
Inside this chapter
Chapter sources- Concurrent requests and task lifecycle
- Run independent reads concurrently within capacity limits. Identify each response by its request ID, and distinguish that correlation from the durable task handle. Use the tasks extension only when both sides support its contract.
Several requests can be in flight at once, and replies can arrive in any order. The client keeps a table of pending ids and hands each reply to whoever is waiting for it. A task handle is a different thing: it names a job that outlives any one request, so it can be polled from a new request, perhaps on another replica. Only rely on the tasks extension after confirming both sides support it.
Example. Two status lookups return in reverse order. Each updates the correct waiting caller and neither starts another export.
Out-of-order replies, matched by id
Request ids correlate messages. E12 and E13 name the long-running jobs. - Authorization and revocation
- Validate token issuer, audience and applicable scope. Bind access to the resource and principal even when the caller already possesses a task identifier. Keep a user’s approval separate from server authorization.
Check that the token came from the expected issuer and was minted for this server (its audience), then check the scope and the specific resource. Do this on every status read, download and cancel. If permissions were revoked after the job started, the current decision wins. Keep the person's approval of an action separate from the server's authorisation: one says they wanted it, the other says they are allowed.
Example. A user loses export access after submitting a job. A later download must pass the current resource check.
Another example. A contractor submits a data export, and their contract ends before it finishes. The export completes, but their download request is denied because their access to the dataset has since been removed.
Knowing E12 is not access to E12
Access is decided at download time, not inherited from submission time. - Operational tracing
- Follow one business task through submission, queue, worker and retrieval. Record terminal state and elapsed time beside attempt-level metrics. Redact payloads before exporting telemetry.
Request-level metrics show each exchange in isolation; a business trace links them under one task ID so you can see where time actually goes. Record the terminal state (completed, failed, cancelled, denied) with the total elapsed time. Redact document contents and tokens before telemetry leaves the service, because traces are widely readable and long-lived.
Example. A 40 ms status call reports a task still queued for eight seconds. Optimizing the status endpoint will not make the worker start sooner.
One export, broken into spans
Span Duration What it tells you Submit request 60 ms fast acceptance Queue wait 8 s worker capacity is the bottleneck Worker run 20 s export work itself Each status call 40 ms polling is cheap and not the problem Download 300 ms artifact delivery Illustrative timings. Optimising the 40 ms status call cannot shorten the 8 s queue. - Cancellation races
- A cancel request can cross with completion: the job may finish just before the cancel arrives. The server should report the true terminal state, and the client should read the state after cancelling rather than assuming the cancel took effect.
Cancellation is a request, not a guarantee. Work may already be done, or partly done with side effects that cannot be undone. Design the worker to check for cancellation at safe points, and make the final state authoritative. Showing 'cancelled' when the export actually exists is a confusing and sometimes risky lie.
Example. A user cancels export E12 at the moment the worker writes the file. The status shows completed, so the UI offers the download instead of claiming it was cancelled.
A cancel only wins if it arrives in time
Terminal states do not change. A cancel that arrives after completion is acknowledged but has no effect.
November 2025 protocol notes
Two responses finish in the opposite order
Concurrent protocol requests can finish out of order or fail at different layers. Correlation IDs connect responses to callers while traces connect user-visible work to downstream services. Authorization and rate limits are enforced per applicable resource and principal.
Run mixed-latency requests and verify that results are delivered to the correct caller. Capture useful timings without recording credentials or unnecessary payloads, and distinguish tool errors from transport or protocol failures.
- High-Performance Concurrency
- Bound simultaneous tool calls according to resource and tenant limits. Multiple read-only lookups can often run together; concurrent writes to the same record may require serialization or a version check. Correlate responses by request ID even when they finish in a different order. Dispatch stock and price reads together with IDs 41 and 42. Deliver price first and check each result reaches the waiting caller with the matching ID.
- Security Hardening
- Apply the protocol’s authorization requirements to protected HTTP services and validate the intended audience of access tokens. Scope credentials to specific resources. Keep client consent, server authorization and downstream API authorization separate so access at one boundary cannot silently expand at another. Present a test token meant for resource A to resource B. Resource B must reject it even when both services recognize the issuer.
- Observability & Metrics
- Measure initialization failures, tool latency, error categories, cancellation and queue delay per server. Trace the host request through the MCP client and onward to downstream dependencies without logging secrets. Distinguish a protocol error from a tool-level business error so operators investigate the correct boundary. Two tools each average 200 ms, but one has a long queue. Include queue time, service time and terminal outcome to distinguish their user-visible behavior.
How it works
Step through the idea, or press Play.
Export request. Submit one authorized export
Understand it
Worked example
Track a long export across independent requests
- 1
Submit one authorized export
The client checks support for tasks and submits export work. The business system records who requested it.
- 2
Track task E12
The service retains a task identity beyond the lifetime of the original JSON-RPC response.
- 3
Poll under the current identity
A new request can check status. A request ID matches this individual response; E12 identifies the ongoing job.
- 4
Authorize the final download
Completion and permission to read the artifact are separate checks. The trace records terminal outcome without including the file contents.
Follow the handoffs
Many request ids, one task
| Step | JSON-RPC id | Task | Outcome |
|---|---|---|---|
| Submit export | 1 | E12 created | requester recorded |
| Poll status | 2 | E12 | queued |
| Poll status, other replica | 3 | E12 | completed |
| Download artifact | 4 | E12 | access checked, file served |
- 1Submittasks support confirmed
- 2QueuedE12 recorded with owner
- 3Worker runstrace spans recorded
- 4Status readsnew request each time
- 5Artifact gatecurrent access checked
The trace records the terminal outcome without copying the file contents.
Summary
The whole topic in one minute.
A task handle enables lookup. The application must still validate the caller and resource on retrieval.
An operator needs separate signals for access denial, application failure, queue time and successful completion. Correlate attempts under a business identifier without recording credentials or sensitive documents. The July release hardens authorization and moves toward Client ID Metadata Documents. Bind credentials to the appropriate issuer and resource, and validate issuer information in the authorization flow.