Train Horn SPL MCP
# Train Horn SPL MCP
A small, open-source [Model Context Protocol](https://modelcontextprotocol.io/) server that estimates how a train horn's sound-pressure level changes with distance.
The calculation is free-field only: inverse-square spreading (`20 * log10` of the distance ratio) plus, when you give a frequency, ISO 9613-1 atmospheric absorption. It will not replace a calibrated sound level meter, and it does not model ground effect, barriers, wind, or reflections.
Portable, battery-powered train horn kits are often specified at one reference distance. This server is a working notebook for turning that figure into a first-order level at another distance, or for asking how far a chosen target level would fall. For product context on cordless and battery-powered train horns, see [Horn Guns](https://hornguns.com/).
## Tools
| Tool | What it does |
| --- | --- |
| `spl_at_distance` | Estimate SPL at `target_distance_m` from a free-field level at `ref_distance_m`. |
| `distance_for_target_spl` | Solve for the distance at which the estimated SPL equals `target_spl_db`. |
| `a_weighting` | IEC 61672-1 A-weighting in dB at a single frequency. |
### `spl_at_distance` / `distance_for_target_spl` arguments
- `source_spl_db` (required): free-field level at the reference distance, in dB
- `ref_distance_m` (required): that reference distance, in metres
- `target_distance_m` or `target_spl_db` (required, depending on the tool)
- `frequency_hz` (optional): pure-tone frequency for ISO 9613-1 absorption. If omitted, only inverse-square spreading is applied.
- `temperature_c` (optional, default 20)
- `humidity_pct` (optional, default 70)
- `pressure_kpa` (optional, default 101.325)
Every result includes a `caveats` field stating the limits of the model.
## Install and run
Requires Python 3.11+.
### With uvx (no install)
```bash
uvx --from git+https://github.com/bosshorncom-cmd/train-horn-spl-mcp train-horn-spl-mcp
```
### With pip
```bash
pip install git+https://github.com/bosshorncom-cmd/train-horn-spl-mcp
train-horn-spl-mcp
```
The process speaks MCP over stdio.
## MCP config example
Claude Desktop, Cursor, or any MCP host that reads a `mcpServers` map:
```json
{
"mcpServers": {
"train-horn-spl": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/bosshorncom-cmd/train-horn-spl-mcp",
"train-horn-spl-mcp"
]
}
}
}
```
Equivalent pip form:
```json
{
"mcpServers": {
"train-horn-spl": {
"command": "train-horn-spl-mcp"
}
}
}
```
## Caveats
- Free-field point-source estimate only.
- No ground effect, reflections, barriers, wind, turbulence, or temperature gradients.
- ISO 9613-1 absorption is defined for a pure tone (or a narrow band). A train horn is broadband; a fuller estimate needs a spectrum.
- A-weighting is returned at one frequency. An overall dB(A) level also needs that spectrum.
- Not a substitute for a calibrated Type 1 or Type 2 sound level meter, or for a field measurement.
## Development
```bash
git clone https://github.com/bosshorncom-cmd/train-horn-spl-mcp
cd train-horn-spl-mcp
uv sync --dev
uv run pytest
```
## License
MIT. Public contact: info@hornguns.com
TDQS
Scored across 3 tools
Each tool targets a distinct operation: forward propagation (spl_at_distance), the numerical inverse (distance_for_target_spl), and a frequency-domain weighting helper (a_weighting). The argument signatures differ clearly (target_distance_m vs target_spl_db), so an agent can pick correctly without reading the bodies.
All three names are snake_case and follow a consistent 'quantity or model being returned' convention rather than verb_noun (spl_at_distance, distance_for_target_spl, a_weighting). This is predictable and readable, but the lack of a verb prefix makes it slightly less self-documenting than an ideal pattern.
Three tools is small but well-matched to a narrowly scoped acoustic calculator: forward model, inverse model, and a weighting utility. Every tool earns its place, with no filler or redundancy.
The core forward/inverse propagation pair is covered, but the domain surface is incomplete: there is no way to apply A-weighting across a spectrum or to chain weighting with propagation in one call, and the tool description itself admits a_weighting is not a complete dB(A) calculation. Ground reflection, barriers, and multi-band train-horn spectra are also unaddressed.