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