@plitzi/sdk-mcp 0.33.2 → 0.34.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.
- package/CHANGELOG.md +62 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/dist/modules/mcp/catalogs/index.d.ts +2 -7
- package/dist/modules/mcp/catalogs/index.js +4 -0
- package/dist/modules/mcp/catalogs/observed.d.ts +1 -1
- package/dist/modules/mcp/catalogs/observed.js +2 -5
- package/dist/modules/mcp/catalogs/pluginCatalog.d.ts +17 -0
- package/dist/modules/mcp/catalogs/pluginCatalog.js +91 -0
- package/dist/modules/mcp/catalogs/registry.js +2 -3
- package/dist/modules/mcp/helpers/agentPrompt.js +9 -9
- package/dist/modules/mcp/helpers/guide.d.ts +2 -2
- package/dist/modules/mcp/helpers/guide.js +117 -50
- package/dist/modules/mcp/helpers/interactions.d.ts +5 -1
- package/dist/modules/mcp/helpers/interactions.js +15 -6
- package/dist/modules/mcp/helpers/space.d.ts +45 -28
- package/dist/modules/mcp/helpers/space.js +87 -87
- package/dist/modules/mcp/helpers/uris.d.ts +9 -0
- package/dist/modules/mcp/helpers/uris.js +10 -1
- package/dist/modules/mcp/index.d.ts +2 -0
- package/dist/modules/mcp/localScreenshotClient.d.ts +51 -0
- package/dist/modules/mcp/localScreenshotClient.js +106 -0
- package/dist/modules/mcp/proxy/rewrite.js +15 -1
- package/dist/modules/mcp/resources/actions.d.ts +25 -0
- package/dist/modules/mcp/resources/actions.js +54 -0
- package/dist/modules/mcp/resources/canonical.d.ts +1 -1
- package/dist/modules/mcp/resources/canonical.js +1 -1
- package/dist/modules/mcp/resources/connectors.d.ts +1 -1
- package/dist/modules/mcp/resources/core.js +1 -1
- package/dist/modules/mcp/resources/index.d.ts +1 -0
- package/dist/modules/mcp/resources/primer.d.ts +8 -1
- package/dist/modules/mcp/resources/primer.js +139 -15
- package/dist/modules/mcp/resources/register.js +24 -4
- package/dist/modules/mcp/resources/renderGuide.js +66 -14
- package/dist/modules/mcp/resources/router.js +3 -1
- package/dist/modules/mcp/resources/schema.js +6 -5
- package/dist/modules/mcp/resources/style.d.ts +2 -1
- package/dist/modules/mcp/resources/style.js +10 -3
- package/dist/modules/mcp/screenshotClient.js +3 -2
- package/dist/modules/mcp/server.js +12 -6
- package/dist/modules/mcp/tests/agentRoundtrip.test.d.ts +1 -0
- package/dist/modules/mcp/tests/layouts.test.d.ts +1 -0
- package/dist/modules/mcp/tools/apply/dispatch.js +30 -1
- package/dist/modules/mcp/tools/apply/index.d.ts +149 -15
- package/dist/modules/mcp/tools/apply/index.js +12 -2
- package/dist/modules/mcp/tools/operations/actions/actions.test.d.ts +1 -0
- package/dist/modules/mcp/tools/operations/actions/deleteAction.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/actions/deleteAction.js +20 -0
- package/dist/modules/mcp/tools/operations/actions/document.d.ts +69 -0
- package/dist/modules/mcp/tools/operations/actions/document.js +73 -0
- package/dist/modules/mcp/tools/operations/actions/index.d.ts +90 -0
- package/dist/modules/mcp/tools/operations/actions/index.js +12 -0
- package/dist/modules/mcp/tools/operations/actions/patchAction.d.ts +45 -0
- package/dist/modules/mcp/tools/operations/actions/patchAction.js +71 -0
- package/dist/modules/mcp/tools/operations/actions/upsertAction.d.ts +47 -0
- package/dist/modules/mcp/tools/operations/actions/upsertAction.js +83 -0
- package/dist/modules/mcp/tools/operations/connectors/index.d.ts +10 -10
- package/dist/modules/mcp/tools/operations/connectors/manifest.d.ts +5 -5
- package/dist/modules/mcp/tools/operations/connectors/patchConnector.d.ts +5 -5
- package/dist/modules/mcp/tools/operations/connectors/upsertConnector.d.ts +5 -5
- package/dist/modules/mcp/tools/operations/index.d.ts +415 -40
- package/dist/modules/mcp/tools/operations/index.js +11 -2
- package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +2 -2
- package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.d.ts +1 -1
- package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +2 -2
- package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.d.ts +1 -1
- package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.js +4 -4
- package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.js +5 -5
- package/dist/modules/mcp/tools/operations/schema/elements/moveElement.js +6 -6
- package/dist/modules/mcp/tools/operations/schema/elements/patchElement.d.ts +1 -1
- package/dist/modules/mcp/tools/operations/schema/elements/patchElement.js +11 -12
- package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.js +1 -1
- package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.js +4 -4
- package/dist/modules/mcp/tools/operations/schema/index.d.ts +2 -0
- package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +2 -2
- package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.d.ts +1 -1
- package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +2 -2
- package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.d.ts +1 -1
- package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.js +4 -4
- package/dist/modules/mcp/tools/operations/schema/operations.d.ts +28 -5
- package/dist/modules/mcp/tools/operations/schema/operations.js +4 -0
- package/dist/modules/mcp/tools/operations/schema/pages/deleteLayout.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/schema/pages/deleteLayout.js +33 -0
- package/dist/modules/mcp/tools/operations/schema/pages/deletePage.js +1 -1
- package/dist/modules/mcp/tools/operations/schema/pages/upsertLayout.d.ts +22 -0
- package/dist/modules/mcp/tools/operations/schema/pages/upsertLayout.js +61 -0
- package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.d.ts +2 -0
- package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +53 -18
- package/dist/modules/mcp/tools/operations/schema/shared.d.ts +5 -1
- package/dist/modules/mcp/tools/operations/schema/shared.js +2 -2
- package/dist/modules/mcp/tools/operations/schema/translator.d.ts +2 -1
- package/dist/modules/mcp/tools/operations/schema/translator.js +21 -9
- package/dist/modules/mcp/tools/operations/schema/write.d.ts +9 -22
- package/dist/modules/mcp/tools/operations/schema/write.js +23 -43
- package/dist/modules/mcp/tools/operations/schemaIds.js +7 -1
- package/dist/modules/mcp/tools/operations/style/fonts/deleteFont.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/style/fonts/deleteFont.js +21 -0
- package/dist/modules/mcp/tools/operations/style/fonts/fonts.test.d.ts +1 -0
- package/dist/modules/mcp/tools/operations/style/fonts/upsertFont.d.ts +35 -0
- package/dist/modules/mcp/tools/operations/style/fonts/upsertFont.js +66 -0
- package/dist/modules/mcp/tools/operations/style/index.d.ts +2 -0
- package/dist/modules/mcp/tools/operations/style/operations.d.ts +34 -0
- package/dist/modules/mcp/tools/operations/style/operations.js +5 -1
- package/dist/modules/mcp/tools/operations/style/translator.d.ts +13 -1
- package/dist/modules/mcp/tools/operations/style/translator.js +18 -1
- package/dist/modules/mcp/tools/operations/style/write.js +1 -1
- package/dist/modules/mcp/tools/preview.d.ts +58 -5
- package/dist/modules/mcp/tools/preview.js +1 -1
- package/dist/modules/mcp/tools/render.d.ts +61 -5
- package/dist/modules/mcp/tools/render.js +10 -3
- package/dist/modules/mcp/tools/screenshot.d.ts +151 -16
- package/dist/modules/mcp/tools/screenshot.js +22 -13
- package/dist/modules/mcp/tools/search.js +3 -3
- package/dist/modules/mcp/tools/shared/interactionReport.d.ts +7 -0
- package/dist/modules/mcp/tools/shared/interactionReport.js +48 -0
- package/dist/modules/mcp/tools/shared/validator/audit.js +4 -4
- package/dist/modules/mcp/tools/shared/validator/batch.d.ts +1 -0
- package/dist/modules/mcp/tools/shared/validator/batch.js +11 -2
- package/dist/modules/mcp/tools/shared/validator/bindings.js +6 -6
- package/dist/modules/mcp/tools/shared/validator/connectors.js +1 -1
- package/dist/modules/mcp/tools/shared/validator/context.d.ts +3 -0
- package/dist/modules/mcp/tools/shared/validator/css.js +1 -1
- package/dist/modules/mcp/tools/shared/validator/index.js +29 -9
- package/dist/modules/mcp/tools/shared/validator/interactions.js +41 -7
- package/dist/modules/mcp/tools/shared/validator/refs.js +4 -4
- package/dist/modules/mcp/tools/validate.d.ts +149 -15
- package/dist/modules/mcp/types/aiSchema.d.ts +33 -4
- package/dist/modules/mcp/types/previewTypes.d.ts +19 -0
- package/dist/modules/mcp/types/screenshotTypes.d.ts +1 -0
- package/dist/modules/mcp/types/toolTypes.d.ts +6 -1
- package/dist/pipeline.js +1 -1
- package/dist/preview/createPreview.d.ts +4 -2
- package/dist/preview/createPreview.js +16 -6
- package/dist/server.d.ts +3 -0
- package/dist/server.js +3 -1
- package/dist/stages/preview.js +20 -1
- package/dist/tests/httpRequest.d.ts +2 -0
- package/package.json +20 -16
- package/skills/plitzi-render/SKILL.md +84 -11
- package/dist/modules/mcp/catalogs/builtinCallbacks.d.ts +0 -19
- package/dist/modules/mcp/catalogs/builtinCallbacks.js +0 -139
- package/dist/modules/mcp/catalogs/builtinComponents.d.ts +0 -4
- package/dist/modules/mcp/catalogs/builtinComponents.js +0 -165
- package/dist/modules/mcp/catalogs/builtinElementCallbacks.d.ts +0 -17
- package/dist/modules/mcp/catalogs/builtinElementCallbacks.js +0 -50
- package/dist/modules/mcp/catalogs/builtinTransformers.d.ts +0 -28
- package/dist/modules/mcp/catalogs/builtinTransformers.js +0 -148
- package/dist/modules/mcp/catalogs/builtinUtilities.d.ts +0 -15
- package/dist/modules/mcp/catalogs/builtinUtilities.js +0 -90
- package/dist/modules/mcp/catalogs/cssCatalog/border.d.ts +0 -4
- package/dist/modules/mcp/catalogs/cssCatalog/border.js +0 -30
- package/dist/modules/mcp/catalogs/cssCatalog/box.d.ts +0 -4
- package/dist/modules/mcp/catalogs/cssCatalog/box.js +0 -31
- package/dist/modules/mcp/catalogs/cssCatalog/helpers.d.ts +0 -34
- package/dist/modules/mcp/catalogs/cssCatalog/helpers.js +0 -185
- package/dist/modules/mcp/catalogs/cssCatalog/index.d.ts +0 -18
- package/dist/modules/mcp/catalogs/cssCatalog/index.js +0 -131
- package/dist/modules/mcp/catalogs/cssCatalog/layout.d.ts +0 -9
- package/dist/modules/mcp/catalogs/cssCatalog/layout.js +0 -99
- package/dist/modules/mcp/catalogs/cssCatalog/visual.d.ts +0 -8
- package/dist/modules/mcp/catalogs/cssCatalog/visual.js +0 -147
- package/dist/modules/mcp/catalogs/paramSpec.d.ts +0 -39
- package/dist/modules/mcp/catalogs/paramSpec.js +0 -69
- package/dist/modules/oauth/authorize.d.ts +0 -7
- package/dist/modules/oauth/authorize.js +0 -177
- package/dist/modules/oauth/challenge.d.ts +0 -11
- package/dist/modules/oauth/challenge.js +0 -33
- package/dist/modules/oauth/consentPage.d.ts +0 -7
- package/dist/modules/oauth/consentPage.js +0 -118
- package/dist/modules/oauth/metadata.d.ts +0 -40
- package/dist/modules/oauth/metadata.js +0 -69
- package/dist/modules/oauth/params.d.ts +0 -5
- package/dist/modules/oauth/params.js +0 -5
- package/dist/modules/oauth/pkce.d.ts +0 -6
- package/dist/modules/oauth/pkce.js +0 -15
- package/dist/modules/oauth/records.d.ts +0 -71
- package/dist/modules/oauth/records.js +0 -46
- package/dist/modules/oauth/register.d.ts +0 -5
- package/dist/modules/oauth/register.js +0 -55
- package/dist/modules/oauth/respond.d.ts +0 -13
- package/dist/modules/oauth/respond.js +0 -44
- package/dist/modules/oauth/token.d.ts +0 -5
- package/dist/modules/oauth/token.js +0 -100
- package/dist/stages/oauth.d.ts +0 -19
- package/dist/stages/oauth.js +0 -114
- /package/dist/modules/mcp/catalogs/{builtinTransformers.test.d.ts → pluginCatalog.test.d.ts} +0 -0
- /package/dist/modules/mcp/{catalogs/cssCatalog/cssCatalog.test.d.ts → localScreenshotClient.test.d.ts} +0 -0
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { randomId } from "./pkce.js";
|
|
2
|
-
import { getClientByFingerprint, putClient, putClientFingerprint } from "./records.js";
|
|
3
|
-
import { sendErrorJson, sendJson } from "./respond.js";
|
|
4
|
-
import { createHash } from "node:crypto";
|
|
5
|
-
//#region src/modules/oauth/register.ts
|
|
6
|
-
var isUsableRedirectUri = (value) => {
|
|
7
|
-
let url;
|
|
8
|
-
try {
|
|
9
|
-
url = new URL(value);
|
|
10
|
-
} catch {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
if (url.protocol === "https:") return true;
|
|
14
|
-
return url.protocol === "http:" && (url.hostname === "localhost" || url.hostname === "127.0.0.1");
|
|
15
|
-
};
|
|
16
|
-
var stringList = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
17
|
-
var nowSeconds = () => Math.floor(Date.now() / 1e3);
|
|
18
|
-
var fingerprintOf = (clientName, redirectUris) => createHash("sha256").update(JSON.stringify([clientName, [...redirectUris].sort()])).digest("base64url");
|
|
19
|
-
/** RFC 7591 dynamic client registration. A remote host has no way to be configured into this server ahead of
|
|
20
|
-
* time, so it registers itself on first connect; the record it gets back is only ever used to pin the redirect
|
|
21
|
-
* target, since a public client authenticates with PKCE rather than with credentials. */
|
|
22
|
-
var handleRegister = async (config, res, body) => {
|
|
23
|
-
if (typeof body !== "object" || body === null) {
|
|
24
|
-
sendErrorJson(res, 400, "invalid_request", "Expected a JSON client metadata object.");
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const metadata = body;
|
|
28
|
-
const redirectUris = stringList(metadata["redirect_uris"]).filter(isUsableRedirectUri);
|
|
29
|
-
if (redirectUris.length === 0) {
|
|
30
|
-
sendErrorJson(res, 400, "invalid_request", "redirect_uris must list at least one https (or loopback) URI.");
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const clientName = typeof metadata["client_name"] === "string" ? metadata["client_name"] : "MCP client";
|
|
34
|
-
const { store } = config.adapters;
|
|
35
|
-
const fingerprint = fingerprintOf(clientName, redirectUris);
|
|
36
|
-
const client = await getClientByFingerprint(store, fingerprint) ?? {
|
|
37
|
-
clientId: randomId(),
|
|
38
|
-
clientName,
|
|
39
|
-
redirectUris,
|
|
40
|
-
issuedAt: nowSeconds()
|
|
41
|
-
};
|
|
42
|
-
await putClient(store, client);
|
|
43
|
-
await putClientFingerprint(store, fingerprint, client.clientId);
|
|
44
|
-
sendJson(res, 201, {
|
|
45
|
-
client_id: client.clientId,
|
|
46
|
-
client_id_issued_at: client.issuedAt,
|
|
47
|
-
client_name: clientName,
|
|
48
|
-
redirect_uris: redirectUris,
|
|
49
|
-
grant_types: config.refreshTtlSeconds === 0 ? ["authorization_code"] : ["authorization_code", "refresh_token"],
|
|
50
|
-
response_types: ["code"],
|
|
51
|
-
token_endpoint_auth_method: "none"
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
//#endregion
|
|
55
|
-
export { handleRegister };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SSRResponseHelpers } from '@plitzi/sdk-shared';
|
|
2
|
-
/** The error codes RFC 6749 defines for the responses this server produces. */
|
|
3
|
-
export type OAuthErrorCode = 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'unauthorized_client' | 'unsupported_grant_type' | 'unsupported_response_type' | 'invalid_scope' | 'access_denied' | 'server_error';
|
|
4
|
-
export declare const sendJson: (res: SSRResponseHelpers, status: number, body: unknown) => void;
|
|
5
|
-
export declare const sendHtml: (res: SSRResponseHelpers, status: number, html: string) => void;
|
|
6
|
-
export declare const sendErrorJson: (res: SSRResponseHelpers, status: number, error: OAuthErrorCode, description: string) => void;
|
|
7
|
-
/** Shown when the authorization request itself is unusable — an unknown client, a `redirect_uri` that is not
|
|
8
|
-
* registered. Redirecting those back would turn the endpoint into an open redirector. */
|
|
9
|
-
export declare const sendErrorPage: (res: SSRResponseHelpers, title: string, detail: string) => void;
|
|
10
|
-
/** The other half of RFC 6749 error handling: once the redirect target is known to be legitimate, failures go
|
|
11
|
-
* back to the client so the host can report them, carrying `state` so it can match the response to its request. */
|
|
12
|
-
export declare const redirectWithError: (res: SSRResponseHelpers, redirectUri: string, error: OAuthErrorCode, description: string, state?: string) => void;
|
|
13
|
-
export declare const redirectWithCode: (res: SSRResponseHelpers, redirectUri: string, code: string, state?: string) => void;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { renderErrorPage } from "./consentPage.js";
|
|
2
|
-
//#region src/modules/oauth/respond.ts
|
|
3
|
-
var sendJson = (res, status, body) => {
|
|
4
|
-
res.setStatus(status);
|
|
5
|
-
res.setHeader("Content-Type", "application/json");
|
|
6
|
-
res.setHeader("Cache-Control", "no-store, no-transform");
|
|
7
|
-
res.send(JSON.stringify(body));
|
|
8
|
-
};
|
|
9
|
-
var sendHtml = (res, status, html) => {
|
|
10
|
-
res.setStatus(status);
|
|
11
|
-
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
12
|
-
res.setHeader("Cache-Control", "no-store, no-transform");
|
|
13
|
-
res.send(html);
|
|
14
|
-
};
|
|
15
|
-
var sendErrorJson = (res, status, error, description) => sendJson(res, status, {
|
|
16
|
-
error,
|
|
17
|
-
error_description: description
|
|
18
|
-
});
|
|
19
|
-
/** Shown when the authorization request itself is unusable — an unknown client, a `redirect_uri` that is not
|
|
20
|
-
* registered. Redirecting those back would turn the endpoint into an open redirector. */
|
|
21
|
-
var sendErrorPage = (res, title, detail) => sendHtml(res, 400, renderErrorPage(title, detail));
|
|
22
|
-
/** The other half of RFC 6749 error handling: once the redirect target is known to be legitimate, failures go
|
|
23
|
-
* back to the client so the host can report them, carrying `state` so it can match the response to its request. */
|
|
24
|
-
var redirectWithError = (res, redirectUri, error, description, state) => {
|
|
25
|
-
const url = new URL(redirectUri);
|
|
26
|
-
url.searchParams.set("error", error);
|
|
27
|
-
url.searchParams.set("error_description", description);
|
|
28
|
-
if (state !== void 0) url.searchParams.set("state", state);
|
|
29
|
-
res.setStatus(302);
|
|
30
|
-
res.setHeader("Location", url.toString());
|
|
31
|
-
res.setHeader("Cache-Control", "no-store, no-transform");
|
|
32
|
-
res.end();
|
|
33
|
-
};
|
|
34
|
-
var redirectWithCode = (res, redirectUri, code, state) => {
|
|
35
|
-
const url = new URL(redirectUri);
|
|
36
|
-
url.searchParams.set("code", code);
|
|
37
|
-
if (state !== void 0) url.searchParams.set("state", state);
|
|
38
|
-
res.setStatus(302);
|
|
39
|
-
res.setHeader("Location", url.toString());
|
|
40
|
-
res.setHeader("Cache-Control", "no-store, no-transform");
|
|
41
|
-
res.end();
|
|
42
|
-
};
|
|
43
|
-
//#endregion
|
|
44
|
-
export { redirectWithCode, redirectWithError, sendErrorJson, sendErrorPage, sendHtml, sendJson };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { OAuthParams } from './params';
|
|
2
|
-
import { OAuthConfig, SSRResponseHelpers } from '@plitzi/sdk-shared';
|
|
3
|
-
/** POST /token. Public clients only, so there is no client authentication to check — PKCE is what proves the
|
|
4
|
-
* caller is the one that started the flow. */
|
|
5
|
-
export declare const handleToken: (config: OAuthConfig, res: SSRResponseHelpers, params: OAuthParams) => Promise<void>;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { scopesOf } from "./metadata.js";
|
|
2
|
-
import { field, optionalField } from "./params.js";
|
|
3
|
-
import { randomId, verifyChallenge } from "./pkce.js";
|
|
4
|
-
import { dropCode, dropRefresh, getCode, getRefresh, putAccess, putRefresh } from "./records.js";
|
|
5
|
-
import { sendErrorJson, sendJson } from "./respond.js";
|
|
6
|
-
//#region src/modules/oauth/token.ts
|
|
7
|
-
var DEFAULT_REFRESH_TTL_SECONDS = 2592e3;
|
|
8
|
-
var DEFAULT_ACCESS_TTL_SECONDS = 2592e3;
|
|
9
|
-
var refreshTtlOf = (config) => config.refreshTtlSeconds ?? DEFAULT_REFRESH_TTL_SECONDS;
|
|
10
|
-
var scopeOf = (config, requested) => requested ?? scopesOf(config).join(" ");
|
|
11
|
-
/** The token response, plus a rotated refresh grant when refresh is enabled. Rotation is unconditional: a refresh
|
|
12
|
-
* token is a long-lived credential, so the one just used never stays valid. */
|
|
13
|
-
var sendTokens = async (config, res, credential, expiresInSeconds, grant) => {
|
|
14
|
-
const ttl = refreshTtlOf(config);
|
|
15
|
-
const bearer = randomId();
|
|
16
|
-
await putAccess(config.adapters.store, bearer, {
|
|
17
|
-
credential,
|
|
18
|
-
clientId: grant.clientId,
|
|
19
|
-
user: grant.user,
|
|
20
|
-
target: grant.target
|
|
21
|
-
}, Math.max(expiresInSeconds ?? DEFAULT_ACCESS_TTL_SECONDS, 1));
|
|
22
|
-
const body = {
|
|
23
|
-
access_token: bearer,
|
|
24
|
-
token_type: "Bearer",
|
|
25
|
-
scope: scopeOf(config, grant.scope)
|
|
26
|
-
};
|
|
27
|
-
if (expiresInSeconds !== void 0) body["expires_in"] = expiresInSeconds;
|
|
28
|
-
if (ttl > 0) {
|
|
29
|
-
const refreshToken = randomId();
|
|
30
|
-
await putRefresh(config.adapters.store, refreshToken, grant, ttl);
|
|
31
|
-
body["refresh_token"] = refreshToken;
|
|
32
|
-
}
|
|
33
|
-
sendJson(res, 200, body);
|
|
34
|
-
};
|
|
35
|
-
var exchangeCode = async (config, res, params) => {
|
|
36
|
-
const code = field(params, "code");
|
|
37
|
-
const record = code ? await getCode(config.adapters.store, code) : void 0;
|
|
38
|
-
if (!record) {
|
|
39
|
-
sendErrorJson(res, 400, "invalid_grant", "The authorization code is unknown or has expired.");
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
await dropCode(config.adapters.store, code);
|
|
43
|
-
if (record.clientId !== field(params, "client_id")) {
|
|
44
|
-
sendErrorJson(res, 400, "invalid_grant", "The authorization code was issued to another client.");
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const redirectUri = optionalField(params, "redirect_uri");
|
|
48
|
-
if (redirectUri !== void 0 && redirectUri !== record.redirectUri) {
|
|
49
|
-
sendErrorJson(res, 400, "invalid_grant", "redirect_uri does not match the authorization request.");
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (!verifyChallenge(field(params, "code_verifier"), record.challenge)) {
|
|
53
|
-
sendErrorJson(res, 400, "invalid_grant", "The PKCE code verifier does not match the challenge.");
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
await sendTokens(config, res, record.token, record.expiresInSeconds, {
|
|
57
|
-
clientId: record.clientId,
|
|
58
|
-
scope: record.scope,
|
|
59
|
-
user: record.user,
|
|
60
|
-
target: record.target
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
var exchangeRefresh = async (config, res, params) => {
|
|
64
|
-
if (refreshTtlOf(config) === 0) {
|
|
65
|
-
sendErrorJson(res, 400, "unsupported_grant_type", "This server issues no refresh tokens.");
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const refreshToken = field(params, "refresh_token");
|
|
69
|
-
const record = refreshToken ? await getRefresh(config.adapters.store, refreshToken) : void 0;
|
|
70
|
-
if (!record) {
|
|
71
|
-
sendErrorJson(res, 400, "invalid_grant", "The refresh token is unknown or has expired.");
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
await dropRefresh(config.adapters.store, refreshToken);
|
|
75
|
-
if (record.clientId !== field(params, "client_id")) {
|
|
76
|
-
sendErrorJson(res, 400, "invalid_grant", "The refresh token was issued to another client.");
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const issued = await config.adapters.issueToken(record.user, record.target);
|
|
80
|
-
if (!issued) {
|
|
81
|
-
sendErrorJson(res, 400, "invalid_grant", "The account no longer has access to this resource.");
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
await sendTokens(config, res, issued.token, issued.expiresInSeconds, record);
|
|
85
|
-
};
|
|
86
|
-
/** POST /token. Public clients only, so there is no client authentication to check — PKCE is what proves the
|
|
87
|
-
* caller is the one that started the flow. */
|
|
88
|
-
var handleToken = async (config, res, params) => {
|
|
89
|
-
switch (field(params, "grant_type")) {
|
|
90
|
-
case "authorization_code":
|
|
91
|
-
await exchangeCode(config, res, params);
|
|
92
|
-
return;
|
|
93
|
-
case "refresh_token":
|
|
94
|
-
await exchangeRefresh(config, res, params);
|
|
95
|
-
return;
|
|
96
|
-
default: sendErrorJson(res, 400, "unsupported_grant_type", "Supported grants: authorization_code, refresh_token.");
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
//#endregion
|
|
100
|
-
export { handleToken };
|
package/dist/stages/oauth.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Stage } from '@plitzi/sdk-server/kernel';
|
|
2
|
-
import { OAuthConfig } from '@plitzi/sdk-shared';
|
|
3
|
-
/** OAuth 2.1 authorization for the MCP server, mounted ONLY when a deployment configures `oauth`. Without it the
|
|
4
|
-
* stage falls straight through and the server keeps its anonymous contract: discovery 404s, the public surface
|
|
5
|
-
* (handshake, listings, the guide, plitzi_render) answers without a token, and nothing below changes.
|
|
6
|
-
*
|
|
7
|
-
* It sits before the MCP stage because that one answers every path on a dedicated MCP server — these endpoints
|
|
8
|
-
* would otherwise be swallowed by the JSON-RPC transport, which is exactly the 406 a host hits on /register. */
|
|
9
|
-
export declare const createOAuthStage: (oauth?: OAuthConfig) => Stage;
|
|
10
|
-
/** The protected-resource half of OAuth: an MCP call that presents no bearer this server can verify is refused
|
|
11
|
-
* with RFC 6750's challenge instead of being served the anonymous surface. That 401 is the whole handshake — it
|
|
12
|
-
* is how a host learns the server needs authorization, where its metadata lives and which scopes to ask for, and
|
|
13
|
-
* a 200 tells it none of that. Only the JSON-RPC POST is guarded: the CORS preflight, the GET 405 and the
|
|
14
|
-
* discovery probes carry no credential and must keep answering as they do.
|
|
15
|
-
*
|
|
16
|
-
* Mounted only when `oauth` is configured. A deployment that configures none keeps the open server it had, where
|
|
17
|
-
* the whole public surface — handshake, listings, the guide, plitzi_render — answers without a token; with OAuth
|
|
18
|
-
* on, the grant that carries no space is what covers that same ground. */
|
|
19
|
-
export declare const createOAuthGuardStage: (oauth?: OAuthConfig) => Stage;
|
package/dist/stages/oauth.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { authorizationServerMetadata, protectedResourceMetadata } from "../modules/oauth/metadata.js";
|
|
2
|
-
import { getAccess } from "../modules/oauth/records.js";
|
|
3
|
-
import { sendErrorJson, sendJson } from "../modules/oauth/respond.js";
|
|
4
|
-
import { handleAuthorizeStart, handleAuthorizeSubmit } from "../modules/oauth/authorize.js";
|
|
5
|
-
import { bearerOf, sendChallenge } from "../modules/oauth/challenge.js";
|
|
6
|
-
import { handleRegister } from "../modules/oauth/register.js";
|
|
7
|
-
import { handleToken } from "../modules/oauth/token.js";
|
|
8
|
-
import { readRawBody } from "@plitzi/sdk-server/kernel";
|
|
9
|
-
//#region src/stages/oauth.ts
|
|
10
|
-
var matchesWellKnown = (path, wellKnown) => path === wellKnown || path.startsWith(`${wellKnown}/`);
|
|
11
|
-
var isOAuthPath = (path) => matchesWellKnown(path, "/.well-known/oauth-protected-resource") || matchesWellKnown(path, "/.well-known/oauth-authorization-server") || path === "/register" || path === "/authorize" || path === "/token";
|
|
12
|
-
var formParams = (req, body) => {
|
|
13
|
-
const params = { ...req.query };
|
|
14
|
-
for (const [key, value] of new URLSearchParams(body).entries()) params[key] = value;
|
|
15
|
-
return params;
|
|
16
|
-
};
|
|
17
|
-
var parseJson = (body) => {
|
|
18
|
-
try {
|
|
19
|
-
return JSON.parse(body);
|
|
20
|
-
} catch {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
/** OAuth 2.1 authorization for the MCP server, mounted ONLY when a deployment configures `oauth`. Without it the
|
|
25
|
-
* stage falls straight through and the server keeps its anonymous contract: discovery 404s, the public surface
|
|
26
|
-
* (handshake, listings, the guide, plitzi_render) answers without a token, and nothing below changes.
|
|
27
|
-
*
|
|
28
|
-
* It sits before the MCP stage because that one answers every path on a dedicated MCP server — these endpoints
|
|
29
|
-
* would otherwise be swallowed by the JSON-RPC transport, which is exactly the 406 a host hits on /register. */
|
|
30
|
-
var createOAuthStage = (oauth) => async (ctx) => {
|
|
31
|
-
const { path, method } = ctx.req;
|
|
32
|
-
if (!oauth || !isOAuthPath(path)) return false;
|
|
33
|
-
const { res } = ctx;
|
|
34
|
-
if (path !== "/authorize") {
|
|
35
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
36
|
-
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
37
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
38
|
-
}
|
|
39
|
-
if (method === "OPTIONS") {
|
|
40
|
-
res.setStatus(204);
|
|
41
|
-
res.end();
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
if (method === "GET" && matchesWellKnown(path, "/.well-known/oauth-protected-resource")) {
|
|
45
|
-
sendJson(res, 200, protectedResourceMetadata(oauth, ctx.req));
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
if (method === "GET" && matchesWellKnown(path, "/.well-known/oauth-authorization-server")) {
|
|
49
|
-
sendJson(res, 200, authorizationServerMetadata(oauth, ctx.req));
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
if (path === "/authorize" && method === "GET") {
|
|
53
|
-
await handleAuthorizeStart(oauth, res, ctx.req.query);
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
if (path === "/authorize" && method === "POST") {
|
|
57
|
-
await handleAuthorizeSubmit(oauth, res, formParams(ctx.req, await readRawBody(ctx.raw)));
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
if (path === "/token" && method === "POST") {
|
|
61
|
-
await handleToken(oauth, res, formParams(ctx.req, await readRawBody(ctx.raw)));
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
if (path === "/register" && method === "POST") {
|
|
65
|
-
await handleRegister(oauth, res, parseJson(await readRawBody(ctx.raw)));
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
sendErrorJson(res, 405, "invalid_request", `${method} is not allowed on ${path}.`);
|
|
69
|
-
return true;
|
|
70
|
-
};
|
|
71
|
-
var CHALLENGE_DESCRIPTIONS = {
|
|
72
|
-
"no-credential": "Authorization is required to use this server.",
|
|
73
|
-
"unknown-credential": "The access token is invalid, expired or revoked.",
|
|
74
|
-
"store-unreachable": "The access token could not be verified right now.",
|
|
75
|
-
"adapter-failed": "The access token could not be verified right now."
|
|
76
|
-
};
|
|
77
|
-
var challengeReason = async (oauth, ctx, token) => {
|
|
78
|
-
if (!token) return "no-credential";
|
|
79
|
-
try {
|
|
80
|
-
const record = await getAccess(oauth.adapters.store, token);
|
|
81
|
-
if (record) {
|
|
82
|
-
const credential = record.credential ?? token;
|
|
83
|
-
ctx.req.headers["x-access-token"] = credential;
|
|
84
|
-
ctx.req.headers.authorization = `Bearer ${credential}`;
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
} catch {
|
|
88
|
-
return "store-unreachable";
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
return await ctx.config.adapters.getGrant?.(ctx.req) === void 0 ? "unknown-credential" : void 0;
|
|
92
|
-
} catch {
|
|
93
|
-
return "adapter-failed";
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
/** The protected-resource half of OAuth: an MCP call that presents no bearer this server can verify is refused
|
|
97
|
-
* with RFC 6750's challenge instead of being served the anonymous surface. That 401 is the whole handshake — it
|
|
98
|
-
* is how a host learns the server needs authorization, where its metadata lives and which scopes to ask for, and
|
|
99
|
-
* a 200 tells it none of that. Only the JSON-RPC POST is guarded: the CORS preflight, the GET 405 and the
|
|
100
|
-
* discovery probes carry no credential and must keep answering as they do.
|
|
101
|
-
*
|
|
102
|
-
* Mounted only when `oauth` is configured. A deployment that configures none keeps the open server it had, where
|
|
103
|
-
* the whole public surface — handshake, listings, the guide, plitzi_render — answers without a token; with OAuth
|
|
104
|
-
* on, the grant that carries no space is what covers that same ground. */
|
|
105
|
-
var createOAuthGuardStage = (oauth) => async (ctx) => {
|
|
106
|
-
if (!oauth || ctx.req.method !== "POST") return false;
|
|
107
|
-
const reason = await challengeReason(oauth, ctx, bearerOf(ctx.req));
|
|
108
|
-
if (!reason) return false;
|
|
109
|
-
ctx.operation = `oauth-challenge:${reason}`;
|
|
110
|
-
sendChallenge(oauth, ctx.req, ctx.res, CHALLENGE_DESCRIPTIONS[reason]);
|
|
111
|
-
return true;
|
|
112
|
-
};
|
|
113
|
-
//#endregion
|
|
114
|
-
export { createOAuthGuardStage, createOAuthStage };
|
/package/dist/modules/mcp/catalogs/{builtinTransformers.test.d.ts → pluginCatalog.test.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|