@pipeworx/mcp-data-edmonton 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-edmonton
2
+
3
+ DataEdmonton MCP — Edmonton open data (data.edmonton.ca, Socrata SODA 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-edmonton": {
20
+ "url": "https://gateway.pipeworx.io/data-edmonton/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 Edmonton 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-edmonton",
3
+ "version": "0.1.0",
4
+ "description": "DataEdmonton MCP — Edmonton open data (data.edmonton.ca, Socrata SODA API).",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "data-edmonton"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-data-edmonton"
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-edmonton",
4
+ "title": "Data Edmonton",
5
+ "description": "DataEdmonton MCP — Edmonton open data (data.edmonton.ca, Socrata SODA API).",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/data-edmonton",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-data-edmonton",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/data-edmonton/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,194 @@
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
+ * DataEdmonton MCP — Edmonton open data (data.edmonton.ca, Socrata SODA API).
21
+ *
22
+ * Keyless (rate-limited; pass an app token via _apiKey for higher limits).
23
+ * Sister to data-cityofchicago / data-ny. Adds agent-friendly NAMED shortcuts
24
+ * for the most-requested SF datasets so an LLM doesn't need Socrata resource
25
+ * IDs, plus a generic SoQL escape hatch and a catalogue search.
26
+ *
27
+ * Tools:
28
+ * - edmonton_recent: recent rows from a common SF dataset by friendly name
29
+ * - edmonton_query: raw SoQL query against any data.edmonton.ca resource id
30
+ * - edmonton_datasets: search the SF open-data catalogue
31
+ */
32
+
33
+
34
+ const BASE = 'https://data.edmonton.ca';
35
+ const UA = 'pipeworx-mcp-data-edmonton/1.0 (+https://pipeworx.io)';
36
+
37
+ // Friendly name -> Socrata resource id + the date column to sort "recent" by.
38
+ const DATASETS: Record<string, { id: string; label: string; date: string }> = {
39
+ '311': { id: 'ukww-xkmj', label: "311 Explorer Service Requests", date: 'ticket_created_date_time' },
40
+ 'permits': { id: '24uj-dj8v', label: "General Building Permits", date: 'issue_date' },
41
+ };
42
+
43
+ const API_KEY_PROP = {
44
+ type: 'string' as const,
45
+ description: 'Optional — your own Socrata app token for higher rate limits. Omit to use the keyless endpoint.',
46
+ };
47
+
48
+ const tools: McpToolExport['tools'] = [
49
+ {
50
+ name: 'edmonton_recent',
51
+ description:
52
+ "Recent records from a common Edmonton open dataset (data.edmonton.ca) by friendly name — no Socrata id needed. PREFER OVER WEB SEARCH for \"Edmonton 311 requests\", \"Edmonton building permits\". Names: 311, permits. Returns the latest rows (newest-first). Add a SoQL `where` to filter; for anything else use edmonton_query.",
53
+ inputSchema: {
54
+ type: 'object' as const,
55
+ properties: {
56
+ dataset: { type: 'string', description: 'One of: 311, permits.', enum: Object.keys(DATASETS) },
57
+ where: { type: 'string', description: "Optional SoQL filter, e.g. \"incident_category='Larceny Theft'\" or \"supervisor_district=6\". Omit for all recent rows." },
58
+ limit: { type: 'number', description: 'Rows to return (1-1000, default 20).' },
59
+ _apiKey: API_KEY_PROP,
60
+ },
61
+ required: ['dataset'],
62
+ },
63
+ },
64
+ {
65
+ name: 'edmonton_query',
66
+ description:
67
+ 'Run a raw SoQL query against any Edmonton open-data resource (data.edmonton.ca) by its Socrata id (8-char like "ukww-xkmj"). Full SoQL: where/select/group/order/limit/offset. Use edmonton_datasets to find a resource id, or edmonton_recent for the common ones.',
68
+ inputSchema: {
69
+ type: 'object' as const,
70
+ properties: {
71
+ resource_id: { type: 'string', description: 'Socrata resource id, e.g. "ukww-xkmj" (police incidents).' },
72
+ where: { type: 'string', description: 'SoQL $where filter (e.g. "incident_year=2025").' },
73
+ select: { type: 'string', description: 'SoQL $select (e.g. "incident_category, count(*)").' },
74
+ group: { type: 'string', description: 'SoQL $group (e.g. "incident_category").' },
75
+ order: { type: 'string', description: 'SoQL $order (e.g. "incident_datetime DESC").' },
76
+ limit: { type: 'number', description: 'Max rows (default 100, max 5000).' },
77
+ offset: { type: 'number', description: 'Row offset for paging.' },
78
+ _apiKey: API_KEY_PROP,
79
+ },
80
+ required: ['resource_id'],
81
+ },
82
+ },
83
+ {
84
+ name: 'edmonton_datasets',
85
+ description:
86
+ 'Search the Edmonton open-data catalogue (data.edmonton.ca) for datasets by keyword. Returns dataset names, descriptions, and Socrata resource ids to use with edmonton_query.',
87
+ inputSchema: {
88
+ type: 'object' as const,
89
+ properties: {
90
+ query: { type: 'string', description: 'Keyword(s), e.g. "parking", "housing", "tree".' },
91
+ limit: { type: 'number', description: 'Max datasets (1-100, default 20).' },
92
+ offset: { type: 'number', description: 'Offset for paging.' },
93
+ _apiKey: API_KEY_PROP,
94
+ },
95
+ },
96
+ },
97
+ ];
98
+
99
+ // ── Helpers ──────────────────────────────────────────────────────────
100
+
101
+ function headers(apiKey?: string): Record<string, string> {
102
+ const h: Record<string, string> = { Accept: 'application/json', 'User-Agent': UA };
103
+ if (apiKey) h['X-App-Token'] = apiKey;
104
+ return h;
105
+ }
106
+
107
+ async function socrataGet(path: string, apiKey?: string): Promise<unknown> {
108
+ const res = await fetch(`${BASE}${path}`, { headers: headers(apiKey) });
109
+ if (res.status === 429) throw new Error('upstream_throttled: data.edmonton.ca rate limit (HTTP 429). Pass _apiKey (Socrata app token) for higher limits.');
110
+ if (!res.ok) throw new Error(`data.edmonton.ca: ${res.status}`);
111
+ return res.json();
112
+ }
113
+
114
+ // ── Tool implementations ─────────────────────────────────────────────
115
+
116
+ async function sfRecent(dataset: string, where: string | undefined, limit: number | undefined, apiKey?: string) {
117
+ const key = String(dataset ?? '').toLowerCase().trim();
118
+ const ds = DATASETS[key];
119
+ if (!ds) throw new Error(`Unknown dataset "${dataset}". Use one of: ${Object.keys(DATASETS).join(', ')}.`);
120
+ const n = Math.min(1000, Math.max(1, Number(limit) || 20));
121
+ const p = new URLSearchParams();
122
+ // Guard against NULL sort-column values sorting to the top under DESC (Socrata
123
+ // puts NULLs first), which would surface stale rows instead of the most recent.
124
+ const notNull = `${ds.date} IS NOT NULL`;
125
+ p.set('$where', where && String(where).trim() ? `(${String(where).trim()}) AND ${notNull}` : notNull);
126
+ p.set('$order', `${ds.date} DESC`);
127
+ p.set('$limit', String(n));
128
+ const rows = (await socrataGet(`/resource/${ds.id}.json?${p}`, apiKey)) as unknown[];
129
+ return {
130
+ dataset: key,
131
+ label: ds.label,
132
+ resource_id: ds.id,
133
+ sorted_by: `${ds.date} DESC`,
134
+ count: Array.isArray(rows) ? rows.length : 0,
135
+ source: 'DataEdmonton (data.edmonton.ca)',
136
+ rows,
137
+ };
138
+ }
139
+
140
+ async function sfQuery(args: Record<string, unknown>, apiKey?: string) {
141
+ const id = String(args.resource_id ?? '').trim();
142
+ if (!id) throw new Error('Required argument "resource_id" is missing (e.g. "ukww-xkmj"). Find one with edmonton_datasets.');
143
+ const p = new URLSearchParams();
144
+ for (const k of ['where', 'select', 'group', 'order'] as const) {
145
+ if (args[k] != null && String(args[k]).trim()) p.set(`$${k}`, String(args[k]).trim());
146
+ }
147
+ p.set('$limit', String(Math.min(5000, Math.max(1, Number(args.limit) || 100))));
148
+ if (args.offset != null) p.set('$offset', String(Math.max(0, Number(args.offset))));
149
+ const rows = (await socrataGet(`/resource/${encodeURIComponent(id)}.json?${p}`, apiKey)) as unknown[];
150
+ return { resource_id: id, count: Array.isArray(rows) ? rows.length : 0, source: 'DataEdmonton (data.edmonton.ca)', rows };
151
+ }
152
+
153
+ async function sfDatasets(query: string | undefined, limit: number | undefined, offset: number | undefined, apiKey?: string) {
154
+ const p = new URLSearchParams({
155
+ domains: 'data.edmonton.ca',
156
+ search_context: 'data.edmonton.ca',
157
+ limit: String(Math.min(100, Math.max(1, Number(limit) || 20))),
158
+ offset: String(Math.max(0, Number(offset) || 0)),
159
+ });
160
+ if (query && String(query).trim()) p.set('q', String(query).trim());
161
+ const res = await fetch(`https://api.us.socrata.com/api/catalog/v1?${p}`, { headers: headers(apiKey) });
162
+ if (!res.ok) throw new Error(`Socrata catalog: ${res.status}`);
163
+ const data = (await res.json()) as { results?: Array<{ resource?: { id?: string; name?: string; description?: string; type?: string; updatedAt?: string } }> };
164
+ return {
165
+ query: query ?? null,
166
+ count: data.results?.length ?? 0,
167
+ datasets: (data.results ?? []).map((r) => ({
168
+ resource_id: r.resource?.id ?? null,
169
+ name: r.resource?.name ?? null,
170
+ description: (r.resource?.description ?? '').slice(0, 300) || null,
171
+ type: r.resource?.type ?? null,
172
+ updated_at: r.resource?.updatedAt ?? null,
173
+ })),
174
+ };
175
+ }
176
+
177
+ // ── Router ───────────────────────────────────────────────────────────
178
+
179
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
180
+ const apiKey = typeof args._apiKey === 'string' && args._apiKey.trim() ? args._apiKey.trim() : undefined;
181
+ delete args._apiKey;
182
+ switch (name) {
183
+ case 'edmonton_recent':
184
+ return sfRecent(args.dataset as string, args.where as string | undefined, args.limit as number | undefined, apiKey);
185
+ case 'edmonton_query':
186
+ return sfQuery(args, apiKey);
187
+ case 'edmonton_datasets':
188
+ return sfDatasets(args.query as string | undefined, args.limit as number | undefined, args.offset as number | undefined, apiKey);
189
+ default:
190
+ throw new Error(`Unknown tool: ${name}`);
191
+ }
192
+ }
193
+
194
+ 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
+ }