---
id: guide.python-serving
title: Serve MCP and content with Python
summary: Run the independent Python reference adapter against compiled discovery
  and content bundles.
type: how-to
area:
  - discovery
  - publishing
subarea:
  - discovery-mcp
  - publishing-hosting
canonical: /publish/python-serving
---

# Serve MCP and content with Python

> Documentation index: [llms.min.txt](https://www.shoalrun.com/llms.min.txt) · Document manifest: [documents.json](https://www.shoalrun.com/documents.json)

Navigation section: [Docs](https://www.shoalrun.com/.well-known/shoalrun/navigation/docs-50f26fe22670.txt) (ID: docs). [All sections and pages](https://www.shoalrun.com/llms.min.txt)

Breadcrumbs: [Docs](https://www.shoalrun.com/what-is-shoalrun.md) > Publish and maintain > Serve MCP and content with Python

**Updated: 2026-11-22.**

**Available since: 1.3.0.**

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](https://www.shoalrun.com/publish/discovery-bundles.md). For Content REST and assets, prepare a separately selected [content export](https://www.shoalrun.com/content-delivery/select.md). 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:

   ```sh
   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](https://www.shoalrun.com/content-delivery/rest.md) 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:

   ```sh
   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:

```sh
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:

```python
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.

## Related reading

### Read first

- [Discovery bundle contract](https://www.shoalrun.com/publish/discovery-bundles.md) — Prepare the discovery data consumed by MCP.

### Reference while working

- [Serve content through REST](https://www.shoalrun.com/content-delivery/rest.md) — Use the shared content client and REST interface.
