Introducing a new way to review your PRs.

Read the announcement

zipstack / unstract

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

View on GitHub

28 documents · Updated Nov 23, 2026

docs / mcp-server

Model Context Protocol server

The Model Context Protocol (MCP) server gives AI clients a controlled way to discover and use Unstract capabilities. It exposes read and action tools for document extraction, workflow operations, pipeline runs, Prompt Studio work, and run history while keeping each session inside its approved deployment or organization scope.

MCP surfaces

Deployment and organization servers

The backend provides two MCP surfaces for different trust boundaries. The deployment server connects a client to one API deployment, while the organization server can discover and act across an organization. Both use the same MCP request model, but each exposes a separate set of tools and accepts a different credential.

The organization surface is optional and is disabled unless the platform setting enables it. Use the deployment surface when a credential must have the smallest possible reach. Use the organization surface when one approved platform credential must manage several resources.

References: backend/…/views.py• L1-11 backend/…/platform_views.py• L1-48 backend/…/urls_v2.py• L78-90

MCP request flow

An MCP client first learns the server identity and instructions. It then lists the tools, selects a tool with its JSON arguments, and receives either a result or an actionable error. The transport keeps protocol errors separate from tool failures so a client can tell whether it sent an invalid request, lacks access, or needs to correct a tool input.

The main interaction follows this path:

sequenceDiagram
    participant Client as MCP client
    participant Server as MCP server
    participant Registry as Tool registry
    participant Platform as Unstract platform

    Client->>Server: initialize
    Server-->>Client: server identity and instructions
    Client->>Server: tools/list
    Server->>Registry: Read scoped tool schemas
    Registry-->>Server: Names, descriptions, input rules
    Server-->>Client: Available tools
    Client->>Server: tools/call
    Server->>Platform: Authenticate, check scope, run tool
    Platform-->>Server: Result or action error
    Server-->>Client: MCP result

References: backend/…/transport.py• L107-145 backend/…/transport.py• L178-290

Tool registry

Tool descriptions and behavior hints

The tool registry is the contract between the server and an AI client. Each registered tool describes its purpose, accepted input, whether it changes state, whether it costs quota, and whether repeating it is safe. The server publishes this information so a client can choose a suitable action before it calls the backend.

The registry preserves a deliberate order. Orientation tools appear first so a client can learn the server scope and recommended sequence before it performs work. The deployment and organization registries remain separate so a tool cannot cross into the wrong access model by mistake.

References: backend/…/registry.py• L16-145 backend/…/registry.py• L148-190 backend/…/registry.py• L734-738

Read and action tools

The tool set groups naturally by the risk and purpose of an operation:

Tool groupPurposeTypical effect
InformationExplain the connected resource or organizationRead deployment, workflow, project, and credential context
ExecutionStart extraction or pipeline workConsume rate or usage quota and produce an execution result
ObservationInspect runs, file outcomes, usage, and workflow shapeSupport diagnosis without exposing credentials
State changeActivate deployments or pause schedulesChange behavior for later callers
Prompt StudioIndex documents and run promptsDrive embedding or LLM work against project documents

The registry does not expose credential creation or rotation. It also does not expose destructive deletion actions. These limits prevent an AI client from turning document content or a mistaken instruction into a credential leak or irreversible loss.

References: backend/…/registry.py• L286-303 backend/…/registry.py• L527-601 backend/…/registry.py• L603-729

Execution and information tools

Deployment extraction

The deployment surface represents one fixed extraction workflow. The client supplies document URLs and optional output choices, but the deployment supplies the prompts and output schema. This keeps document processing consistent with the published API deployment rather than allowing each call to redefine the workflow.

Extraction can finish during the call or return a pending execution identifier. A client must treat the identifier as the handle for later status checks and must not repeat the extraction when it only needs the result.

flowchart LR
    A[Read deployment information] --> B[Submit document URLs]
    B --> C{Extraction finished?}
    C -->|Yes| D[Use final result]
    C -->|No| E[Poll execution status]
    E --> F{Terminal status?}
    F -->|No| E
    F -->|Yes| D

References: backend/…/info.py• L11-67 backend/…/execution.py• L136-257 backend/…/execution.py• L293-401

Organization discovery and observation

The organization surface helps a client build a safe picture of the available resources before it acts. It can find deployments, workflows, pipelines, Prompt Studio projects, and the identifiers needed by later calls. It can also show recent executions, per-file outcomes, workflow structure, and recorded usage.

These tools support a discovery-then-action pattern. A client should use the returned identifiers and current state to confirm its target before it starts billable work or changes a shared resource.

References: backend/…/platform.py• L54-195 backend/…/observability.py• L42-214 backend/…/observability.py• L217-251

Access boundaries

Deployment scope

The deployment server authenticates with the API key belonging to the named deployment. A successful session can inspect that deployment and run its workflow, but it cannot use the same session to discover or operate on another deployment. The URL identifies the organization and deployment, while the bearer key proves access to that exact target.

Execution status follows the same boundary. A status request is valid only for an execution created by the connected deployment, which prevents one deployment key from reading or acknowledging another deployment's result.

References: backend/…/views.py• L31-102 backend/…/urls.py• L1-27 backend/…/execution.py• L334-364

Organization scope

The organization server authenticates with a platform API key that the platform auth layer has already tied to an organization and permission tier. The session can reach the organization's resources through the platform's visibility rules. Because the caller is a service account, the effective resource reach is organization-wide rather than the narrower view of one human user.

Tool access has two further controls. The tool declares the permission level that matches its REST behavior, and billable tools claim a temporary organization call budget before they run. A read-only platform key cannot use this POST-based MCP surface, and budget exhaustion is temporary rather than a permanent permission failure.

References: backend/…/platform_views.py• L40-184 backend/…/context.py• L13-41 backend/…/spend_guard.py• L1-31

Data exposure boundary

The server returns only the fields needed for an AI client to understand a resource or act on it. Workflow shape and connector names may be visible, but connector credentials, provider keys, and other secret configuration are not part of the MCP result. Tool failures are also reduced to safe messages instead of passing raw provider or connector errors to the client.

References: backend/…/observability.py• L1-14 backend/…/observability.py• L165-214 backend/…/execution.py• L229-257

Workflow integration

Workflow discovery and execution

An API deployment is a published entry point to a workflow. The MCP server exposes this relationship through deployment information, workflow listings, workflow endpoint shape, tool-step listings, pipeline controls, and execution history. This lets a client understand what a workflow is wired to do before it runs or changes it.

The organization surface can trigger a pipeline independently of its schedule and can pause or resume that schedule. These actions affect the shared organization immediately. They are not previews or dry runs, so discovery and confirmation must come first.

References: backend/…/registry.py• L397-523 backend/…/observability.py• L254-380 backend/…/platform.py• L457-523

Prompt Studio operations

Prompt Studio is the authoring path for extraction prompts before they are used in a project or deployment. MCP clients can discover projects, documents, and prompts, then index a document or run one prompt, several prompts, or the full project prompt set.

These operations use the platform's existing Prompt Studio behavior so that project access, indexing rules, and task dispatch remain consistent with the rest of the product. They are billable because they perform embedding or LLM work. The usual safe sequence is to list the project resources, index a document once, and then choose the smallest prompt operation that answers the question.

References: backend/…/prompt_studio.py• L1-12 backend/…/prompt_studio.py• L226-255 backend/…/registry.py• L603-684

Cross-surface extraction

The two MCP surfaces run the same extraction workflow but offer different blast radii. The deployment surface gets its target from the credential and reaches one deployment. The organization surface discovers the target by deployment name and can use one platform credential across the organization.

This makes the choice a product and security decision rather than a difference in extraction behavior:

NeedSuitable surface
Limit a credential to one extraction endpointDeployment MCP server
Discover and manage several organization resourcesOrganization MCP server
Run the same deployment workflow from an organization sessionOrganization MCP server's extraction tool

See Backend API platform, Backend API v2, Backend workflow management, and Workflow execution for the surrounding API, workflow, and run concepts.

References: backend/…/platform_execution.py• L1-26 backend/…/platform_execution.py• L45-170 backend/…/platform.py• L178-187

Change checklist

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

  • Keep the deployment and organization registries separate when adding a tool. A tool placed on the wrong registry can widen its credential scope without changing its handler.
  • Keep tool descriptions, behavior hints, and billable flags aligned with the actual side effects. Clients use these declarations to decide whether to retry or ask for confirmation.
  • Preserve the deployment route outside the platform-auth bypass boundary. Preserve the organization route under the tenant path so its middleware authentication remains active.
  • When an execution result or identifier changes, update both the extraction path and its status lookup. The two surfaces must keep their deployment or organization ownership checks.
  • When a workflow or Prompt Studio action returns new resource data, keep credential and provider-secret fields outside the MCP response contract.

Important failure modes

TriggerConsequenceGuard
Client calls a deployment with a wrong or missing bearer keyThe session is rejected without revealing whether the deployment existsDeployment authentication returns one failure message for all key and lookup failures
Organization MCP is mounted under the deployment pathOrganization tools can bypass the middleware that authenticates platform keysKeep the organization route under the tenant path and enable it only through its platform setting
Client repeats extraction after receiving an execution identifierA second extraction consumes more quota and creates new workPoll the matching status tool instead
Client reads a completed result more than onceThe one-shot result may already be acknowledged and unavailableTreat a successful final read as consumption of the result
Client starts billable work with an invalid target or after budget exhaustionThe call is refused, or repeated calls can spend the organization budgetResolve billable targets before charging and apply the organization call budget
Tool output includes raw model or serializer dataConnector credentials or provider keys can enter the AI contextReturn named safe fields and redact failure and result structures

Key files

FileWhy to read it
backend/…/transport.pyUnderstand the shared MCP handshake, tool listing, dispatch, and error contract.
backend/…/registry.pyUnderstand the two tool surfaces and the meaning of tool scope, side effects, and cost.
backend/…/views.pyUnderstand deployment-scoped authentication and session boundaries.
backend/…/platform_views.pyUnderstand organization authentication, permission checks, and billable-call gating.
backend/…/execution.pyFollow document extraction and execution-result retrieval.
backend/…/platform_execution.pyCompare organization-wide extraction with deployment-scoped extraction.
backend/…/observability.pyUnderstand how workflow runs and usage support diagnosis.
backend/…/prompt_studio.pyUnderstand how MCP connects Prompt Studio projects to billable prompt work.
backend/…/platform_urls.pyVerify the organization route stays inside the platform authentication boundary.