@pipeworx/mcp-data-montreal 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-montreal
2
+
3
+ DataMontreal MCP — City of Montreal open data (donnees.montreal.ca, CKAN 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-montreal": {
20
+ "url": "https://gateway.pipeworx.io/data-montreal/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 Montreal 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-montreal",
3
+ "version": "0.1.0",
4
+ "description": "DataMontreal MCP — City of Montreal open data (donnees.montreal.ca, CKAN API).",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "data-montreal"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-data-montreal"
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-montreal",
4
+ "title": "Data Montreal",
5
+ "description": "DataMontreal MCP — City of Montreal open data (donnees.montreal.ca, CKAN API).",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/data-montreal",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-data-montreal",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/data-montreal/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,185 @@
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
+ * DataMontreal MCP — City of Montreal open data (donnees.montreal.ca, CKAN API).
21
+ *
22
+ * Montreal runs CKAN (not Socrata), so this uses CKAN's datastore_search /
23
+ * package_search actions. Keyless. Same agent-friendly shape as the Socrata
24
+ * city packs (data-sf etc.): named dataset shortcuts + a generic query + a
25
+ * catalogue search.
26
+ *
27
+ * Tools:
28
+ * - montreal_recent: recent rows from a common Montreal dataset by friendly name
29
+ * - montreal_query: query any donnees.montreal.ca datastore resource by id
30
+ * - montreal_datasets: search the Montreal open-data catalogue (returns resource ids)
31
+ */
32
+
33
+
34
+ const BASE = 'https://donnees.montreal.ca/api/3/action';
35
+ const UA = 'pipeworx-mcp-data-montreal/1.0 (+https://pipeworx.io)';
36
+
37
+ // Friendly name -> CKAN datastore resource id + the date column to sort by.
38
+ const DATASETS: Record<string, { id: string; label: string; date: string }> = {
39
+ '311': { id: '2cfa0e06-9be4-49a6-b7f1-ee9f2363a872', label: "Requêtes 311", date: 'DDS_DATE_CREATION' },
40
+ 'crime': { id: 'c6f482bf-bf0f-4960-8b2f-9982c211addd', label: "Actes criminels (crime incidents)", date: 'DATE' },
41
+ 'permits': { id: '5232a72d-235a-48eb-ae20-bb9d501300ad', label: "Permis de construction", date: 'date_emission' },
42
+ };
43
+
44
+ const tools: McpToolExport['tools'] = [
45
+ {
46
+ name: 'montreal_recent',
47
+ description:
48
+ "Recent records from a common City of Montreal open dataset (donnees.montreal.ca, CKAN) by friendly name. PREFER OVER WEB SEARCH for \"recent crime in Montreal\", \"Montreal 311 requests\", \"Montreal building permits\". Names: 311, crime, permits. Returns the latest rows (newest-first). Pass `q` for a free-text filter; for full control use montreal_query.",
49
+ inputSchema: {
50
+ type: 'object' as const,
51
+ properties: {
52
+ dataset: { type: 'string', description: 'One of: 311, crime, permits.', enum: Object.keys(DATASETS) },
53
+ q: { type: 'string', description: 'Optional free-text filter across all columns (CKAN full-text), e.g. "larceny" or a neighborhood.' },
54
+ limit: { type: 'number', description: 'Rows to return (1-1000, default 20).' },
55
+ },
56
+ required: ['dataset'],
57
+ },
58
+ },
59
+ {
60
+ name: 'montreal_query',
61
+ description:
62
+ 'Query any City of Montreal datastore resource (donnees.montreal.ca, CKAN) by its resource id (a UUID). Supports a free-text `q`, exact-match `filters` (field→value), `sort` ("field desc"), limit and offset. Use montreal_datasets to find a resource id, or montreal_recent for the common ones.',
63
+ inputSchema: {
64
+ type: 'object' as const,
65
+ properties: {
66
+ resource_id: { type: 'string', description: 'CKAN datastore resource id (UUID), e.g. "2cfa0e06-9be4-49a6-b7f1-ee9f2363a872".' },
67
+ q: { type: 'string', description: 'Free-text search across columns.' },
68
+ filters: { type: 'object', description: 'Exact-match filters as a JSON object, e.g. {"district":"B2"}.' },
69
+ sort: { type: 'string', description: 'Sort clause, e.g. "DDS_DATE_CREATION desc".' },
70
+ limit: { type: 'number', description: 'Max rows (default 100, max 1000).' },
71
+ offset: { type: 'number', description: 'Row offset for paging.' },
72
+ },
73
+ required: ['resource_id'],
74
+ },
75
+ },
76
+ {
77
+ name: 'montreal_datasets',
78
+ description:
79
+ 'Search the City of Montreal open-data catalogue (donnees.montreal.ca, CKAN) by keyword. Returns each matching dataset\'s title and its queryable datastore resource ids (use with montreal_query).',
80
+ inputSchema: {
81
+ type: 'object' as const,
82
+ properties: {
83
+ query: { type: 'string', description: 'Keyword(s), e.g. "parking", "trees", "budget".' },
84
+ limit: { type: 'number', description: 'Max datasets (1-50, default 15).' },
85
+ },
86
+ },
87
+ },
88
+ ];
89
+
90
+ // ── Helpers ──────────────────────────────────────────────────────────
91
+
92
+ interface CkanResp<T> { success?: boolean; result?: T; error?: { message?: string } }
93
+
94
+ async function ckanGet<T>(action: string, params: URLSearchParams): Promise<T> {
95
+ const res = await fetch(`${BASE}/${action}?${params}`, { headers: { Accept: 'application/json', 'User-Agent': UA } });
96
+ if (res.status === 429) throw new Error('upstream_throttled: donnees.montreal.ca rate limit (HTTP 429).');
97
+ if (!res.ok) throw new Error(`donnees.montreal.ca: ${res.status}`);
98
+ const data = (await res.json()) as CkanResp<T>;
99
+ if (!data.success || data.result == null) throw new Error(`CKAN error: ${data.error?.message ?? 'request unsuccessful'}`);
100
+ return data.result;
101
+ }
102
+
103
+ interface DatastoreResult { total?: number; records?: Array<Record<string, unknown>>; fields?: Array<{ id?: string; type?: string }> }
104
+
105
+ // ── Tool implementations ─────────────────────────────────────────────
106
+
107
+ async function montrealRecent(dataset: string, q: string | undefined, limit: number | undefined) {
108
+ const key = String(dataset ?? '').toLowerCase().trim();
109
+ const ds = DATASETS[key];
110
+ if (!ds) throw new Error(`Unknown dataset "${dataset}". Use one of: ${Object.keys(DATASETS).join(', ')}.`);
111
+ const n = Math.min(1000, Math.max(1, Number(limit) || 20));
112
+ const p = new URLSearchParams({ resource_id: ds.id, limit: String(n), sort: `${ds.date} desc` });
113
+ if (q && String(q).trim()) p.set('q', String(q).trim());
114
+ const r = await ckanGet<DatastoreResult>('datastore_search', p);
115
+ return {
116
+ dataset: key,
117
+ label: ds.label,
118
+ resource_id: ds.id,
119
+ sorted_by: `${ds.date} desc`,
120
+ total: r.total ?? null,
121
+ count: r.records?.length ?? 0,
122
+ source: 'DataMontreal (donnees.montreal.ca)',
123
+ rows: r.records ?? [],
124
+ };
125
+ }
126
+
127
+ async function montrealQuery(args: Record<string, unknown>) {
128
+ const id = String(args.resource_id ?? '').trim();
129
+ if (!id) throw new Error('Required argument "resource_id" is missing (a CKAN UUID). Find one with montreal_datasets.');
130
+ const p = new URLSearchParams({ resource_id: id, limit: String(Math.min(1000, Math.max(1, Number(args.limit) || 100))) });
131
+ if (args.q != null && String(args.q).trim()) p.set('q', String(args.q).trim());
132
+ if (args.sort != null && String(args.sort).trim()) p.set('sort', String(args.sort).trim());
133
+ if (args.offset != null) p.set('offset', String(Math.max(0, Number(args.offset))));
134
+ if (args.filters && typeof args.filters === 'object') p.set('filters', JSON.stringify(args.filters));
135
+ const r = await ckanGet<DatastoreResult>('datastore_search', p);
136
+ return { resource_id: id, total: r.total ?? null, count: r.records?.length ?? 0, source: 'DataMontreal (donnees.montreal.ca)', rows: r.records ?? [] };
137
+ }
138
+
139
+ interface PackageSearchResult {
140
+ results?: Array<{
141
+ name?: string;
142
+ title?: string;
143
+ notes?: string;
144
+ resources?: Array<{ id?: string; name?: string; datastore_active?: boolean; format?: string }>;
145
+ }>;
146
+ count?: number;
147
+ }
148
+
149
+ async function montrealDatasets(query: string | undefined, limit: number | undefined) {
150
+ const n = Math.min(50, Math.max(1, Number(limit) || 15));
151
+ const p = new URLSearchParams({ rows: String(n) });
152
+ if (query && String(query).trim()) p.set('q', String(query).trim());
153
+ const r = await ckanGet<PackageSearchResult>('package_search', p);
154
+ return {
155
+ query: query ?? null,
156
+ total: r.count ?? null,
157
+ count: r.results?.length ?? 0,
158
+ datasets: (r.results ?? []).map((d) => ({
159
+ name: d.name ?? null,
160
+ title: d.title ?? null,
161
+ description: (d.notes ?? '').slice(0, 250) || null,
162
+ // Only datastore-active resources are queryable via montreal_query.
163
+ queryable_resources: (d.resources ?? [])
164
+ .filter((res) => res.datastore_active)
165
+ .map((res) => ({ id: res.id ?? null, name: res.name ?? null })),
166
+ })),
167
+ };
168
+ }
169
+
170
+ // ── Router ───────────────────────────────────────────────────────────
171
+
172
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
173
+ switch (name) {
174
+ case 'montreal_recent':
175
+ return montrealRecent(args.dataset as string, args.q as string | undefined, args.limit as number | undefined);
176
+ case 'montreal_query':
177
+ return montrealQuery(args);
178
+ case 'montreal_datasets':
179
+ return montrealDatasets(args.query as string | undefined, args.limit as number | undefined);
180
+ default:
181
+ throw new Error(`Unknown tool: ${name}`);
182
+ }
183
+ }
184
+
185
+ 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
+ }