@dangahagan/weather-mcp 1.34.8 → 1.35.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.
Files changed (38) hide show
  1. package/README.md +7 -4
  2. package/dist/config/http.d.ts +55 -0
  3. package/dist/config/http.d.ts.map +1 -0
  4. package/dist/config/http.js +128 -0
  5. package/dist/config/http.js.map +1 -0
  6. package/dist/errors/ApiError.d.ts +1 -0
  7. package/dist/errors/ApiError.d.ts.map +1 -1
  8. package/dist/errors/ApiError.js +20 -4
  9. package/dist/errors/ApiError.js.map +1 -1
  10. package/dist/http.d.ts +20 -0
  11. package/dist/http.d.ts.map +1 -0
  12. package/dist/http.js +137 -0
  13. package/dist/http.js.map +1 -0
  14. package/dist/server/httpApp.d.ts +53 -0
  15. package/dist/server/httpApp.d.ts.map +1 -0
  16. package/dist/server/httpApp.js +172 -0
  17. package/dist/server/httpApp.js.map +1 -0
  18. package/dist/server/oauthDiscovery.d.ts +44 -0
  19. package/dist/server/oauthDiscovery.d.ts.map +1 -0
  20. package/dist/server/oauthDiscovery.js +96 -0
  21. package/dist/server/oauthDiscovery.js.map +1 -0
  22. package/dist/server/shutdown.d.ts +2 -2
  23. package/dist/server/shutdown.js +2 -2
  24. package/dist/server/tokenVerifier.d.ts +54 -0
  25. package/dist/server/tokenVerifier.d.ts.map +1 -0
  26. package/dist/server/tokenVerifier.js +122 -0
  27. package/dist/server/tokenVerifier.js.map +1 -0
  28. package/dist/server/weatherServer.d.ts +3 -2
  29. package/dist/server/weatherServer.d.ts.map +1 -1
  30. package/dist/server/weatherServer.js +3 -2
  31. package/dist/server/weatherServer.js.map +1 -1
  32. package/dist/services/noaa.d.ts.map +1 -1
  33. package/dist/services/noaa.js +4 -1
  34. package/dist/services/noaa.js.map +1 -1
  35. package/dist/services/openmeteo.d.ts.map +1 -1
  36. package/dist/services/openmeteo.js +5 -2
  37. package/dist/services/openmeteo.js.map +1 -1
  38. package/package.json +15 -9
@@ -0,0 +1,172 @@
1
+ /**
2
+ * The HTTP entry's express app: an OAuth 2.1 resource server in front of a
3
+ * stateless Streamable HTTP transport.
4
+ *
5
+ * `createHttpApp()` builds the app and returns it. It is side-effect-free: it
6
+ * binds no port, registers no signal handler, starts no timer and reads no
7
+ * environment. `src/http.ts` starts everything, so a test can build the app and
8
+ * bind it to loopback itself (G61).
9
+ *
10
+ * The stages run in this order, and a new middleware goes into this order:
11
+ *
12
+ * 1. GET /healthz constant body, no upstream probe, ahead of host
13
+ * validation so a proxy or container probe that sends
14
+ * Host: 127.0.0.1 still gets an answer
15
+ * 2. host validation the SDK's DNS-rebinding guard: Host must name the
16
+ * public URL's host, on every other route
17
+ * 3. metadata router RFC 9728 protected-resource document (and the
18
+ * issuer's RFC 8414 mirror), unauthenticated
19
+ * 4. on the MCP route, every method:
20
+ * access log method, status, duration; nothing else
21
+ * missing-token check classifies `missing` for the log; the SDK answers
22
+ * requireBearerAuth 401 with WWW-Authenticate naming the metadata URL,
23
+ * 403 for a missing required scope
24
+ * 5. POST only: a 256 KB JSON body limit, then a fresh Server and transport
25
+ * per request (stateless transports are single-use)
26
+ * 6. any other method: 405, after auth, so the route never answers without a token
27
+ * 7. a final error handler, so express never reaches its default handler,
28
+ * which writes err.stack to stderr through console.error
29
+ *
30
+ * No log line on this path carries the Authorization header, a token, a claim,
31
+ * the subject, a request body, a header or the route path (the path may be an
32
+ * operator's secret-by-obscurity).
33
+ */
34
+ import express from 'express';
35
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
36
+ import { hostHeaderValidation } from '@modelcontextprotocol/sdk/server/middleware/hostHeaderValidation.js';
37
+ import { requireBearerAuth } from '@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js';
38
+ import { getOAuthProtectedResourceMetadataUrl, mcpAuthMetadataRouter } from '@modelcontextprotocol/sdk/server/auth/router.js';
39
+ import { describeErrorForLogging, logger } from '../utils/logger.js';
40
+ import { createWeatherServer } from './weatherServer.js';
41
+ import { logTokenRejection } from './tokenVerifier.js';
42
+ /** A tools/call is a few hundred bytes; the SDK's own 4 MiB default is far above any real request. */
43
+ export const HTTP_BODY_LIMIT = '256kb';
44
+ function jsonRpcError(code, message) {
45
+ return { jsonrpc: '2.0', error: { code, message }, id: null };
46
+ }
47
+ /** The SDK middleware's own test (bearerAuth.js): a "Bearer" type and a non-empty token. */
48
+ function hasBearerToken(header) {
49
+ if (!header)
50
+ return false;
51
+ const [type, token] = header.split(' ');
52
+ return type.toLowerCase() === 'bearer' && Boolean(token);
53
+ }
54
+ /** A client-side body-parser failure carries a string `type` and a 4xx `status`. */
55
+ function clientErrorStatus(err) {
56
+ if (typeof err !== 'object' || err === null)
57
+ return undefined;
58
+ const { type, status } = err;
59
+ if (typeof type !== 'string')
60
+ return undefined;
61
+ return typeof status === 'number' && status >= 400 && status < 500 ? status : undefined;
62
+ }
63
+ export function createHttpApp(deps) {
64
+ const { config, verifier, oauthMetadata, locationStore } = deps;
65
+ const createServer = deps.createServer ?? createWeatherServer;
66
+ const route = config.publicUrl.pathname;
67
+ const { requiredScopes } = config;
68
+ const app = express();
69
+ app.disable('x-powered-by');
70
+ // The route is the public URL's exact path: /MCP and /mcp/ are not /mcp.
71
+ app.set('case sensitive routing', true);
72
+ app.set('strict routing', true);
73
+ // 1. Liveness. Answers before host validation; the body is a constant, so a
74
+ // rebinding read learns nothing.
75
+ app.get('/healthz', (_req, res) => {
76
+ res.json({ status: 'ok' });
77
+ });
78
+ // 2. Host validation. URL.hostname keeps IPv6 bracketed, the form the SDK expects (G109).
79
+ app.use(hostHeaderValidation([config.publicUrl.hostname]));
80
+ // 3. Discovery documents, unauthenticated.
81
+ app.use(mcpAuthMetadataRouter({
82
+ oauthMetadata,
83
+ resourceServerUrl: config.publicUrl,
84
+ scopesSupported: requiredScopes.length > 0 ? requiredScopes : undefined
85
+ }));
86
+ // 4. Every method on the MCP route: access log, then auth.
87
+ app.all(route, (req, res, next) => {
88
+ const started = performance.now();
89
+ // 'close' fires for a completed response and for a client that hung up
90
+ // first, so every request gets exactly one line.
91
+ res.once('close', () => {
92
+ const finished = res.writableFinished;
93
+ logger.info('HTTP request', {
94
+ method: req.method,
95
+ status: finished ? res.statusCode : 'aborted',
96
+ durationMs: Math.round(performance.now() - started)
97
+ });
98
+ // The verifier never sees a scope failure: the SDK decides it after verification.
99
+ const challenge = res.getHeader('WWW-Authenticate');
100
+ if (finished && res.statusCode === 403 && typeof challenge === 'string' && challenge.includes('insufficient_scope')) {
101
+ logTokenRejection('scope');
102
+ }
103
+ });
104
+ next();
105
+ }, (req, _res, next) => {
106
+ // The SDK writes the 401 itself; this only names the reason once, for the log.
107
+ if (!hasBearerToken(req.headers.authorization))
108
+ logTokenRejection('missing');
109
+ next();
110
+ }, requireBearerAuth({
111
+ verifier,
112
+ requiredScopes,
113
+ resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(config.publicUrl),
114
+ expectedResource: config.publicUrl
115
+ }));
116
+ // 5. One Server and one transport per request, closed when the response closes.
117
+ app.post(route, express.json({ limit: HTTP_BODY_LIMIT }), async (req, res) => {
118
+ const server = createServer({ locationStore });
119
+ const transport = new StreamableHTTPServerTransport({
120
+ sessionIdGenerator: undefined,
121
+ enableJsonResponse: true
122
+ });
123
+ // Registered before the first await, so a client that hangs up mid-request
124
+ // still releases both (G20).
125
+ res.on('close', () => {
126
+ void Promise.allSettled([transport.close(), server.close()]);
127
+ });
128
+ try {
129
+ await server.connect(transport);
130
+ await transport.handleRequest(req, res, req.body);
131
+ }
132
+ catch (error) {
133
+ logger.error('HTTP request failed', undefined, { error: describeErrorForLogging(error) });
134
+ if (!res.headersSent)
135
+ res.status(500).json(jsonRpcError(-32603, 'Internal server error'));
136
+ else
137
+ res.end();
138
+ }
139
+ });
140
+ // 6. Every other method, after auth.
141
+ app.all(route, (_req, res) => {
142
+ res.set('Allow', 'POST').status(405).json(jsonRpcError(-32000, 'Method not allowed'));
143
+ });
144
+ // 7. The last middleware. Express recognises an error handler by its four
145
+ // parameters. It never calls next(err), so express's default handler, which
146
+ // prints err.stack, is never reached.
147
+ app.use((err, _req, res, next) => {
148
+ void next;
149
+ const status = clientErrorStatus(err) ?? 500;
150
+ // Class and code only, even under LOG_PII: a body-parser message quotes the request body.
151
+ const { name, code } = describeErrorForLogging(err);
152
+ logger.warn('HTTP request rejected', { status, error: { name, code } });
153
+ if (res.headersSent) {
154
+ res.end();
155
+ return;
156
+ }
157
+ if (status === 413) {
158
+ res.status(413).json(jsonRpcError(-32600, 'Request body too large'));
159
+ }
160
+ else if (status === 400) {
161
+ res.status(400).json(jsonRpcError(-32700, 'Parse error'));
162
+ }
163
+ else if (status < 500) {
164
+ res.status(status).json(jsonRpcError(-32600, 'Invalid request'));
165
+ }
166
+ else {
167
+ res.status(500).json(jsonRpcError(-32603, 'Internal server error'));
168
+ }
169
+ });
170
+ return app;
171
+ }
172
+ //# sourceMappingURL=httpApp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpApp.js","sourceRoot":"","sources":["../../src/server/httpApp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,OAA2D,MAAM,SAAS,CAAC;AAElF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,qEAAqE,CAAC;AAC3G,OAAO,EAAE,iBAAiB,EAAE,MAAM,gEAAgE,CAAC;AACnG,OAAO,EACL,oCAAoC,EACpC,qBAAqB,EACtB,MAAM,iDAAiD,CAAC;AAKzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAA6B,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,sGAAsG;AACtG,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAYvC,SAAS,YA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AC,CAAC;QACpD,MAAM,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACxE,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC;YACpB,GAAG,CAAC,GAAG,EAAE,CAAC;YACV,OAAO;QACT,CAAC;QACD,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC,CAAC;QACvE,CAAC;aAAM,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YAC1B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;QAC5D,CAAC;aAAM,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;YACxB,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC;QACnE,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC,CAAC;QACtE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Issuer discovery for the HTTP entry's fail-closed startup.
3
+ *
4
+ * Contract, not garnish: the entry reads the authorization server's metadata
5
+ * before it listens, and refuses to start if the answer is missing or wrong. An
6
+ * auth layer that degraded silently to "no verification" would be an open
7
+ * instance, so every problem here becomes a refusal.
8
+ *
9
+ * The module wraps the SDK's `discoverAuthorizationServerMetadata` (RFC 8414,
10
+ * then OpenID Connect Discovery) and adds three checks the SDK does not make:
11
+ * the metadata names exactly the configured issuer (RFC 8414 section 3.3, a
12
+ * byte-for-byte compare with no trailing-slash normalisation), it publishes a
13
+ * `jwks_uri`, and that URI is https (http only for a loopback host).
14
+ *
15
+ * The whole discovery runs under one deadline (`DISCOVERY_TIMEOUT_MS`). The SDK
16
+ * sets none, so an issuer that accepts the connection and never answers would
17
+ * otherwise hold startup, unbound and silent, for undici's 300 s. The deadline
18
+ * races each fetch rather than only signalling it, so a fetch that ignores its
19
+ * signal cannot hold startup either. A timeout is `ERR_DISCOVERY_UNREADABLE`.
20
+ *
21
+ * `discoverIssuer` never throws. The SDK throws on a 5xx and on a schema
22
+ * failure, and those errors embed the endpoint URL, so no thrown text is passed
23
+ * on. Each failure maps to one fixed message that quotes neither the URL, the
24
+ * issuer value nor the upstream error (GOTCHAS G123). The messages are exported
25
+ * because the docs copy them verbatim.
26
+ */
27
+ import type { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js';
28
+ import { type OAuthMetadata } from '@modelcontextprotocol/sdk/shared/auth.js';
29
+ export declare const ERR_DISCOVERY_UNREADABLE = "could not read the authorization server's metadata from WEATHER_OAUTH_ISSUER";
30
+ export declare const ERR_DISCOVERY_ISSUER_MISMATCH = "the authorization server's metadata names a different issuer than WEATHER_OAUTH_ISSUER";
31
+ export declare const ERR_DISCOVERY_NO_JWKS_URI = "the authorization server publishes no jwks_uri; JWT access tokens cannot be verified";
32
+ export declare const ERR_DISCOVERY_JWKS_URI_HTTPS = "the authorization server's jwks_uri must be an https URL";
33
+ /** Upper bound on the whole discovery, every well-known URL included. */
34
+ export declare const DISCOVERY_TIMEOUT_MS = 10000;
35
+ export type DiscoveryResult = {
36
+ ok: true;
37
+ metadata: OAuthMetadata;
38
+ jwksUri: URL;
39
+ } | {
40
+ ok: false;
41
+ error: string;
42
+ };
43
+ export declare function discoverIssuer(issuerUrl: URL, issuer: string, fetchFn?: FetchLike, timeoutMs?: number): Promise<DiscoveryResult>;
44
+ //# sourceMappingURL=oauthDiscovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthDiscovery.d.ts","sourceRoot":"","sources":["../../src/server/oauthDiscovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAEnG,eAAO,MAAM,wBAAwB,iFAC2C,CAAC;AACjF,eAAO,MAAM,6BAA6B,2FACgD,CAAC;AAC3F,eAAO,MAAM,yBAAyB,yFACkD,CAAC;AACzF,eAAO,MAAM,4BAA4B,6DAA6D,CAAC;AAKvG,yEAAyE;AACzE,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAiB3C,MAAM,MAAM,eAAe,GACvB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,GACnD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAMjC,wBAAsB,cAAc,CAClC,SAAS,EAAE,GAAG,EACd,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,SAAS,EACnB,SAAS,GAAE,MAA6B,GACvC,OAAO,CAAC,eAAe,CAAC,CAqC1B"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Issuer discovery for the HTTP entry's fail-closed startup.
3
+ *
4
+ * Contract, not garnish: the entry reads the authorization server's metadata
5
+ * before it listens, and refuses to start if the answer is missing or wrong. An
6
+ * auth layer that degraded silently to "no verification" would be an open
7
+ * instance, so every problem here becomes a refusal.
8
+ *
9
+ * The module wraps the SDK's `discoverAuthorizationServerMetadata` (RFC 8414,
10
+ * then OpenID Connect Discovery) and adds three checks the SDK does not make:
11
+ * the metadata names exactly the configured issuer (RFC 8414 section 3.3, a
12
+ * byte-for-byte compare with no trailing-slash normalisation), it publishes a
13
+ * `jwks_uri`, and that URI is https (http only for a loopback host).
14
+ *
15
+ * The whole discovery runs under one deadline (`DISCOVERY_TIMEOUT_MS`). The SDK
16
+ * sets none, so an issuer that accepts the connection and never answers would
17
+ * otherwise hold startup, unbound and silent, for undici's 300 s. The deadline
18
+ * races each fetch rather than only signalling it, so a fetch that ignores its
19
+ * signal cannot hold startup either. A timeout is `ERR_DISCOVERY_UNREADABLE`.
20
+ *
21
+ * `discoverIssuer` never throws. The SDK throws on a 5xx and on a schema
22
+ * failure, and those errors embed the endpoint URL, so no thrown text is passed
23
+ * on. Each failure maps to one fixed message that quotes neither the URL, the
24
+ * issuer value nor the upstream error (GOTCHAS G123). The messages are exported
25
+ * because the docs copy them verbatim.
26
+ */
27
+ import { discoverAuthorizationServerMetadata } from '@modelcontextprotocol/sdk/client/auth.js';
28
+ import { OAuthMetadataSchema } from '@modelcontextprotocol/sdk/shared/auth.js';
29
+ export const ERR_DISCOVERY_UNREADABLE = "could not read the authorization server's metadata from WEATHER_OAUTH_ISSUER";
30
+ export const ERR_DISCOVERY_ISSUER_MISMATCH = "the authorization server's metadata names a different issuer than WEATHER_OAUTH_ISSUER";
31
+ export const ERR_DISCOVERY_NO_JWKS_URI = 'the authorization server publishes no jwks_uri; JWT access tokens cannot be verified';
32
+ export const ERR_DISCOVERY_JWKS_URI_HTTPS = "the authorization server's jwks_uri must be an https URL";
33
+ // URL.hostname keeps IPv6 literals bracketed (GOTCHAS G109).
34
+ const JWKS_LOOPBACK = new Set(['localhost', '127.0.0.1', '[::1]']);
35
+ /** Upper bound on the whole discovery, every well-known URL included. */
36
+ export const DISCOVERY_TIMEOUT_MS = 10_000;
37
+ /** `base`, with every call aborted and rejected once `deadline` fires. */
38
+ function underDeadline(base, deadline) {
39
+ return (url, init) => {
40
+ const signal = init?.signal ? AbortSignal.any([init.signal, deadline]) : deadline;
41
+ if (signal.aborted)
42
+ return Promise.reject(signal.reason);
43
+ return new Promise((resolve, reject) => {
44
+ const onAbort = () => reject(signal.reason);
45
+ signal.addEventListener('abort', onAbort, { once: true });
46
+ base(url, { ...init, signal }).then(resolve, reject).finally(() => {
47
+ signal.removeEventListener('abort', onAbort);
48
+ });
49
+ });
50
+ };
51
+ }
52
+ function refuse(error) {
53
+ return { ok: false, error };
54
+ }
55
+ export async function discoverIssuer(issuerUrl, issuer, fetchFn, timeoutMs = DISCOVERY_TIMEOUT_MS) {
56
+ try {
57
+ let found;
58
+ try {
59
+ const deadlined = underDeadline(fetchFn ?? fetch, AbortSignal.timeout(timeoutMs));
60
+ found = await discoverAuthorizationServerMetadata(issuerUrl, { fetchFn: deadlined });
61
+ }
62
+ catch {
63
+ return refuse(ERR_DISCOVERY_UNREADABLE);
64
+ }
65
+ if (found === undefined)
66
+ return refuse(ERR_DISCOVERY_UNREADABLE);
67
+ // Project through the OAuth schema so the type is exact for the SDK router.
68
+ const parsed = OAuthMetadataSchema.safeParse(found);
69
+ if (!parsed.success)
70
+ return refuse(ERR_DISCOVERY_UNREADABLE);
71
+ const metadata = parsed.data;
72
+ if (metadata.issuer !== issuer)
73
+ return refuse(ERR_DISCOVERY_ISSUER_MISMATCH);
74
+ const rawJwks = metadata['jwks_uri'];
75
+ if (rawJwks === undefined || rawJwks === null)
76
+ return refuse(ERR_DISCOVERY_NO_JWKS_URI);
77
+ if (typeof rawJwks !== 'string')
78
+ return refuse(ERR_DISCOVERY_JWKS_URI_HTTPS);
79
+ let jwksUri;
80
+ try {
81
+ jwksUri = new URL(rawJwks);
82
+ }
83
+ catch {
84
+ return refuse(ERR_DISCOVERY_JWKS_URI_HTTPS);
85
+ }
86
+ const secure = jwksUri.protocol === 'https:' ||
87
+ (jwksUri.protocol === 'http:' && JWKS_LOOPBACK.has(jwksUri.hostname));
88
+ if (!secure)
89
+ return refuse(ERR_DISCOVERY_JWKS_URI_HTTPS);
90
+ return { ok: true, metadata, jwksUri };
91
+ }
92
+ catch {
93
+ return refuse(ERR_DISCOVERY_UNREADABLE);
94
+ }
95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AAM;YAAE,OAAO,MAAM,CAAC,6BAA6B,CAAC,CAAC;QAE7E,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;QACrC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC,yBAAyB,CAAC,CAAC;QACxF,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,OAAO,MAAM,CAAC,4BAA4B,CAAC,CAAC;QAE7E,IAAI,OAAY,CAAC;QACjB,IAAI,CAAC;YACH,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,MAAM,CAAC,4BAA4B,CAAC,CAAC;QAC9C,CAAC;QACD,MAAM,MAAM,GACV,OAAO,CAAC,QAAQ,KAAK,QAAQ;YAC7B,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM;YAAE,OAAO,MAAM,CAAC,4BAA4B,CAAC,CAAC;QAEzD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,wBAAwB,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC"}
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Shutdown coordinator: one bounded, run-once teardown for every way the stdio session can end.
2
+ * Shutdown coordinator: one bounded, run-once teardown for every way a server process can end.
3
3
  *
4
4
  * `src/index.ts` wires stdin `end`/`close`, `server.onclose`, `SIGTERM` and `SIGINT` to the one
5
- * trigger this module returns. The contracts:
5
+ * trigger this module returns; `src/http.ts` wires `SIGTERM` and `SIGINT` only. The contracts:
6
6
  *
7
7
  * - **Run once.** The first trigger starts the run; every later trigger — including one fired from
8
8
  * inside a step, as `server.close()` fires `server.onclose` — returns the same promise.
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Shutdown coordinator: one bounded, run-once teardown for every way the stdio session can end.
2
+ * Shutdown coordinator: one bounded, run-once teardown for every way a server process can end.
3
3
  *
4
4
  * `src/index.ts` wires stdin `end`/`close`, `server.onclose`, `SIGTERM` and `SIGINT` to the one
5
- * trigger this module returns. The contracts:
5
+ * trigger this module returns; `src/http.ts` wires `SIGTERM` and `SIGINT` only. The contracts:
6
6
  *
7
7
  * - **Run once.** The first trigger starts the run; every later trigger — including one fired from
8
8
  * inside a step, as `server.close()` fires `server.onclose` — returns the same promise.
@@ -0,0 +1,54 @@
1
+ /**
2
+ * OAuth 2.1 resource-server token verification for the HTTP entry.
3
+ *
4
+ * The HTTP entry never issues a token. It checks a JWT access token against the
5
+ * authorization server's JWKS and maps the result into the SDK's `AuthInfo`, so
6
+ * `requireBearerAuth` (the SDK middleware) writes every 401/403 itself.
7
+ *
8
+ * Three SDK behaviours shape this module (bearerAuth.js, SDK 1.32.1):
9
+ * - Only an `InvalidTokenError` becomes a 401 with `WWW-Authenticate`, and only a
10
+ * `ServerError` a clean 500. Any other error is a 500 with a generic body, so every
11
+ * failure here is wrapped in one of the two.
12
+ * - The error's message is written into `WWW-Authenticate` unescaped, so every
13
+ * message here is a fixed literal. A `jose` message can quote claim values.
14
+ * - The middleware compares `authInfo.resource` with its `expectedResource` and
15
+ * requires a numeric `expiresAt`, so both are always set.
16
+ *
17
+ * A `jose` error is classified by class and `.claim`, never by message (G123).
18
+ */
19
+ import { type JWTVerifyGetKey } from 'jose';
20
+ import type { OAuthTokenVerifier } from '@modelcontextprotocol/sdk/server/auth/provider.js';
21
+ import { type Logger } from '../utils/logger.js';
22
+ /**
23
+ * Asymmetric algorithms only. The resource server holds no shared secret, and an
24
+ * `HS256` token "signed" with a public key is the classic key-confusion attack.
25
+ */
26
+ export declare const ACCEPTED_TOKEN_ALGORITHMS: readonly ['RS256', 'RS384', 'RS512', 'PS256', 'PS384', 'PS512', 'ES256', 'ES384', 'ES512', 'EdDSA'];
27
+ /**
28
+ * Why a request's token was refused. `missing` and `scope` are decided by the
29
+ * HTTP app (`src/server/httpApp.ts`); the other four here.
30
+ */
31
+ export type TokenRejectionReason = 'missing' | 'invalid' | 'expired' | 'audience' | 'jwks_unavailable' | 'scope';
32
+ /**
33
+ * Log one rejected request. The one site of the message, so every reason class
34
+ * reads the same. The record carries the reason and nothing else: no token, no
35
+ * claim, no subject, no error text, at any level and under `LOG_PII` too.
36
+ */
37
+ export declare function logTokenRejection(reason: TokenRejectionReason, log?: Pick<Logger, 'warn'>): void;
38
+ export interface TokenVerifierOptions {
39
+ /** The issuer every token's `iss` must equal. */
40
+ issuer: string;
41
+ /** The public URL, exactly as configured. Every token's `aud` must contain it (RFC 8707). */
42
+ audience: string;
43
+ /** `createRemoteJWKSet(jwksUri)` in production, `createLocalJWKSet(...)` in tests. */
44
+ getKey: JWTVerifyGetKey;
45
+ logger?: Pick<Logger, 'warn'>;
46
+ }
47
+ /**
48
+ * Build the verifier `requireBearerAuth` calls once per request.
49
+ *
50
+ * Scope enforcement is not here: it stays in the SDK middleware, so the 403 and
51
+ * its `scope=` hint are the SDK's.
52
+ */
53
+ export declare function createTokenVerifier(options: TokenVerifierOptions): OAuthTokenVerifier;
54
+ //# sourceMappingURL=tokenVerifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenVerifier.d.ts","sourceRoot":"","sources":["../../src/server/tokenVerifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAsC,KAAK,eAAe,EAAE,MAAM,MAAM,CAAC;AAEhF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AAE5F,OAAO,EAA2B,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,yBAAyB,YACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EACzB,OAAO,EAAE,OAAO,EAAE,OAAO,EACzB,OAAO,EAAE,OAAO,EAAE,OAAO,EACzB,OAAO,CACC,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAC5B,SAAS,GACT,SAAS,GACT,SAAS,GACT,UAAU,GACV,kBAAkB,GAClB,OAAO,CAAC;AAEZ;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,GAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAiB,GAAG,IAAI,CAE/G;AAED,MAAM,WAAW,oBAAoB;IACnC,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,6FAA6F;IAC7F,QAAQ,EAAE,MAAM,CAAC;IACjB,sFAAsF;IACtF,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AA+CD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,kBAAkB,CAuCrF"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * OAuth 2.1 resource-server token verification for the HTTP entry.
3
+ *
4
+ * The HTTP entry never issues a token. It checks a JWT access token against the
5
+ * authorization server's JWKS and maps the result into the SDK's `AuthInfo`, so
6
+ * `requireBearerAuth` (the SDK middleware) writes every 401/403 itself.
7
+ *
8
+ * Three SDK behaviours shape this module (bearerAuth.js, SDK 1.32.1):
9
+ * - Only an `InvalidTokenError` becomes a 401 with `WWW-Authenticate`, and only a
10
+ * `ServerError` a clean 500. Any other error is a 500 with a generic body, so every
11
+ * failure here is wrapped in one of the two.
12
+ * - The error's message is written into `WWW-Authenticate` unescaped, so every
13
+ * message here is a fixed literal. A `jose` message can quote claim values.
14
+ * - The middleware compares `authInfo.resource` with its `expectedResource` and
15
+ * requires a numeric `expiresAt`, so both are always set.
16
+ *
17
+ * A `jose` error is classified by class and `.claim`, never by message (G123).
18
+ */
19
+ import { errors, jwtVerify } from 'jose';
20
+ import { InvalidTokenError, ServerError } from '@modelcontextprotocol/sdk/server/auth/errors.js';
21
+ import { logger as defaultLogger } from '../utils/logger.js';
22
+ /**
23
+ * Asymmetric algorithms only. The resource server holds no shared secret, and an
24
+ * `HS256` token "signed" with a public key is the classic key-confusion attack.
25
+ */
26
+ export const ACCEPTED_TOKEN_ALGORITHMS = [
27
+ 'RS256', 'RS384', 'RS512',
28
+ 'PS256', 'PS384', 'PS512',
29
+ 'ES256', 'ES384', 'ES512',
30
+ 'EdDSA'
31
+ ];
32
+ /**
33
+ * Log one rejected request. The one site of the message, so every reason class
34
+ * reads the same. The record carries the reason and nothing else: no token, no
35
+ * claim, no subject, no error text, at any level and under `LOG_PII` too.
36
+ */
37
+ export function logTokenRejection(reason, log = defaultLogger) {
38
+ log.warn('Access token rejected', { reason, securityEvent: true });
39
+ }
40
+ const UNAVAILABLE_MESSAGE = 'Token verification is temporarily unavailable';
41
+ function classify(error) {
42
+ if (error instanceof errors.JWTExpired) {
43
+ return { reason: 'expired', error: new InvalidTokenError('Token has expired') };
44
+ }
45
+ if (error instanceof errors.JWTClaimValidationFailed && error.claim === 'aud') {
46
+ return { reason: 'audience', error: new InvalidTokenError('Token was not issued for this resource') };
47
+ }
48
+ // The JWKS could not be read. A 401 here would send every client into a
49
+ // re-login loop during an authorization-server outage, so it is a 500.
50
+ // - JWKSTimeout: the fetch outlived jose's timeout.
51
+ // - Not a JOSEError at all: the fetch itself failed (DNS, refused, reset).
52
+ // - The bare JOSEError class: jose throws it only for a non-200 or an
53
+ // unparseable JWKS response (jwks/remote.js). Matched by exact class.
54
+ if (error instanceof errors.JWKSTimeout ||
55
+ !(error instanceof errors.JOSEError) ||
56
+ error.constructor === errors.JOSEError) {
57
+ return { reason: 'jwks_unavailable', error: new ServerError(UNAVAILABLE_MESSAGE) };
58
+ }
59
+ // Signature, iss, missing exp, alg, no matching kid, malformed.
60
+ return { reason: 'invalid', error: new InvalidTokenError('Invalid access token') };
61
+ }
62
+ function clientIdOf(payload) {
63
+ if (typeof payload.client_id === 'string')
64
+ return payload.client_id;
65
+ if (typeof payload.azp === 'string')
66
+ return payload.azp;
67
+ return '';
68
+ }
69
+ function scopesOf(payload) {
70
+ // Always an array: the SDK's scope check calls .includes on it.
71
+ if (typeof payload.scope === 'string')
72
+ return payload.scope.split(' ').filter(s => s.length > 0);
73
+ const scp = payload.scp;
74
+ if (Array.isArray(scp) && scp.every((s) => typeof s === 'string'))
75
+ return [...scp];
76
+ return [];
77
+ }
78
+ /**
79
+ * Build the verifier `requireBearerAuth` calls once per request.
80
+ *
81
+ * Scope enforcement is not here: it stays in the SDK middleware, so the 403 and
82
+ * its `scope=` hint are the SDK's.
83
+ */
84
+ export function createTokenVerifier(options) {
85
+ const { issuer, audience, getKey } = options;
86
+ const log = options.logger ?? defaultLogger;
87
+ // Parsed once, so a bad audience fails at construction rather than per request.
88
+ const resourceHref = new URL(audience).href;
89
+ return {
90
+ async verifyAccessToken(token) {
91
+ let payload;
92
+ try {
93
+ ({ payload } = await jwtVerify(token, getKey, {
94
+ issuer,
95
+ audience,
96
+ algorithms: [...ACCEPTED_TOKEN_ALGORITHMS],
97
+ requiredClaims: ['exp']
98
+ }));
99
+ }
100
+ catch (error) {
101
+ const rejection = classify(error);
102
+ logTokenRejection(rejection.reason, log);
103
+ throw rejection.error;
104
+ }
105
+ // requiredClaims makes jose refuse a token without a numeric exp, so this
106
+ // only narrows the type.
107
+ if (typeof payload.exp !== 'number') {
108
+ logTokenRejection('invalid', log);
109
+ throw new InvalidTokenError('Invalid access token');
110
+ }
111
+ return {
112
+ token,
113
+ clientId: clientIdOf(payload),
114
+ scopes: scopesOf(payload),
115
+ expiresAt: payload.exp,
116
+ // A fresh URL per call: AuthInfo reaches tool handlers, and URL is mutable.
117
+ resource: new URL(resourceHref)
118
+ };
119
+ }
120
+ };
121
+ }
122
+ //# sourceMappingURL=tokenVerifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenVerifier.js","s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G,GAAG,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC;IAC5C,gFAAgF;IAChF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;IAE5C,OAAO;QACL,KAAK,CAAC,iBAAiB,CAAC,KAAa;YACnC,IAAI,OAAmB,CAAC;YACxB,IAAI,CAAC;gBACH,CAAC,EAAE,OAAO,EAAE,GAAG,MAAM,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE;oBAC5C,MAAM;oBACN,QAAQ;oBACR,UAAU,EAAE,CAAC,GAAG,yBAAyB,CAAC;oBAC1C,cAAc,EAAE,CAAC,KAAK,CAAC;iBACxB,CAAC,CAAC,CAAC;YACN,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAClC,iBAAiB,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBACzC,MAAM,SAAS,CAAC,KAAK,CAAC;YACxB,CAAC;YAED,0EAA0E;YAC1E,yBAAyB;YACzB,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACpC,iBAAiB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;gBAClC,MAAM,IAAI,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;YACtD,CAAC;YAED,OAAO;gBACL,KAAK;gBACL,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC;gBAC7B,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC;gBACzB,SAAS,EAAE,OAAO,CAAC,GAAG;gBACtB,4EAA4E;gBAC5E,QAAQ,EAAE,IAAI,GAAG,CAAC,YAAY,CAAC;aAChC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -18,8 +18,9 @@
18
18
  *
19
19
  * The services are module-scope singletons on purpose: two createWeatherServer()
20
20
  * calls in one process share one set of upstream caches, which is what a
21
- * per-session transport wants. src/index.ts — the stdio entry — is the only
22
- * consumer today; the factory is not a published API.
21
+ * per-session transport wants. src/index.ts (stdio) and src/server/httpApp.ts
22
+ * (HTTP, one Server per request) are the consumers; the factory is not a
23
+ * published API.
23
24
  */
24
25
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
25
26
  import type { LocationStore } from '../services/locationStore.js';
@@ -1 +1 @@
1
- {"version":3,"file":"weatherServer.d.ts","sourceRoot":"","sources":["../../src/server/weatherServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAsBnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AA6BlE;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,cAAc,QAAU,CAAC;AAoOtC;;GAEG;AACH,eAAO,MAAM,gBAAgB;;cAEnB,cAAc;;;kBAGZ,QAAQ;;;oBA5FhB,IAAI,EAAE,QAAQ;oBACd,WAAW;oBACX,IAAI;;;oBAGJ,IAAI,EAAE,QAAQ;oBACd,WAAW;oBACX,IAAI;;;oBAGJ,IAAI,EAAE,QAAQ;oBACd,WAAW;oBACX,IAAI;;;oBAGJ,IAAI,EAAE,QAAQ;oBACd,WAAW;oBACX,IAAI;;;oBAGJ,IAAI,EAAE,QAAQ;oBACd,WAAW;oBACX,IAAI;;;oBAGJ,IAAI,EAAE,QAAQ;oBACd,WAAW;oBACX,IAAI;;;oBAGJ,IAAI,EAAE,QAAQ;oBACd,WAAW;oBACX,IAAI;;;oBAoBJ,IAAI,EAAE,QAAQ;oBACd,WAAW;oBACX,OAAO;oBACP,OAAO;;;oBAGP,IAAI,EAAE,QAAQ;oBACd,WAAW;oBACX,OAAO;oBACP,OAAO;;;oBAGP,IAAI,EAAE,QAAQ;oBACd,WAAW;;;oBAGX,IAAI,EAAE,QAAQ;oBACd,WAAW;;;oBASX,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AU;oBACR,IAAI,EAAE,OAAO;oBACb,KAAK;wBACH,IAAI,EAAE,QAAQ;;oBAEhB,WAAW;;;YAGf,QAAQ;;;;QAKV,IAAI,EAAE,sBAAsB;QAC5B,WAAW;QACX,WAAW;YACT,IAAI,EAAE,QAAQ;YACd,UAAU;YACV,QAAQ;;;;QAKV,IAAI,EAAE,oBAAoB;QAC1B,WAAW;QACX,WAAW;YACT,IAAI,EAAE,QAAQ;YACd,UAAU;gBACR,KAAK;oBACH,IAAI,EAAE,QAAQ;oBACd,WAAW;;;YAGf,QAAQ;;;;QAKV,IAAI,EAAE,uBAAuB;QAC7B,WAAW;QACX,WAAW;YACT,IAAI,EAAE,QAAQ;YACd,UAAU;gBACR,KAAK;oBACH,IAAI,EAAE,QAAQ;oBACd,WAAW;;;YAGf,QAAQ;;;CAGb,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC;;yFAEqF;IACrF,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CA8KzE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAGzC"}
@@ -18,8 +18,9 @@
18
18
  *
19
19
  * The services are module-scope singletons on purpose: two createWeatherServer()
20
20
  * calls in one process share one set of upstream caches, which is what a
21
- * per-session transport wants. src/index.ts — the stdio entry — is the only
22
- * consumer today; the factory is not a published API.
21
+ * per-session transport wants. src/index.ts (stdio) and src/server/httpApp.ts
22
+ * (HTTP, one Server per request) are the consumers; the factory is not a
23
+ * published API.
23
24
  */
24
25
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
25
26
  import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';