Skip to content

Commit 119649d

Browse files
added HTTP transport
1 parent 342cad2 commit 119649d

7 files changed

Lines changed: 561 additions & 287 deletions

File tree

README.md

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,26 @@ The server can be configured with the following environment variables:
8282
| Variable | Description |
8383
|----------|-------------|
8484
| `NASA_API_KEY` | Your NASA API key (get at api.nasa.gov) |
85+
| `MCP_TRANSPORT` | Transport mode: `stdio` (default) or `http` for Streamable HTTP |
86+
| `MCP_HTTP_HOST` | Host for Streamable HTTP mode (default: `127.0.0.1`) |
87+
| `MCP_HTTP_PORT` | Port for Streamable HTTP mode (default: `3000`) |
88+
| `MCP_HTTP_PATH` | MCP endpoint path for Streamable HTTP mode (default: `/mcp`) |
89+
90+
## Transport Modes
91+
92+
By default, the server runs over stdio for local MCP clients such as Cursor and Claude Desktop.
93+
94+
To run the optional Streamable HTTP transport:
95+
96+
```bash
97+
MCP_TRANSPORT=http MCP_HTTP_PORT=3000 NASA_API_KEY=YOUR_API_KEY npm start
98+
```
99+
100+
The Streamable HTTP endpoint will be available at:
101+
102+
```text
103+
http://127.0.0.1:3000/mcp
104+
```
85105

86106
## Included NASA APIs
87107

@@ -267,15 +287,16 @@ For detailed examples, see the [Inspector Test Examples](docs/inspector-test-exa
267287

268288
## MCP Client Usage
269289

270-
This server follows the official Model Context Protocol. Here's an example of how to use it with the MCP SDK:
290+
This server follows the official Model Context Protocol. For local clients, use the default stdio configuration shown above. For Streamable HTTP mode, start the server with `MCP_TRANSPORT=http`, then connect with the MCP SDK:
271291

272292
```typescript
273293
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
274-
import { HttpClientTransport } from "@modelcontextprotocol/sdk/client/http.js";
294+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
295+
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
275296

276-
const transport = new HttpClientTransport({
277-
url: "http://localhost:3000",
278-
});
297+
const transport = new StreamableHTTPClientTransport(
298+
new URL("http://127.0.0.1:3000/mcp")
299+
);
279300

280301
const client = new Client({
281302
name: "mcp-client",
@@ -286,46 +307,61 @@ await client.connect(transport);
286307

287308
// Example: Get today's Astronomy Picture of the Day
288309
const apodResult = await client.request({
289-
method: "nasa/apod",
290-
params: {}
291-
});
310+
method: "tools/call",
311+
params: {
312+
name: "nasa/apod",
313+
arguments: {}
314+
}
315+
}, CallToolResultSchema);
292316

293317
// Example: Get Mars Rover photos
294318
const marsRoverResult = await client.request({
295-
method: "nasa/mars-rover",
296-
params: { rover: "curiosity", sol: 1000 }
297-
});
319+
method: "tools/call",
320+
params: {
321+
name: "nasa/mars-rover",
322+
arguments: { rover: "curiosity", sol: 1000 }
323+
}
324+
}, CallToolResultSchema);
298325

299326
// Example: Search for Near Earth Objects
300327
const neoResults = await client.request({
301-
method: "nasa/neo",
328+
method: "tools/call",
302329
params: {
303-
start_date: '2023-01-01',
304-
end_date: '2023-01-07'
330+
name: "nasa/neo",
331+
arguments: {
332+
start_date: "2023-01-01",
333+
end_date: "2023-01-07"
334+
}
305335
}
306-
});
336+
}, CallToolResultSchema);
307337

308338
// Example: Get satellite imagery from GIBS
309339
const satelliteImage = await client.request({
310-
method: "nasa/gibs",
340+
method: "tools/call",
311341
params: {
312-
layer: 'MODIS_Terra_CorrectedReflectance_TrueColor',
313-
date: '2023-01-01'
342+
name: "nasa/gibs",
343+
arguments: {
344+
layer: "MODIS_Terra_CorrectedReflectance_TrueColor",
345+
date: "2023-01-01"
346+
}
314347
}
315-
});
348+
}, CallToolResultSchema);
316349

317350
// Example: Use the new POWER API
318351
const powerData = await client.request({
319-
method: "nasa/power",
352+
method: "tools/call",
320353
params: {
321-
parameters: "T2M,PRECTOTCORR,WS10M",
322-
community: "re",
323-
latitude: 40.7128,
324-
longitude: -74.0060,
325-
start: "20220101",
326-
end: "20220107"
354+
name: "nasa/power",
355+
arguments: {
356+
parameters: "T2M,PRECTOTCORR,WS10M",
357+
community: "re",
358+
latitude: 40.7128,
359+
longitude: -74.0060,
360+
start: "20220101",
361+
end: "20220107"
362+
}
327363
}
328-
});
364+
}, CallToolResultSchema);
329365
```
330366

331367
## Contributing

0 commit comments

Comments
 (0)