@pipeworx/mcp-sciencebase 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 +21 -0
- package/README.md +55 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +246 -0
- package/tsconfig.json +14 -0
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-sciencebase
|
|
2
|
+
|
|
3
|
+
USGS ScienceBase catalog MCP.
|
|
4
|
+
|
|
5
|
+
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 860+ 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
|
+
"sciencebase": {
|
|
20
|
+
"url": "https://gateway.pipeworx.io/sciencebase/mcp"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or connect to the full Pipeworx gateway for access to all 860+ 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 Sciencebase 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-sciencebase",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "USGS ScienceBase catalog MCP.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "sciencebase"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-sciencebase"
|
|
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/sciencebase",
|
|
4
|
+
"title": "Sciencebase",
|
|
5
|
+
"description": "USGS ScienceBase catalog MCP.",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/sciencebase",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-sciencebase",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/sciencebase/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
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
|
+
* USGS ScienceBase catalog MCP.
|
|
21
|
+
*
|
|
22
|
+
* Keyless search across the U.S. Geological Survey's scientific data catalog
|
|
23
|
+
* (sciencebase.gov) — datasets, projects, and publications with metadata,
|
|
24
|
+
* contacts, web links, and direct file/download links. The catalog is
|
|
25
|
+
* hierarchical (collections contain sub-items), so items can be drilled into.
|
|
26
|
+
* Keyless.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const BASE = 'https://www.sciencebase.gov/catalog';
|
|
31
|
+
const UA = 'pipeworx/1.0 (+https://pipeworx.io)';
|
|
32
|
+
|
|
33
|
+
// The catalog API returns only id/link/title/relatedItems unless `fields=` is
|
|
34
|
+
// passed. These are the fields confirmed to populate on real items live.
|
|
35
|
+
const SEARCH_FIELDS =
|
|
36
|
+
'title,summary,browseCategories,browseTypes,dates,contacts,webLinks,tags,distributionLinks';
|
|
37
|
+
const ITEM_FIELDS =
|
|
38
|
+
'title,summary,browseCategories,browseTypes,dates,contacts,webLinks,tags,distributionLinks,files,parentId,hasChildren';
|
|
39
|
+
|
|
40
|
+
interface SbDate { type?: string; dateString?: string; label?: string }
|
|
41
|
+
interface SbContact { name?: string; type?: string }
|
|
42
|
+
interface SbWebLink { type?: string; uri?: string; title?: string }
|
|
43
|
+
interface SbDistLink { name?: string; uri?: string; title?: string }
|
|
44
|
+
interface SbFile { name?: string; url?: string; contentType?: string; size?: number }
|
|
45
|
+
interface SbItem {
|
|
46
|
+
id?: string;
|
|
47
|
+
title?: string;
|
|
48
|
+
summary?: string;
|
|
49
|
+
browseCategories?: string[];
|
|
50
|
+
browseTypes?: string[];
|
|
51
|
+
dates?: SbDate[];
|
|
52
|
+
contacts?: SbContact[];
|
|
53
|
+
webLinks?: SbWebLink[];
|
|
54
|
+
distributionLinks?: SbDistLink[];
|
|
55
|
+
files?: SbFile[];
|
|
56
|
+
hasChildren?: boolean;
|
|
57
|
+
parentId?: string;
|
|
58
|
+
link?: { url?: string };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const tools: McpToolExport['tools'] = [
|
|
62
|
+
{
|
|
63
|
+
name: 'search_items',
|
|
64
|
+
description:
|
|
65
|
+
"Search the USGS ScienceBase catalog (sciencebase.gov) — the U.S. Geological Survey's scientific data catalog of datasets, publications, and projects, with summaries, categories, dates, and direct download links. Keyless.",
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
query: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
description: 'Free-text search, e.g. "streamflow", "earthquake hazard", "Landsat vegetation".',
|
|
72
|
+
},
|
|
73
|
+
category: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
description:
|
|
76
|
+
'Optional. Narrow to a single catalog category: "Data", "Publication", "Project", or "Collection".',
|
|
77
|
+
},
|
|
78
|
+
limit: { type: 'number', description: 'Max results, default 10, max 25.' },
|
|
79
|
+
},
|
|
80
|
+
required: ['query'],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'get_item',
|
|
85
|
+
description:
|
|
86
|
+
'Get a single ScienceBase catalog item by id — full summary, categories, types, dates, contacts, web links, and attached files (download URLs). e.g. id "58f8be37e4b0b7ea5452260e". Keyless.',
|
|
87
|
+
inputSchema: {
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties: {
|
|
90
|
+
id: {
|
|
91
|
+
type: 'string',
|
|
92
|
+
description: 'A ScienceBase item id, e.g. "58f8be37e4b0b7ea5452260e" (from search_items results).',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
required: ['id'],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'item_children',
|
|
100
|
+
description:
|
|
101
|
+
'List the child items of a ScienceBase catalog item. The catalog is hierarchical — collections and folders contain sub-items (use get_item to check has_children). Keyless.',
|
|
102
|
+
inputSchema: {
|
|
103
|
+
type: 'object',
|
|
104
|
+
properties: {
|
|
105
|
+
parent_id: { type: 'string', description: 'The id of the parent catalog item, e.g. "58e64ab1e4b09da6799ac732".' },
|
|
106
|
+
limit: { type: 'number', description: 'Max children, default 15, max 30.' },
|
|
107
|
+
},
|
|
108
|
+
required: ['parent_id'],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
114
|
+
try {
|
|
115
|
+
switch (name) {
|
|
116
|
+
case 'search_items':
|
|
117
|
+
return searchItems(args);
|
|
118
|
+
case 'get_item':
|
|
119
|
+
return getItem(args);
|
|
120
|
+
case 'item_children':
|
|
121
|
+
return itemChildren(args);
|
|
122
|
+
default:
|
|
123
|
+
return { error: `Unknown tool: ${name}` };
|
|
124
|
+
}
|
|
125
|
+
} catch (e) {
|
|
126
|
+
return { error: e instanceof Error ? e.message : String(e) };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function sbGet(path: string, params: Record<string, string>): Promise<unknown> {
|
|
131
|
+
const qs = new URLSearchParams({ format: 'json', ...params }).toString();
|
|
132
|
+
const res = await fetch(`${BASE}${path}?${qs}`, {
|
|
133
|
+
headers: { Accept: 'application/json', 'User-Agent': UA },
|
|
134
|
+
});
|
|
135
|
+
if (res.status === 404) return { __notFound: true };
|
|
136
|
+
if (!res.ok) return { __error: `ScienceBase: ${res.status} ${(await res.text()).slice(0, 200)}` };
|
|
137
|
+
return res.json();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function truncate(s: unknown, n: number): string | undefined {
|
|
141
|
+
if (typeof s !== 'string' || !s) return undefined;
|
|
142
|
+
return s.length > n ? `${s.slice(0, n)}…` : s;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function firstDate(dates: SbDate[] | undefined): string | undefined {
|
|
146
|
+
if (!Array.isArray(dates) || dates.length === 0) return undefined;
|
|
147
|
+
const pub = dates.find((d) => d.type === 'Publication' || d.type === 'publication');
|
|
148
|
+
return (pub ?? dates[0]).dateString;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function mapItem(raw: SbItem, opts: { full: boolean }): Record<string, unknown> {
|
|
152
|
+
if (!opts.full) {
|
|
153
|
+
return {
|
|
154
|
+
id: raw.id,
|
|
155
|
+
title: raw.title,
|
|
156
|
+
summary: truncate(raw.summary, 300),
|
|
157
|
+
categories: raw.browseCategories ?? [],
|
|
158
|
+
date: firstDate(raw.dates),
|
|
159
|
+
data_links: (raw.distributionLinks ?? [])
|
|
160
|
+
.slice(0, 5)
|
|
161
|
+
.map((d) => ({ title: d.title ?? d.name, uri: d.uri })),
|
|
162
|
+
url: raw.link?.url,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
id: raw.id,
|
|
167
|
+
title: raw.title,
|
|
168
|
+
summary: raw.summary,
|
|
169
|
+
categories: raw.browseCategories ?? [],
|
|
170
|
+
types: raw.browseTypes ?? [],
|
|
171
|
+
dates: (raw.dates ?? []).map((d) => ({ type: d.type, date: d.dateString })),
|
|
172
|
+
contacts: (raw.contacts ?? []).slice(0, 8).map((c) => ({ name: c.name, type: c.type })),
|
|
173
|
+
web_links: (raw.webLinks ?? []).slice(0, 8).map((w) => ({ title: w.title, uri: w.uri, type: w.type })),
|
|
174
|
+
files: (raw.files ?? []).slice(0, 15).map((f) => ({
|
|
175
|
+
name: f.name,
|
|
176
|
+
url: f.url,
|
|
177
|
+
content_type: f.contentType,
|
|
178
|
+
size_bytes: f.size,
|
|
179
|
+
})),
|
|
180
|
+
has_children: raw.hasChildren ?? false,
|
|
181
|
+
parent_id: raw.parentId,
|
|
182
|
+
url: raw.link?.url,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function searchItems(args: Record<string, unknown>): Promise<unknown> {
|
|
187
|
+
const query = typeof args.query === 'string' ? args.query.trim() : '';
|
|
188
|
+
if (!query) return { error: 'provide a query', query: args.query ?? null };
|
|
189
|
+
let limit = typeof args.limit === 'number' ? Math.floor(args.limit) : 10;
|
|
190
|
+
if (!Number.isFinite(limit) || limit < 1) limit = 10;
|
|
191
|
+
if (limit > 25) limit = 25;
|
|
192
|
+
|
|
193
|
+
const params: Record<string, string> = { q: query, max: String(limit), fields: SEARCH_FIELDS };
|
|
194
|
+
const category = typeof args.category === 'string' ? args.category.trim() : '';
|
|
195
|
+
if (category) params.filter = `browseCategory=${category}`;
|
|
196
|
+
|
|
197
|
+
const data = (await sbGet('/items', params)) as Record<string, unknown>;
|
|
198
|
+
if (data.__error) return { error: data.__error };
|
|
199
|
+
|
|
200
|
+
const items = Array.isArray(data.items) ? (data.items as SbItem[]) : [];
|
|
201
|
+
return {
|
|
202
|
+
total: data.total ?? items.length,
|
|
203
|
+
count: items.length,
|
|
204
|
+
items: items.map((it) => mapItem(it, { full: false })),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function getItem(args: Record<string, unknown>): Promise<unknown> {
|
|
209
|
+
const id = typeof args.id === 'string' ? args.id.trim() : '';
|
|
210
|
+
if (!id) return { error: 'provide an item id', id: args.id ?? null };
|
|
211
|
+
|
|
212
|
+
const data = (await sbGet(`/item/${encodeURIComponent(id)}`, { fields: ITEM_FIELDS })) as Record<string, unknown>;
|
|
213
|
+
if (data.__notFound) return { error: 'item not found', id };
|
|
214
|
+
if (data.__error) return { error: data.__error };
|
|
215
|
+
|
|
216
|
+
return mapItem(data as SbItem, { full: true });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function itemChildren(args: Record<string, unknown>): Promise<unknown> {
|
|
220
|
+
const parentId = typeof args.parent_id === 'string' ? args.parent_id.trim() : '';
|
|
221
|
+
if (!parentId) return { error: 'provide a parent_id', parent_id: args.parent_id ?? null };
|
|
222
|
+
let limit = typeof args.limit === 'number' ? Math.floor(args.limit) : 15;
|
|
223
|
+
if (!Number.isFinite(limit) || limit < 1) limit = 15;
|
|
224
|
+
if (limit > 30) limit = 30;
|
|
225
|
+
|
|
226
|
+
const data = (await sbGet('/items', {
|
|
227
|
+
parentId,
|
|
228
|
+
max: String(limit),
|
|
229
|
+
fields: 'title,summary,browseCategories',
|
|
230
|
+
})) as Record<string, unknown>;
|
|
231
|
+
if (data.__error) return { error: data.__error };
|
|
232
|
+
|
|
233
|
+
const items = Array.isArray(data.items) ? (data.items as SbItem[]) : [];
|
|
234
|
+
return {
|
|
235
|
+
parent_id: parentId,
|
|
236
|
+
count: items.length,
|
|
237
|
+
children: items.map((it) => ({
|
|
238
|
+
id: it.id,
|
|
239
|
+
title: it.title,
|
|
240
|
+
summary: truncate(it.summary, 200),
|
|
241
|
+
categories: it.browseCategories ?? [],
|
|
242
|
+
})),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
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
|
+
}
|