@pipeworx/mcp-bts 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-bts
2
+
3
+ U.S. Bureau of Transportation Statistics (BTS) — data.bts.gov open-data portal (Socrata platform).
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 693+ 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
+ "bts": {
20
+ "url": "https://gateway.pipeworx.io/bts/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 693+ 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 Bts 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-bts",
3
+ "version": "0.1.0",
4
+ "description": "U.S. Bureau of Transportation Statistics (BTS) — data.bts.gov open-data portal (Socrata platform).",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "bts"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-bts"
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/bts",
4
+ "title": "Bts",
5
+ "description": "U.S. Bureau of Transportation Statistics (BTS) — data.bts.gov open-data portal (Socrata platform).",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/bts",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-bts",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/bts/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,141 @@
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
+ * U.S. Bureau of Transportation Statistics (BTS) — data.bts.gov open-data portal (Socrata platform).
21
+ *
22
+ * Keyless: Socrata serves moderate traffic without an app token, so no API key is required.
23
+ * BTS publishes federal transportation data: aviation (passenger counts, on-time performance,
24
+ * air fares, airline financials), freight movement, transit ridership, border crossings,
25
+ * highway/transportation safety, and the Monthly Transportation Statistics time series.
26
+ *
27
+ * Workflow:
28
+ * 1. search_datasets(q) -> find datasets + their Socrata 4x4 ids (e.g. "crem-w557")
29
+ * 2. dataset_columns(datasetId) -> learn field names/types to $select/$where on
30
+ * 3. query_dataset(datasetId) -> pull rows with SoQL ($select/$where/$order/$group/$q)
31
+ */
32
+
33
+
34
+ const CATALOG = 'https://api.us.socrata.com/api/catalog/v1';
35
+ const PORTAL = 'https://data.bts.gov';
36
+ const UA = 'pipeworx-mcp-bts/1.0 (+https://pipeworx.io)';
37
+
38
+ const tools: McpToolExport['tools'] = [
39
+ {
40
+ name: 'search_datasets',
41
+ description:
42
+ 'Search datasets published on the U.S. Bureau of Transportation Statistics open-data portal ' +
43
+ '(data.bts.gov). Returns each dataset\'s Socrata 4x4 id (e.g. "crem-w557"), name, and description. ' +
44
+ 'Use the id with dataset_columns and query_dataset. BTS covers aviation (passenger counts, on-time ' +
45
+ 'performance, air fares, airline financials), freight movement, transit ridership, border crossings, ' +
46
+ 'and transportation safety. Example queries: "aviation", "border crossing", "transit", "freight".',
47
+ inputSchema: {
48
+ type: 'object',
49
+ properties: {
50
+ q: { type: 'string', description: 'Full-text search query, e.g. "aviation" or "border crossing".' },
51
+ limit: { type: 'number', description: 'Max datasets to return (default 20).' },
52
+ offset: { type: 'number', description: 'Pagination offset (default 0).' },
53
+ },
54
+ required: ['q'],
55
+ },
56
+ },
57
+ {
58
+ name: 'dataset_columns',
59
+ description:
60
+ 'List the columns of a data.bts.gov dataset: field name (used in SoQL $select/$where), human label, ' +
61
+ 'and data type (number, text, calendar_date, etc.). Call this before query_dataset so you know which ' +
62
+ 'fields exist. datasetId is the Socrata 4x4 code from search_datasets.',
63
+ inputSchema: {
64
+ type: 'object',
65
+ properties: {
66
+ datasetId: { type: 'string', description: 'Socrata 4x4 id, e.g. "crem-w557".' },
67
+ },
68
+ required: ['datasetId'],
69
+ },
70
+ },
71
+ {
72
+ name: 'query_dataset',
73
+ description:
74
+ 'Query rows from a data.bts.gov dataset using SoQL. datasetId is the Socrata 4x4 code from ' +
75
+ 'search_datasets. SoQL clauses: $select (columns / aggregates like "count(*)" or "avg(air_fare)"), ' +
76
+ '$where (SQL-like filter, e.g. "date > \'2024-01-01\' AND state=\'TX\'"), $order ("date desc"), ' +
77
+ '$group, $q (full-text across the row). Use dataset_columns first to learn field names. Returns an ' +
78
+ 'array of row objects keyed by field name. Default $limit is 50 (Socrata max per page is 50000).',
79
+ inputSchema: {
80
+ type: 'object',
81
+ properties: {
82
+ datasetId: { type: 'string', description: 'Socrata 4x4 id, e.g. "crem-w557".' },
83
+ $select: { type: 'string', description: 'Columns or aggregates, e.g. "date, safety_general_aviation".' },
84
+ $where: { type: 'string', description: 'SQL-like filter, e.g. "date > \'2024-01-01\'".' },
85
+ $order: { type: 'string', description: 'Sort, e.g. "date desc".' },
86
+ $group: { type: 'string', description: 'Group-by field(s) for aggregation.' },
87
+ $q: { type: 'string', description: 'Full-text search across the whole row.' },
88
+ $limit: { type: 'number', description: 'Rows to return (default 50).' },
89
+ $offset: { type: 'number', description: 'Pagination offset (default 0).' },
90
+ },
91
+ required: ['datasetId'],
92
+ },
93
+ },
94
+ ];
95
+
96
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
97
+ switch (name) {
98
+ case 'search_datasets': {
99
+ const q = reqStr(args, 'q', '"aviation"');
100
+ const params = new URLSearchParams({ domains: 'data.bts.gov', q });
101
+ params.set('limit', String(numOr(args.limit, 20)));
102
+ params.set('offset', String(numOr(args.offset, 0)));
103
+ return getJson(`${CATALOG}?${params.toString()}`);
104
+ }
105
+ case 'dataset_columns': {
106
+ const id = reqStr(args, 'datasetId', '"crem-w557"');
107
+ return getJson(`${PORTAL}/api/views/${encodeURIComponent(id)}.json`);
108
+ }
109
+ case 'query_dataset': {
110
+ const id = reqStr(args, 'datasetId', '"crem-w557"');
111
+ const params = new URLSearchParams();
112
+ for (const clause of ['$select', '$where', '$order', '$group', '$q']) {
113
+ const v = args[clause];
114
+ if (typeof v === 'string' && v.trim()) params.set(clause, v);
115
+ }
116
+ params.set('$limit', String(numOr(args.$limit, 50)));
117
+ params.set('$offset', String(numOr(args.$offset, 0)));
118
+ return getJson(`${PORTAL}/resource/${encodeURIComponent(id)}.json?${params.toString()}`);
119
+ }
120
+ default:
121
+ throw new Error(`Unknown tool: ${name}`);
122
+ }
123
+ }
124
+
125
+ async function getJson(url: string): Promise<unknown> {
126
+ const res = await fetch(url, { headers: { Accept: 'application/json', 'User-Agent': UA } });
127
+ if (!res.ok) throw new Error(`BTS: ${res.status} ${await res.text().then((t) => t.slice(0, 200))}`);
128
+ return res.json();
129
+ }
130
+
131
+ function reqStr(args: Record<string, unknown>, key: string, example: string): string {
132
+ const v = args[key];
133
+ if (typeof v !== 'string' || !v.trim()) throw new Error(`Required argument "${key}" is missing. Pass a string like ${example}.`);
134
+ return v;
135
+ }
136
+
137
+ function numOr(v: unknown, fallback: number): number {
138
+ return typeof v === 'number' && Number.isFinite(v) ? v : fallback;
139
+ }
140
+
141
+ 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
+ }