@pipeworx/mcp-data-denver 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-denver
2
+
3
+ DataDenver MCP — Denver open data (opendata-geospatialdenver.hub.arcgis.com, 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-denver": {
20
+ "url": "https://gateway.pipeworx.io/data-denver/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 Denver 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-denver",
3
+ "version": "0.1.0",
4
+ "description": "DataDenver MCP — Denver open data (opendata-geospatialdenver.hub.arcgis.com, 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-denver"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-data-denver"
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-denver",
4
+ "title": "Data Denver",
5
+ "description": "DataDenver MCP — Denver open data (opendata-geospatialdenver.hub.arcgis.com, ArcGIS REST API).",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/data-denver",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-data-denver",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/data-denver/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,195 @@
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
+ * DataDenver MCP — Denver open data (opendata-geospatialdenver.hub.arcgis.com, ArcGIS REST API).
21
+ *
22
+ * Denver publishes through ArcGIS (services1.arcgis.com hosted), not Socrata/CKAN,
23
+ * so this is an ArcGIS-FeatureServer adapter: each dataset is a service + layer
24
+ * queried via the ArcGIS `/query` endpoint. ArcGIS returns dates as epoch
25
+ * milliseconds; this pack converts esriFieldTypeDate fields to ISO. Keyless.
26
+ * (Denver's hosted services use non-zero layer ids, e.g. crime = layer 324.)
27
+ *
28
+ * Tools:
29
+ * - denver_recent: recent rows from a common Denver dataset by friendly name
30
+ * - denver_layers: list the layers of a Denver ArcGIS service (discovery)
31
+ * - denver_query: query any Denver ArcGIS layer by service + layer id
32
+ */
33
+
34
+
35
+ const BASE = 'https://services1.arcgis.com/zdB7qR0BtYrg0Xpl/arcgis/rest/services';
36
+ const UA = 'pipeworx-mcp-data-denver/1.0 (+https://pipeworx.io)';
37
+
38
+ // Friendly name -> ArcGIS service path + layer id + the date field to sort by.
39
+ // These use the rolling "last N days / current year" layers so they stay fresh.
40
+ const DATASETS: Record<string, { service: string; layer: number; label: string; date: string }> = {
41
+ crime: { service: 'ODC_CRIME_OFFENSES_P/FeatureServer', layer: 324, label: 'Denver Police Crime Offenses', date: 'FIRST_OCCURRENCE_DATE' },
42
+ };
43
+
44
+ // Known Denver ArcGIS services worth browsing with denver_layers.
45
+ const SERVICES: Record<string, string> = {
46
+ crime: 'ODC_CRIME_OFFENSES_P/FeatureServer',
47
+ };
48
+
49
+ const tools: McpToolExport['tools'] = [
50
+ {
51
+ name: 'denver_recent',
52
+ description:
53
+ "Recent records from Denver open data (opendata-geospatialdenver.hub.arcgis.com / ArcGIS) by friendly name. PREFER OVER WEB SEARCH for \"recent crime in Denver\". Names: crime (Denver Police offenses). Returns the latest rows (newest-first), with ArcGIS epoch dates converted to ISO. Add an ArcGIS `where` to filter; to reach other Denver layers use denver_layers + denver_query.",
54
+ inputSchema: {
55
+ type: 'object' as const,
56
+ properties: {
57
+ dataset: { type: 'string', description: 'Currently: crime.', enum: Object.keys(DATASETS) },
58
+ where: { type: 'string', description: "Optional ArcGIS SQL where, e.g. \"OFFENSE='THEFT/OTHER'\" or \"WARD='2'\". Omit for all recent rows." },
59
+ limit: { type: 'number', description: 'Rows to return (1-1000, default 20).' },
60
+ },
61
+ required: ['dataset'],
62
+ },
63
+ },
64
+ {
65
+ name: 'denver_layers',
66
+ description:
67
+ 'List the layers of a Denver ArcGIS service (for discovery). Pass a known short name (crime) or a full ArcGIS service path (e.g. "ODC_CRIME_OFFENSES_P/FeatureServer"). Omit `service` to list the known Denver services. Returns layer id + name to use with denver_query.',
68
+ inputSchema: {
69
+ type: 'object' as const,
70
+ properties: {
71
+ service: { type: 'string', description: 'Short name (crime) or full ArcGIS service path. Omit to list known services.' },
72
+ },
73
+ },
74
+ },
75
+ {
76
+ name: 'denver_query',
77
+ description:
78
+ 'Query any Denver ArcGIS layer by service path + layer id. Full ArcGIS query: where, out_fields, order_by, limit. Use denver_layers to find a service/layer, or denver_recent for the common ones. Epoch dates are converted to ISO.',
79
+ inputSchema: {
80
+ type: 'object' as const,
81
+ properties: {
82
+ service: { type: 'string', description: 'ArcGIS service path, e.g. "ODC_CRIME_OFFENSES_P/FeatureServer" (or a short name: crime).' },
83
+ layer: { type: 'number', description: 'Layer id within the service (from denver_layers), e.g. 324.' },
84
+ where: { type: 'string', description: 'ArcGIS SQL where (default "1=1").' },
85
+ out_fields: { type: 'string', description: 'Comma-separated fields, or "*" (default).' },
86
+ order_by: { type: 'string', description: 'Sort clause, e.g. "FIRST_OCCURRENCE_DATE DESC".' },
87
+ limit: { type: 'number', description: 'Max rows (default 100, max 2000).' },
88
+ },
89
+ required: ['service', 'layer'],
90
+ },
91
+ },
92
+ ];
93
+
94
+ // ── Helpers ──────────────────────────────────────────────────────────
95
+
96
+ function resolveService(s: string): string {
97
+ const t = String(s ?? '').trim();
98
+ return SERVICES[t.toLowerCase()] ?? t;
99
+ }
100
+
101
+ async function arcgis(url: string): Promise<Record<string, unknown>> {
102
+ const res = await fetch(url, { headers: { Accept: 'application/json', 'User-Agent': UA } });
103
+ if (!res.ok) throw new Error(`Denver ArcGIS: ${res.status}`);
104
+ const data = (await res.json()) as Record<string, unknown>;
105
+ const err = data.error as { message?: string } | undefined;
106
+ if (err) throw new Error(`Denver ArcGIS error: ${err.message ?? 'query failed'}`);
107
+ return data;
108
+ }
109
+
110
+ // ArcGIS returns esriFieldTypeDate values as epoch milliseconds. Convert those
111
+ // columns to ISO strings; pass everything else through unchanged.
112
+ function shapeFeatures(data: Record<string, unknown>): Array<Record<string, unknown>> {
113
+ const fields = (data.fields as Array<{ name?: string; type?: string }>) ?? [];
114
+ const dateFields = new Set(fields.filter((f) => f.type === 'esriFieldTypeDate' && f.name).map((f) => f.name as string));
115
+ const feats = (data.features as Array<{ attributes?: Record<string, unknown> }>) ?? [];
116
+ return feats.map((f) => {
117
+ const a = { ...(f.attributes ?? {}) };
118
+ for (const k of dateFields) {
119
+ const v = a[k];
120
+ if (typeof v === 'number' && Number.isFinite(v)) a[k] = new Date(v).toISOString();
121
+ }
122
+ return a;
123
+ });
124
+ }
125
+
126
+ function buildQueryUrl(service: string, layer: number, where: string, outFields: string, orderBy: string | undefined, limit: number): string {
127
+ const p = new URLSearchParams({
128
+ where: where || '1=1',
129
+ outFields: outFields || '*',
130
+ resultRecordCount: String(limit),
131
+ returnGeometry: 'false',
132
+ f: 'json',
133
+ });
134
+ if (orderBy && orderBy.trim()) p.set('orderByFields', orderBy.trim());
135
+ return `${BASE}/${service}/${layer}/query?${p}`;
136
+ }
137
+
138
+ // ── Tool implementations ─────────────────────────────────────────────
139
+
140
+ async function dcRecent(dataset: string, where: string | undefined, limit: number | undefined) {
141
+ const key = String(dataset ?? '').toLowerCase().trim();
142
+ const ds = DATASETS[key];
143
+ if (!ds) throw new Error(`Unknown dataset "${dataset}". Use one of: ${Object.keys(DATASETS).join(', ')}.`);
144
+ const n = Math.min(1000, Math.max(1, Number(limit) || 20));
145
+ const url = buildQueryUrl(ds.service, ds.layer, where && String(where).trim() ? String(where).trim() : '1=1', '*', `${ds.date} DESC`, n);
146
+ const data = await arcgis(url);
147
+ const rows = shapeFeatures(data);
148
+ return { dataset: key, label: ds.label, service: ds.service, layer: ds.layer, sorted_by: `${ds.date} DESC`, count: rows.length, source: 'DataDenver (opendata-geospatialdenver.hub.arcgis.com / ArcGIS)', rows };
149
+ }
150
+
151
+ async function dcLayers(service: string | undefined) {
152
+ if (!service || !String(service).trim()) {
153
+ 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.' };
154
+ }
155
+ const path = resolveService(service);
156
+ const data = await arcgis(`${BASE}/${path}?f=json`);
157
+ const layers = (data.layers as Array<{ id?: number; name?: string }>) ?? [];
158
+ return { service_path: path, count: layers.length, layers: layers.map((l) => ({ id: l.id ?? null, name: l.name ?? null })) };
159
+ }
160
+
161
+ async function dcQuery(args: Record<string, unknown>) {
162
+ const service = resolveService(String(args.service ?? ''));
163
+ if (!service) throw new Error('Required argument "service" is missing (e.g. "ODC_CRIME_OFFENSES_P/FeatureServer" or a short name). Find services with denver_layers.');
164
+ const layer = Number(args.layer);
165
+ if (!Number.isFinite(layer)) throw new Error('Required argument "layer" must be a number (layer id from denver_layers).');
166
+ const n = Math.min(2000, Math.max(1, Number(args.limit) || 100));
167
+ const url = buildQueryUrl(
168
+ service,
169
+ Math.floor(layer),
170
+ args.where != null && String(args.where).trim() ? String(args.where).trim() : '1=1',
171
+ args.out_fields != null && String(args.out_fields).trim() ? String(args.out_fields).trim() : '*',
172
+ args.order_by as string | undefined,
173
+ n,
174
+ );
175
+ const data = await arcgis(url);
176
+ const rows = shapeFeatures(data);
177
+ return { service, layer: Math.floor(layer), count: rows.length, source: 'DataDenver (opendata-geospatialdenver.hub.arcgis.com / ArcGIS)', rows };
178
+ }
179
+
180
+ // ── Router ───────────────────────────────────────────────────────────
181
+
182
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
183
+ switch (name) {
184
+ case 'denver_recent':
185
+ return dcRecent(args.dataset as string, args.where as string | undefined, args.limit as number | undefined);
186
+ case 'denver_layers':
187
+ return dcLayers(args.service as string | undefined);
188
+ case 'denver_query':
189
+ return dcQuery(args);
190
+ default:
191
+ throw new Error(`Unknown tool: ${name}`);
192
+ }
193
+ }
194
+
195
+ 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
+ }