Introducing a new way to review your PRs.

Read the announcement

capsoftware / cap

Open source Loom alternative. Beautiful, shareable screen recordings.

View on GitHub

31 documents · Updated Nov 23, 2026

docs / infrastructure-mcp-tooling

Infrastructure MCP tooling

Infrastructure MCP tooling gives an AI client safe access to Cap Infra. It turns tool calls into video, speech, account, and documentation actions, then returns compact results with the next useful step. See also Web product, Web application routes, Web API and domain services, and Developer infrastructure platform.

System role

MCP server boundary

The @cap/infra-mcp package is an MCP access layer for the developer platform. A local MCP client starts the server over standard input and output. The server uses an app secret key to call the Cap Infra REST API, so it does not need Cap Desktop or a Cap user login. References: packages/…/README.md• L1-7, packages/…/server.ts• L36-45

The server exposes typed tools rather than a general REST proxy. Each tool describes its accepted input, whether it reads, writes, or deletes data, and the next action for work that is still in progress. This lets an agent focus on the media task while the server manages API details. References: packages/…/server.ts• L60-94, packages/…/tool.ts• L9-39, packages/…/runner.ts• L14-24

Tool surfaces

The package supports two access surfaces that share the same product workflows. The local surface can read a file from the machine that runs the MCP server. The hosted surface cannot read that machine's files, so it offers signed storage links and short tool budgets for an agent or another service to upload the file directly. References: packages/…/tool.ts• L20-30, packages/…/tools.ts• L953-958, packages/…/hosted.ts• L23-37, packages/…/hosted-upload.ts• L75-83

Product workflows

Video lifecycle

Video tools move a source file into Cap Infra and return playback or sharing links. A local client uploads a file in one call. A hosted client imports a public file URL or creates a multipart upload that the file-owning machine completes. Both paths then use the same wait, read, list, and delete actions. References: packages/…/README.md• L46-56, packages/…/tools.ts• L331-601, packages/…/hosted-upload.ts• L78-83

The video flow is asynchronous because file transfer and media encoding finish at different times. A video can be ready to play while an optional link is still missing. The result reports the links that exist and tells the agent whether to keep waiting, use another link, or inspect the video later. References: packages/…/tools.ts• L475-555, packages/…/wait.ts• L40-91, packages/…/SKILL.md• L18-27

This diagram shows the shared video path from a source to a usable result.

flowchart LR
    A[Local file or public URL] --> B[Create or resume video]
    B --> C[Upload or Cap download]
    C --> D[Encode video]
    D --> E[Wait for playable links]
    E --> F[Playback, share, or embed result]
    E --> G[Status or recovery action]

References: packages/…/tools.ts• L331-555 packages/…/upload.ts• L364-472 packages/…/hosted-upload.ts• L188-313

Speech-to-text lifecycle

Transcript tools accept exactly one source: a public media URL, a local file on the local surface, or a ready stored video. They create a transcript, wait for completion, and expose text or optional word and segment timings. The same domain lists and deletes transcripts. References: packages/…/tools.ts• L604-898, packages/…/README.md• L56-61

The source affects how the file reaches Cap Infra, but not the agent-facing job lifecycle. A video source must have a usable MP4. A local file is stored before transcription starts. An idempotency key lets a repeated create request return the same transcript instead of starting another billed job. References: packages/…/tools.ts• L194-284, packages/…/tools.ts• L286-329, packages/…/tools.ts• L650-727

Account and documentation access

Account tools show credit, upload eligibility, storage use, rates, and the transaction ledger. They let an agent check cost and service state before starting work. Credit cannot be bought through MCP, so credit errors include a console link for a signed-in person. References: packages/…/tools.ts• L900-948, packages/…/credit-link.ts• L31-80, packages/…/errors.ts• L50-64

The docs_read tool gives an agent focused access to the Cap Infra documentation. It returns an outline or one matching section from setup, REST API, webhooks, or billing pages. The response is limited and can link to the full page, which keeps product guidance small enough for a tool result. References: packages/…/docs.ts• L6-20, packages/…/docs.ts• L169-236, packages/…/docs.ts• L281-322

Request and data boundary

Tool input contract

Tool schemas define the input contract before a request reaches the API. They reject unknown fields and explain which fields the tool accepts. Tool results use a small, stable set of fields instead of passing full API records to the client. References: packages/…/tool.ts• L47-71, packages/…/shape.ts• L15-58, packages/…/shape.ts• L110-122

The result contract separates normal results from failures. A normal result is compact JSON with status and next-step information where needed. A failure has an error code, message, optional hint, API details, and recovery context. This makes an error actionable without exposing the full transport response. References: packages/…/runner.ts• L26-59, packages/…/runner.ts• L70-140, packages/…/errors.ts• L3-47

API request shaping

The request boundary maps each tool action to an approved API method, path, authentication mode, query set, body set, and header set. It rejects fields outside that route. This keeps the MCP contract aligned with the documented developer API and prevents accidental data transfer. References: packages/…/routes.ts• L1-34, packages/…/routes.ts• L36-94, packages/…/http.ts• L192-218

Normal API calls use the app secret. Storage-session calls use a short-lived upload token. The two credentials stay separate even though both are managed through the same tool flow. Redirects are rejected so a mistaken API address does not silently send credentials to another origin. References: packages/…/http.ts• L250-305, packages/…/upload.ts• L94-137

File and upload handling

Local file actions verify that a path names a readable, non-empty media file within the relevant size limit before transfer. The checks also distinguish self-contained media from playlists and non-media files. This prevents a bad source from creating an incomplete remote record. References: packages/…/files.ts• L23-29, packages/…/files.ts• L101-162, packages/…/media-sniff.ts• L60-103

Video uploads use resumable parts with bounded parallel work and progress events. Hosted uploads expose only a limited batch of signed part links at a time. The agent keeps the upload identity and part tags so it can request the next links or finish the same upload without starting a second video. References: packages/…/upload.ts• L178-325, packages/…/hosted-upload.ts• L241-293

Transcript files use a separate file step because Cap Infra creates the transcript record before it stores the source. The result therefore distinguishes a record with no file from a file that was stored but may already be processing. References: packages/…/tools.ts• L194-284

Output redaction

The server removes app secrets, upload tokens, and signed storage credentials from tool results, logs, and progress events. It also removes query and fragment data from source URLs shown to the agent. This preserves useful job context without exposing credentials. References: packages/…/redact.ts• L1-14, packages/…/redact.ts• L20-47, packages/…/shape.ts• L29-39, packages/…/runner.ts• L70-109

Retry and recovery behavior

Safe request retry

The API client retries only read requests when a temporary network or server failure occurs. It honors Retry-After for rate limits and shares the resulting pause across requests that use the same app secret. Write requests are not repeated automatically because a repeat could create duplicate media or charges. References: packages/…/http.ts• L125-189, packages/…/http.ts• L221-247

The client turns API, network, timeout, redirect, and cancellation conditions into tool errors with a code and recovery hint. Credit failures add the console destination. The agent can therefore choose between fixing input, waiting, checking state, or asking a person to add credit. References: packages/…/http.ts• L69-113, packages/…/runner.ts• L112-140, packages/…/errors.ts• L50-71

Long-running work

Wait tools poll until a job reaches a final state or the caller's time limit ends. Polls slow down over time and respect rate-limit advice. A timed-out result keeps the last known state and names the same wait action, so a client timeout does not require a new job. References: packages/…/wait.ts• L23-91, packages/…/tools.ts• L179-192, packages/…/README.md• L70-75

Upload recovery

Upload recovery separates known incomplete work from uncertain completion. When no file reached Cap Infra, the agent can retry with the same video ID or delete the empty record. When completion was unclear, the agent must read the video first because the upload may have finished and may already be encoding. The hosted flow keeps stored parts when it resumes an existing upload. References: packages/…/upload.ts• L328-362, packages/…/upload.ts• L453-472, packages/…/hosted-upload.ts• L295-312, packages/…/SKILL.md• L29-34

Transcript recovery

Transcript recovery follows the same safety rule after a local file is stored. If starting the job has an unclear result, the transcript may be running and may be billed. The agent checks it with a read or wait action before deleting it or creating another transcript. References: packages/…/tools.ts• L247-282, packages/…/SKILL.md• L44-50

Client configuration and transport

Local configuration

The local server needs a Cap Infra secret key and defaults to the production API. A custom API URL is allowed for secure endpoints and local HTTP development. Invalid configuration stops startup before tool calls begin, and the key is never printed. References: packages/…/config.ts• L1-15, packages/…/config.ts• L17-70, packages/…/README.md• L17-24

The local client communicates over standard input and output. The server sends ordinary logs to standard error and can send progress when the client supplies a progress token. Both logs and progress pass through the same redaction boundary as results. References: packages/…/server.ts• L36-45, packages/…/server.ts• L66-91, packages/…/runner.ts• L91-109

Hosted execution limits

The hosted surface runs each tool within a short request budget and limits wait calls to a shorter interval than the local server. This matches a web request lifecycle. Agents must call the same wait tool again when a hosted result has timedOut. References: packages/…/hosted.ts• L23-37, packages/…/hosted.ts• L70-108

Change checklist

When these files or sections are changed, remember to consider these:

  • Update the route contract and tool input shaping together when an API method, field, or authentication mode changes.
  • Preserve the local and hosted surface split when changing file-source inputs or upload tools.
  • Preserve the distinction between an incomplete upload and an upload with unknown completion before changing retry or abort behavior.
  • Keep wait results resumable when changing polling limits, client budgets, or final-state rules.
  • Keep secret keys, upload tokens, signed URLs, and source URL query data covered when adding result fields or log events.
  • Keep credit links scoped to the correct app when changing usage responses or hosted app context.
  • Keep documentation page names, section lookup, byte limits, and cache behavior aligned when changing docs_read.

Important failure modes

TriggerConsequenceGuard
A public key, upload token, or invalid value is supplied as CAP_SECRET_KEYThe server stops before it serves toolsValidate the secret-key shape at startup and report the console source without printing the value
A route receives a field outside its approved contractThe request fails before it reaches the APIKeep route definitions and tool shaping in sync
An API rate limit or temporary read failure occursA call can fail or consume its deadlineHonor Retry-After, share the pause, and retry only safe reads
Upload completion has an unclear resultA retry can create duplicate video dataReturn videoStatus: unknown and require a state check before retry or delete
A transcript file is stored but start status is unclearA second transcript can create a duplicate chargeReturn transcriptStatus: unknown and require a status check first
A signed storage URL or secret enters a result or logCredentials can leak to the MCP client or operator logsRedact values before serialization, logging, and progress notification
A wait reaches its time limitThe job remains active but the client may treat the call as failedReturn the last state with timedOut and a repeat action
A hosted upload request exposes too many or expired part linksThe agent cannot finish the file safely or must restart link creationLimit each result and allow the same upload to resume with fresh links

Key files

FileWhy to read it
packages/…/README.mdProduct purpose, setup boundary, tool contract, costs, limits, and recovery guidance
packages/…/server.tsLocal MCP boundary, tool registration, instructions, progress, and logging
packages/…/hosted.tsHosted tool surface and its request budget
packages/…/tools.tsVideo, transcript, account, and documentation workflows
packages/…/hosted-upload.tsHosted multipart upload contract and resume path
packages/…/http.tsAPI request rules, authentication split, deadlines, and retry behavior
packages/…/upload.tsLocal video upload lifecycle and uncertain-completion recovery
packages/…/wait.tsShared polling, backoff, and timeout behavior
packages/…/routes.tsApproved mapping between API operations and request fields
packages/…/redact.tsCredential and signed-link protection for outputs and logs
packages/…/docs.tsFocused documentation lookup and response limits
packages/…/config.tsStartup configuration and API endpoint rules