Shoalrun documentation frameworkMenu
For agents
Start with https://www.shoalrun.com/llms.txt for the documentation index, then read the Markdown pages it links. Skip to article. Documentation index. Read this page as Markdown.
How to

Serve MCP and content with Python

Run the independent Python reference adapter against compiled discovery and content bundles.

Updated Since 1.3.0
Read as Markdown

The Python reference adapter serves compiled content without invoking Node. It supports read-only MCP over HTTP or stdio, the existing Content REST API, and exported assets. You can run it for local checks or import its application boundary into your own host.

For MCP, supply a discovery bundle with --discovery. For Content REST and in-app assets, supply a content export with --content. Supply both when the process should expose both interfaces; content-only serving needs no discovery bundle.

Before you begin

Use Python 3.10 or newer and Shoalrun's adapters/serving/python/shoalrun_server.py. It uses Python's standard library and needs no additional Python packages. Building the input bundles still needs Shoalrun and Node.

For MCP, prepare a discovery bundle. For Content REST and assets, prepare a separately selected content export. Prepare both when serving both interfaces. Don't use the discovery bundle as a content export. The directory names below are examples; use the bundles selected by your project configuration.

  1. Start an HTTP preview

    From the project containing node_modules/@shoalrun/cli, supply either or both bundles:

    python3 node_modules/@shoalrun/cli/adapters/serving/python/shoalrun_server.py   --discovery ./discovery-bundle   --content ./content-bundle   --host 127.0.0.1 --port 8776
    

    The adapter writes its listening address to standard error. It exposes MCP at /mcp, the Content REST API at /content/v1/resources, and content files beneath the export's publicBase. With both inputs, their publication coordinates must match. Stop the preview with Ctrl+C.

    Omit --content for MCP only, or omit --discovery for Content REST and assets only. --port 0 selects an available port. The discovery directory isn't exposed as a generic static file mount.

  2. Check MCP and content reads

    If you supplied --discovery, connect an HTTP MCP client to http://127.0.0.1:8776/mcp. Check that it discovers the five documentation tools, then search and read a known page. The endpoint uses finite JSON responses to POST requests, without a persistent MCP session or standalone event stream.

    If you supplied --content, use openRestContentSource with baseUrl: 'http://127.0.0.1:8776/content/v1' outside the browser, or /content/v1 when the app shares the origin. Select the export's exact publication. Serve content through REST shows the client interface and revision behavior.

  3. Run the compatibility checks

    The bundled conformance checker requires MCP. For content-only serving, use the REST-client check in the preceding step. When serving MCP, compare the running service against the exact bundles it serves:

    node node_modules/@shoalrun/cli/adapters/serving/conformance.mjs   --discovery ./discovery-bundle --mcp-url http://127.0.0.1:8776/mcp   --content ./content-bundle --content-url http://127.0.0.1:8776/content/v1
    

    Omit both content arguments to check only MCP. The checker runs on Node; the server under test doesn't need it. It checks protocol negotiation, selected resources, exact reads, and rejected out-of-scope requests. A passing run doesn't prove your host's authentication or source classification is correct.

    For an authenticated host, provide request headers through SHOALRUN_CONFORMANCE_HEADERS as a JSON object. Keep credential values outside tracked files and command examples.

Use stdio instead

A client can launch the adapter without an HTTP listener:

python3 node_modules/@shoalrun/cli/adapters/serving/python/shoalrun_server.py   --discovery ./discovery-bundle --stdio

Standard output contains only newline-delimited JSON-RPC responses. HTTP content delivery isn't available through that stdio connection.

Embed the application boundary

Import DiscoverySource, ContentSource, and Application from the packaged shoalrun_server.py module using your Python application's module-loading convention:

app = Application(
    discovery=DiscoverySource('/releases/example/discovery'),
    content=ContentSource('/releases/example/content'),
    allowed_hosts=['docs.example.com'],
    allowed_origins=['https://app.example.com'],
)
status, headers, body = app.handle(method, request_target, request_headers, body)

Authorize the request in your host before calling handle, including static asset requests. It returns a status, response headers, and bytes. The CLI's repeatable --allowed-host and --allowed-origin options configure the same boundary. Defaults allow loopback hosts and no browser origins.

The included ThreadingHTTPServer listener is a local reference host. Your production environment supplies TLS, authentication, concurrency and traffic limits, routing, and lifecycle. Reference responses use Cache-Control: no-store, including pinned content. Only inventoried content files and assets can be read through the static mount.

Understand the differences

Portable lexical search requires every query term to occur in a document and boosts title matches. Its ranking differs from Node's optimized search. Results report encoding: utf8-bytes-upper-bound and conservatively budget the serialized UTF-8 byte length, including metadata. They don't claim exact cl100k_base counts. Oversized pages or sections return a budget error; increase maxTokens rather than expecting partial Markdown.

Open a new source for a new revision. File reads recheck their size and digest, and changed representations fail. The adapter doesn't retain historical revisions or supply fallback content from another directory.

HTML, Markdown, and agents

MCP returns selected Markdown and discovery metadata. Content REST returns the export's passive HTML or Markdown, and your app supplies the interface and styling. Both use the same compiled resources as other adapters; Python doesn't recreate browser components or alter the build selection.

Read first

Reference while working