@pipeworx/mcp-nrel 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-nrel
2
+
3
+ NREL MCP — wraps the US National Renewable Energy Laboratory developer API
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 965+ 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
+ "nrel": {
20
+ "url": "https://gateway.pipeworx.io/nrel/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 965+ 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 Nrel 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-nrel",
3
+ "version": "0.1.0",
4
+ "description": "NREL MCP — wraps the US National Renewable Energy Laboratory developer API",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "nrel"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-nrel"
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/nrel",
4
+ "title": "Nrel",
5
+ "description": "NREL MCP — wraps the US National Renewable Energy Laboratory developer API",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/nrel",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-nrel",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/nrel/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,299 @@
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
+ * NREL MCP — wraps the US National Renewable Energy Laboratory developer API
21
+ * (developer.nrel.gov, served via api.data.gov).
22
+ *
23
+ * Tools:
24
+ * - pvwatts: solar energy production estimate for a PV system (PVWatts v8)
25
+ * - solar_resource: solar resource (sunlight: DNI/GHI) for a location
26
+ * - alt_fuel_stations: EV charging / alternative fuel stations near a point or state
27
+ * - utility_rates: electricity utility rates ($/kWh) for a location
28
+ *
29
+ * Dual-key: pass your own NREL / api.data.gov key via the OPTIONAL _apiKey
30
+ * argument for higher limits; otherwise the shared Pipeworx key is used.
31
+ * The key is sent as the `api_key` query parameter. All requests are GET.
32
+ */
33
+
34
+
35
+ const BASE_URL = 'https://developer.nrel.gov';
36
+
37
+ const tools: McpToolExport['tools'] = [
38
+ {
39
+ name: 'pvwatts',
40
+ description:
41
+ 'Solar energy production estimate (PVWatts v8) for a photovoltaic system at a lat/lon. Returns estimated annual AC energy (kWh), capacity factor, solar radiation, and monthly production. Example: pvwatts({ lat: 40.0, lon: -105.25, system_capacity: 4 })',
42
+ inputSchema: {
43
+ type: 'object' as const,
44
+ properties: {
45
+ lat: { type: 'number', description: 'Latitude in decimal degrees, e.g. 40.0' },
46
+ lon: { type: 'number', description: 'Longitude in decimal degrees, e.g. -105.25' },
47
+ system_capacity: { type: 'number', description: 'System size in kW DC (default 4)' },
48
+ tilt: { type: 'number', description: 'Array tilt in degrees (default 20)' },
49
+ azimuth: { type: 'number', description: 'Array azimuth in degrees, 180 = south (default 180)' },
50
+ array_type: {
51
+ type: 'number',
52
+ description:
53
+ 'Array type: 0=fixed open rack, 1=fixed roof mount, 2=1-axis tracking, 3=1-axis backtracking, 4=2-axis tracking (default 1)',
54
+ },
55
+ module_type: {
56
+ type: 'number',
57
+ description: 'Module type: 0=standard, 1=premium, 2=thin film (default 0)',
58
+ },
59
+ losses: { type: 'number', description: 'System losses in percent (default 14)' },
60
+ _apiKey: {
61
+ type: 'string',
62
+ description:
63
+ 'Optional — your own NREL / api.data.gov API key for higher limits; omit to use the shared Pipeworx key.',
64
+ },
65
+ },
66
+ required: ['lat', 'lon'],
67
+ },
68
+ },
69
+ {
70
+ name: 'solar_resource',
71
+ description:
72
+ 'Solar resource (sunlight) for a location: average direct normal irradiance (DNI), global horizontal irradiance (GHI), and tilt-at-latitude radiation, annual plus monthly. Example: solar_resource({ lat: 40.0, lon: -105.25 })',
73
+ inputSchema: {
74
+ type: 'object' as const,
75
+ properties: {
76
+ lat: { type: 'number', description: 'Latitude in decimal degrees, e.g. 40.0' },
77
+ lon: { type: 'number', description: 'Longitude in decimal degrees, e.g. -105.25' },
78
+ _apiKey: {
79
+ type: 'string',
80
+ description:
81
+ 'Optional — your own NREL / api.data.gov API key for higher limits; omit to use the shared Pipeworx key.',
82
+ },
83
+ },
84
+ required: ['lat', 'lon'],
85
+ },
86
+ },
87
+ {
88
+ name: 'alt_fuel_stations',
89
+ description:
90
+ 'EV charging / alternative fuel stations near a point (lat/lon + radius) or within a state. Filter by fuel type (ELEC, E85, LPG, CNG, HY, etc.). Returns station names, addresses, EV connectors/network, access hours, and distance. Example: alt_fuel_stations({ lat: 40.0, lon: -105.25, fuel_type: "ELEC", radius: 25 })',
91
+ inputSchema: {
92
+ type: 'object' as const,
93
+ properties: {
94
+ lat: { type: 'number', description: 'Latitude in decimal degrees (with lon, searches by radius)' },
95
+ lon: { type: 'number', description: 'Longitude in decimal degrees (with lat, searches by radius)' },
96
+ state: { type: 'string', description: '2-letter US state code (used when lat/lon not given), e.g. "CO"' },
97
+ fuel_type: {
98
+ type: 'string',
99
+ description: "Fuel type code, e.g. 'ELEC', 'E85', 'LPG', 'CNG', 'HY' (default 'ELEC')",
100
+ },
101
+ radius: { type: 'number', description: 'Search radius in miles when lat/lon given (default 25)' },
102
+ limit: { type: 'number', description: 'Max stations to return (default 20, max 50)' },
103
+ _apiKey: {
104
+ type: 'string',
105
+ description:
106
+ 'Optional — your own NREL / api.data.gov API key for higher limits; omit to use the shared Pipeworx key.',
107
+ },
108
+ },
109
+ required: [],
110
+ },
111
+ },
112
+ {
113
+ name: 'utility_rates',
114
+ description:
115
+ 'Electricity utility rates ($/kWh) for a location: the serving utility plus average residential, commercial, and industrial rates. Example: utility_rates({ lat: 40.0, lon: -105.25 })',
116
+ inputSchema: {
117
+ type: 'object' as const,
118
+ properties: {
119
+ lat: { type: 'number', description: 'Latitude in decimal degrees, e.g. 40.0' },
120
+ lon: { type: 'number', description: 'Longitude in decimal degrees, e.g. -105.25' },
121
+ _apiKey: {
122
+ type: 'string',
123
+ description:
124
+ 'Optional — your own NREL / api.data.gov API key for higher limits; omit to use the shared Pipeworx key.',
125
+ },
126
+ },
127
+ required: ['lat', 'lon'],
128
+ },
129
+ },
130
+ ];
131
+
132
+ // NREL/api.data.gov: key goes in the `api_key` query param. All GET.
133
+ // Returns an error object (not a throw) for missing key / non-2xx so the
134
+ // gateway surfaces a clean, actionable payload.
135
+ async function nrelGet(apiKey: string, path: string, params: URLSearchParams): Promise<unknown> {
136
+ if (!apiKey) {
137
+ return { error: 'api_key_required', message: 'No NREL/api.data.gov key available.' };
138
+ }
139
+ params.set('api_key', apiKey);
140
+ const res = await fetch(`${BASE_URL}${path}?${params}`);
141
+ if (!res.ok) {
142
+ const text = await res.text();
143
+ return { error: res.status, message: text };
144
+ }
145
+ return res.json();
146
+ }
147
+
148
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
149
+ const apiKey = args._apiKey as string;
150
+ delete args._apiKey;
151
+
152
+ switch (name) {
153
+ case 'pvwatts':
154
+ return pvwatts(args, apiKey);
155
+ case 'solar_resource':
156
+ return solarResource(args, apiKey);
157
+ case 'alt_fuel_stations':
158
+ return altFuelStations(args, apiKey);
159
+ case 'utility_rates':
160
+ return utilityRates(args, apiKey);
161
+ default:
162
+ throw new Error(`Unknown tool: ${name}`);
163
+ }
164
+ }
165
+
166
+ async function pvwatts(args: Record<string, unknown>, apiKey: string) {
167
+ const params = new URLSearchParams({
168
+ lat: String(args.lat),
169
+ lon: String(args.lon),
170
+ system_capacity: String(args.system_capacity ?? 4),
171
+ tilt: String(args.tilt ?? 20),
172
+ azimuth: String(args.azimuth ?? 180),
173
+ array_type: String(args.array_type ?? 1),
174
+ module_type: String(args.module_type ?? 0),
175
+ losses: String(args.losses ?? 14),
176
+ });
177
+ const data = (await nrelGet(apiKey, '/api/pvwatts/v8.json', params)) as
178
+ | {
179
+ outputs?: {
180
+ ac_annual?: number;
181
+ solrad_annual?: number;
182
+ capacity_factor?: number;
183
+ ac_monthly?: number[];
184
+ };
185
+ station_info?: { city?: string; state?: string };
186
+ errors?: unknown;
187
+ }
188
+ | { error: unknown; message: unknown };
189
+ if ('error' in data) return data;
190
+
191
+ const { outputs, station_info, errors } = data;
192
+ return {
193
+ ac_annual_kwh: outputs?.ac_annual,
194
+ capacity_factor: outputs?.capacity_factor,
195
+ solrad_annual: outputs?.solrad_annual,
196
+ ac_monthly_kwh: outputs?.ac_monthly,
197
+ station: `${station_info?.city}, ${station_info?.state}`,
198
+ errors,
199
+ };
200
+ }
201
+
202
+ async function solarResource(args: Record<string, unknown>, apiKey: string) {
203
+ const params = new URLSearchParams({ lat: String(args.lat), lon: String(args.lon) });
204
+ const data = (await nrelGet(apiKey, '/api/solar/solar_resource/v1.json', params)) as
205
+ | {
206
+ outputs?: {
207
+ avg_dni?: { annual?: number; monthly?: Record<string, number> };
208
+ avg_ghi?: { annual?: number; monthly?: Record<string, number> };
209
+ avg_lat_tilt?: { annual?: number; monthly?: Record<string, number> };
210
+ };
211
+ }
212
+ | { error: unknown; message: unknown };
213
+ if ('error' in data) return data;
214
+
215
+ const { outputs } = data;
216
+ return {
217
+ avg_dni_annual: outputs?.avg_dni?.annual,
218
+ avg_ghi_annual: outputs?.avg_ghi?.annual,
219
+ avg_lat_tilt_annual: outputs?.avg_lat_tilt?.annual,
220
+ ghi_monthly: outputs?.avg_ghi?.monthly,
221
+ };
222
+ }
223
+
224
+ async function altFuelStations(args: Record<string, unknown>, apiKey: string) {
225
+ const params = new URLSearchParams({
226
+ fuel_type: (args.fuel_type as string) ?? 'ELEC',
227
+ limit: String(Math.min(50, (args.limit as number) ?? 20)),
228
+ });
229
+ if (args.lat !== undefined && args.lon !== undefined) {
230
+ params.set('latitude', String(args.lat));
231
+ params.set('longitude', String(args.lon));
232
+ params.set('radius', String(args.radius ?? 25));
233
+ } else if (args.state) {
234
+ params.set('state', String(args.state));
235
+ }
236
+
237
+ const data = (await nrelGet(apiKey, '/api/alt-fuel-stations/v1.json', params)) as
238
+ | {
239
+ total_results?: number;
240
+ fuel_stations?: Array<{
241
+ station_name?: string;
242
+ street_address?: string;
243
+ city?: string;
244
+ state?: string;
245
+ zip?: string;
246
+ fuel_type_code?: string;
247
+ ev_connector_types?: string[];
248
+ ev_network?: string;
249
+ access_days_time?: string;
250
+ latitude?: number;
251
+ longitude?: number;
252
+ distance?: number;
253
+ }>;
254
+ }
255
+ | { error: unknown; message: unknown };
256
+ if ('error' in data) return data;
257
+
258
+ const { total_results, fuel_stations } = data;
259
+ return {
260
+ total: total_results,
261
+ stations: (fuel_stations || []).map((s) => ({
262
+ name: s.station_name,
263
+ address: `${s.street_address}, ${s.city}, ${s.state} ${s.zip}`,
264
+ fuel_type: s.fuel_type_code,
265
+ ev_connectors: s.ev_connector_types,
266
+ ev_network: s.ev_network,
267
+ access: s.access_days_time,
268
+ lat: s.latitude,
269
+ lon: s.longitude,
270
+ distance: s.distance,
271
+ })),
272
+ };
273
+ }
274
+
275
+ async function utilityRates(args: Record<string, unknown>, apiKey: string) {
276
+ const params = new URLSearchParams({ lat: String(args.lat), lon: String(args.lon) });
277
+ const data = (await nrelGet(apiKey, '/api/utility_rates/v3.json', params)) as
278
+ | {
279
+ outputs?: {
280
+ utility_name?: string;
281
+ company_id?: string;
282
+ residential?: number;
283
+ commercial?: number;
284
+ industrial?: number;
285
+ };
286
+ }
287
+ | { error: unknown; message: unknown };
288
+ if ('error' in data) return data;
289
+
290
+ const { outputs } = data;
291
+ return {
292
+ utility: outputs?.utility_name,
293
+ residential_rate: outputs?.residential,
294
+ commercial_rate: outputs?.commercial,
295
+ industrial_rate: outputs?.industrial,
296
+ };
297
+ }
298
+
299
+ 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
+ }