post-engineer-mcp 1.31.0 → 1.33.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 (88) hide show
  1. package/README.md +51 -9
  2. package/dist/analytics.d.ts +1 -0
  3. package/dist/analytics.js +23 -1
  4. package/dist/analytics.js.map +1 -1
  5. package/dist/client-posts.d.ts +10 -0
  6. package/dist/client-posts.js +15 -0
  7. package/dist/client-posts.js.map +1 -0
  8. package/dist/client-publishing-accounts.d.ts +3 -0
  9. package/dist/client-publishing-accounts.js +18 -0
  10. package/dist/client-publishing-accounts.js.map +1 -0
  11. package/dist/client-types.d.ts +140 -0
  12. package/dist/client-types.js +2 -0
  13. package/dist/client-types.js.map +1 -0
  14. package/dist/client-user-media.d.ts +29 -0
  15. package/dist/client-user-media.js +135 -0
  16. package/dist/client-user-media.js.map +1 -0
  17. package/dist/client-video-task.d.ts +2 -0
  18. package/dist/client-video-task.js +9 -0
  19. package/dist/client-video-task.js.map +1 -0
  20. package/dist/client.d.ts +11 -134
  21. package/dist/client.js +32 -40
  22. package/dist/client.js.map +1 -1
  23. package/dist/cloned-voice-client.d.ts +11 -0
  24. package/dist/cloned-voice-client.js +134 -0
  25. package/dist/cloned-voice-client.js.map +1 -0
  26. package/dist/cloned-voice-tools.d.ts +70 -0
  27. package/dist/cloned-voice-tools.js +60 -0
  28. package/dist/cloned-voice-tools.js.map +1 -0
  29. package/dist/http-auth.d.ts +27 -0
  30. package/dist/http-auth.js +148 -0
  31. package/dist/http-auth.js.map +1 -0
  32. package/dist/http-rate-limit.d.ts +14 -0
  33. package/dist/http-rate-limit.js +28 -0
  34. package/dist/http-rate-limit.js.map +1 -0
  35. package/dist/http-transport.d.ts +13 -0
  36. package/dist/http-transport.js +311 -0
  37. package/dist/http-transport.js.map +1 -0
  38. package/dist/image-guards.d.ts +6 -0
  39. package/dist/image-guards.js +30 -0
  40. package/dist/image-guards.js.map +1 -0
  41. package/dist/index.js +69 -29
  42. package/dist/index.js.map +1 -1
  43. package/dist/language.d.ts +11 -0
  44. package/dist/language.js +19 -0
  45. package/dist/language.js.map +1 -0
  46. package/dist/limits.d.ts +39 -0
  47. package/dist/limits.js +39 -0
  48. package/dist/limits.js.map +1 -1
  49. package/dist/prompts.d.ts +9 -0
  50. package/dist/prompts.js +125 -0
  51. package/dist/prompts.js.map +1 -0
  52. package/dist/require-title.d.ts +1 -0
  53. package/dist/require-title.js +12 -0
  54. package/dist/require-title.js.map +1 -0
  55. package/dist/schedule-shapes.d.ts +70 -0
  56. package/dist/schedule-shapes.js +98 -0
  57. package/dist/schedule-shapes.js.map +1 -0
  58. package/dist/script-segments.d.ts +49 -0
  59. package/dist/script-segments.js +222 -0
  60. package/dist/script-segments.js.map +1 -0
  61. package/dist/single-video-shape.d.ts +340 -0
  62. package/dist/single-video-shape.js +74 -0
  63. package/dist/single-video-shape.js.map +1 -0
  64. package/dist/tools-call.d.ts +4 -0
  65. package/dist/tools-call.js +25 -0
  66. package/dist/tools-call.js.map +1 -0
  67. package/dist/tools-posts.d.ts +41 -0
  68. package/dist/tools-posts.js +45 -0
  69. package/dist/tools-posts.js.map +1 -0
  70. package/dist/tools-publishing-accounts.d.ts +29 -0
  71. package/dist/tools-publishing-accounts.js +38 -0
  72. package/dist/tools-publishing-accounts.js.map +1 -0
  73. package/dist/tools-single-video.d.ts +10 -0
  74. package/dist/tools-single-video.js +143 -0
  75. package/dist/tools-single-video.js.map +1 -0
  76. package/dist/tools-user-media.d.ts +27 -0
  77. package/dist/tools-user-media.js +38 -0
  78. package/dist/tools-user-media.js.map +1 -0
  79. package/dist/tools.d.ts +32 -230
  80. package/dist/tools.js +42 -295
  81. package/dist/tools.js.map +1 -1
  82. package/dist/video-task-tools.d.ts +14 -0
  83. package/dist/video-task-tools.js +20 -0
  84. package/dist/video-task-tools.js.map +1 -0
  85. package/dist/voice-filters.d.ts +21 -0
  86. package/dist/voice-filters.js +76 -0
  87. package/dist/voice-filters.js.map +1 -0
  88. package/package.json +6 -2
@@ -0,0 +1,70 @@
1
+ import { z } from 'zod';
2
+ import type { PostEngineerClient } from './client.js';
3
+ import { type McpToolResponse } from './tools-call.js';
4
+ export declare const ListClonedVoicesShape: {};
5
+ export declare const ListClonedVoicesSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
6
+ export declare const CreateClonedVoiceShape: {
7
+ audioUrl: z.ZodString;
8
+ language: z.ZodEffects<z.ZodString, string, string>;
9
+ consent: z.ZodLiteral<true>;
10
+ denoise: z.ZodBoolean;
11
+ };
12
+ export declare const CreateClonedVoiceSchema: z.ZodObject<{
13
+ audioUrl: z.ZodString;
14
+ language: z.ZodEffects<z.ZodString, string, string>;
15
+ consent: z.ZodLiteral<true>;
16
+ denoise: z.ZodBoolean;
17
+ }, "strip", z.ZodTypeAny, {
18
+ language: string;
19
+ consent: true;
20
+ denoise: boolean;
21
+ audioUrl: string;
22
+ }, {
23
+ language: string;
24
+ consent: true;
25
+ denoise: boolean;
26
+ audioUrl: string;
27
+ }>;
28
+ export declare const DeleteClonedVoiceShape: {
29
+ cloneId: z.ZodString;
30
+ };
31
+ export declare const DeleteClonedVoiceSchema: z.ZodObject<{
32
+ cloneId: z.ZodString;
33
+ }, "strip", z.ZodTypeAny, {
34
+ cloneId: string;
35
+ }, {
36
+ cloneId: string;
37
+ }>;
38
+ export declare const GetClonedVoiceShape: {
39
+ cloneId: z.ZodString;
40
+ };
41
+ export declare const GetClonedVoiceSchema: z.ZodObject<{
42
+ cloneId: z.ZodString;
43
+ }, "strip", z.ZodTypeAny, {
44
+ cloneId: string;
45
+ }, {
46
+ cloneId: string;
47
+ }>;
48
+ export declare const PreviewClonedVoiceShape: {
49
+ cloneId: z.ZodString;
50
+ language: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
51
+ text: z.ZodOptional<z.ZodString>;
52
+ };
53
+ export declare const PreviewClonedVoiceSchema: z.ZodObject<{
54
+ cloneId: z.ZodString;
55
+ language: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
56
+ text: z.ZodOptional<z.ZodString>;
57
+ }, "strip", z.ZodTypeAny, {
58
+ cloneId: string;
59
+ language?: string | undefined;
60
+ text?: string | undefined;
61
+ }, {
62
+ cloneId: string;
63
+ language?: string | undefined;
64
+ text?: string | undefined;
65
+ }>;
66
+ export declare function handleListClonedVoices(client: PostEngineerClient): Promise<McpToolResponse>;
67
+ export declare function handleCreateClonedVoice(client: PostEngineerClient, args: z.infer<typeof CreateClonedVoiceSchema>): Promise<McpToolResponse>;
68
+ export declare function handleGetClonedVoice(client: PostEngineerClient, args: z.infer<typeof GetClonedVoiceSchema>): Promise<McpToolResponse>;
69
+ export declare function handleDeleteClonedVoice(client: PostEngineerClient, args: z.infer<typeof DeleteClonedVoiceSchema>): Promise<McpToolResponse>;
70
+ export declare function handlePreviewClonedVoice(client: PostEngineerClient, args: z.infer<typeof PreviewClonedVoiceSchema>): Promise<McpToolResponse>;
@@ -0,0 +1,60 @@
1
+ import { z } from 'zod';
2
+ import { createClonedVoiceFromUrl, deleteClonedVoice, getClonedVoice, listClonedVoices, previewClonedVoice, } from './cloned-voice-client.js';
3
+ import { handleLibraryCall } from './tools-call.js';
4
+ import { isEnglishLanguage, ONLY_ENGLISH_CLONE_MESSAGE } from './language.js';
5
+ import { CLONE_PREVIEW_TEXT_MAX_CHARS } from './limits.js';
6
+ export const ListClonedVoicesShape = {};
7
+ export const ListClonedVoicesSchema = z.object(ListClonedVoicesShape);
8
+ export const CreateClonedVoiceShape = {
9
+ audioUrl: z.string().url().describe('HTTPS URL of a short reference recording (MP3, WAV, M4A, or WebM, max 20MB)'),
10
+ language: z
11
+ .string()
12
+ .min(1)
13
+ .refine(isEnglishLanguage, { message: ONLY_ENGLISH_CLONE_MESSAGE })
14
+ .describe('Language code for the clone — English only for now (e.g. en, en-us)'),
15
+ consent: z.literal(true).describe('Must be true: caller confirms consent to voice cloning'),
16
+ denoise: z
17
+ .boolean()
18
+ .describe('Clean background noise from the recording before cloning (recommended true; false for studio audio)'),
19
+ };
20
+ export const CreateClonedVoiceSchema = z.object(CreateClonedVoiceShape);
21
+ export const DeleteClonedVoiceShape = {
22
+ cloneId: z.string().min(1).describe('Cloned voice id from list_cloned_voices'),
23
+ };
24
+ export const DeleteClonedVoiceSchema = z.object(DeleteClonedVoiceShape);
25
+ export const GetClonedVoiceShape = {
26
+ cloneId: z.string().min(1).describe('Cloned voice id (the id returned by create_cloned_voice or list_cloned_voices)'),
27
+ };
28
+ export const GetClonedVoiceSchema = z.object(GetClonedVoiceShape);
29
+ export const PreviewClonedVoiceShape = {
30
+ cloneId: z.string().min(1).describe('Ready cloned voice id'),
31
+ language: z
32
+ .string()
33
+ .refine(isEnglishLanguage, { message: ONLY_ENGLISH_CLONE_MESSAGE })
34
+ .optional()
35
+ .describe('Optional preview language override — English only for now'),
36
+ text: z
37
+ .string()
38
+ .trim()
39
+ .min(1)
40
+ .max(CLONE_PREVIEW_TEXT_MAX_CHARS)
41
+ .optional()
42
+ .describe(`Optional words for the clone to speak (1-${CLONE_PREVIEW_TEXT_MAX_CHARS} chars, English). Omit to hear the fixed sample. Previews are free and limited to 10 per user per day.`),
43
+ };
44
+ export const PreviewClonedVoiceSchema = z.object(PreviewClonedVoiceShape);
45
+ export async function handleListClonedVoices(client) {
46
+ return handleLibraryCall(() => listClonedVoices(client), 'listing cloned voices');
47
+ }
48
+ export async function handleCreateClonedVoice(client, args) {
49
+ return handleLibraryCall(() => createClonedVoiceFromUrl(client, args.audioUrl, args.language, args.consent, args.denoise), 'creating cloned voice', 'Voice clone registration started');
50
+ }
51
+ export async function handleGetClonedVoice(client, args) {
52
+ return handleLibraryCall(() => getClonedVoice(client, args.cloneId), 'getting cloned voice');
53
+ }
54
+ export async function handleDeleteClonedVoice(client, args) {
55
+ return handleLibraryCall(() => deleteClonedVoice(client, args.cloneId), 'deleting cloned voice', 'Cloned voice deleted');
56
+ }
57
+ export async function handlePreviewClonedVoice(client, args) {
58
+ return handleLibraryCall(() => previewClonedVoice(client, args.cloneId, args.language, args.text), 'previewing cloned voice');
59
+ }
60
+ //# sourceMappingURL=cloned-voice-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloned-voice-tools.js","sourceRoot":"","sources":["../src/cloned-voice-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAwB,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAE3D,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAEtE,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,6EAA6E,CAAC;IAClH,QAAQ,EAAE,CAAC;SACR,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,MAAM,CAAC,iBAAiB,EAAE,EAAE,OAAO,EAAE,0BAA0B,EAAE,CAAC;SAClE,QAAQ,CAAC,qEAAqE,CAAC;IAClF,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,wDAAwD,CAAC;IAC3F,OAAO,EAAE,CAAC;SACP,OAAO,EAAE;SACT,QAAQ,CAAC,qGAAqG,CAAC;CACnH,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAExE,MAAM,CAAC,M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,KAAK,UAAU,uBAAuB,CAC3C,MAA0B,EAC1B,IAA6C;IAE7C,OAAO,iBAAiB,CACtB,GAAG,EAAE,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,EAChG,uBAAuB,EACvB,kCAAkC,CACnC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAA0B,EAC1B,IAA0C;IAE1C,OAAO,iBAAiB,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,sBAAsB,CAAC,CAAC;AAC/F,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAA0B,EAC1B,IAA6C;IAE7C,OAAO,iBAAiB,CACtB,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,EAC7C,uBAAuB,EACvB,sBAAsB,CACvB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,MAA0B,EAC1B,IAA8C;IAE9C,OAAO,iBAAiB,CACtB,GAAG,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,EACxE,yBAAyB,CAC1B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ export interface HttpAuthConfig {
3
+ issuer: string;
4
+ resource: string;
5
+ jwksUrl: string;
6
+ rateLimitPerMinute: number;
7
+ }
8
+ export interface AuthContext {
9
+ sub: string;
10
+ clientId: string;
11
+ /** The verified bearer, forwarded to the web API for this request. */
12
+ bearer: string;
13
+ }
14
+ export interface HttpAuthenticator {
15
+ verify(token: string): Promise<AuthContext>;
16
+ }
17
+ export declare function parseHttpAuthOptions(env: NodeJS.ProcessEnv): HttpAuthConfig | null;
18
+ export declare function createHttpAuthenticator(config: HttpAuthConfig): HttpAuthenticator;
19
+ export declare function authenticateHttpRequest(req: IncomingMessage, authenticator: HttpAuthenticator): Promise<AuthContext | null>;
20
+ export declare function bearerTokenPresented(req: IncomingMessage): boolean;
21
+ export declare function protectedResourceMetadataUrl(resource: string): string | null;
22
+ export declare function unauthorizedHttpResponse(res: ServerResponse, config: HttpAuthConfig, tokenPresented?: boolean): void;
23
+ export declare function protectedResourceDocument(config: HttpAuthConfig): {
24
+ resource: string;
25
+ authorization_servers: string[];
26
+ scopes_supported: string[];
27
+ };
@@ -0,0 +1,148 @@
1
+ import { createRemoteJWKSet, jwtVerify } from 'jose';
2
+ // Default per-subject rate limit for the remote endpoint: 120 requests
3
+ // per minute, mirroring the web's post-detail profile (120/min) — the
4
+ // nearest web profile for a polled read surface. Generation itself is
5
+ // additionally limited server-side by the web's video-job profiles, so
6
+ // this limit is abuse protection, not spend protection.
7
+ const DEFAULT_RATE_LIMIT_PER_MINUTE = 120;
8
+ // Parse the OAuth configuration from the environment. Returns null
9
+ // when auth is not configured at all (loopback mode); throws on a
10
+ // malformed rate limit so the process fails fast instead of running
11
+ // with an unintended limit.
12
+ export function parseHttpAuthOptions(env) {
13
+ // Mirror apps/web/lib/oauth/config.ts: the web strips trailing slashes
14
+ // before these values become expected token claims, so the MCP side
15
+ // must expect the normalized forms or a trailing slash in env would
16
+ // reject every otherwise-valid token.
17
+ const issuer = env.MCP_OAUTH_ISSUER?.trim().replace(/\/+$/, '');
18
+ const resource = env.MCP_RESOURCE?.trim().replace(/\/+$/, '');
19
+ if (issuer === undefined || issuer === '' || resource === undefined || resource === '') {
20
+ return null;
21
+ }
22
+ const jwksUrl = env.MCP_OAUTH_JWKS_URL?.trim() || `${issuer}/.well-known/jwks.json`;
23
+ const rateLimitRaw = env.MCP_HTTP_RATE_LIMIT_PER_MINUTE?.trim();
24
+ let rateLimitPerMinute = DEFAULT_RATE_LIMIT_PER_MINUTE;
25
+ if (rateLimitRaw !== undefined && rateLimitRaw !== '') {
26
+ const parsed = Number(rateLimitRaw);
27
+ if (!Number.isInteger(parsed) || parsed <= 0) {
28
+ throw new Error(`Invalid MCP HTTP rate limit: "${rateLimitRaw}" — pass a positive integer for MCP_HTTP_RATE_LIMIT_PER_MINUTE.`);
29
+ }
30
+ rateLimitPerMinute = parsed;
31
+ }
32
+ return { issuer, resource, jwksUrl, rateLimitPerMinute };
33
+ }
34
+ function requiredClaim(payload, name) {
35
+ const value = payload[name];
36
+ if (typeof value !== 'string' || value === '') {
37
+ throw new Error(`Token is missing required claim ${name}.`);
38
+ }
39
+ return value;
40
+ }
41
+ // Build a verifier bound to one JWKS URL. The remote JWK set caches
42
+ // keys (jose's default) so every request does not refetch the JWKS.
43
+ export function createHttpAuthenticator(config) {
44
+ const jwks = createRemoteJWKSet(new URL(config.jwksUrl));
45
+ return {
46
+ async verify(token) {
47
+ const { payload } = await jwtVerify(token, jwks, {
48
+ issuer: config.issuer,
49
+ audience: config.resource,
50
+ algorithms: ['ES256'],
51
+ });
52
+ if (payload.token_use !== 'access') {
53
+ throw new Error('Unexpected token_use (expected access).');
54
+ }
55
+ const scope = requiredClaim(payload, 'scope');
56
+ if (!scope.split(' ').includes('mcp:tools')) {
57
+ throw new Error('Token scope does not include mcp:tools.');
58
+ }
59
+ return {
60
+ sub: requiredClaim(payload, 'sub'),
61
+ clientId: requiredClaim(payload, 'client_id'),
62
+ bearer: token,
63
+ };
64
+ },
65
+ };
66
+ }
67
+ // Extract and verify the Bearer token of one request. Returns null for
68
+ // a missing header, a non-Bearer scheme, a non-JWT value (an API key
69
+ // is not an OAuth token and is never accepted here), or any
70
+ // verification failure. Never throws, never logs the token.
71
+ export async function authenticateHttpRequest(req, authenticator) {
72
+ const authorization = req.headers.authorization;
73
+ if (authorization === undefined)
74
+ return null;
75
+ const parts = authorization.split(' ');
76
+ if (parts.length !== 2 || parts[0] !== 'Bearer')
77
+ return null;
78
+ const token = parts[1];
79
+ if (token === undefined || token === '' || token.split('.').length !== 3)
80
+ return null;
81
+ try {
82
+ return await authenticator.verify(token);
83
+ }
84
+ catch {
85
+ return null;
86
+ }
87
+ }
88
+ // Whether the request presented a Bearer token at all (scheme
89
+ // case-insensitive, non-empty value), regardless of whether it
90
+ // verifies. Used only to decide the 401 challenge's error code.
91
+ export function bearerTokenPresented(req) {
92
+ const authorization = req.headers.authorization;
93
+ if (authorization === undefined)
94
+ return false;
95
+ const parts = authorization.split(' ');
96
+ return parts.length === 2 && parts[0]?.toLowerCase() === 'bearer' && parts[1] !== '';
97
+ }
98
+ // Strip characters that would break out of a quoted header value.
99
+ function headerSafe(value) {
100
+ return value.replace(/["\r\n]/g, '');
101
+ }
102
+ // The protected-resource metadata URL for a resource identifier, when
103
+ // the identifier is a URL: the origin serves the RFC 9728 document at
104
+ // /.well-known/oauth-protected-resource. Null for opaque identifiers,
105
+ // where no metadata URL can be derived.
106
+ export function protectedResourceMetadataUrl(resource) {
107
+ try {
108
+ return `${new URL(resource).origin}/.well-known/oauth-protected-resource`;
109
+ }
110
+ catch {
111
+ return null;
112
+ }
113
+ }
114
+ // Answer 401 for an unauthenticated /mcp request. The WWW-Authenticate
115
+ // header carries realm, resource, and (when derivable) resource_metadata
116
+ // so an MCP-spec client can discover the authorization server; the
117
+ // error="invalid_token" code is included only when a token was actually
118
+ // presented (RFC 6750: no error code for a request lacking credentials).
119
+ // The body names no tool and no token.
120
+ export function unauthorizedHttpResponse(res, config, tokenPresented = false) {
121
+ const params = [
122
+ 'Bearer realm="post-engineer-mcp"',
123
+ `resource="${headerSafe(config.resource)}"`,
124
+ ];
125
+ const metadataUrl = protectedResourceMetadataUrl(config.resource);
126
+ if (metadataUrl !== null)
127
+ params.push(`resource_metadata="${headerSafe(metadataUrl)}"`);
128
+ if (tokenPresented)
129
+ params.push('error="invalid_token"');
130
+ params.push('error_description="A valid OAuth access token is required."');
131
+ res.writeHead(401, {
132
+ 'content-type': 'application/json',
133
+ 'www-authenticate': params.join(', '),
134
+ });
135
+ res.end(JSON.stringify({ error: 'Authentication required.' }));
136
+ }
137
+ // RFC 9728 protected-resource metadata for this endpoint: the resource
138
+ // itself, the authorization server that issues its tokens, and the
139
+ // scopes the endpoint accepts. Served at
140
+ // /.well-known/oauth-protected-resource (see http-transport.ts).
141
+ export function protectedResourceDocument(config) {
142
+ return {
143
+ resource: config.resource,
144
+ authorization_servers: [config.issuer],
145
+ scopes_supported: ['mcp:tools', 'offline_access'],
146
+ };
147
+ }
148
+ //# sourceMappingURL=http-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-auth.js","sourceRoot":"","sources":["../src/http-auth.ts"],"names":[],"mappings":"AA8BA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAoBrD,uEAAuE;AACvE,sEAAsE;AACtE,sEAAsE;AACtE,uEAAuE;AACvE,wDAAwD;AACxD,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAE1C,mEAAmE;AACnE,kEAAkE;AAClE,oEAAoE;AACpE,4BAA4B;AAC5B,MAAM,UAAU,oBAAoB,CAAC,GAAsB;IACzD,uEAAuE;IACvE,oEAAoE;IACpE,oEAAoE;IACpE,sCAAsC;IACtC,MAAM,MAAM,GAAG,GAAG,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,GAAG,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC9D,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,EAAE,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACvF,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,CAAC,kBAAkB,EAAE,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AG,4BAA4B,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClE,IAAI,WAAW,KAAK,IAAI;QAAE,MAAM,CAAC,IAAI,CAAC,sBAAsB,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACxF,IAAI,cAAc;QAAE,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACzD,MAAM,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAC;IAC3E,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,cAAc,EAAE,kBAAkB;QAClC,kBAAkB,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;KACtC,CAAC,CAAC;IACH,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,uEAAuE;AACvE,mEAAmE;AACnE,yCAAyC;AACzC,iEAAiE;AACjE,MAAM,UAAU,yBAAyB,CAAC,MAAsB;IAK9D,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,qBAAqB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;QACtC,gBAAgB,EAAE,CAAC,WAAW,EAAE,gBAAgB,CAAC;KAClD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ export interface HttpRateLimitResult {
2
+ allowed: boolean;
3
+ retryAfterSeconds: number;
4
+ }
5
+ export interface HttpRateLimiterOptions {
6
+ limit: number;
7
+ windowMs: number;
8
+ /** Clock override for tests; defaults to the real clock. */
9
+ now?: () => number;
10
+ }
11
+ export interface HttpRateLimiter {
12
+ check(key: string): HttpRateLimitResult;
13
+ }
14
+ export declare function createHttpRateLimiter(options: HttpRateLimiterOptions): HttpRateLimiter;
@@ -0,0 +1,28 @@
1
+ export function createHttpRateLimiter(options) {
2
+ const now = options.now ?? (() => Date.now());
3
+ const counters = new Map();
4
+ return {
5
+ check(key) {
6
+ const current = now();
7
+ // Lazy cleanup: expired windows are dropped when found, so the
8
+ // table tracks only subjects active in the current window.
9
+ for (const [storedKey, counter] of counters) {
10
+ if (current - counter.windowStart >= options.windowMs) {
11
+ counters.delete(storedKey);
12
+ }
13
+ }
14
+ const existing = counters.get(key);
15
+ if (existing === undefined) {
16
+ counters.set(key, { count: 1, windowStart: current });
17
+ return { allowed: true, retryAfterSeconds: 0 };
18
+ }
19
+ existing.count += 1;
20
+ if (existing.count <= options.limit) {
21
+ return { allowed: true, retryAfterSeconds: 0 };
22
+ }
23
+ const remainingMs = existing.windowStart + options.windowMs - current;
24
+ return { allowed: false, retryAfterSeconds: Math.ceil(remainingMs / 1000) };
25
+ },
26
+ };
27
+ }
28
+ //# sourceMappingURL=http-rate-limit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-rate-limit.js","sourceRoot":"","sources":["../src/http-rate-limit.ts"],"names":[],"mappings":"AA4BA,MAAM,UAAU,qBAAqB,CAAC,OAA+B;IACnE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;IAClD,OAAO;QACL,KAAK,CAAC,GAAW;YACf,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC;YACtB,+DAA+D;YAC/D,2DAA2D;YAC3D,KAAK,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,QAAQ,EAAE,CAAC;gBAC5C,IAAI,OAAO,GAAG,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;oBACtD,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBAC7B,CAAC;YACH,CAAC;YACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;gBACtD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC,EAAE,CAAC;YACjD,CAAC;YACD,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC;YACpB,IAAI,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC,EAAE,CAAC;YACjD,CAAC;YACD,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC;YACtE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC;QAC9E,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { type AuthContext, type HttpAuthConfig } from './http-auth.js';
3
+ export interface HttpTransportOptions {
4
+ host: string;
5
+ port: number;
6
+ allowRemote: boolean;
7
+ }
8
+ export interface HttpTransportHandle {
9
+ url: string;
10
+ close(): Promise<void>;
11
+ }
12
+ export declare function parseHttpTransportOptions(argv: string[], env: NodeJS.ProcessEnv): HttpTransportOptions | null;
13
+ export declare function serveHttpTransport(serverFactory: (auth?: AuthContext) => McpServer, options: HttpTransportOptions, auth?: HttpAuthConfig | null): Promise<HttpTransportHandle>;