Skip to main content

Contexture

简体中文 · Handbook · Specification · Changelog

Implementations: Python (this repository) · TypeScript · Go

Contexture is a Python framework for exposing a large application capability graph to agents without placing every tool and instruction in the model's context at once. You declare Roles, Skills, and Tools; Contexture compiles an immutable graph and serves a small, fixed MCP gateway that discloses only the branch an agent chooses.

The same application runtime can back explicit REST routes for human interfaces. Contexture is a Controller layer: it does not contain an agent loop, call a model, or replace your business services.

  • Python 3.11–3.14
  • MCP stdio and Streamable HTTP
  • Typed and marked with py.typed
  • Apache-2.0
  • Stable 1.0 public API governed by Semantic Versioning

Install

With uv:

uv tool install contexture-mcp
contexture --version

Or add it to a Python project:

uv add contexture-mcp
# or: python -m pip install contexture-mcp

To pin this release, request contexture-mcp==1.0.0.

Five-minute application

contexture new hello-context
cd hello-context
uv sync
uv run contexture check

The authoring model is deliberately small:

from contexture import Contexture, Role, Skill, Tool


class CheckStatus(Tool):
    def __init__(self) -> None:
        super().__init__(
            name="check-status",
            description="Return the status of one service.",
            read_only=True,
        )

    async def invoke(self, service: str) -> dict[str, str]:
        return {"service": service, "status": "ready"}


class Diagnose(Skill):
    def __init__(self) -> None:
        super().__init__(
            name="diagnose",
            description="Diagnose an unhealthy service.",
            instructions="Read status first, then explain the evidence.",
            uses=("operations/check-status",),
        )


class Operations(Role):
    def __init__(self) -> None:
        super().__init__(
            name="operations",
            description="Handle service operations.",
            instructions="Inspect before proposing a change.",
            skills=[Diagnose()],
            tools=[CheckStatus()],
        )


app = Contexture(name="service-operations", roots=(Operations,))

Contexture never infers public names or descriptions from class names or docstrings. A Tool's invoke() type hints produce its input schema and validate the same call, so schema and runtime cannot drift independently.

Development loop

uv run contexture check
uv run contexture list
uv run contexture inspect operations/diagnose
uv run contexture call operations/check-status --input '{"service":"api"}'
uv run contexture serve

check validates without opening external connections. list shows canonical refs. inspect replays what an agent will receive. call executes a local read-only Tool through the production binding; writing Tools require an explicit --allow-write.

One declaration vocabulary

Concept What you write Meaning
Contexture one application value Lazy composition root
Role subclass + constructor Responsibility and containment boundary
PreProcess / PostProcess specialized Roles + constructors Optional preparation and finishing procedures with dedicated capabilities
Skill subclass + constructor Procedure the model follows
Tool subclass + typed invoke() Deterministic code Contexture executes
Prompt subclass + constructor User-triggered entrance to an existing node
Resource subclass + constructor Host-readable URI backed by a read-only Tool
Channels optional subclass Shared external dependencies and lifecycle

Role, Skill, and Tool form the graph. Prompt and Resource provide another protocol entrance to a ref the graph already owns. Use prompt_roots for complete trees that only the user-controlled Prompt plane may enter.

The stable 1.0 API lets a Role hold optional pre_process and post_process Roles. ACTIVE composes fixed, recognizable framework instruction blocks around unchanged business Role.instructions, naming the actual refs to open before starting or finishing. Procedures stay hidden until opened; opening executes nothing and never bypasses approval. With both fields absent, existing output and obligations are unchanged. Applications may also use binding_instruction to mark their own non-enforceable hard rules under their own authority. See the authoring example and ADR 023.

Progressive disclosure

MCP hosts always see five fixed model-controlled tools:

contexture_discover
contexture_inspect
contexture_open
contexture_invoke_read_only
contexture_invoke

discover returns root cards. inspect compares a shortlist through one level of pure routing cards without activating instructions or disclosing Tool schemas. Opening a Role returns its instructions and one level of child Role, Skill, and Tool cards. A Tool card carries the ref, input schema, and read-only classification needed to invoke it. Business Tools never inflate MCP's top-level tool list.

The two invoke doors let a host apply approval policy from the visible MCP readOnlyHint. Calling through the wrong door is refused. Disclosure helps a model decide what exists; it is not authorization.

Connect an MCP host

After local checks pass, let the host own the stdio process:

claude mcp add --scope project hello-context -- uv run contexture serve
codex mcp add                 hello-context -- uv run contexture serve

For Streamable HTTP:

uv run contexture serve --transport streamable-http --port 8080

Non-loopback HTTP requires an explicit authentication or anonymous-access decision plus allowed hosts/origins. Configure these with ContextureOptions. See the handbook.

An HTTP deployment can attenuate a request to complete subtrees with the Contexture-Select header and HeaderSurfaceSelector. Exact refs such as team/notebook-editor select that complete subtree; team/* selects each direct member subtree, and * never crosses /. The legacy Contexture-Roots and HeaderRootSelector names remain compatible. An application-owned ceiling derived from the verified Principal can restrict the selection further. Selection is a surface boundary, not permission policy.

from contexture.server import HeaderSurfaceSelector, compile_application

server = compile_application(app).server(
    surface_selector=HeaderSurfaceSelector(),
)

Human-facing REST routes

An agent benefits from navigation; a dashboard has already chosen its pages and buttons. Expose an explicit Tool allowlist:

from contexture.server import compile_application
from contexture.web import RestSurface, Route
from my_context import app

compiled = compile_application(app)
rest = RestSurface(
    compiled.runtime(),
    routes=(Route("GET", "/v1/status", "operations/check-status"),),
)
asgi_app = rest.asgi_app()

GET/HEAD routes may target only read-only Tools. Writing routes may target only writing Tools. Unlisted refs are unreachable through REST.

Public API

Use contexture for declarations and contexture.server for advanced hosting. Their export sets are regression-tested. contexture.core and concrete server submodules are implementation details even though Python can import them.

Work on Contexture

git clone https://github.com/CarterShi01/contexture-mcp.git
cd contexture-mcp
uv sync --extra dev
uv run --extra dev pytest -q
uv run --extra dev pyright
uv run --extra dev ruff check contexture tests
uv build
uv run --extra dev twine check --strict dist/*

Read the contribution guide before changing a contract, the handbook for application development, and the language-neutral specification when implementing another binding. Report vulnerabilities according to SECURITY.md.

License

Apache-2.0. See LICENSE.

Metadata

Release files for contexture-mcp 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for contexture-mcp 1.0.0
File Size Uploaded Provenance Actions
contexture_mcp-1.0.0.tar.gz 137.6 kB With provenance Details for contexture_mcp-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for contexture-mcp 1.0.0
File Interpreter ABI Platform Actions
contexture_mcp-1.0.0-py3-none-any.whl Python 3 none any Details for contexture_mcp-1.0.0-py3-none-any.whl

Total release size: 317.0 kB

Release files / contexture_mcp-1.0.0.tar.gz

Download URL contexture_mcp-1.0.0.tar.gz
Size 137.6 kB
Tags Source
SHA-256 checksum
How to use checksums
91029f56b74bf76e3875a7610305eebe62f57ea111bf32833685a3bb5b2273bb
BLAKE2b-256 checksum
How to use checksums
b654b49447e6ce9695d669776e4c62d0220956bde85e185072cab4a8c0c3ac8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / contexture_mcp-1.0.0-py3-none-any.whl

Download URL contexture_mcp-1.0.0-py3-none-any.whl
Size 179.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b8b7d077eedf775fa99f40010ccf655a2539defdf6d06718aaabd3533a413b4
BLAKE2b-256 checksum
How to use checksums
323fec312cfd36595b56dd1bb54c8d66d86728236a2a63b2fa1596603b84d909
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Security for contexture-mcp 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for contexture_mcp-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page