Skip to main content
Glama
asouthern729

Public Safety MCP Server

by asouthern729
README.md
# Public Safety MCP Server

An MCP (Model Context Protocol) server exposing CAD (Computer-Aided Dispatch), AVL (Automatic Vehicle Location), and NERIS incident data as tools for use by Claude and other MCP clients.

## Overview

The server connects to a Microsoft SQL Server database (CAD/AVL data) and the NERIS public incident API, and exposes both generic database access tools and purpose-built operational query tools over a single streamable HTTP MCP endpoint.

## Requirements

- Node.js
- Access to the CAD/AVL MSSQL database
- A NERIS API subscription key

## Setup

```bash
npm install
```

Create `config/config.env` with:

```
MCP_HOST=
MCP_PORT=

PS_DB_SERVER=
PS_DB_DATABASE=
PS_DB_USER=
PS_DB_PASSWORD=

NERIS_SUBSCRIPTION_KEY=
NERIS_API_KEY=
```

## Development

```bash
npm run dev     # run with tsx + nodemon, auto-reload
npm run build   # compile TypeScript to dist/ (tsc + tsc-alias)
npm start       # run compiled server from dist/
npm run deploy  # rsync build + config to production host and restart via pm2
```

The server listens on `MCP_PORT` (default `7001`) and exposes:

- `GET /publicsafety/health` — health check
- `POST /publicsafety` — MCP streamable HTTP endpoint

## Project Structure

```
app.ts              Server entrypoint
routes/              Express routes (MCP endpoint, tile proxy)
tools/
  mssql/             Generic DB tools: listTables, describeTable, executeQuery, getTablePreview
  cad/               CAD operational tools: call volume, by-hour/day-of-week, top call types, incident search/activity log, raw query
  avl/               AVL/GPS tools: unit tracking, movement detection, incident response time, breadcrumb report rendering
  neris/             NERIS API client and incident list/get tools
  combined/          Cross-source tools (e.g. CAD-NERIS join on incident timestamps)
utils/registerTools.ts  Registers all tools with the MCP server
config/config.env    Environment configuration (not committed)
skills/              Claude skill definitions (CAD, AVL) packaged as .zip
```

## Tools

Tools are aggregated in `tools/index.ts` and registered on the `McpServer` in `app.ts` via `registerAllTools`. See individual files under `tools/` for each tool's schema and behavior.

## Notes

- CAD/AVL coordinates are stored as scaled integers in the database and transformed by the server before rendering on maps.
- The CAD-NERIS join correlates records by matching CAD's First Unit Assigned Time to NERIS's OnsetDate (truncated to seconds).
- `cadIncidentSearchTool` is intentionally slim (9 columns, required date range) to avoid context overflow; use `cadQueryTool` for arbitrary queries.