## Host MCP server with Starlette: Streamed Responses

### Summary
Deploy an MCP server built with Starlette on Ample using the streaming response service pattern. Compute runs the app in an isolated microVM behind a public HTTPS URL, and a managed PostgreSQL 16 database is auto-provisioned and injected as `DATABASE_URL`. It has been verified on Starlette with the following characteristics of a Server-Sent Events endpoint:
- Read incrementally through the public HTTPS gateway.
- Five one-second chunks arrived spread over time with the first within seconds (not buffered).
- A 70-second stream of 36 chunks completed past common 60-second idle timeouts.
- A client that disconnected after two chunks was observed and recorded by the server (`disconnected=true`).

**Note:** Your event schema, reconnection strategy, and any per-request duration ceiling beyond the 70 seconds measured were not separately tested; treat the MCP server-specific behavior as part of your application code.

### Representative Queries
- Host MCP server with Starlette: streamed responses
- Where can I host an MCP server built with Starlette?
- I need a tested end-to-end streaming transport, timeout behavior, and client disconnect handling.

### Resource Requirements
- `primitive:compute`
- `primitive:postgres`

### Infrastructure Requirements
1. **Compute**  
   - Status: Verified  
   - Summary: Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes.

2. **Postgres**  
   - Status: Verified  
   - Summary: Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database, with no `DATABASE_URL` supplied.

### Prerequisites
- A Starlette project that builds and starts with the documented commands (pip install into `.ample/python` from `requirements.txt`, then `uvicorn` from `run.py` reading `PORT` on the `python-3.12` template).
- A PostgreSQL driver reading `DATABASE_URL` at runtime (auto-provisioned when omitted, or supplied with `--env`).
- An Ample account token with `servers:write`, `databases:read` permissions.

### Tested Configuration
- **Template:** python-3.12  
- **Runtime:** python  
- **Size:** s-1vcpu-1gb  
- **Install Command:** `python3 -m pip install --target .ample/python -r requirements.txt`  
- **Start Command:** `PYTHONPATH=.ample/python:${PYTHONPATH:-} python3 run.py`

### Workflow Steps
1. **Build and start**  
   - Command: `pip install into .ample/python from requirements.txt, then uvicorn from run.py reading PORT on the python-3.12 template. The server must bind 0.0.0.0 on PORT.`

2. **Implement the pattern on PostgreSQL**  
   - Body: Copy the approach into your schema; keep migrations idempotent and run them with `--release-command`.

3. **Deploy**  
   - Command: `ample deploy . --name  --public --start "python3 run.py"`

4. **Verify**  
   - Command: `ample logs  --kind build`

### Example
- **Title:** Starlette pattern fixture  
  **Description:** Multi-pattern Starlette app whose streaming response service module was checked live; the module is under `tests/deploy-canaries/_pattern-modules`.
  **Source Reference:** `tests/deploy-canaries/starlette-patterns`

### Success Checks
1. App responds on its public URL  
   - Kind: `http_get`  
   - Path: `/`  
   - Expect: `ample canary starlette patterns`

2. Streaming-response-service self-test  
   - Kind: `http_get`  
   - Path: `/p/streaming-response-service`  
   - Expect: `an SSE stream: data: id=, then chunk events one interval apart (read incrementally: first chunk within seconds, chunks spread over the interval), then data: done; /status?id= reports sent=N disconnected=true|false done=true|false`

### Limitations
- Verified on the python-3.12 template at s-1vcpu-1gb with the example fixture; other sizes, templates, and Starlette major versions are not verified.
- The MCP server itself (your event schema, reconnection strategy, and any per-request duration ceiling beyond the 70 seconds measured) is application code and was not separately tested; the pattern checks are what was verified.
- Region, compliance attestations, and request-duration limits are unknown and not claimed.
- Apps auto-pause when idle and wake on the next request; always-on is an operator setting, not a plan feature.
- Managed PostgreSQL 16 only; extensions, connection limits, and backup or restore procedures are not verified; apps and their databases are placed together.

### Cost Estimate
- **Currency:** USD  
- **Monthly Amount:** $10.00  
- **Note:** Always-on monthly price of the tested sizes; apps and databases auto-pause when idle.

### Evidence Summary
1. **Kind:** canary_run  
   - Summary: Starlette pattern fixture deployed on Ample; checks passed for streaming-response-service and configuration-secrets.  
   - Observed At: 2026-09-21T01:21:36Z
2. **Limitations:** Unknowns; compliance attestations are unknown; none are claimed.
