mcp-trellis 0.1.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/LICENSE +21 -0
- package/README.md +595 -0
- package/dist/adapters/node.d.ts +47 -0
- package/dist/adapters/node.d.ts.map +1 -0
- package/dist/adapters/node.js +116 -0
- package/dist/adapters/node.js.map +1 -0
- package/dist/app.d.ts +69 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +101 -0
- package/dist/app.js.map +1 -0
- package/dist/auth/bearer.d.ts +21 -0
- package/dist/auth/bearer.d.ts.map +1 -0
- package/dist/auth/bearer.js +32 -0
- package/dist/auth/bearer.js.map +1 -0
- package/dist/clients.d.ts +33 -0
- package/dist/clients.d.ts.map +1 -0
- package/dist/clients.js +63 -0
- package/dist/clients.js.map +1 -0
- package/dist/dispatch.d.ts +7 -0
- package/dist/dispatch.d.ts.map +1 -0
- package/dist/dispatch.js +79 -0
- package/dist/dispatch.js.map +1 -0
- package/dist/http.d.ts +17 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +38 -0
- package/dist/http.js.map +1 -0
- package/dist/jsonrpc.d.ts +32 -0
- package/dist/jsonrpc.d.ts.map +1 -0
- package/dist/jsonrpc.js +17 -0
- package/dist/jsonrpc.js.map +1 -0
- package/dist/methods.d.ts +52 -0
- package/dist/methods.d.ts.map +1 -0
- package/dist/methods.js +114 -0
- package/dist/methods.js.map +1 -0
- package/dist/oauth/authorize.d.ts +3 -0
- package/dist/oauth/authorize.d.ts.map +1 -0
- package/dist/oauth/authorize.js +109 -0
- package/dist/oauth/authorize.js.map +1 -0
- package/dist/oauth/base64url.d.ts +5 -0
- package/dist/oauth/base64url.d.ts.map +1 -0
- package/dist/oauth/base64url.js +17 -0
- package/dist/oauth/base64url.js.map +1 -0
- package/dist/oauth/clientauth.d.ts +19 -0
- package/dist/oauth/clientauth.d.ts.map +1 -0
- package/dist/oauth/clientauth.js +76 -0
- package/dist/oauth/clientauth.js.map +1 -0
- package/dist/oauth/codes.d.ts +30 -0
- package/dist/oauth/codes.d.ts.map +1 -0
- package/dist/oauth/codes.js +93 -0
- package/dist/oauth/codes.js.map +1 -0
- package/dist/oauth/constants.d.ts +32 -0
- package/dist/oauth/constants.d.ts.map +1 -0
- package/dist/oauth/constants.js +30 -0
- package/dist/oauth/constants.js.map +1 -0
- package/dist/oauth/metadata.d.ts +45 -0
- package/dist/oauth/metadata.d.ts.map +1 -0
- package/dist/oauth/metadata.js +36 -0
- package/dist/oauth/metadata.js.map +1 -0
- package/dist/oauth/pkce.d.ts +4 -0
- package/dist/oauth/pkce.d.ts.map +1 -0
- package/dist/oauth/pkce.js +17 -0
- package/dist/oauth/pkce.js.map +1 -0
- package/dist/oauth/redirect.d.ts +11 -0
- package/dist/oauth/redirect.d.ts.map +1 -0
- package/dist/oauth/redirect.js +26 -0
- package/dist/oauth/redirect.js.map +1 -0
- package/dist/oauth/resource.d.ts +7 -0
- package/dist/oauth/resource.d.ts.map +1 -0
- package/dist/oauth/resource.js +44 -0
- package/dist/oauth/resource.js.map +1 -0
- package/dist/oauth/revoke.d.ts +4 -0
- package/dist/oauth/revoke.d.ts.map +1 -0
- package/dist/oauth/revoke.js +30 -0
- package/dist/oauth/revoke.js.map +1 -0
- package/dist/oauth/router.d.ts +18 -0
- package/dist/oauth/router.d.ts.map +1 -0
- package/dist/oauth/router.js +105 -0
- package/dist/oauth/router.js.map +1 -0
- package/dist/oauth/scope.d.ts +11 -0
- package/dist/oauth/scope.d.ts.map +1 -0
- package/dist/oauth/scope.js +24 -0
- package/dist/oauth/scope.js.map +1 -0
- package/dist/oauth/token.d.ts +3 -0
- package/dist/oauth/token.d.ts.map +1 -0
- package/dist/oauth/token.js +137 -0
- package/dist/oauth/token.js.map +1 -0
- package/dist/oauth/types.d.ts +115 -0
- package/dist/oauth/types.d.ts.map +1 -0
- package/dist/oauth/types.js +28 -0
- package/dist/oauth/types.js.map +1 -0
- package/dist/oauth/wellknown.d.ts +8 -0
- package/dist/oauth/wellknown.d.ts.map +1 -0
- package/dist/oauth/wellknown.js +35 -0
- package/dist/oauth/wellknown.js.map +1 -0
- package/dist/protocol.d.ts +4 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +14 -0
- package/dist/protocol.js.map +1 -0
- package/dist/registry.d.ts +37 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +61 -0
- package/dist/registry.js.map +1 -0
- package/dist/server.d.ts +11 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +11 -0
- package/dist/server.js.map +1 -0
- package/dist/tools.d.ts +80 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +97 -0
- package/dist/tools.js.map +1 -0
- package/dist/validate.d.ts +23 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +88 -0
- package/dist/validate.js.map +1 -0
- package/docs/diagrams/architecture.svg +1 -0
- package/docs/diagrams/first-connection.svg +1 -0
- package/docs/diagrams/ports.svg +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** OAuth scope handling — space-delimited sets (RFC 6749 §3.3). */
|
|
2
|
+
import { OAUTH_ERRORS } from "./constants.js";
|
|
3
|
+
import { oauthError } from "./types.js";
|
|
4
|
+
export const parseScope = (raw) => raw
|
|
5
|
+
.split(" ")
|
|
6
|
+
.map((entry) => entry.trim())
|
|
7
|
+
.filter((entry) => entry.length > 0);
|
|
8
|
+
export const formatScope = (scopes) => scopes.join(" ");
|
|
9
|
+
/**
|
|
10
|
+
* Scopes the client asked for, or the full advertised set when `scope` is omitted.
|
|
11
|
+
* Duplicates are collapsed so the granted string is stable.
|
|
12
|
+
*/
|
|
13
|
+
export const requestedScopes = (raw, advertised) => {
|
|
14
|
+
const parsed = raw ? parseScope(raw) : [...advertised];
|
|
15
|
+
return [...new Set(parsed)];
|
|
16
|
+
};
|
|
17
|
+
/** Any scope outside the advertised set → invalid_scope. */
|
|
18
|
+
export const firstScopeError = (requested, advertised) => {
|
|
19
|
+
const unknown = requested.find((scope) => !advertised.includes(scope));
|
|
20
|
+
if (unknown === undefined)
|
|
21
|
+
return null;
|
|
22
|
+
return oauthError(OAUTH_ERRORS.invalidScope, 400, `unsupported scope: ${unknown}`);
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/oauth/scope.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAY,EAAE,CAClD,GAAG;KACA,KAAK,CAAC,GAAG,CAAC;KACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;KAC5B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAEzC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAgB,EAAU,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,GAAW,EACX,UAAoB,EACV,EAAE;IACZ,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;IACvD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,4DAA4D;AAC5D,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,SAAmB,EACnB,UAAoB,EACH,EAAE;IACnB,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACvC,OAAO,UAAU,CACf,YAAY,CAAC,YAAY,EACzB,GAAG,EACH,sBAAsB,OAAO,EAAE,CAChC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/oauth/token.ts"],"names":[],"mappings":"AAUA,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAC;AA4KpB,eAAO,MAAM,WAAW,GACtB,SAAS,OAAO,EAChB,SAAS,kBAAkB,KAC1B,OAAO,CAAC,QAAQ,CA4ClB,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { requireHttpMethod } from "../http.js";
|
|
2
|
+
import { firstClientAuthError, readClientAuth } from "./clientauth.js";
|
|
3
|
+
import { consumeAuthCode } from "./codes.js";
|
|
4
|
+
import { GRANT_TYPES, OAUTH_ERRORS } from "./constants.js";
|
|
5
|
+
import { verifyPkceS256 } from "./pkce.js";
|
|
6
|
+
import { canonicalResource, firstResourceError, resourcesEqual, } from "./resource.js";
|
|
7
|
+
import { oauthError, resolveSecret, tokenResponse, } from "./types.js";
|
|
8
|
+
const POST_ONLY = new Set(["POST"]);
|
|
9
|
+
const NO_CORS = { cors: false };
|
|
10
|
+
const readJsonBody = async (request) => {
|
|
11
|
+
const body = (await request.json());
|
|
12
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
13
|
+
throw new Error("malformed request body");
|
|
14
|
+
}
|
|
15
|
+
return Object.fromEntries(Object.entries(body)
|
|
16
|
+
.filter(([, value]) => value != null)
|
|
17
|
+
.map(([key, value]) => [key, String(value)]));
|
|
18
|
+
};
|
|
19
|
+
const readFormBody = async (request) => {
|
|
20
|
+
const params = new URLSearchParams(await request.text());
|
|
21
|
+
return Object.fromEntries([...params.entries()]);
|
|
22
|
+
};
|
|
23
|
+
const BODY_READERS = [
|
|
24
|
+
{ match: (ctype) => ctype.includes("application/json"), read: readJsonBody },
|
|
25
|
+
{ match: () => true, read: readFormBody },
|
|
26
|
+
];
|
|
27
|
+
const readTokenBody = async (request) => {
|
|
28
|
+
const ctype = request.headers.get("Content-Type") ?? "";
|
|
29
|
+
const reader = BODY_READERS.find((entry) => entry.match(ctype))?.read ?? readFormBody;
|
|
30
|
+
return reader(request);
|
|
31
|
+
};
|
|
32
|
+
const handleRefresh = async ({ body, options, expectedResource, clientId, }) => {
|
|
33
|
+
if (!options.ports.refreshAccessToken) {
|
|
34
|
+
return oauthError(OAUTH_ERRORS.unsupportedGrantType, 400, "refresh_token not enabled");
|
|
35
|
+
}
|
|
36
|
+
const refreshToken = body.refresh_token ?? "";
|
|
37
|
+
if (!refreshToken) {
|
|
38
|
+
return oauthError(OAUTH_ERRORS.invalidRequest, 400, "refresh_token required");
|
|
39
|
+
}
|
|
40
|
+
const resourceError = firstResourceError(body.resource ?? "", expectedResource);
|
|
41
|
+
if (resourceError)
|
|
42
|
+
return resourceError;
|
|
43
|
+
// ponytail: AS cannot verify the refresh token's original audience; the port owns that check.
|
|
44
|
+
const minted = await options.ports.refreshAccessToken({
|
|
45
|
+
refreshToken,
|
|
46
|
+
clientId,
|
|
47
|
+
resource: expectedResource,
|
|
48
|
+
});
|
|
49
|
+
if (!minted) {
|
|
50
|
+
return oauthError(OAUTH_ERRORS.invalidGrant, 400, "invalid refresh_token");
|
|
51
|
+
}
|
|
52
|
+
return tokenResponse(minted);
|
|
53
|
+
};
|
|
54
|
+
const firstAuthCodeMismatch = (record, body, clientId) => {
|
|
55
|
+
const rule = [
|
|
56
|
+
{
|
|
57
|
+
ok: record.redirectUri === (body.redirect_uri ?? ""),
|
|
58
|
+
description: "redirect_uri mismatch",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
ok: record.clientId === clientId,
|
|
62
|
+
description: "client_id mismatch",
|
|
63
|
+
},
|
|
64
|
+
].find((entry) => !entry.ok);
|
|
65
|
+
return rule
|
|
66
|
+
? oauthError(OAUTH_ERRORS.invalidGrant, 400, rule.description)
|
|
67
|
+
: null;
|
|
68
|
+
};
|
|
69
|
+
const handleAuthCode = async ({ request, body, options, expectedResource, clientId, }) => {
|
|
70
|
+
const resourceError = firstResourceError(body.resource ?? "", expectedResource);
|
|
71
|
+
if (resourceError)
|
|
72
|
+
return resourceError;
|
|
73
|
+
const secret = await resolveSecret(options.ports, request);
|
|
74
|
+
const record = await consumeAuthCode(secret, body.code ?? "", {
|
|
75
|
+
codeStore: options.ports.codeStore,
|
|
76
|
+
});
|
|
77
|
+
if (!record) {
|
|
78
|
+
return oauthError(OAUTH_ERRORS.invalidGrant, 400, "invalid or expired code");
|
|
79
|
+
}
|
|
80
|
+
const mismatch = firstAuthCodeMismatch(record, body, clientId);
|
|
81
|
+
if (mismatch)
|
|
82
|
+
return mismatch;
|
|
83
|
+
if (!resourcesEqual(record.resource, expectedResource)) {
|
|
84
|
+
return oauthError(OAUTH_ERRORS.invalidTarget, 400, "auth code bound to a different resource");
|
|
85
|
+
}
|
|
86
|
+
if (!(await verifyPkceS256(body.code_verifier ?? "", record.codeChallenge))) {
|
|
87
|
+
return oauthError(OAUTH_ERRORS.invalidGrant, 400, "pkce verification failed");
|
|
88
|
+
}
|
|
89
|
+
const minted = await options.ports.mintAccessToken({
|
|
90
|
+
userId: record.userId,
|
|
91
|
+
clientId,
|
|
92
|
+
scope: record.scope,
|
|
93
|
+
resource: record.resource,
|
|
94
|
+
});
|
|
95
|
+
return tokenResponse(minted, record.scope);
|
|
96
|
+
};
|
|
97
|
+
const GRANT_HANDLERS = {
|
|
98
|
+
[GRANT_TYPES.authorizationCode]: handleAuthCode,
|
|
99
|
+
[GRANT_TYPES.refreshToken]: handleRefresh,
|
|
100
|
+
};
|
|
101
|
+
export const handleToken = async (request, options) => {
|
|
102
|
+
const methodError = requireHttpMethod(request, POST_ONLY, NO_CORS);
|
|
103
|
+
if (methodError)
|
|
104
|
+
return methodError;
|
|
105
|
+
let body;
|
|
106
|
+
try {
|
|
107
|
+
body = await readTokenBody(request);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return oauthError(OAUTH_ERRORS.invalidRequest, 400, "malformed request body");
|
|
111
|
+
}
|
|
112
|
+
const auth = readClientAuth(request, body);
|
|
113
|
+
if (!auth) {
|
|
114
|
+
return oauthError(OAUTH_ERRORS.invalidRequest, 400, "client_id required");
|
|
115
|
+
}
|
|
116
|
+
const clientAuthError = await firstClientAuthError(auth, options);
|
|
117
|
+
if (clientAuthError)
|
|
118
|
+
return clientAuthError;
|
|
119
|
+
const url = new URL(request.url);
|
|
120
|
+
const expectedResource = canonicalResource(url.origin, options.resourcePath);
|
|
121
|
+
const handler = GRANT_HANDLERS[body.grant_type ?? ""];
|
|
122
|
+
if (!handler) {
|
|
123
|
+
const supported = [GRANT_TYPES.authorizationCode];
|
|
124
|
+
if (options.ports.refreshAccessToken) {
|
|
125
|
+
supported.push(GRANT_TYPES.refreshToken);
|
|
126
|
+
}
|
|
127
|
+
return oauthError(OAUTH_ERRORS.unsupportedGrantType, 400, `supported: ${supported.join(", ")}`);
|
|
128
|
+
}
|
|
129
|
+
return handler({
|
|
130
|
+
request,
|
|
131
|
+
body,
|
|
132
|
+
options,
|
|
133
|
+
expectedResource,
|
|
134
|
+
clientId: auth.clientId,
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/oauth/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAuB,MAAM,YA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oBAAoB,EACjC,GAAG,EACH,cAAc,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACrC,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;QACb,OAAO;QACP,IAAI;QACJ,OAAO;QACP,gBAAgB;QAChB,QAAQ,EAAE,IAAI,CAAC,QAAQ;KACxB,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type TokenEndpointAuthMethod } from "./constants.js";
|
|
2
|
+
import type { CodeStore } from "./codes.js";
|
|
3
|
+
import type { RedirectAllowlistOptions } from "./redirect.js";
|
|
4
|
+
export type OAuthUser = {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A client registered ahead of time (pre-registration).
|
|
9
|
+
* Gemini Enterprise and other confidential clients arrive this way —
|
|
10
|
+
* the org registers with its own IdP and configures the pair here.
|
|
11
|
+
*/
|
|
12
|
+
export type RegisteredClient = {
|
|
13
|
+
clientId: string;
|
|
14
|
+
/** Exact-match redirect URIs. Checked instead of the global allowlist. */
|
|
15
|
+
redirectUris: string[];
|
|
16
|
+
tokenEndpointAuthMethod: TokenEndpointAuthMethod;
|
|
17
|
+
};
|
|
18
|
+
export type ClientStore = {
|
|
19
|
+
/** Resolve a pre-registered client, or null when unknown. */
|
|
20
|
+
get: (clientId: string) => Promise<RegisteredClient | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Verify a presented client secret. Required for confidential clients.
|
|
23
|
+
* Secret storage and comparison stay in your implementation — the library
|
|
24
|
+
* never sees or persists credentials.
|
|
25
|
+
*/
|
|
26
|
+
verifySecret?: (clientId: string, presented: string) => Promise<boolean>;
|
|
27
|
+
};
|
|
28
|
+
export type MintedToken = {
|
|
29
|
+
accessToken: string;
|
|
30
|
+
tokenType?: string;
|
|
31
|
+
expiresIn: number;
|
|
32
|
+
scope?: string;
|
|
33
|
+
refreshToken?: string;
|
|
34
|
+
};
|
|
35
|
+
export type MintAccessTokenInput = {
|
|
36
|
+
userId: string;
|
|
37
|
+
clientId: string;
|
|
38
|
+
scope: string;
|
|
39
|
+
/** RFC 8707 resource — mint with aud bound to this URI. */
|
|
40
|
+
resource: string;
|
|
41
|
+
};
|
|
42
|
+
export type RefreshAccessTokenInput = {
|
|
43
|
+
refreshToken: string;
|
|
44
|
+
clientId: string;
|
|
45
|
+
/**
|
|
46
|
+
* RFC 8707 resource for the refreshed access token.
|
|
47
|
+
* Implementations MUST reject refresh tokens not originally issued for this resource.
|
|
48
|
+
*/
|
|
49
|
+
resource: string;
|
|
50
|
+
};
|
|
51
|
+
export type RevokeTokenInput = {
|
|
52
|
+
token: string;
|
|
53
|
+
clientId: string;
|
|
54
|
+
tokenTypeHint?: "access_token" | "refresh_token";
|
|
55
|
+
};
|
|
56
|
+
export type OAuthPorts = {
|
|
57
|
+
/** HMAC secret for signing auth codes. */
|
|
58
|
+
codeSecret: string | ((req: Request) => string | Promise<string>);
|
|
59
|
+
/** Resolve the logged-in user, or null → redirect to login. */
|
|
60
|
+
resolveUser: (req: Request) => Promise<OAuthUser | null>;
|
|
61
|
+
/** Where to send unauthenticated authorize requests. */
|
|
62
|
+
loginUrl: (req: Request, nextPath: string) => string;
|
|
63
|
+
/** Mint an access token bound to the consenting user and resource audience. */
|
|
64
|
+
mintAccessToken: (input: MintAccessTokenInput) => Promise<MintedToken>;
|
|
65
|
+
/** Optional refresh_token grant. Presence advertises the grant. */
|
|
66
|
+
refreshAccessToken?: (input: RefreshAccessTokenInput) => Promise<MintedToken | null>;
|
|
67
|
+
/**
|
|
68
|
+
* RFC 7009. Presence mounts `/revoke` and advertises `revocation_endpoint`.
|
|
69
|
+
* Well-formed authenticated revoke is HTTP 200 even if the token is unknown
|
|
70
|
+
* (`invalid_request` / `invalid_client` still apply). `verifyToken` and
|
|
71
|
+
* `refreshAccessToken` MUST consult the same store; unknown tokens and
|
|
72
|
+
* tokens not issued to `clientId` MUST no-op (not throw).
|
|
73
|
+
*/
|
|
74
|
+
revokeToken?: (input: RevokeTokenInput) => Promise<void>;
|
|
75
|
+
/** Shared single-use jti store for multi-instance; in-memory default otherwise. */
|
|
76
|
+
codeStore?: CodeStore;
|
|
77
|
+
/** Pre-registered clients. Required to serve confidential clients. */
|
|
78
|
+
clientStore?: ClientStore;
|
|
79
|
+
};
|
|
80
|
+
export type OAuthRouterOptions = {
|
|
81
|
+
ports: OAuthPorts;
|
|
82
|
+
resourcePath?: string;
|
|
83
|
+
oauthPath?: string;
|
|
84
|
+
realm?: string;
|
|
85
|
+
scopes?: string[];
|
|
86
|
+
redirect?: RedirectAllowlistOptions;
|
|
87
|
+
/** Advertised in AS metadata. Defaults to `["none"]` (public clients only). */
|
|
88
|
+
tokenEndpointAuthMethods?: TokenEndpointAuthMethod[];
|
|
89
|
+
/**
|
|
90
|
+
* Allow a `client_id` not resolved by `clientStore` to authorize and
|
|
91
|
+
* exchange tokens as a public client (PKCE only — no secret).
|
|
92
|
+
*
|
|
93
|
+
* Default **true** (DCR / CIMD connectors). Set **false** when every
|
|
94
|
+
* client is pre-registered: `/register` is unmounted, dropped from AS
|
|
95
|
+
* metadata, and an unrecognized `client_id` is rejected with
|
|
96
|
+
* `unauthorized_client` at `authorize` and `invalid_client` at `token`
|
|
97
|
+
* and `revoke`. `createMcpApp` derives this from `clients` via
|
|
98
|
+
* `hasDynamicClient`.
|
|
99
|
+
*/
|
|
100
|
+
allowUnregisteredClients?: boolean;
|
|
101
|
+
};
|
|
102
|
+
/** Default true — see `OAuthRouterOptions.allowUnregisteredClients`. */
|
|
103
|
+
export declare const unregisteredClientsAllowed: (options: OAuthRouterOptions) => boolean;
|
|
104
|
+
/** Scopes this AS advertises and is willing to grant. */
|
|
105
|
+
export declare const advertisedScopes: (options: OAuthRouterOptions) => string[];
|
|
106
|
+
export declare const resolveSecret: (ports: OAuthPorts, req: Request) => Promise<string>;
|
|
107
|
+
export declare const oauthError: (error: string, status: number, description?: string) => Response;
|
|
108
|
+
/** Direct JSON error when this AS does not serve unknown `client_id`s. */
|
|
109
|
+
export declare const unregisteredClientError: (options: OAuthRouterOptions, reject: {
|
|
110
|
+
code: string;
|
|
111
|
+
status: number;
|
|
112
|
+
}) => Response | null;
|
|
113
|
+
/** `grantedScope` is what the auth code carried; the port may narrow it further. */
|
|
114
|
+
export declare const tokenResponse: (minted: MintedToken, grantedScope?: string) => Response;
|
|
115
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAG9D,MAAM,MAAM,SAAS,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,uBAAuB,EAAE,uBAAuB,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,6DAA6D;IAC7D,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC5D;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1E,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MA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3
|
+
/** Default true — see `OAuthRouterOptions.allowUnregisteredClients`. */
|
|
4
|
+
export const unregisteredClientsAllowed = (options) => options.allowUnregisteredClients !== false;
|
|
5
|
+
/** Scopes this AS advertises and is willing to grant. */
|
|
6
|
+
export const advertisedScopes = (options) => options.scopes ?? [DEFAULT_SCOPE];
|
|
7
|
+
export const resolveSecret = async (ports, req) => {
|
|
8
|
+
if (typeof ports.codeSecret === "string")
|
|
9
|
+
return ports.codeSecret;
|
|
10
|
+
return ports.codeSecret(req);
|
|
11
|
+
};
|
|
12
|
+
export const oauthError = (error, status, description) => jsonResponse(description ? { error, error_description: description } : { error }, status, undefined, { cors: false });
|
|
13
|
+
const UNREGISTERED_CLIENT_DESCRIPTION = "unknown client_id — this server only serves pre-registered clients";
|
|
14
|
+
/** Direct JSON error when this AS does not serve unknown `client_id`s. */
|
|
15
|
+
export const unregisteredClientError = (options, reject) => {
|
|
16
|
+
if (unregisteredClientsAllowed(options))
|
|
17
|
+
return null;
|
|
18
|
+
return oauthError(reject.code, reject.status, UNREGISTERED_CLIENT_DESCRIPTION);
|
|
19
|
+
};
|
|
20
|
+
/** `grantedScope` is what the auth code carried; the port may narrow it further. */
|
|
21
|
+
export const tokenResponse = (minted, grantedScope) => jsonResponse({
|
|
22
|
+
access_token: minted.accessToken,
|
|
23
|
+
token_type: minted.tokenType ?? "bearer",
|
|
24
|
+
expires_in: minted.expiresIn,
|
|
25
|
+
scope: minted.scope ?? grantedScope ?? DEFAULT_SCOPE,
|
|
26
|
+
...(minted.refreshToken ? { refresh_token: minted.refreshToken } : {}),
|
|
27
|
+
}, 200, undefined, { cors: false });
|
|
28
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgC,MAAM,gBAAgB,CAAC;AAG7E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY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AAU,EAAE,MAAM,CAAC,SAAS,IAAI,QAAQ;IACxC,UAAU,EAAE,MAAM,CAAC,SAAS;IAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,YAAY,IAAI,aAAa;IACpD,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;CACvE,EACD,GAAG,EACH,SAAS,EACT,EAAE,IAAI,EAAE,KAAK,EAAE,CAChB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type OAuthRouterOptions } from "./types.js";
|
|
2
|
+
export declare const handleWellKnown: (request: Request, options: OAuthRouterOptions, paths: {
|
|
3
|
+
prmPaths: Set<string>;
|
|
4
|
+
asPaths: Set<string>;
|
|
5
|
+
resourcePath: string;
|
|
6
|
+
oauthPath: string;
|
|
7
|
+
}) => Promise<Response | null>;
|
|
8
|
+
//# sourceMappingURL=wellknown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wellknown.d.ts","sourceRoot":"","sources":["../../src/oauth/wellknown.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAC;AAUpB,eAAO,MAAM,eAAe,GAC1B,SAAS,OAAO,EAChB,SAAS,kBAAkB,EAC3B,OAAO;IACL,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,KACA,OAAO,CAAC,QAAQ,GAAG,IAAI,CAuBzB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsonResponse, requireHttpMethod } from "../http.js";
|
|
2
|
+
import { authorizationServerMetadata, protectedResourceMetadata, } from "./metadata.js";
|
|
3
|
+
import { GRANT_TYPES } from "./constants.js";
|
|
4
|
+
import { unregisteredClientsAllowed, } from "./types.js";
|
|
5
|
+
const GET_ONLY = new Set(["GET"]);
|
|
6
|
+
const grantTypesOf = (ports) => {
|
|
7
|
+
const grants = [GRANT_TYPES.authorizationCode];
|
|
8
|
+
if (ports.refreshAccessToken)
|
|
9
|
+
grants.push(GRANT_TYPES.refreshToken);
|
|
10
|
+
return grants;
|
|
11
|
+
};
|
|
12
|
+
export const handleWellKnown = async (request, options, paths) => {
|
|
13
|
+
const url = new URL(request.url);
|
|
14
|
+
const path = url.pathname;
|
|
15
|
+
if (!paths.prmPaths.has(path) && !paths.asPaths.has(path))
|
|
16
|
+
return null;
|
|
17
|
+
const methodError = requireHttpMethod(request, GET_ONLY);
|
|
18
|
+
if (methodError)
|
|
19
|
+
return methodError;
|
|
20
|
+
const metaOpts = {
|
|
21
|
+
origin: url.origin,
|
|
22
|
+
resourcePath: paths.resourcePath,
|
|
23
|
+
oauthPath: paths.oauthPath,
|
|
24
|
+
grantTypes: grantTypesOf(options.ports),
|
|
25
|
+
scopes: options.scopes,
|
|
26
|
+
tokenEndpointAuthMethods: options.tokenEndpointAuthMethods,
|
|
27
|
+
dcrEnabled: unregisteredClientsAllowed(options),
|
|
28
|
+
revocationEnabled: Boolean(options.ports.revokeToken),
|
|
29
|
+
};
|
|
30
|
+
const body = paths.prmPaths.has(path)
|
|
31
|
+
? protectedResourceMetadata(metaOpts)
|
|
32
|
+
: authorizationServerMetadata(metaOpts);
|
|
33
|
+
return jsonResponse(body);
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=wellknown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wellknown.js","sourceRoot":"","sources":["../../src/oauth/wellknown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,GAE1B,MAAM,eAAe,C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iBAAiB,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC;KACtD,CAAC;IAEF,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;QACnC,CAAC,CAAC,yBAAyB,CAAC,QAAQ,CAAC;QACrC,CAAC,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC;IAC1C,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,aAI5B,CAAC;AAEH,eAAO,MAAM,wBAAwB,eAAe,CAAC;AAErD,eAAO,MAAM,mBAAmB,GAC9B,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,MAMF,CAAC"}
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const PROTOCOL_VERSIONS = new Set([
|
|
2
|
+
"2024-11-05",
|
|
3
|
+
"2025-03-26",
|
|
4
|
+
"2025-06-18",
|
|
5
|
+
]);
|
|
6
|
+
export const DEFAULT_PROTOCOL_VERSION = "2024-11-05";
|
|
7
|
+
export const pickProtocolVersion = (params) => {
|
|
8
|
+
const requested = params?.protocolVersion;
|
|
9
|
+
if (typeof requested === "string" && PROTOCOL_VERSIONS.has(requested)) {
|
|
10
|
+
return requested;
|
|
11
|
+
}
|
|
12
|
+
return DEFAULT_PROTOCOL_VERSION;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IACvC,YAAY;IACZ,YAAY;IACZ,YAAY;CACb,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC;AAErD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAAgC,EACxB,EAAE;IACV,MAAM,SAAS,GAAG,MAAM,EAAE,eAAe,CAAC;IAC1C,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;QACtE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { JsonSchema } from "./validate.js";
|
|
2
|
+
export type ToolResult = {
|
|
3
|
+
content: Array<{
|
|
4
|
+
type: "text";
|
|
5
|
+
text: string;
|
|
6
|
+
}>;
|
|
7
|
+
isError?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type ToolHandler<TCtx> = (ctx: TCtx, args: Record<string, unknown>) => Promise<ToolResult | string> | ToolResult | string;
|
|
10
|
+
export type ToolDef<TCtx> = {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
inputSchema: JsonSchema;
|
|
14
|
+
scope?: string;
|
|
15
|
+
handler: ToolHandler<TCtx>;
|
|
16
|
+
};
|
|
17
|
+
export type ToolListEntry = {
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
inputSchema: JsonSchema;
|
|
21
|
+
};
|
|
22
|
+
export type ToolRegistry<TCtx> = {
|
|
23
|
+
list: () => ToolListEntry[];
|
|
24
|
+
get: (name: string) => ToolDef<TCtx> | undefined;
|
|
25
|
+
call: (name: string, ctx: TCtx, args: Record<string, unknown>) => Promise<ToolResult>;
|
|
26
|
+
};
|
|
27
|
+
export type RegistryOptions = {
|
|
28
|
+
/** Validate tools/call args against inputSchema. Default false. */
|
|
29
|
+
validateArgs?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Map tool exceptions to client-visible text.
|
|
32
|
+
* Default: `"Tool execution failed"` (no exception leakage).
|
|
33
|
+
*/
|
|
34
|
+
onToolError?: (exc: unknown) => string;
|
|
35
|
+
};
|
|
36
|
+
export declare const createToolRegistry: <TCtx>(tools: ToolDef<TCtx>[], options?: RegistryOptions) => ToolRegistry<TCtx>;
|
|
37
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,IAAI,IAAI,CAC9B,GAAG,EAAE,IAAI,EACT,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,OAAO,CAAC,UAAU,GAAG,MAAM,CAAC,GAAG,UAAU,GAAG,MAAM,CAAC;AAExD,MAAM,MAAM,OAAO,CAAC,IAAI,IAAI;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,UAAU,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,UAAU,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,IAAI,IAAI;IAC/B,IAAI,EAAE,MAAM,aAAa,EAAE,CAAC;IAC5B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IACjD,IAAI,EAAE,CACJ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,IAAI,EACT,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,OAAO,CAAC,UAAU,CAAC,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,mEAAmE;IACnE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;CACxC,CAAC;AAoCF,eAAO,MAAM,kBAAkB,GAAI,IAAI,EACrC,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,EACtB,UAAS,eAAoB,KAC5B,YAAY,CAAC,IAAI,CAgCnB,CAAC"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { validateAgainstSchema } from "./validate.js";
|
|
2
|
+
const DEFAULT_TOOL_ERROR = "Tool execution failed";
|
|
3
|
+
/**
|
|
4
|
+
* Map a tool exception to client-visible text.
|
|
5
|
+
* A throwing or non-string `onToolError` falls back to the redacted default —
|
|
6
|
+
* a mapper must never turn a tool failure into a transport failure.
|
|
7
|
+
*/
|
|
8
|
+
const resolveToolError = (exc, onToolError) => {
|
|
9
|
+
if (!onToolError)
|
|
10
|
+
return DEFAULT_TOOL_ERROR;
|
|
11
|
+
try {
|
|
12
|
+
const mapped = onToolError(exc);
|
|
13
|
+
return typeof mapped === "string" && mapped.length > 0
|
|
14
|
+
? mapped
|
|
15
|
+
: DEFAULT_TOOL_ERROR;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return DEFAULT_TOOL_ERROR;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const asToolResult = (out) => {
|
|
22
|
+
if (typeof out === "string") {
|
|
23
|
+
return { content: [{ type: "text", text: out }], isError: false };
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
};
|
|
27
|
+
const errorResult = (message) => ({
|
|
28
|
+
content: [{ type: "text", text: message }],
|
|
29
|
+
isError: true,
|
|
30
|
+
});
|
|
31
|
+
export const createToolRegistry = (tools, options = {}) => {
|
|
32
|
+
const byName = new Map(tools.map((t) => [t.name, t]));
|
|
33
|
+
if (byName.size !== tools.length) {
|
|
34
|
+
throw new Error("duplicate tool names in registry");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
list: () => tools.map(({ name, description, inputSchema }) => ({
|
|
38
|
+
name,
|
|
39
|
+
description,
|
|
40
|
+
inputSchema,
|
|
41
|
+
})),
|
|
42
|
+
get: (name) => byName.get(name),
|
|
43
|
+
call: async (name, ctx, args) => {
|
|
44
|
+
const tool = byName.get(name);
|
|
45
|
+
if (!tool)
|
|
46
|
+
return errorResult(`Unknown tool: ${name}`);
|
|
47
|
+
if (options.validateArgs) {
|
|
48
|
+
const errors = validateAgainstSchema(args, tool.inputSchema);
|
|
49
|
+
if (errors.length > 0)
|
|
50
|
+
return errorResult(errors.join("; "));
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return asToolResult(await tool.handler(ctx, args));
|
|
54
|
+
}
|
|
55
|
+
catch (exc) {
|
|
56
|
+
return errorResult(resolveToolError(exc, options.onToolError));
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AA8CtD,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAEnD;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,CACvB,GAAY,EACZ,WAA2C,EACnC,EAAE;IACV,IAAI,CAAC,WAAW;QAAE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,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;YACjD,IAAI;YACJ,WAAW;YACX,WAAW;SACZ,CAAC,CAAC;QAEL,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;QAE/B,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YAC9B,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC9B,IAAI,CAAC,IAAI;gBAAE,OAAO,WAAW,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;YAEvD,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;gBACzB,MAAM,MAAM,GAAG,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;gBAC7D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;oBAAE,OAAO,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAC/D,CAAC;YAED,IAAI,CAAC;gBACH,OAAO,YAAY,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;YACrD,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,WAAW,CAAC,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { createMcpApp, type McpApp, type McpAppOptions, type McpAppAuth, type VerifiedToken, } from "./app.js";
|
|
2
|
+
export { CLIENT_PROFILES, DEFAULT_CLIENTS, authMethodsFor, redirectUrisFor, preRegisteredClients, hasDynamicClient, type ClientName, type ClientProfile, } from "./clients.js";
|
|
3
|
+
export { createMcpHandler, type McpHandler, type McpHandlerOptions, type McpPorts, type Principal, type AuditEntry, type ServerInfo, } from "./dispatch.js";
|
|
4
|
+
export { createToolRegistry, type ToolDef, type ToolHandler, type ToolResult, type ToolRegistry, type ToolListEntry, type RegistryOptions, } from "./registry.js";
|
|
5
|
+
export { defineTool, apiTool, type StandardSchemaV1, type DefineToolOptions, type ApiToolOptions, type ApiRequest, } from "./tools.js";
|
|
6
|
+
export { rpcResult, rpcError, JSONRPC_PARSE_ERROR, JSONRPC_INVALID_REQUEST, JSONRPC_METHOD_NOT_FOUND, JSONRPC_INVALID_PARAMS, JSONRPC_INTERNAL_ERROR, JSONRPC_UNAUTHORIZED, type JsonRpcId, type JsonRpcRequest, type JsonRpcResponse, } from "./jsonrpc.js";
|
|
7
|
+
export { pickProtocolVersion, PROTOCOL_VERSIONS, DEFAULT_PROTOCOL_VERSION, } from "./protocol.js";
|
|
8
|
+
export { parseBearer, timingSafeEqual, matchesAny, wwwAuthenticateHeader, rejectQueryToken, type WwwAuthenticateOptions, } from "./auth/bearer.js";
|
|
9
|
+
export { validateAgainstSchema, JSON_SCHEMA_TYPES, type JsonSchema } from "./validate.js";
|
|
10
|
+
export { jsonResponse, emptyResponse, optionsResponse, corsHeaders, methodNotAllowed, } from "./http.js";
|
|
11
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,eAAe,EACf,eAAe,EACf,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,UAAU,GAChB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,kBAAkB,EAClB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,UAAU,EACV,OAAO,EACP,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,UAAU,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,SAAS,EACT,QAAQ,EACR,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,WAAW,EACX,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,sBAAsB,GAC5B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1F,OAAO,EACL,YAAY,EACZ,aAAa,EACb,eAAe,EACf,WAAW,EACX,gBAAgB,GACjB,MAAM,WAAW,CAAC"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { createMcpApp, } from "./app.js";
|
|
2
|
+
export { CLIENT_PROFILES, DEFAULT_CLIENTS, authMethodsFor, redirectUrisFor, preRegisteredClients, hasDynamicClient, } from "./clients.js";
|
|
3
|
+
export { createMcpHandler, } from "./dispatch.js";
|
|
4
|
+
export { createToolRegistry, } from "./registry.js";
|
|
5
|
+
export { defineTool, apiTool, } from "./tools.js";
|
|
6
|
+
export { rpcResult, rpcError, JSONRPC_PARSE_ERROR, JSONRPC_INVALID_REQUEST, JSONRPC_METHOD_NOT_FOUND, JSONRPC_INVALID_PARAMS, JSONRPC_INTERNAL_ERROR, JSONRPC_UNAUTHORIZED, } from "./jsonrpc.js";
|
|
7
|
+
export { pickProtocolVersion, PROTOCOL_VERSIONS, DEFAULT_PROTOCOL_VERSION, } from "./protocol.js";
|
|
8
|
+
export { parseBearer, timingSafeEqual, matchesAny, wwwAuthenticateHeader, rejectQueryToken, } from "./auth/bearer.js";
|
|
9
|
+
export { validateAgainstSchema, JSON_SCHEMA_TYPES } from "./validate.js";
|
|
10
|
+
export { jsonResponse, emptyResponse, optionsResponse, corsHeaders, methodNotAllowed, } from "./http.js";
|
|
11
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAKb,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,eAAe,EACf,eAAe,EACf,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,gBAAgB,GAGjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,GAOjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,kBAAkB,GAOnB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,UAAU,EACV,OAAO,GAKR,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,SAAS,EACT,QAAQ,EACR,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,GAIrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,WAAW,EACX,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAmB,MAAM,eAAe,CAAC;AAE1F,OAAO,EACL,YAAY,EACZ,aAAa,EACb,eAAe,EACf,WAAW,EACX,gBAAgB,GACjB,MAAM,WAAW,CAAC"}
|