Skip to content

Commit 55eb348

Browse files
use underscore for parameters and transform where needed
1 parent 6ace883 commit 55eb348

13 files changed

+83
-32
lines changed

docs/inspector-test-examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ Get fireball data:
301301
{
302302
"method": "jpl/fireball",
303303
"params": {
304-
"date-min": "2022-01-01",
304+
"date_min": "2022-01-01",
305305
"limit": 5
306306
}
307307
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programcomputer/nasa-mcp-server",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"description": "Model Context Protocol (MCP) server for NASA APIs",
55
"main": "dist/index.js",
66
"files": [

src/handlers/jpl/cad.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from 'axios';
22
import { addResource } from '../../resources';
3+
import { transformParamsToHyphenated } from '../../utils/param-transformer';
34

45
/**
56
* Handler for JPL SB Close Approach (CAD) API
@@ -18,8 +19,11 @@ export async function cadHandler(args: Record<string, any>) {
1819
// Validate parameters if needed
1920
// Parameters are fairly flexible in this API, so minimal validation is needed
2021

22+
// Transform parameter names from underscore to hyphenated format
23+
const transformedParams = transformParamsToHyphenated(args);
24+
2125
// Make the API request
22-
const response = await axios.get(baseUrl, { params: args });
26+
const response = await axios.get(baseUrl, { params: transformedParams });
2327
const data = response.data;
2428

2529
// Create a resource URI that represents this query
@@ -43,8 +47,8 @@ export async function cadHandler(args: Record<string, any>) {
4347
resourceUri = `jpl://cad/list${constraints ? '?' + constraints : ''}`;
4448

4549
// Create a readable name based on date range and body
46-
const dateMin = args['date-min'] || 'now';
47-
const dateMax = args['date-max'] || '+60';
50+
const dateMin = args['date_min'] || 'now';
51+
const dateMax = args['date_max'] || '+60';
4852
const body = args.body || 'Earth';
4953

5054
resourceName = `Close approaches to ${body} from ${dateMin} to ${dateMax}`;

src/handlers/jpl/fireball.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { z } from 'zod';
22
import axios from 'axios';
3+
import { transformParamsToHyphenated } from '../../utils/param-transformer';
34

45
// Schema for validating JPL Fireball request parameters
56
export const fireballParamsSchema = z.object({
@@ -33,8 +34,11 @@ export async function jplFireballHandler(params: FireballParams) {
3334
// Construct the Fireball API URL
3435
const url = 'https://ssd-api.jpl.nasa.gov/fireball.api';
3536

37+
// Transform parameter names from underscore to hyphenated format
38+
const transformedParams = transformParamsToHyphenated(params);
39+
3640
// Make the request to the Fireball API
37-
const response = await axios.get(url, { params });
41+
const response = await axios.get(url, { params: transformedParams });
3842

3943
return {
4044
content: [

src/handlers/jpl/jd_cal.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from 'axios';
22
import { addResource } from '../../resources';
3+
import { transformParamsToHyphenated } from '../../utils/param-transformer';
34

45
/**
56
* Handler for JPL Julian Date Calendar Conversion API
@@ -25,8 +26,11 @@ export async function jdCalHandler(args: Record<string, any>) {
2526
};
2627
}
2728

29+
// Transform parameter names from underscore to hyphenated format
30+
const transformedParams = transformParamsToHyphenated(args);
31+
2832
// Make the API request
29-
const response = await axios.get(baseUrl, { params: args });
33+
const response = await axios.get(baseUrl, { params: transformedParams });
3034
const data = response.data;
3135

3236
// Add response to resources

src/handlers/jpl/nhats.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from 'axios';
22
import { addResource } from '../../resources';
3+
import { transformParamsToHyphenated } from '../../utils/param-transformer';
34

45
/**
56
* Handler for JPL NHATS API (Human-accessible NEOs data)
@@ -18,8 +19,11 @@ export async function nhatsHandler(args: Record<string, any>) {
1819
// Validate parameters if needed
1920
// Parameters are fairly flexible in this API, so minimal validation is needed
2021

22+
// Transform parameter names from underscore to hyphenated format
23+
const transformedParams = transformParamsToHyphenated(args);
24+
2125
// Make the API request
22-
const response = await axios.get(baseUrl, { params: args });
26+
const response = await axios.get(baseUrl, { params: transformedParams });
2327
const data = response.data;
2428

2529
// Create a resource URI that represents this query

src/handlers/jpl/periodic_orbits.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from 'axios';
22
import { addResource } from '../../resources';
3+
import { transformParamsToHyphenated } from '../../utils/param-transformer';
34

45
// Define expected parameters based on documentation
56
// Required: sys, family
@@ -36,8 +37,11 @@ export async function periodicOrbitsHandler(args: PeriodicOrbitParams) {
3637
// Base URL for the Periodic Orbits API
3738
const baseUrl = 'https://ssd-api.jpl.nasa.gov/periodic_orbits.api';
3839

40+
// Transform parameter names from underscore to hyphenated format
41+
const transformedParams = transformParamsToHyphenated(args);
42+
3943
// Make the API request using GET with parameters
40-
const response = await axios.get(baseUrl, { params: args });
44+
const response = await axios.get(baseUrl, { params: transformedParams });
4145
const data = response.data;
4246

4347
// Create a resource URI

src/handlers/jpl/sbdb.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { z } from 'zod';
22
import axios from 'axios';
3+
import { transformParamsToHyphenated } from '../../utils/param-transformer';
34

45
// Schema for validating JPL Small-Body Database request parameters
56
export const sbdbParamsSchema = z.object({
@@ -58,8 +59,11 @@ export async function jplSbdbHandler(params: SbdbParams) {
5859
if (ca_tbl !== 'approach') queryParams.ca_tbl = ca_tbl;
5960
if (format !== 'json') queryParams.format = format;
6061

62+
// Transform parameter names from underscore to hyphenated format
63+
const transformedParams = transformParamsToHyphenated(queryParams);
64+
6165
// Make the request to SBDB API
62-
const response = await axios.get(url, { params: queryParams });
66+
const response = await axios.get(url, { params: transformedParams });
6367

6468
// Return the response
6569
return {

src/handlers/jpl/sentry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from 'axios';
22
import { addResource } from '../../resources';
3+
import { transformParamsToHyphenated } from '../../utils/param-transformer';
34

45
/**
56
* Handler for JPL Sentry API
@@ -14,8 +15,11 @@ export async function sentryHandler(args: Record<string, any>) {
1415
// Base URL for the Sentry API
1516
const baseUrl = 'https://ssd-api.jpl.nasa.gov/sentry.api';
1617

18+
// Transform parameter names from underscore to hyphenated format
19+
const transformedParams = transformParamsToHyphenated(args);
20+
1721
// Make the API request
18-
const response = await axios.get(baseUrl, { params: args });
22+
const response = await axios.get(baseUrl, { params: transformedParams });
1923
const data = response.data;
2024

2125
// Create a resource URI that represents this query

src/index.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,17 @@ const jplPrompts = [
316316
description: "Find close approaches of asteroids and comets to Earth or other planets",
317317
arguments: [
318318
{
319-
name: "dist-max",
319+
name: "dist_max",
320320
description: "Maximum approach distance in lunar distances (LD)",
321321
required: false
322322
},
323323
{
324-
name: "date-min",
324+
name: "date_min",
325325
description: "Start date for search (YYYY-MM-DD)",
326326
required: false
327327
},
328328
{
329-
name: "date-max",
329+
name: "date_max",
330330
description: "End date for search (YYYY-MM-DD)",
331331
required: false
332332
},
@@ -342,17 +342,17 @@ const jplPrompts = [
342342
description: "Retrieve data about fireballs detected by US Government sensors",
343343
arguments: [
344344
{
345-
name: "date-min",
345+
name: "date_min",
346346
description: "Start date for fireball data (YYYY-MM-DD)",
347347
required: false
348348
},
349349
{
350-
name: "date-max",
350+
name: "date_max",
351351
description: "End date for fireball data (YYYY-MM-DD)",
352352
required: false
353353
},
354354
{
355-
name: "energy-min",
355+
name: "energy_min",
356356
description: "Minimum energy in kilotons of TNT",
357357
required: false
358358
}
@@ -408,7 +408,7 @@ async function startServer() {
408408
{
409409
name: "NASA MCP Server",
410410
description: "Model Context Protocol server for NASA APIs",
411-
version: "1.0.11"
411+
version: "1.0.12"
412412
},
413413
{
414414
capabilities: {
@@ -1044,11 +1044,11 @@ async function startServer() {
10441044
type: "number",
10451045
description: "Maximum number of results to return"
10461046
},
1047-
"date-min": {
1047+
"date_min": {
10481048
type: "string",
10491049
description: "Start date (YYYY-MM-DD)"
10501050
},
1051-
"date-max": {
1051+
"date_max": {
10521052
type: "string",
10531053
description: "End date (YYYY-MM-DD)"
10541054
}
@@ -1123,19 +1123,19 @@ async function startServer() {
11231123
inputSchema: {
11241124
type: "object",
11251125
properties: {
1126-
"dist-max": {
1126+
"dist_max": {
11271127
type: "string",
11281128
description: "Maximum approach distance (e.g., 0.05, 10LD). Default: 0.05 au"
11291129
},
1130-
"dist-min": {
1130+
"dist_min": {
11311131
type: "string",
11321132
description: "Minimum approach distance. Default: none"
11331133
},
1134-
"date-min": {
1134+
"date_min": {
11351135
type: "string",
11361136
description: "Start date for search (YYYY-MM-DD). Default: now"
11371137
},
1138-
"date-max": {
1138+
"date_max": {
11391139
type: "string",
11401140
description: "End date for search (YYYY-MM-DD). Default: +60 days"
11411141
},
@@ -1176,11 +1176,11 @@ async function startServer() {
11761176
type: "number",
11771177
description: "Maximum number of results to return"
11781178
},
1179-
"date-min": {
1179+
"date_min": {
11801180
type: "string",
11811181
description: "Start date (YYYY-MM-DD)"
11821182
},
1183-
"date-max": {
1183+
"date_max": {
11841184
type: "string",
11851185
description: "End date (YYYY-MM-DD)"
11861186
},
@@ -1192,15 +1192,15 @@ async function startServer() {
11921192
type: "string",
11931193
description: "Object SPK-ID"
11941194
},
1195-
"h-max": {
1195+
"h_max": {
11961196
type: "number",
11971197
description: "Maximum absolute magnitude (size filter)"
11981198
},
1199-
"ps-min": {
1199+
"ps_min": {
12001200
type: "string",
12011201
description: "Minimum Palermo Scale value"
12021202
},
1203-
"ip-min": {
1203+
"ip_min": {
12041204
type: "string",
12051205
description: "Minimum impact probability"
12061206
},

src/utils/api-client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios, { AxiosRequestConfig } from 'axios';
22
import dotenv from 'dotenv';
33
import path from 'path';
4+
import { transformParamsToHyphenated } from './param-transformer';
45

56
// Try to load environment variables from .env file with absolute path
67
dotenv.config();
@@ -111,7 +112,10 @@ export async function jplApiRequest(
111112
try {
112113
// JPL endpoints might use the NASA API key, but check exceptions like Scout
113114
let apiKey = process.env.NASA_API_KEY;
114-
let paramsToSend = { ...params }; // Start with original params
115+
116+
// Transform parameter names from underscore to hyphenated format
117+
// as the JPL APIs expect hyphenated parameter names
118+
let paramsToSend = transformParamsToHyphenated(params);
115119

116120
// Only add api_key if required and available, and not for scout.api
117121
if (endpoint !== '/scout.api' && apiKey) {

src/utils/param-transformer.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Transforms parameter names from underscore format to hyphenated format.
3+
* This is needed because the MCP API accepts underscore format (typical for JS/Python),
4+
* but the external JPL APIs expect hyphenated format.
5+
*
6+
* @param params Original parameters with underscore format
7+
* @returns Transformed parameters with hyphenated format
8+
*/
9+
export function transformParamsToHyphenated(params: Record<string, any>): Record<string, any> {
10+
const transformed: Record<string, any> = {};
11+
12+
for (const [key, value] of Object.entries(params)) {
13+
// Replace underscores with hyphens for parameter names
14+
const transformedKey = key.replace(/_/g, '-');
15+
transformed[transformedKey] = value;
16+
}
17+
18+
return transformed;
19+
}

0 commit comments

Comments
 (0)