@interstellar-tools/mcp 0.1.2 → 0.2.1
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/README.md +22 -23
- package/dist/bin.js +13 -6
- package/dist/bin.js.map +1 -1
- package/dist/bodies.d.ts +3 -3
- package/dist/bodies.d.ts.map +1 -1
- package/dist/bodies.js +10 -18
- package/dist/bodies.js.map +1 -1
- package/dist/http.d.ts +12 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +37 -1
- package/dist/http.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -44,7 +44,8 @@ claude mcp add interstellar-tools -- npx -y @interstellar-tools/mcp
|
|
|
44
44
|
|
|
45
45
|
Web assistants such as claude.ai, ChatGPT and Mistral Le Chat connect to remote
|
|
46
46
|
servers only. Serve Streamable HTTP and put it behind HTTPS (a tunnel such as
|
|
47
|
-
`cloudflared tunnel --url http://localhost:3000
|
|
47
|
+
`cloudflared tunnel --url http://localhost:3000 --http-host-header localhost:3000`
|
|
48
|
+
is enough for testing):
|
|
48
49
|
|
|
49
50
|
```shell
|
|
50
51
|
npx -y @interstellar-tools/mcp --http --port 3000
|
|
@@ -52,7 +53,10 @@ npx -y @interstellar-tools/mcp --http --port 3000
|
|
|
52
53
|
```
|
|
53
54
|
|
|
54
55
|
The server is stateless and binds to `127.0.0.1` unless you pass
|
|
55
|
-
`--host 0.0.0.0`.
|
|
56
|
+
`--host 0.0.0.0`. On loopback it only answers requests addressed to `localhost`,
|
|
57
|
+
`127.0.0.1` or `[::1]`, which protects it from DNS rebinding; pass
|
|
58
|
+
`--allowed-hosts` with your public host name when you serve it elsewhere.
|
|
59
|
+
Step-by-step setup for each assistant is in the
|
|
56
60
|
[MCP guide](https://phun-ky.net/interstellar-tools/guide/mcp/).
|
|
57
61
|
|
|
58
62
|
## Units
|
|
@@ -64,22 +68,22 @@ returned as `{ "rad": …, "deg": … }`.
|
|
|
64
68
|
|
|
65
69
|
## Tools
|
|
66
70
|
|
|
67
|
-
| Tool | What it computes
|
|
68
|
-
| ---------------------------- |
|
|
69
|
-
| `gravitational_parameter` | μ = G·(M + m) from masses
|
|
70
|
-
| `circular_speed` | Circular orbit speed at radius r
|
|
71
|
-
| `escape_speed` | Escape speed at radius r
|
|
72
|
-
| `vis_viva_speed` | Speed at radius r on an orbit with semi-major axis a
|
|
73
|
-
| `kepler_period` | Orbital period from semi-major axis
|
|
74
|
-
| `peri_apoapsis_radii` | Periapsis and apoapsis radii from a and e
|
|
75
|
-
| `sphere_of_influence_radius` | Laplace sphere of influence
|
|
76
|
-
| `hohmann_transfer` | Both burns, total Δv and transfer time
|
|
77
|
-
| `rocket_delta_v` | Tsiolkovsky rocket equation from Isp and masses
|
|
78
|
-
| `plane_change_delta_v` | Δv for a pure inclination change
|
|
79
|
-
| `solve_kepler` | Eccentric anomaly from mean anomaly and eccentricity
|
|
80
|
-
| `convert_anomaly` | Mean ↔ eccentric ↔ true anomaly (elliptic orbits)
|
|
81
|
-
| `convert_time` | Duration between units, attoseconds to gigayears
|
|
82
|
-
| `find_body` | Look up planets, moons, stars, comets, … by name
|
|
71
|
+
| Tool | What it computes |
|
|
72
|
+
| ---------------------------- | ------------------------------------------------------ |
|
|
73
|
+
| `gravitational_parameter` | μ = G·(M + m) from masses |
|
|
74
|
+
| `circular_speed` | Circular orbit speed at radius r |
|
|
75
|
+
| `escape_speed` | Escape speed at radius r |
|
|
76
|
+
| `vis_viva_speed` | Speed at radius r on an orbit with semi-major axis a |
|
|
77
|
+
| `kepler_period` | Orbital period from semi-major axis |
|
|
78
|
+
| `peri_apoapsis_radii` | Periapsis and apoapsis radii from a and e |
|
|
79
|
+
| `sphere_of_influence_radius` | Laplace sphere of influence |
|
|
80
|
+
| `hohmann_transfer` | Both burns, total Δv and transfer time |
|
|
81
|
+
| `rocket_delta_v` | Tsiolkovsky rocket equation from Isp and masses |
|
|
82
|
+
| `plane_change_delta_v` | Δv for a pure inclination change |
|
|
83
|
+
| `solve_kepler` | Eccentric anomaly from mean anomaly and eccentricity |
|
|
84
|
+
| `convert_anomaly` | Mean ↔ eccentric ↔ true anomaly (elliptic orbits) |
|
|
85
|
+
| `convert_time` | Duration between units, attoseconds to gigayears |
|
|
86
|
+
| `find_body` | Look up planets, moons, stars, comets, … by name or id |
|
|
83
87
|
|
|
84
88
|
All tools are pure and offline: no network access, no side effects.
|
|
85
89
|
|
|
@@ -89,11 +93,6 @@ Each dataset in `@interstellar-tools/constants` is available as a JSON resource
|
|
|
89
93
|
at `interstellar://datasets/{name}`, where `name` is one of `planets`, `moons`,
|
|
90
94
|
`stars`, `comets`, `asteroids`, `asteroid-belts`, `galaxies` or `systems`.
|
|
91
95
|
|
|
92
|
-
> [!NOTE]
|
|
93
|
-
>
|
|
94
|
-
> The Alpha Centauri entries are left out of `stars` until their orbital model
|
|
95
|
-
> is corrected.
|
|
96
|
-
|
|
97
96
|
## Programmatic use
|
|
98
97
|
|
|
99
98
|
```ts
|
package/dist/bin.js
CHANGED
|
@@ -9,23 +9,30 @@ const { values } = parseArgs({
|
|
|
9
9
|
http: { type: 'boolean', default: false },
|
|
10
10
|
port: { type: 'string', default: process.env.PORT ?? '3000' },
|
|
11
11
|
host: { type: 'string', default: '127.0.0.1' },
|
|
12
|
+
'allowed-hosts': { type: 'string' },
|
|
12
13
|
help: { type: 'boolean', short: 'h', default: false }
|
|
13
14
|
}
|
|
14
15
|
});
|
|
15
16
|
if (values.help) {
|
|
16
17
|
process.stdout
|
|
17
|
-
.write(`Usage: interstellar-tools-mcp [--http] [--port <n>] [--host <addr>]
|
|
18
|
+
.write(`Usage: interstellar-tools-mcp [--http] [--port <n>] [--host <addr>] [--allowed-hosts <names>]
|
|
18
19
|
|
|
19
|
-
(default)
|
|
20
|
-
--http
|
|
21
|
-
--port <n>
|
|
22
|
-
--host <addr>
|
|
20
|
+
(default) Serve over stdio, for clients that launch the server themselves
|
|
21
|
+
--http Serve Streamable HTTP at http://<host>:<port>/mcp
|
|
22
|
+
--port <n> HTTP port (default: $PORT or 3000)
|
|
23
|
+
--host <addr> HTTP bind address (default: 127.0.0.1)
|
|
24
|
+
--allowed-hosts <names> Comma-separated host names requests may use
|
|
25
|
+
(default: localhost, 127.0.0.1 and [::1] on loopback)
|
|
23
26
|
`);
|
|
24
27
|
}
|
|
25
28
|
else if (values.http) {
|
|
26
29
|
const http = await startHttpServer({
|
|
27
30
|
port: Number(values.port),
|
|
28
|
-
host: values.host
|
|
31
|
+
host: values.host,
|
|
32
|
+
allowedHosts: values['allowed-hosts']
|
|
33
|
+
?.split(',')
|
|
34
|
+
.map((name) => name.trim())
|
|
35
|
+
.filter(Boolean)
|
|
29
36
|
});
|
|
30
37
|
const { address, port } = http.address();
|
|
31
38
|
// stdout stays clean for stdio clients; logs go to stderr
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAGjF,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE;QACP,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE;QACzC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,EAAE;QAC7D,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE;QAC9C,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,G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AI;QACjB,YAAY,EAAE,MAAM,CAAC,eAAe,CAAC;YACnC,EAAE,KAAK,CAAC,GAAG,CAAC;aACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;aAC1B,MAAM,CAAC,OAAO,CAAC;KACnB,CAAC,CAAC;IACH,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,EAAiB,CAAC;IAExD,0DAA0D;IAC1D,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,qDAAqD,OAAO,IAAI,IAAI,QAAQ,CAC7E,CAAC;AACJ,CAAC;KAAM,CAAC;IACN,MAAM,YAAY,EAAE,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;AAC3D,CAAC"}
|
package/dist/bodies.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare const DATASETS: {
|
|
|
9
9
|
readonly data: import("@interstellar-tools/types").MoonsType;
|
|
10
10
|
};
|
|
11
11
|
readonly stars: {
|
|
12
|
-
readonly description: "Stars
|
|
13
|
-
readonly data: import("@interstellar-tools/types").
|
|
12
|
+
readonly description: "Stars.";
|
|
13
|
+
readonly data: import("@interstellar-tools/types").StarsType;
|
|
14
14
|
};
|
|
15
15
|
readonly comets: {
|
|
16
16
|
readonly description: "Comets.";
|
|
@@ -29,7 +29,7 @@ export declare const DATASETS: {
|
|
|
29
29
|
readonly data: import("@interstellar-tools/types").GalaxiesType;
|
|
30
30
|
};
|
|
31
31
|
readonly systems: {
|
|
32
|
-
readonly description: "
|
|
32
|
+
readonly description: "Systems: the barycenters that stars and planets orbit, nested for multiple stars.";
|
|
33
33
|
readonly data: import("@interstellar-tools/types").SystemsType;
|
|
34
34
|
};
|
|
35
35
|
};
|
package/dist/bodies.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bodies.d.ts","sourceRoot":"","sources":["../src/bodies.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,SAAS,EAEV,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"bodies.d.ts","sourceRoot":"","sources":["../src/bodies.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,SAAS,EAEV,MAAM,yCAAyC,CAAC;AAKjD,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBX,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,QAAQ,CAAC;AAUpD,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,SAyE/C,CAAC"}
|
package/dist/bodies.js
CHANGED
|
@@ -2,34 +2,25 @@ import { ASTEROID_BELTS, ASTEROIDS, COMETS, GALAXIES, MOONS, PLANETS, STARS, SYS
|
|
|
2
2
|
import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { PURE_TOOL, result } from './tools/shared.js';
|
|
5
|
-
/**
|
|
6
|
-
* The Alpha Centauri entries in `STARS` currently carry the Sun's galactic
|
|
7
|
-
* orbit instead of the binary + Proxima system, so they are held back until
|
|
8
|
-
* that model lands.
|
|
9
|
-
*/
|
|
10
|
-
const isTrusted = (body) => !(typeof body.system === 'object' &&
|
|
11
|
-
body.system !== null &&
|
|
12
|
-
'name' in body.system &&
|
|
13
|
-
body.system.name === 'Alpha Centauri');
|
|
14
5
|
export const DATASETS = {
|
|
15
6
|
planets: {
|
|
16
7
|
description: 'Planets and dwarf planets of the Solar System.',
|
|
17
8
|
data: PLANETS
|
|
18
9
|
},
|
|
19
10
|
moons: { description: 'Natural satellites.', data: MOONS },
|
|
20
|
-
stars: {
|
|
21
|
-
description: 'Stars (Alpha Centauri entries omitted pending a fix).',
|
|
22
|
-
data: STARS.filter(isTrusted)
|
|
23
|
-
},
|
|
11
|
+
stars: { description: 'Stars.', data: STARS },
|
|
24
12
|
comets: { description: 'Comets.', data: COMETS },
|
|
25
13
|
asteroids: { description: 'Asteroids.', data: ASTEROIDS },
|
|
26
14
|
'asteroid-belts': { description: 'Asteroid belts.', data: ASTEROID_BELTS },
|
|
27
15
|
galaxies: { description: 'Galaxies.', data: GALAXIES },
|
|
28
|
-
systems: {
|
|
16
|
+
systems: {
|
|
17
|
+
description: 'Systems: the barycenters that stars and planets orbit, nested for multiple stars.',
|
|
18
|
+
data: SYSTEMS
|
|
19
|
+
}
|
|
29
20
|
};
|
|
30
21
|
const DATASET_NAMES = Object.keys(DATASETS);
|
|
31
22
|
const uriFor = (name) => `interstellar://datasets/${name}`;
|
|
32
|
-
const UNITS_NOTE = 'Values carry their own units ({ value, unit }); `a` is usually in au, `period` in days (negative =
|
|
23
|
+
const UNITS_NOTE = 'Each body has a stable `id` and names the body, system or galaxy it is bound to in `parent`; `orbit` holds its elements around that parent. Values carry their own units ({ value, unit }); `orbit.a` is usually in au, `orbit.period` in days (negative = counter-clockwise), `radius` in km, `orbit.angle` in radians at J2000.';
|
|
33
24
|
export const registerBodies = (server) => {
|
|
34
25
|
server.registerResource('dataset', new ResourceTemplate('interstellar://datasets/{name}', {
|
|
35
26
|
list: () => ({
|
|
@@ -63,12 +54,12 @@ export const registerBodies = (server) => {
|
|
|
63
54
|
});
|
|
64
55
|
server.registerTool('find_body', {
|
|
65
56
|
title: 'Find celestial body',
|
|
66
|
-
description: `Look up celestial bodies by name (case-insensitive substring) across the bundled datasets. ${UNITS_NOTE}
|
|
57
|
+
description: `Look up celestial bodies by name or id (case-insensitive substring) across the bundled datasets. ${UNITS_NOTE} Only some stars carry a mass (in solar masses); use known μ values with the orbit tools.`,
|
|
67
58
|
inputSchema: {
|
|
68
59
|
query: z
|
|
69
60
|
.string()
|
|
70
61
|
.min(1)
|
|
71
|
-
.describe('Name or part of
|
|
62
|
+
.describe('Name, id or part of one, e.g. "mars" or "alpha-centauri".'),
|
|
72
63
|
dataset: z
|
|
73
64
|
.enum(DATASET_NAMES)
|
|
74
65
|
.optional()
|
|
@@ -79,7 +70,8 @@ export const registerBodies = (server) => {
|
|
|
79
70
|
const needle = query.trim().toLowerCase();
|
|
80
71
|
const names = dataset ? [dataset] : DATASET_NAMES;
|
|
81
72
|
const matches = names.flatMap((name) => DATASETS[name].data
|
|
82
|
-
.filter((body) => body.name.toLowerCase().includes(needle)
|
|
73
|
+
.filter((body) => body.name.toLowerCase().includes(needle) ||
|
|
74
|
+
body.id.includes(needle))
|
|
83
75
|
.map((body) => ({ dataset: name, body })));
|
|
84
76
|
return result({ count: matches.length, matches });
|
|
85
77
|
});
|
package/dist/bodies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bodies.js","sourceRoot":"","sources":["../src/bodies.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,MAAM,EACN,QAAQ,EACR,KAAK,EACL,OAAO,EACP,KAAK,EACL,OAAO,EACR,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,gBAAgB,EACjB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEtD
|
|
1
|
+
{"version":3,"file":"bodies.js","sourceRoot":"","sources":["../src/bodies.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,MAAM,EACN,QAAQ,EACR,KAAK,EACL,OAAO,EACP,KAAK,EACL,OAAO,EACR,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,gBAAgB,EACjB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,OAAO,EAAE;QACP,WAAW,EAAE,gDAAgD;QAC7D,IAAI,EAAE,OAAO;KACd;IACD,KAAK,EA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AAC,CAAC,aAAa,CAAC;QAClD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACpC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAgD;aAC7D,MAAM,CACL,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;YACxC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAC3B;aACA,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAC5C,CAAC;QAEF,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IACpD,CAAC,CACF,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/http.d.ts
CHANGED
|
@@ -6,12 +6,23 @@ export interface HttpServerOptionsInterface {
|
|
|
6
6
|
host?: string;
|
|
7
7
|
/** Path that serves MCP requests. */
|
|
8
8
|
path?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Host names a request's `Host` header may name. Defaults to the loopback
|
|
11
|
+
* names when bound to loopback, which blocks DNS rebinding: a web page that
|
|
12
|
+
* points its own domain at 127.0.0.1 still sends that domain as `Host`.
|
|
13
|
+
* Required to restrict hosts when binding to another interface.
|
|
14
|
+
*/
|
|
15
|
+
allowedHosts?: string[];
|
|
9
16
|
}
|
|
10
17
|
/**
|
|
11
18
|
* Serve the MCP server over Streamable HTTP, for clients that only accept
|
|
12
19
|
* remote servers. Runs stateless: every request gets a fresh server, which is
|
|
13
20
|
* cheap because every tool is a pure calculation.
|
|
14
21
|
*
|
|
22
|
+
* Requests whose `Host` header isn't allowed are rejected with 403 before they
|
|
23
|
+
* reach the server. Bound to loopback (the default), only `localhost`,
|
|
24
|
+
* `127.0.0.1` and `[::1]` are allowed, which protects against DNS rebinding.
|
|
25
|
+
*
|
|
15
26
|
* @example
|
|
16
27
|
* ```ts
|
|
17
28
|
* import { startHttpServer } from '@interstellar-tools/mcp';
|
|
@@ -19,5 +30,5 @@ export interface HttpServerOptionsInterface {
|
|
|
19
30
|
* await startHttpServer({ port: 3000 }); // http://127.0.0.1:3000/mcp
|
|
20
31
|
* ```
|
|
21
32
|
*/
|
|
22
|
-
export declare const startHttpServer: ({ port, host, path }: HttpServerOptionsInterface) => Promise<Server>;
|
|
33
|
+
export declare const startHttpServer: ({ port, host, path, allowedHosts }: HttpServerOptionsInterface) => Promise<Server>;
|
|
23
34
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,MAAM,EAEZ,MAAM,WAAW,CAAC;AAInB,MAAM,WAAW,0BAA0B;IACzC,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAkCD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,GAAI,oCAK7B,0BAA0B,KAAG,OAAO,CAAC,MAAM,CAmD7C,CAAC"}
|
package/dist/http.js
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
1
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
2
2
|
import { createServer as createHttpServer } from 'node:http';
|
|
3
3
|
import { createServer } from './server.js';
|
|
4
|
+
const LOOPBACK = ['127.0.0.1', 'localhost', '::1'];
|
|
5
|
+
const LOOPBACK_HOSTS = ['127.0.0.1', 'localhost', '[::1]'];
|
|
6
|
+
/** Answer a rejected request with a JSON-RPC error, without reading its body. */
|
|
7
|
+
const reject = (res, message) => {
|
|
8
|
+
res.writeHead(403, { 'content-type': 'application/json' }).end(JSON.stringify({
|
|
9
|
+
jsonrpc: '2.0',
|
|
10
|
+
error: { code: -32000, message },
|
|
11
|
+
id: null
|
|
12
|
+
}));
|
|
13
|
+
};
|
|
14
|
+
/** The request's `Host` name if allowed, or the reason it isn't. */
|
|
15
|
+
const checkHost = (req, allowed) => {
|
|
16
|
+
const header = req.headers.host;
|
|
17
|
+
if (!header)
|
|
18
|
+
return { ok: false, reason: 'Missing Host header' };
|
|
19
|
+
try {
|
|
20
|
+
const { hostname } = new URL(`http://${header}`);
|
|
21
|
+
return allowed.includes(hostname)
|
|
22
|
+
? { ok: true }
|
|
23
|
+
: { ok: false, reason: `Invalid Host: ${hostname}` };
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return { ok: false, reason: `Invalid Host header: ${header}` };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
4
29
|
/**
|
|
5
30
|
* Serve the MCP server over Streamable HTTP, for clients that only accept
|
|
6
31
|
* remote servers. Runs stateless: every request gets a fresh server, which is
|
|
7
32
|
* cheap because every tool is a pure calculation.
|
|
8
33
|
*
|
|
34
|
+
* Requests whose `Host` header isn't allowed are rejected with 403 before they
|
|
35
|
+
* reach the server. Bound to loopback (the default), only `localhost`,
|
|
36
|
+
* `127.0.0.1` and `[::1]` are allowed, which protects against DNS rebinding.
|
|
37
|
+
*
|
|
9
38
|
* @example
|
|
10
39
|
* ```ts
|
|
11
40
|
* import { startHttpServer } from '@interstellar-tools/mcp';
|
|
@@ -13,8 +42,15 @@ import { createServer } from './server.js';
|
|
|
13
42
|
* await startHttpServer({ port: 3000 }); // http://127.0.0.1:3000/mcp
|
|
14
43
|
* ```
|
|
15
44
|
*/
|
|
16
|
-
export const startHttpServer = ({ port, host = '127.0.0.1', path = '/mcp' }) => {
|
|
45
|
+
export const startHttpServer = ({ port, host = '127.0.0.1', path = '/mcp', allowedHosts = LOOPBACK.includes(host) ? LOOPBACK_HOSTS : undefined }) => {
|
|
17
46
|
const http = createHttpServer(async (req, res) => {
|
|
47
|
+
if (allowedHosts) {
|
|
48
|
+
const check = checkHost(req, allowedHosts);
|
|
49
|
+
if (!check.ok) {
|
|
50
|
+
reject(res, check.reason);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
18
54
|
const { pathname } = new URL(req.url ?? '/', 'http://localhost');
|
|
19
55
|
if (pathname !== path) {
|
|
20
56
|
res.writeHead(404, { 'content-type': 'text/plain' }).end('Not found');
|
package/dist/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAEnG,OAAO,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAEnG,OAAO,EACL,YAAY,IAAI,gBAAgB,EAIjC,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAkB3C,MAAM,QAAQ,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AACnD,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AAC3D,iFAAiF;AACjF,MAAM,MAAM,GAAG,CAAC,GAAmB,EAAE,OAAe,EAAE,EAAE;IACtD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC,GAAG,CAC5D,IAAI,CAAC,SAAS,CAAC;QACb,OAA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AAC,KAAK,CAAC,EAAE;oBAC/C,EAAE,EAAE,IAAI;iBACT,CAAC,CACH,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interstellar-tools/mcp",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Model Context Protocol (MCP) server exposing interstellar-tools orbital mechanics equations and celestial body datasets to AI assistants.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"test:ci": "glob-bin -c \"node --import tsx --test --no-warnings --experimental-test-coverage --test-reporter=cobertura --test-reporter-destination=coverage/cobertura-coverage.xml --test-reporter=spec --test-reporter-destination=stdout\" \"**/__tests__/**/*.spec.ts\""
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@interstellar-tools/constants": "^0.
|
|
59
|
-
"@interstellar-tools/equations": "^0.
|
|
58
|
+
"@interstellar-tools/constants": "^0.61.0",
|
|
59
|
+
"@interstellar-tools/equations": "^0.61.0",
|
|
60
60
|
"@interstellar-tools/temporal": "^0.60.0",
|
|
61
|
-
"@interstellar-tools/types": "^0.
|
|
61
|
+
"@interstellar-tools/types": "^0.61.0",
|
|
62
62
|
"@modelcontextprotocol/sdk": "1.31.0",
|
|
63
63
|
"zod": "4.6.5"
|
|
64
64
|
},
|