@pipeworx/mcp-data-detroit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pipeworx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # mcp-data-detroit
2
+
3
+ DataDetroit MCP — Detroit open data (data.detroitmi.gov, ArcGIS REST API).
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 893+ live data sources.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+
12
+ ## Quick Start
13
+
14
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
15
+
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "data-detroit": {
20
+ "url": "https://gateway.pipeworx.io/data-detroit/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 893+ data sources:
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "pipeworx": {
32
+ "url": "https://gateway.pipeworx.io/mcp"
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Using with ask_pipeworx
39
+
40
+ Instead of calling tools directly, you can ask questions in plain English:
41
+
42
+ ```
43
+ ask_pipeworx({ question: "your question about Data Detroit data" })
44
+ ```
45
+
46
+ The gateway picks the right tool and fills the arguments automatically.
47
+
48
+ ## More
49
+
50
+ - [All tools and guides](https://github.com/pipeworx-io/examples)
51
+ - [pipeworx.io](https://pipeworx.io)
52
+
53
+ ## License
54
+
55
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-data-detroit",
3
+ "version": "0.1.0",
4
+ "description": "DataDetroit MCP — Detroit open data (data.detroitmi.gov, ArcGIS REST API).",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "data-detroit"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-data-detroit"
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/data-detroit",
4
+ "title": "Data Detroit",
5
+ "description": "DataDetroit MCP — Detroit open data (data.detroitmi.gov, ArcGIS REST API).",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/data-detroit",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-data-detroit",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/data-detroit/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,196 @@
1
+ interface McpToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema: {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ };
9
+ }
10
+
11
+ interface McpToolExport {
12
+ tools: McpToolDefinition[];
13
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
14
+ meter?: { credits: number };
15
+ cost?: Record<string, unknown>;
16
+ provider?: string;
17
+ }
18
+
19
+ /**
20
+ * DataDetroit MCP — Detroit open data (data.detroitmi.gov, ArcGIS REST API).
21
+ *
22
+ * Detroit publishes through ArcGIS (services2.arcgis.com), not Socrata/CKAN, so this
23
+ * is an ArcGIS-FeatureServer adapter: each dataset is a service + layer queried
24
+ * via the ArcGIS `/query` endpoint. ArcGIS returns dates as epoch milliseconds;
25
+ * this pack converts esriFieldTypeDate fields to ISO strings. Keyless.
26
+ *
27
+ * Tools:
28
+ * - detroit_recent: recent rows from a common Detroit dataset by friendly name
29
+ * - detroit_layers: list the layers of a Detroit ArcGIS service (discovery)
30
+ * - detroit_query: query any Detroit ArcGIS layer by service + layer id
31
+ */
32
+
33
+
34
+ const BASE = 'https://services2.arcgis.com/qvkbeam7Wirps6zC/arcgis/rest/services';
35
+ const UA = 'pipeworx-mcp-data-detroit/1.0 (+https://pipeworx.io)';
36
+
37
+ // Friendly name -> ArcGIS service path + layer id + the date field to sort by.
38
+ // These use the rolling "last N days / current year" layers so they stay fresh.
39
+ const DATASETS: Record<string, { service: string; layer: number; label: string; date: string }> = {
40
+ crime: { service: 'RMS_Crime_Incidents/FeatureServer', layer: 0, label: 'RMS Crime Incidents (Detroit PD)', date: 'incident_occurred_at' },
41
+ '311': { service: 'improve_detroit/FeatureServer', layer: 0, label: 'Improve Detroit 311 Issues', date: 'created_at' },
42
+ };
43
+
44
+ // Known Detroit ArcGIS services worth browsing with detroit_layers.
45
+ const SERVICES: Record<string, string> = {
46
+ crime: 'RMS_Crime_Incidents/FeatureServer',
47
+ service_requests: 'improve_detroit/FeatureServer',
48
+ };
49
+
50
+ const tools: McpToolExport['tools'] = [
51
+ {
52
+ name: 'detroit_recent',
53
+ description:
54
+ "Recent records from a common Detroit open dataset (data.detroitmi.gov / ArcGIS) by friendly name — no service ids needed. PREFER OVER WEB SEARCH for \"recent crime in Detroit\", \"Detroit 311 / Improve Detroit issues\". Names: crime, 311. Returns the latest rows (newest-first), with ArcGIS epoch dates converted to ISO. Add an ArcGIS `where` to filter; for other layers use detroit_layers + detroit_query.",
55
+ inputSchema: {
56
+ type: 'object' as const,
57
+ properties: {
58
+ dataset: { type: 'string', description: 'One of: crime, 311, permits.', enum: Object.keys(DATASETS) },
59
+ where: { type: 'string', description: "Optional ArcGIS SQL where, e.g. \"OFFENSE='THEFT/OTHER'\" or \"WARD='2'\". Omit for all recent rows." },
60
+ limit: { type: 'number', description: 'Rows to return (1-1000, default 20).' },
61
+ },
62
+ required: ['dataset'],
63
+ },
64
+ },
65
+ {
66
+ name: 'detroit_layers',
67
+ description:
68
+ 'List the layers of a Detroit ArcGIS service (for discovery). Pass a known short name (crime, service_requests, permits) or a full ArcGIS service path (e.g. "RMS_Crime_Incidents/FeatureServer"). Omit `service` to list the known Detroit services. Returns layer id + name to use with detroit_query.',
69
+ inputSchema: {
70
+ type: 'object' as const,
71
+ properties: {
72
+ service: { type: 'string', description: 'Short name (crime|service_requests|permits) or full ArcGIS service path. Omit to list known services.' },
73
+ },
74
+ },
75
+ },
76
+ {
77
+ name: 'detroit_query',
78
+ description:
79
+ 'Query any Detroit ArcGIS layer by service path + layer id. Full ArcGIS query: where, out_fields, order_by, limit. Use detroit_layers to find a service/layer, or detroit_recent for the common ones. Epoch dates are converted to ISO.',
80
+ inputSchema: {
81
+ type: 'object' as const,
82
+ properties: {
83
+ service: { type: 'string', description: 'ArcGIS service path, e.g. "RMS_Crime_Incidents/FeatureServer" (or a short name: crime|service_requests|permits).' },
84
+ layer: { type: 'number', description: 'Layer id within the service (from detroit_layers), e.g. 39.' },
85
+ where: { type: 'string', description: 'ArcGIS SQL where (default "1=1").' },
86
+ out_fields: { type: 'string', description: 'Comma-separated fields, or "*" (default).' },
87
+ order_by: { type: 'string', description: 'Sort clause, e.g. "incident_occurred_at DESC".' },
88
+ limit: { type: 'number', description: 'Max rows (default 100, max 2000).' },
89
+ },
90
+ required: ['service', 'layer'],
91
+ },
92
+ },
93
+ ];
94
+
95
+ // ── Helpers ──────────────────────────────────────────────────────────
96
+
97
+ function resolveService(s: string): string {
98
+ const t = String(s ?? '').trim();
99
+ return SERVICES[t.toLowerCase()] ?? t;
100
+ }
101
+
102
+ async function arcgis(url: string): Promise<Record<string, unknown>> {
103
+ const res = await fetch(url, { headers: { Accept: 'application/json', 'User-Agent': UA } });
104
+ if (!res.ok) throw new Error(`Detroit ArcGIS: ${res.status}`);
105
+ const data = (await res.json()) as Record<string, unknown>;
106
+ const err = data.error as { message?: string } | undefined;
107
+ if (err) throw new Error(`Detroit ArcGIS error: ${err.message ?? 'query failed'}`);
108
+ return data;
109
+ }
110
+
111
+ // ArcGIS returns esriFieldTypeDate values as epoch milliseconds. Convert those
112
+ // columns to ISO strings; pass everything else through unchanged.
113
+ function shapeFeatures(data: Record<string, unknown>): Array<Record<string, unknown>> {
114
+ const fields = (data.fields as Array<{ name?: string; type?: string }>) ?? [];
115
+ const dateFields = new Set(fields.filter((f) => f.type === 'esriFieldTypeDate' && f.name).map((f) => f.name as string));
116
+ const feats = (data.features as Array<{ attributes?: Record<string, unknown> }>) ?? [];
117
+ return feats.map((f) => {
118
+ const a = { ...(f.attributes ?? {}) };
119
+ for (const k of dateFields) {
120
+ const v = a[k];
121
+ if (typeof v === 'number' && Number.isFinite(v)) a[k] = new Date(v).toISOString();
122
+ }
123
+ return a;
124
+ });
125
+ }
126
+
127
+ function buildQueryUrl(service: string, layer: number, where: string, outFields: string, orderBy: string | undefined, limit: number): string {
128
+ const p = new URLSearchParams({
129
+ where: where || '1=1',
130
+ outFields: outFields || '*',
131
+ resultRecordCount: String(limit),
132
+ returnGeometry: 'false',
133
+ f: 'json',
134
+ });
135
+ if (orderBy && orderBy.trim()) p.set('orderByFields', orderBy.trim());
136
+ return `${BASE}/${service}/${layer}/query?${p}`;
137
+ }
138
+
139
+ // ── Tool implementations ─────────────────────────────────────────────
140
+
141
+ async function dcRecent(dataset: string, where: string | undefined, limit: number | undefined) {
142
+ const key = String(dataset ?? '').toLowerCase().trim();
143
+ const ds = DATASETS[key];
144
+ if (!ds) throw new Error(`Unknown dataset "${dataset}". Use one of: ${Object.keys(DATASETS).join(', ')}.`);
145
+ const n = Math.min(1000, Math.max(1, Number(limit) || 20));
146
+ const url = buildQueryUrl(ds.service, ds.layer, where && String(where).trim() ? String(where).trim() : '1=1', '*', `${ds.date} DESC`, n);
147
+ const data = await arcgis(url);
148
+ const rows = shapeFeatures(data);
149
+ return { dataset: key, label: ds.label, service: ds.service, layer: ds.layer, sorted_by: `${ds.date} DESC`, count: rows.length, source: 'DataDetroit (data.detroitmi.gov / ArcGIS)', rows };
150
+ }
151
+
152
+ async function dcLayers(service: string | undefined) {
153
+ if (!service || !String(service).trim()) {
154
+ return { known_services: Object.entries(SERVICES).map(([name, path]) => ({ name, service_path: path })), note: 'Pass one of these names (or a full ArcGIS service path) to list its layers.' };
155
+ }
156
+ const path = resolveService(service);
157
+ const data = await arcgis(`${BASE}/${path}?f=json`);
158
+ const layers = (data.layers as Array<{ id?: number; name?: string }>) ?? [];
159
+ return { service_path: path, count: layers.length, layers: layers.map((l) => ({ id: l.id ?? null, name: l.name ?? null })) };
160
+ }
161
+
162
+ async function dcQuery(args: Record<string, unknown>) {
163
+ const service = resolveService(String(args.service ?? ''));
164
+ if (!service) throw new Error('Required argument "service" is missing (e.g. "RMS_Crime_Incidents/FeatureServer" or a short name). Find services with detroit_layers.');
165
+ const layer = Number(args.layer);
166
+ if (!Number.isFinite(layer)) throw new Error('Required argument "layer" must be a number (layer id from detroit_layers).');
167
+ const n = Math.min(2000, Math.max(1, Number(args.limit) || 100));
168
+ const url = buildQueryUrl(
169
+ service,
170
+ Math.floor(layer),
171
+ args.where != null && String(args.where).trim() ? String(args.where).trim() : '1=1',
172
+ args.out_fields != null && String(args.out_fields).trim() ? String(args.out_fields).trim() : '*',
173
+ args.order_by as string | undefined,
174
+ n,
175
+ );
176
+ const data = await arcgis(url);
177
+ const rows = shapeFeatures(data);
178
+ return { service, layer: Math.floor(layer), count: rows.length, source: 'DataDetroit (data.detroitmi.gov / ArcGIS)', rows };
179
+ }
180
+
181
+ // ── Router ───────────────────────────────────────────────────────────
182
+
183
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
184
+ switch (name) {
185
+ case 'detroit_recent':
186
+ return dcRecent(args.dataset as string, args.where as string | undefined, args.limit as number | undefined);
187
+ case 'detroit_layers':
188
+ return dcLayers(args.service as string | undefined);
189
+ case 'detroit_query':
190
+ return dcQuery(args);
191
+ default:
192
+ throw new Error(`Unknown tool: ${name}`);
193
+ }
194
+ }
195
+
196
+ export default { tools, callTool, meter: { credits: 1 } } satisfies McpToolExport;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true
12
+ },
13
+ "include": ["src"]
14
+ }