@payloadcms/plugin-mcp 4.0.0-canary.20 → 4.0.0-canary.20261117
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/bin.js +0 -7
- package/dist/endpoint/access.d.ts +20 -4
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +73 -11
- package/dist/endpoint/access.js.map +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +58 -4
- package/dist/endpoint/index.js.map +1 -1
- package/dist/endpoint/oauth.d.ts +37 -0
- package/dist/endpoint/oauth.d.ts.map +1 -0
- package/dist/endpoint/oauth.js +105 -0
- package/dist/endpoint/oauth.js.map +1 -0
- package/dist/endpoint/oauthLoginToken.d.ts +27 -0
- package/dist/endpoint/oauthLoginToken.d.ts.map +1 -0
- package/dist/endpoint/oauthLoginToken.js +86 -0
- package/dist/endpoint/oauthLoginToken.js.map +1 -0
- package/dist/endpoint/oauthServer.d.ts +28 -0
- package/dist/endpoint/oauthServer.d.ts.map +1 -0
- package/dist/endpoint/oauthServer.js +455 -0
- package/dist/endpoint/oauthServer.js.map +1 -0
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/rsc.d.ts +2 -0
- package/dist/exports/rsc.d.ts.map +1 -0
- package/dist/exports/rsc.js +3 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -10
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +2 -2
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +36 -24
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/authTools.js +80 -56
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countTool.js +9 -14
- package/dist/mcp/builtin/collections/countTool.js.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.js +9 -13
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +48 -49
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +47 -44
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.js +31 -37
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.d.ts +21 -21
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.js +34 -70
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.js +11 -26
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +28 -46
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +17 -26
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.js +16 -30
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +30 -14
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.js +14 -26
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +55 -87
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +11 -11
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -1
- package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
- package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
- package/dist/mcp/builtin/formatEntityError.js +55 -0
- package/dist/mcp/builtin/formatEntityError.js.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +3 -2
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.js +9 -13
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +10 -16
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +13 -24
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.js +13 -29
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +29 -13
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.js +15 -22
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +27 -36
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +4 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.js +4 -3
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +131 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/seal.d.ts +17 -0
- package/dist/utils/seal.d.ts.map +1 -0
- package/dist/utils/seal.js +24 -0
- package/dist/utils/seal.js.map +1 -0
- package/dist/utils/toStandardSchema.js.map +1 -1
- package/dist/views/Authorize/AllowButtons/index.d.ts +18 -0
- package/dist/views/Authorize/AllowButtons/index.d.ts.map +1 -0
- package/dist/views/Authorize/AllowButtons/index.js +88 -0
- package/dist/views/Authorize/AllowButtons/index.js.map +1 -0
- package/dist/views/Authorize/index.css +19 -0
- package/dist/views/Authorize/index.d.ts +9 -0
- package/dist/views/Authorize/index.d.ts.map +1 -0
- package/dist/views/Authorize/index.js +98 -0
- package/dist/views/Authorize/index.js.map +1 -0
- package/package.json +30 -28
- package/src/endpoint/access.ts +81 -9
- package/src/endpoint/index.ts +50 -4
- package/src/endpoint/oauth.ts +108 -0
- package/src/endpoint/oauthLoginToken.ts +100 -0
- package/src/endpoint/oauthServer.ts +472 -0
- package/src/exports/client.ts +1 -1
- package/src/exports/rsc.ts +1 -0
- package/src/index.ts +53 -9
- package/src/mcp/buildMcpServer.ts +40 -30
- package/src/mcp/builtin/collections/authTools.ts +82 -71
- package/src/mcp/builtin/collections/countTool.ts +9 -21
- package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
- package/src/mcp/builtin/collections/createTool.ts +71 -96
- package/src/mcp/builtin/collections/deleteTool.ts +40 -66
- package/src/mcp/builtin/collections/duplicateTool.ts +36 -86
- package/src/mcp/builtin/collections/fileInput.spec.ts +2 -2
- package/src/mcp/builtin/collections/fileInput.ts +44 -81
- package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
- package/src/mcp/builtin/collections/findTool.ts +24 -106
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
- package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +23 -12
- package/src/mcp/builtin/collections/restoreVersionTool.ts +15 -57
- package/src/mcp/builtin/collections/updateTool.ts +55 -109
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +12 -12
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
- package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
- package/src/mcp/builtin/globals/findTool.ts +13 -52
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
- package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +21 -11
- package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
- package/src/mcp/builtin/globals/updateTool.ts +38 -61
- package/src/mcp/sanitizeMCPConfig.ts +2 -0
- package/src/stdio.ts +2 -2
- package/src/types.ts +130 -10
- package/src/utils/seal.ts +46 -0
- package/src/utils/toStandardSchema.ts +1 -1
- package/src/views/Authorize/AllowButtons/index.tsx +97 -0
- package/src/views/Authorize/index.css +19 -0
- package/src/views/Authorize/index.tsx +100 -0
- package/dist/mcp/builtin/collections/fileInput.spec.js +0 -86
- package/dist/mcp/builtin/collections/fileInput.spec.js.map +0 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
- package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
- package/dist/mcp/builtin/validateEntityData.js +0 -82
- package/dist/mcp/builtin/validateEntityData.js.map +0 -1
- package/dist/utils/getVirtualFieldNames.d.ts +0 -14
- package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
- package/dist/utils/getVirtualFieldNames.js +0 -35
- package/dist/utils/getVirtualFieldNames.js.map +0 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +0 -28
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
- package/dist/utils/transformPointDataToPayload.d.ts +0 -7
- package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
- package/dist/utils/transformPointDataToPayload.js +0 -28
- package/dist/utils/transformPointDataToPayload.js.map +0 -1
- package/dist/utils/whereSchema.d.ts +0 -9
- package/dist/utils/whereSchema.d.ts.map +0 -1
- package/dist/utils/whereSchema.js +0 -13
- package/dist/utils/whereSchema.js.map +0 -1
- package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
- package/src/mcp/builtin/validateEntityData.ts +0 -132
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +0 -123
- package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
- package/src/utils/transformPointDataToPayload.ts +0 -40
- package/src/utils/whereSchema.ts +0 -24
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { APIError, createAuthToken, executeAuthStrategies, redeemRefreshToken } from 'payload';
|
|
2
|
+
import { seal, unseal } from '../utils/seal.js';
|
|
3
|
+
/**
|
|
4
|
+
* The default `issueToken`: a Payload login token, sealed so it only works for MCP, where
|
|
5
|
+
* `authenticateLoginToken` unseals it. Otherwise an MCP client could use it as the user's admin
|
|
6
|
+
* panel login. When the collection uses sessions, the client also gets a refresh token.
|
|
7
|
+
*/ export const issueLoginToken = async ({ client, req })=>{
|
|
8
|
+
const collectionConfig = req.payload.collections[req.user.collection].config;
|
|
9
|
+
if (collectionConfig.auth.disableLocalStrategy) {
|
|
10
|
+
throw new APIError(`MCP clients can't get Payload login tokens for the "${collectionConfig.slug}" collection because its local strategy is disabled. Pass oauth.issueToken to the MCP plugin.`);
|
|
11
|
+
}
|
|
12
|
+
// The full document, like the one a password login starts its session on
|
|
13
|
+
const user = await req.payload.db.findOne({
|
|
14
|
+
collection: collectionConfig.slug,
|
|
15
|
+
req,
|
|
16
|
+
where: {
|
|
17
|
+
id: {
|
|
18
|
+
equals: req.user.id
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const { refreshToken, token } = await createAuthToken({
|
|
23
|
+
type: 'mcp',
|
|
24
|
+
collectionConfig,
|
|
25
|
+
// App schemes like `com.example.app:/callback` have no host
|
|
26
|
+
email: user.email,
|
|
27
|
+
label: client.name,
|
|
28
|
+
metadata: {
|
|
29
|
+
redirectHost: new URL(client.redirectURI).host || client.redirectURI
|
|
30
|
+
},
|
|
31
|
+
req,
|
|
32
|
+
shouldCreateRefreshToken: true,
|
|
33
|
+
user
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
accessToken: sealLoginToken({
|
|
37
|
+
req,
|
|
38
|
+
token
|
|
39
|
+
}),
|
|
40
|
+
expiresIn: collectionConfig.auth.tokenExpiration,
|
|
41
|
+
refreshToken
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/** The default `refreshToken`. Payload logs out the session when a refresh token is reused. */ export const refreshLoginToken = async ({ refreshToken, req, reuseInterval })=>{
|
|
45
|
+
const refreshed = await redeemRefreshToken({
|
|
46
|
+
refreshToken,
|
|
47
|
+
req,
|
|
48
|
+
reuseInterval
|
|
49
|
+
});
|
|
50
|
+
return refreshed && {
|
|
51
|
+
accessToken: sealLoginToken({
|
|
52
|
+
req,
|
|
53
|
+
token: refreshed.token
|
|
54
|
+
}),
|
|
55
|
+
expiresIn: refreshed.collectionConfig.auth.tokenExpiration,
|
|
56
|
+
refreshToken: refreshed.refreshToken
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/** Finds the user of an MCP request's access token from `issueLoginToken`. */ export const authenticateLoginToken = async ({ req, token })=>{
|
|
60
|
+
const loginToken = unseal({
|
|
61
|
+
type: 'access',
|
|
62
|
+
req,
|
|
63
|
+
value: token
|
|
64
|
+
});
|
|
65
|
+
if (!loginToken) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const headers = new Headers({
|
|
69
|
+
Authorization: `JWT ${loginToken.token}`,
|
|
70
|
+
DisableAutologin: 'true'
|
|
71
|
+
});
|
|
72
|
+
return (await executeAuthStrategies({
|
|
73
|
+
headers,
|
|
74
|
+
payload: req.payload,
|
|
75
|
+
req
|
|
76
|
+
})).user;
|
|
77
|
+
};
|
|
78
|
+
const sealLoginToken = ({ req, token })=>seal({
|
|
79
|
+
type: 'access',
|
|
80
|
+
data: {
|
|
81
|
+
token
|
|
82
|
+
},
|
|
83
|
+
req
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=oauthLoginToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoint/oauthLoginToken.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { APIError, createAuthToken, executeAuthStrategies, redeemRefreshToken } from 'payload'\n\nimport type { MCPOAuthTokens } from '../types.js'\n\nimport { seal, unseal } from '../utils/seal.js'\n\n/**\n * The default `issueToken`: a Payload login token, sealed so it only works for MCP, where\n * `authenticateLoginToken` unseals it. Otherwise an MCP client could use it as the user's admin\n * panel login. When the collection uses sessions, the client also gets a refresh token.\n */\nexport const issueLoginToken = async ({\n client,\n req,\n}: {\n client: { name: string; redirectURI: string }\n req: PayloadRequest\n}): Promise<MCPOAuthTokens> => {\n const collectionConfig = req.payload.collections[req.user!.collection]!.config\n\n if (collectionConfig.auth.disableLocalStrategy) {\n throw new APIError(\n `MCP clients can't get Payload login tokens for the \"${collectionConfig.slug}\" collection because its local strategy is disabled. Pass oauth.issueToken to the MCP plugin.`,\n )\n }\n\n // The full document, like the one a password login starts its session on\n const user = (await req.payload.db.findOne<NonNullable<PayloadRequest['user']>>({\n collection: collectionConfig.slug,\n req,\n where: { id: { equals: req.user!.id } },\n }))!\n\n const { refreshToken, token } = await createAuthToken({\n type: 'mcp',\n collectionConfig,\n // App schemes like `com.example.app:/callback` have no host\n email: user.email!,\n label: client.name,\n metadata: { redirectHost: new URL(client.redirectURI).host || client.redirectURI },\n req,\n shouldCreateRefreshToken: true,\n user,\n })\n\n return {\n accessToken: sealLoginToken({ req, token }),\n expiresIn: collectionConfig.auth.tokenExpiration,\n refreshToken,\n }\n}\n\n/** The default `refreshToken`. Payload logs out the session when a refresh token is reused. */\nexport const refreshLoginToken = async ({\n refreshToken,\n req,\n reuseInterval,\n}: {\n refreshToken: string\n req: PayloadRequest\n /** See `redeemRefreshToken`. */\n reuseInterval?: number\n}): Promise<MCPOAuthTokens | null> => {\n const refreshed = await redeemRefreshToken({ refreshToken, req, reuseInterval })\n\n return (\n refreshed && {\n accessToken: sealLoginToken({ req, token: refreshed.token }),\n expiresIn: refreshed.collectionConfig.auth.tokenExpiration,\n refreshToken: refreshed.refreshToken,\n }\n )\n}\n\n/** Finds the user of an MCP request's access token from `issueLoginToken`. */\nexport const authenticateLoginToken = async ({\n req,\n token,\n}: {\n req: PayloadRequest\n token: string\n}): Promise<PayloadRequest['user']> => {\n const loginToken = unseal<{ token: string }>({ type: 'access', req, value: token })\n\n if (!loginToken) {\n return null\n }\n\n const headers = new Headers({\n Authorization: `JWT ${loginToken.token}`,\n DisableAutologin: 'true',\n })\n\n return (await executeAuthStrategies({ headers, payload: req.payload, req })).user\n}\n\nconst sealLoginToken = ({ req, token }: { req: PayloadRequest; token: string }): string =>\n seal({ type: 'access', data: { token }, req })\n"],"names":["APIError","createAuthToken","executeAuthStrategies","redeemRefreshToken","seal","unseal","issueLoginToken","client","req","collectionConfig","payload","collections","user","collection","config","auth","disableLocalStrategy","slug","db","findOne","where","id","equals","refreshToken","token","type","email","label","name","metadata","redirectHost","URL","redirectURI","host","shouldCreateRefreshToken","accessToken","sealLoginToken","expiresIn","tokenExpiration","refreshLoginToken","reuseInterval","refreshed","authenticateLoginToken","loginToken","value","headers","Headers","Authorization","DisableAutologin","data"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,eAAe,EAAEC,qBAAqB,EAAEC,kBAAkB,QAAQ,UAAS;AAI9F,SAASC,IAAI,EAAEC,MAAM,QAAQ,mBAAkB;AAE/C;;;;CAIC,GACD,OAAO,MAAMC,kBAAkB,OAAO,EAC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Y;IACtC;AAEJ,EAAC;AAED,4EAA4E,GAC5E,OAAO,MAAMmB,yBAAyB,OAAO,EAC3ClC,GAAG,EACHgB,KAAK,EAIN;IACC,MAAMmB,aAAatC,OAA0B;QAAEoB,MAAM;QAAUjB;QAAKoC,OAAOpB;IAAM;IAEjF,IAAI,CAACmB,YAAY;QACf,OAAO;IACT;IAEA,MAAME,UAAU,IAAIC,QAAQ;QAC1BC,eAAe,CAAC,IAAI,EAAEJ,WAAWnB,KAAK,EAAE;QACxCwB,kBAAkB;IACpB;IAEA,OAAO,AAAC,CAAA,MAAM9C,sBAAsB;QAAE2C;QAASnC,SAASF,IAAIE,OAAO;QAAEF;IAAI,EAAC,EAAGI,IAAI;AACnF,EAAC;AAED,MAAMwB,iBAAiB,CAAC,EAAE5B,GAAG,EAAEgB,KAAK,EAA0C,GAC5EpB,KAAK;QAAEqB,MAAM;QAAUwB,MAAM;YAAEzB;QAAM;QAAGhB;IAAI"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Endpoint } from 'payload';
|
|
2
|
+
export type Client = {
|
|
3
|
+
name: string;
|
|
4
|
+
redirectURIs: string[];
|
|
5
|
+
};
|
|
6
|
+
export type Consent = {
|
|
7
|
+
clientID: string;
|
|
8
|
+
codeChallenge: string;
|
|
9
|
+
collection: string;
|
|
10
|
+
redirectURI: string;
|
|
11
|
+
state: null | string;
|
|
12
|
+
userID: number | string;
|
|
13
|
+
};
|
|
14
|
+
/** Why `MCPAuthorizeView` can't show the Allow form. */
|
|
15
|
+
export type AuthorizeViewError = 'expired' | 'forbidden' | 'invalid-link';
|
|
16
|
+
/** The admin page where users allow MCP clients, `MCPAuthorizeView`. */
|
|
17
|
+
export declare const authorizeViewPath = "/mcp/authorize";
|
|
18
|
+
/**
|
|
19
|
+
* Turns Payload into the OAuth authorization server for MCP clients when `oauth.type` is
|
|
20
|
+
* `'builtin'`. Clients register, the user allows them after logging in to the admin panel, and
|
|
21
|
+
* the client receives the tokens `issueToken` creates.
|
|
22
|
+
*
|
|
23
|
+
* Clients, consent forms, authorization codes, and refresh tokens are encrypted and handed to the
|
|
24
|
+
* client instead of being stored. Only the default tokens write to the database, to the user's
|
|
25
|
+
* login sessions.
|
|
26
|
+
*/
|
|
27
|
+
export declare const oauthServerEndpoints: Endpoint[];
|
|
28
|
+
//# sourceMappingURL=oauthServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauthServer.d.ts","sourceRoot":"","sources":["../../src/endpoint/oauthServer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,SAAS,CAAA;AAcvE,MAAM,MAAM,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA;AAE7D,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,IAAI,GAAG,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;CACxB,CAAA;AASD,wDAAwD;AACxD,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,WAAW,GAAG,cAAc,CAAA;AAEzE,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,mBAAmB,CAAA;AAOjD;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,EAqC1C,CAAA"}
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { OAuthErrorCode } from '@modelcontextprotocol/server';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import { formatAdminURL } from 'payload/shared';
|
|
4
|
+
import { getPluginConfig } from '../utils/getPluginConfig.js';
|
|
5
|
+
import { seal, unseal } from '../utils/seal.js';
|
|
6
|
+
import { canUseMCP } from './access.js';
|
|
7
|
+
import { getMCPResource } from './oauth.js';
|
|
8
|
+
import { issueLoginToken, refreshLoginToken } from './oauthLoginToken.js';
|
|
9
|
+
/** The admin page where users allow MCP clients, `MCPAuthorizeView`. */ export const authorizeViewPath = '/mcp/authorize';
|
|
10
|
+
/**
|
|
11
|
+
* Turns Payload into the OAuth authorization server for MCP clients when `oauth.type` is
|
|
12
|
+
* `'builtin'`. Clients register, the user allows them after logging in to the admin panel, and
|
|
13
|
+
* the client receives the tokens `issueToken` creates.
|
|
14
|
+
*
|
|
15
|
+
* Clients, consent forms, authorization codes, and refresh tokens are encrypted and handed to the
|
|
16
|
+
* client instead of being stored. Only the default tokens write to the database, to the user's
|
|
17
|
+
* login sessions.
|
|
18
|
+
*/ export const oauthServerEndpoints = [
|
|
19
|
+
{
|
|
20
|
+
disableAuth: true,
|
|
21
|
+
handler: (req)=>withIssuer(req, (issuer)=>metadataResponse(issuer)),
|
|
22
|
+
method: 'get',
|
|
23
|
+
// OpenID discovery is the only metadata location MCP clients check below the issuer's path,
|
|
24
|
+
// which lets this work under /api without a route at the site root
|
|
25
|
+
path: '/mcp/oauth/.well-known/openid-configuration'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
disableAuth: true,
|
|
29
|
+
handler: (req)=>withIssuer(req, ()=>Response.json({
|
|
30
|
+
keys: []
|
|
31
|
+
})),
|
|
32
|
+
method: 'get',
|
|
33
|
+
path: '/mcp/oauth/jwks'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
disableAuth: true,
|
|
37
|
+
handler: (req)=>withIssuer(req, ()=>register(req)),
|
|
38
|
+
method: 'post',
|
|
39
|
+
path: '/mcp/oauth/register'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
handler: (req)=>withIssuer(req, ()=>authorize(req)),
|
|
43
|
+
method: 'get',
|
|
44
|
+
path: '/mcp/oauth/authorize'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
handler: (req)=>withIssuer(req, (issuer)=>approve({
|
|
48
|
+
issuer,
|
|
49
|
+
req
|
|
50
|
+
})),
|
|
51
|
+
method: 'post',
|
|
52
|
+
path: '/mcp/oauth/authorize'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
disableAuth: true,
|
|
56
|
+
handler: (req)=>withIssuer(req, ()=>token(req)),
|
|
57
|
+
method: 'post',
|
|
58
|
+
path: '/mcp/oauth/token'
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
/** The authorization server URL, or `undefined` when Payload isn't the authorization server. */ const getIssuer = (req)=>getPluginConfig({
|
|
62
|
+
config: req.payload.config
|
|
63
|
+
}).oauth?.type === 'builtin' ? `${getMCPResource({
|
|
64
|
+
req
|
|
65
|
+
})}/oauth` : undefined;
|
|
66
|
+
const withIssuer = (req, handler)=>{
|
|
67
|
+
const issuer = getIssuer(req);
|
|
68
|
+
return issuer ? handler(issuer) : new Response(null, {
|
|
69
|
+
status: 404
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The user logged in to this browser, who can allow MCP clients. Tokens and API keys in the
|
|
74
|
+
* `Authorization` header can't, or an MCP client could use its access token to approve itself a
|
|
75
|
+
* new, separate login.
|
|
76
|
+
*/ const getBrowserUser = (req)=>req.headers.has('Authorization') ? null : req.user;
|
|
77
|
+
const metadataResponse = (issuer)=>Response.json({
|
|
78
|
+
authorization_endpoint: `${issuer}/authorize`,
|
|
79
|
+
authorization_response_iss_parameter_supported: true,
|
|
80
|
+
code_challenge_methods_supported: [
|
|
81
|
+
'S256'
|
|
82
|
+
],
|
|
83
|
+
grant_types_supported: [
|
|
84
|
+
'authorization_code',
|
|
85
|
+
'refresh_token'
|
|
86
|
+
],
|
|
87
|
+
// Required by OpenID discovery. No ID tokens are issued.
|
|
88
|
+
id_token_signing_alg_values_supported: [
|
|
89
|
+
'RS256'
|
|
90
|
+
],
|
|
91
|
+
issuer,
|
|
92
|
+
jwks_uri: `${issuer}/jwks`,
|
|
93
|
+
registration_endpoint: `${issuer}/register`,
|
|
94
|
+
response_types_supported: [
|
|
95
|
+
'code'
|
|
96
|
+
],
|
|
97
|
+
subject_types_supported: [
|
|
98
|
+
'public'
|
|
99
|
+
],
|
|
100
|
+
token_endpoint: `${issuer}/token`,
|
|
101
|
+
token_endpoint_auth_methods_supported: [
|
|
102
|
+
'none'
|
|
103
|
+
]
|
|
104
|
+
}, // Not cached, since without `serverURL` its URLs come from the request
|
|
105
|
+
{
|
|
106
|
+
headers: {
|
|
107
|
+
'Access-Control-Allow-Origin': '*',
|
|
108
|
+
'Cache-Control': 'no-store'
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const register = async (req)=>{
|
|
112
|
+
const { client_name, redirect_uris } = await req.json().catch(()=>({}));
|
|
113
|
+
if (!Array.isArray(redirect_uris) || !redirect_uris.length || !redirect_uris.every(isValidRedirectURI)) {
|
|
114
|
+
return Response.json({
|
|
115
|
+
error: OAuthErrorCode.InvalidRedirectUri
|
|
116
|
+
}, {
|
|
117
|
+
status: 400
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
const client = {
|
|
121
|
+
name: typeof client_name === 'string' ? client_name : 'An MCP client',
|
|
122
|
+
redirectURIs: redirect_uris
|
|
123
|
+
};
|
|
124
|
+
return Response.json({
|
|
125
|
+
client_id: seal({
|
|
126
|
+
type: 'client',
|
|
127
|
+
data: client,
|
|
128
|
+
req
|
|
129
|
+
}),
|
|
130
|
+
client_name: client.name,
|
|
131
|
+
grant_types: [
|
|
132
|
+
'authorization_code',
|
|
133
|
+
'refresh_token'
|
|
134
|
+
],
|
|
135
|
+
redirect_uris: client.redirectURIs,
|
|
136
|
+
response_types: [
|
|
137
|
+
'code'
|
|
138
|
+
],
|
|
139
|
+
token_endpoint_auth_method: 'none'
|
|
140
|
+
}, {
|
|
141
|
+
status: 201
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
const authorize = async (req)=>{
|
|
145
|
+
const url = new URL(req.url);
|
|
146
|
+
const params = url.searchParams;
|
|
147
|
+
const clientID = params.get('client_id');
|
|
148
|
+
const client = unseal({
|
|
149
|
+
type: 'client',
|
|
150
|
+
req,
|
|
151
|
+
value: clientID
|
|
152
|
+
});
|
|
153
|
+
// Optional when the client registered only one
|
|
154
|
+
const redirectURI = params.get('redirect_uri') ?? (client?.redirectURIs.length === 1 ? client.redirectURIs[0] : null);
|
|
155
|
+
// Never redirect to an address the client didn't register
|
|
156
|
+
if (!client || !redirectURI || !client.redirectURIs.includes(redirectURI)) {
|
|
157
|
+
return redirectToAuthorizeView({
|
|
158
|
+
params: {
|
|
159
|
+
error: 'invalid-link'
|
|
160
|
+
},
|
|
161
|
+
req
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
const state = params.get('state');
|
|
165
|
+
const codeChallenge = params.get('code_challenge');
|
|
166
|
+
// Not sent to the client's address: anyone can register a client, so that would let a link to
|
|
167
|
+
// this site send users to any site without them doing anything
|
|
168
|
+
if (params.get('response_type') !== 'code' || params.get('code_challenge_method') !== 'S256' || !codeChallenge) {
|
|
169
|
+
return redirectToAuthorizeView({
|
|
170
|
+
params: {
|
|
171
|
+
error: 'invalid-link'
|
|
172
|
+
},
|
|
173
|
+
req
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const user = getBrowserUser(req);
|
|
177
|
+
if (!user) {
|
|
178
|
+
const loginURL = formatAdminURL({
|
|
179
|
+
adminRoute: req.payload.config.routes.admin,
|
|
180
|
+
path: req.payload.config.admin.routes.login
|
|
181
|
+
});
|
|
182
|
+
return new Response(null, {
|
|
183
|
+
headers: {
|
|
184
|
+
Location: `${loginURL}?redirect=${encodeURIComponent(url.pathname + url.search)}`
|
|
185
|
+
},
|
|
186
|
+
status: 302
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// Users who can't use MCP aren't asked to allow a client that couldn't do anything for them
|
|
190
|
+
if (!await canUseMCP({
|
|
191
|
+
req
|
|
192
|
+
})) {
|
|
193
|
+
return redirectToAuthorizeView({
|
|
194
|
+
params: {
|
|
195
|
+
error: 'forbidden'
|
|
196
|
+
},
|
|
197
|
+
req
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
const consent = {
|
|
201
|
+
clientID: clientID,
|
|
202
|
+
codeChallenge,
|
|
203
|
+
collection: user.collection,
|
|
204
|
+
redirectURI,
|
|
205
|
+
state,
|
|
206
|
+
userID: user.id
|
|
207
|
+
};
|
|
208
|
+
return redirectToAuthorizeView({
|
|
209
|
+
params: {
|
|
210
|
+
consent: seal({
|
|
211
|
+
type: 'consent',
|
|
212
|
+
data: consent,
|
|
213
|
+
expiresInSeconds: 20 * 60,
|
|
214
|
+
req
|
|
215
|
+
})
|
|
216
|
+
},
|
|
217
|
+
req
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
const approve = async ({ issuer, req })=>{
|
|
221
|
+
// The Allow page is part of the admin panel, which other sites may be able to frame. Only
|
|
222
|
+
// accepting clicks from a top-level page stops them from tricking users into clicking Allow.
|
|
223
|
+
// Browsers too old to send the header get through here, but the page hides its buttons in frames.
|
|
224
|
+
const fetchDestination = req.headers.get('Sec-Fetch-Dest');
|
|
225
|
+
// Only the Allow page itself may submit the form, not a copy of it on another site
|
|
226
|
+
const fetchSite = req.headers.get('Sec-Fetch-Site');
|
|
227
|
+
if (fetchDestination && fetchDestination !== 'document' || fetchSite && fetchSite !== 'same-origin') {
|
|
228
|
+
return new Response(null, {
|
|
229
|
+
status: 403
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
const form = new URLSearchParams(await req.text());
|
|
233
|
+
const consent = unseal({
|
|
234
|
+
type: 'consent',
|
|
235
|
+
req,
|
|
236
|
+
value: form.get('consent')
|
|
237
|
+
});
|
|
238
|
+
const client = consent && unseal({
|
|
239
|
+
type: 'client',
|
|
240
|
+
req,
|
|
241
|
+
value: consent.clientID
|
|
242
|
+
});
|
|
243
|
+
const user = getBrowserUser(req);
|
|
244
|
+
// The form is only valid for the user it was shown to
|
|
245
|
+
if (!consent || !client || user?.id !== consent.userID || user.collection !== consent.collection) {
|
|
246
|
+
return redirectToAuthorizeView({
|
|
247
|
+
params: {
|
|
248
|
+
error: 'expired'
|
|
249
|
+
},
|
|
250
|
+
req
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
const { clientID, codeChallenge, redirectURI, state } = consent;
|
|
254
|
+
// Responses to the client name this server in `iss`, so clients that use several authorization
|
|
255
|
+
// servers can tell which one answered
|
|
256
|
+
if (form.get('decision') !== 'allow') {
|
|
257
|
+
return redirect({
|
|
258
|
+
params: {
|
|
259
|
+
error: OAuthErrorCode.AccessDenied,
|
|
260
|
+
iss: issuer,
|
|
261
|
+
state
|
|
262
|
+
},
|
|
263
|
+
redirectURI
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
// Checked again since the Allow page was shown, so no tokens are issued to users who lost access
|
|
267
|
+
if (!await canUseMCP({
|
|
268
|
+
req
|
|
269
|
+
})) {
|
|
270
|
+
return redirectToAuthorizeView({
|
|
271
|
+
params: {
|
|
272
|
+
error: 'forbidden'
|
|
273
|
+
},
|
|
274
|
+
req
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const code = {
|
|
278
|
+
clientID,
|
|
279
|
+
codeChallenge,
|
|
280
|
+
redirectURI,
|
|
281
|
+
tokens: await getTokenHooks(req).issueToken({
|
|
282
|
+
client: {
|
|
283
|
+
name: client.name,
|
|
284
|
+
redirectURI
|
|
285
|
+
},
|
|
286
|
+
req
|
|
287
|
+
})
|
|
288
|
+
};
|
|
289
|
+
return redirect({
|
|
290
|
+
params: {
|
|
291
|
+
code: seal({
|
|
292
|
+
type: 'code',
|
|
293
|
+
data: code,
|
|
294
|
+
expiresInSeconds: 60,
|
|
295
|
+
req
|
|
296
|
+
}),
|
|
297
|
+
iss: issuer,
|
|
298
|
+
state
|
|
299
|
+
},
|
|
300
|
+
redirectURI
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
const token = async (req)=>{
|
|
304
|
+
const form = new URLSearchParams(await req.text());
|
|
305
|
+
const clientID = form.get('client_id');
|
|
306
|
+
const grantType = form.get('grant_type');
|
|
307
|
+
if (grantType !== 'authorization_code' && grantType !== 'refresh_token') {
|
|
308
|
+
return Response.json({
|
|
309
|
+
error: grantType ? OAuthErrorCode.UnsupportedGrantType : OAuthErrorCode.InvalidRequest
|
|
310
|
+
}, {
|
|
311
|
+
status: 400
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
const requiredParams = grantType === 'refresh_token' ? [
|
|
315
|
+
'refresh_token'
|
|
316
|
+
] : [
|
|
317
|
+
'code',
|
|
318
|
+
'code_verifier'
|
|
319
|
+
];
|
|
320
|
+
if (!clientID || requiredParams.some((param)=>!form.get(param))) {
|
|
321
|
+
return Response.json({
|
|
322
|
+
error: OAuthErrorCode.InvalidRequest
|
|
323
|
+
}, {
|
|
324
|
+
status: 400
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
const tokens = grantType === 'refresh_token' ? await refresh({
|
|
328
|
+
clientID,
|
|
329
|
+
form,
|
|
330
|
+
req
|
|
331
|
+
}) : await redeemCode({
|
|
332
|
+
clientID,
|
|
333
|
+
form,
|
|
334
|
+
req
|
|
335
|
+
});
|
|
336
|
+
if (!tokens) {
|
|
337
|
+
return Response.json({
|
|
338
|
+
error: OAuthErrorCode.InvalidGrant
|
|
339
|
+
}, {
|
|
340
|
+
status: 400
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return Response.json({
|
|
344
|
+
access_token: tokens.accessToken,
|
|
345
|
+
expires_in: tokens.expiresIn,
|
|
346
|
+
refresh_token: tokens.refreshToken && seal({
|
|
347
|
+
type: 'refresh',
|
|
348
|
+
data: {
|
|
349
|
+
clientID,
|
|
350
|
+
refreshToken: tokens.refreshToken
|
|
351
|
+
},
|
|
352
|
+
req
|
|
353
|
+
}),
|
|
354
|
+
token_type: 'Bearer'
|
|
355
|
+
}, {
|
|
356
|
+
headers: {
|
|
357
|
+
'Cache-Control': 'no-store'
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
const redeemCode = async ({ clientID, form, req })=>{
|
|
362
|
+
const code = unseal({
|
|
363
|
+
type: 'code',
|
|
364
|
+
req,
|
|
365
|
+
value: form.get('code')
|
|
366
|
+
});
|
|
367
|
+
if (code?.clientID === clientID && // OAuth 2.1 clients leave it out, since PKCE does its job. OAuth 2.0 clients send it, and it must
|
|
368
|
+
// match then.
|
|
369
|
+
(!form.has('redirect_uri') || form.get('redirect_uri') === code.redirectURI) && // PKCE: only the client that started the sign-in knows the verifier
|
|
370
|
+
createHash('sha256').update(form.get('code_verifier') ?? '').digest('base64url') === code.codeChallenge) {
|
|
371
|
+
// A code must only work once. Trading it also trades its refresh token, with no leeway, so
|
|
372
|
+
// using the code again counts as a copied refresh token: it's refused, and the tokens revoked.
|
|
373
|
+
const hooks = getTokenHooks(req);
|
|
374
|
+
if (hooks.refreshToken && code.tokens.refreshToken) {
|
|
375
|
+
return await hooks.refreshToken({
|
|
376
|
+
refreshToken: code.tokens.refreshToken,
|
|
377
|
+
req,
|
|
378
|
+
reuseInterval: 0
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return code.tokens;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
const refresh = async ({ clientID, form, req })=>{
|
|
385
|
+
const refreshToken = unseal({
|
|
386
|
+
type: 'refresh',
|
|
387
|
+
req,
|
|
388
|
+
value: form.get('refresh_token')
|
|
389
|
+
});
|
|
390
|
+
// Only the client a refresh token was issued to can use it
|
|
391
|
+
if (refreshToken?.clientID === clientID) {
|
|
392
|
+
return await getTokenHooks(req).refreshToken?.({
|
|
393
|
+
refreshToken: refreshToken.refreshToken,
|
|
394
|
+
req
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
/** `issueToken` and `refreshToken`, or the defaults for Payload login tokens. */ const getTokenHooks = (req)=>{
|
|
399
|
+
const oauth = getPluginConfig({
|
|
400
|
+
config: req.payload.config
|
|
401
|
+
}).oauth;
|
|
402
|
+
return oauth.issueToken ? {
|
|
403
|
+
issueToken: oauth.issueToken,
|
|
404
|
+
refreshToken: oauth.refreshToken
|
|
405
|
+
} : {
|
|
406
|
+
issueToken: issueLoginToken,
|
|
407
|
+
refreshToken: refreshLoginToken
|
|
408
|
+
};
|
|
409
|
+
};
|
|
410
|
+
const redirect = ({ params, redirectURI })=>{
|
|
411
|
+
const location = new URL(redirectURI);
|
|
412
|
+
for (const [key, value] of Object.entries(params)){
|
|
413
|
+
if (value) {
|
|
414
|
+
location.searchParams.set(key, value);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return new Response(null, {
|
|
418
|
+
headers: {
|
|
419
|
+
Location: location.href
|
|
420
|
+
},
|
|
421
|
+
status: 302
|
|
422
|
+
});
|
|
423
|
+
};
|
|
424
|
+
/**
|
|
425
|
+
* Accepts https, http to the user's own computer only, since the code would otherwise travel
|
|
426
|
+
* unencrypted, and app schemes like `cursor://` that desktop apps register to receive the code.
|
|
427
|
+
*/ const isValidRedirectURI = (uri)=>{
|
|
428
|
+
if (typeof uri !== 'string' || !URL.canParse(uri) || uri.includes('#')) {
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
const { hostname, protocol } = new URL(uri);
|
|
432
|
+
if (protocol === 'http:') {
|
|
433
|
+
return [
|
|
434
|
+
'[::1]',
|
|
435
|
+
'127.0.0.1',
|
|
436
|
+
'localhost'
|
|
437
|
+
].includes(hostname);
|
|
438
|
+
}
|
|
439
|
+
// Browser schemes that run or show content instead of sending the code to an app
|
|
440
|
+
return protocol !== 'javascript:' && protocol !== 'data:';
|
|
441
|
+
};
|
|
442
|
+
/** Sends the browser to `MCPAuthorizeView`, with the Allow form or the reason it can't show it. */ const redirectToAuthorizeView = ({ params, req })=>{
|
|
443
|
+
const viewURL = formatAdminURL({
|
|
444
|
+
adminRoute: req.payload.config.routes.admin,
|
|
445
|
+
path: authorizeViewPath
|
|
446
|
+
});
|
|
447
|
+
return new Response(null, {
|
|
448
|
+
headers: {
|
|
449
|
+
Location: `${viewURL}?${new URLSearchParams(params)}`
|
|
450
|
+
},
|
|
451
|
+
status: 302
|
|
452
|
+
});
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
//# sourceMappingURL=oauthServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoint/oauthServer.ts"],"sourcesContent":["import type {\n OAuthClientInformationFull,\n OAuthTokens,\n OpenIdProviderDiscoveryMetadata,\n} from '@modelcontextprotocol/server'\nimport type { Endpoint, PayloadHandler, PayloadRequest } from 'payload'\n\nimport { OAuthErrorCode } from '@modelcontextprotocol/server'\nimport { createHash } from 'crypto'\nimport { formatAdminURL } from 'payload/shared'\n\nimport type { MCPBuiltinOAuthConfig, MCPOAuthTokens } from '../types.js'\n\nimport { getPluginConfig } from '../utils/getPluginConfig.js'\nimport { seal, unseal } from '../utils/seal.js'\nimport { canUseMCP } from './access.js'\nimport { getMCPResource } from './oauth.js'\nimport { issueLoginToken, refreshLoginToken } from './oauthLoginToken.js'\n\nexport type Client = { name: string; redirectURIs: string[] }\n\nexport type Consent = {\n clientID: string\n codeChallenge: string\n collection: string\n redirectURI: string\n state: null | string\n userID: number | string\n}\n\ntype Code = {\n clientID: string\n codeChallenge: string\n redirectURI: string\n tokens: MCPOAuthTokens\n}\n\n/** Why `MCPAuthorizeView` can't show the Allow form. */\nexport type AuthorizeViewError = 'expired' | 'forbidden' | 'invalid-link'\n\n/** The admin page where users allow MCP clients, `MCPAuthorizeView`. */\nexport const authorizeViewPath = '/mcp/authorize'\n\ntype RefreshToken = {\n clientID: string\n refreshToken: string\n}\n\n/**\n * Turns Payload into the OAuth authorization server for MCP clients when `oauth.type` is\n * `'builtin'`. Clients register, the user allows them after logging in to the admin panel, and\n * the client receives the tokens `issueToken` creates.\n *\n * Clients, consent forms, authorization codes, and refresh tokens are encrypted and handed to the\n * client instead of being stored. Only the default tokens write to the database, to the user's\n * login sessions.\n */\nexport const oauthServerEndpoints: Endpoint[] = [\n {\n disableAuth: true,\n handler: (req) => withIssuer(req, (issuer) => metadataResponse(issuer)),\n method: 'get',\n // OpenID discovery is the only metadata location MCP clients check below the issuer's path,\n // which lets this work under /api without a route at the site root\n path: '/mcp/oauth/.well-known/openid-configuration',\n },\n {\n disableAuth: true,\n handler: (req) => withIssuer(req, () => Response.json({ keys: [] })),\n method: 'get',\n path: '/mcp/oauth/jwks',\n },\n {\n disableAuth: true,\n handler: (req) => withIssuer(req, () => register(req)),\n method: 'post',\n path: '/mcp/oauth/register',\n },\n {\n handler: (req) => withIssuer(req, () => authorize(req)),\n method: 'get',\n path: '/mcp/oauth/authorize',\n },\n {\n handler: (req) => withIssuer(req, (issuer) => approve({ issuer, req })),\n method: 'post',\n path: '/mcp/oauth/authorize',\n },\n {\n disableAuth: true,\n handler: (req) => withIssuer(req, () => token(req)),\n method: 'post',\n path: '/mcp/oauth/token',\n },\n]\n\n/** The authorization server URL, or `undefined` when Payload isn't the authorization server. */\nconst getIssuer = (req: PayloadRequest): string | undefined =>\n getPluginConfig({ config: req.payload.config }).oauth?.type === 'builtin'\n ? `${getMCPResource({ req })}/oauth`\n : undefined\n\nconst withIssuer = (\n req: PayloadRequest,\n handler: (issuer: string) => Promise<Response> | Response,\n): Promise<Response> | Response => {\n const issuer = getIssuer(req)\n return issuer ? handler(issuer) : new Response(null, { status: 404 })\n}\n\n/**\n * The user logged in to this browser, who can allow MCP clients. Tokens and API keys in the\n * `Authorization` header can't, or an MCP client could use its access token to approve itself a\n * new, separate login.\n */\nconst getBrowserUser = (req: PayloadRequest): PayloadRequest['user'] =>\n req.headers.has('Authorization') ? null : req.user\n\nconst metadataResponse = (issuer: string): Response =>\n Response.json(\n {\n authorization_endpoint: `${issuer}/authorize`,\n authorization_response_iss_parameter_supported: true,\n code_challenge_methods_supported: ['S256'],\n grant_types_supported: ['authorization_code', 'refresh_token'],\n // Required by OpenID discovery. No ID tokens are issued.\n id_token_signing_alg_values_supported: ['RS256'],\n issuer,\n jwks_uri: `${issuer}/jwks`,\n registration_endpoint: `${issuer}/register`,\n response_types_supported: ['code'],\n subject_types_supported: ['public'],\n token_endpoint: `${issuer}/token`,\n token_endpoint_auth_methods_supported: ['none'],\n } satisfies OpenIdProviderDiscoveryMetadata,\n // Not cached, since without `serverURL` its URLs come from the request\n { headers: { 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'no-store' } },\n )\n\nconst register: PayloadHandler = async (req) => {\n const { client_name, redirect_uris } = await req.json!().catch(() => ({}))\n\n if (\n !Array.isArray(redirect_uris) ||\n !redirect_uris.length ||\n !redirect_uris.every(isValidRedirectURI)\n ) {\n return Response.json({ error: OAuthErrorCode.InvalidRedirectUri }, { status: 400 })\n }\n\n const client: Client = {\n name: typeof client_name === 'string' ? client_name : 'An MCP client',\n redirectURIs: redirect_uris,\n }\n\n return Response.json(\n {\n client_id: seal({ type: 'client', data: client, req }),\n client_name: client.name,\n grant_types: ['authorization_code', 'refresh_token'],\n redirect_uris: client.redirectURIs,\n response_types: ['code'],\n token_endpoint_auth_method: 'none',\n } satisfies OAuthClientInformationFull,\n { status: 201 },\n )\n}\n\nconst authorize: PayloadHandler = async (req) => {\n const url = new URL(req.url!)\n const params = url.searchParams\n const clientID = params.get('client_id')\n const client = unseal<Client>({ type: 'client', req, value: clientID })\n // Optional when the client registered only one\n const redirectURI =\n params.get('redirect_uri') ??\n (client?.redirectURIs.length === 1 ? client.redirectURIs[0]! : null)\n\n // Never redirect to an address the client didn't register\n if (!client || !redirectURI || !client.redirectURIs.includes(redirectURI)) {\n return redirectToAuthorizeView({ params: { error: 'invalid-link' }, req })\n }\n\n const state = params.get('state')\n const codeChallenge = params.get('code_challenge')\n\n // Not sent to the client's address: anyone can register a client, so that would let a link to\n // this site send users to any site without them doing anything\n if (\n params.get('response_type') !== 'code' ||\n params.get('code_challenge_method') !== 'S256' ||\n !codeChallenge\n ) {\n return redirectToAuthorizeView({ params: { error: 'invalid-link' }, req })\n }\n\n const user = getBrowserUser(req)\n\n if (!user) {\n const loginURL = formatAdminURL({\n adminRoute: req.payload.config.routes.admin,\n path: req.payload.config.admin.routes.login,\n })\n\n return new Response(null, {\n headers: {\n Location: `${loginURL}?redirect=${encodeURIComponent(url.pathname + url.search)}`,\n },\n status: 302,\n })\n }\n\n // Users who can't use MCP aren't asked to allow a client that couldn't do anything for them\n if (!(await canUseMCP({ req }))) {\n return redirectToAuthorizeView({ params: { error: 'forbidden' }, req })\n }\n\n const consent: Consent = {\n clientID: clientID!,\n codeChallenge,\n collection: user.collection,\n redirectURI,\n state,\n userID: user.id,\n }\n\n return redirectToAuthorizeView({\n params: { consent: seal({ type: 'consent', data: consent, expiresInSeconds: 20 * 60, req }) },\n req,\n })\n}\n\nconst approve = async ({\n issuer,\n req,\n}: {\n issuer: string\n req: PayloadRequest\n}): Promise<Response> => {\n // The Allow page is part of the admin panel, which other sites may be able to frame. Only\n // accepting clicks from a top-level page stops them from tricking users into clicking Allow.\n // Browsers too old to send the header get through here, but the page hides its buttons in frames.\n const fetchDestination = req.headers.get('Sec-Fetch-Dest')\n // Only the Allow page itself may submit the form, not a copy of it on another site\n const fetchSite = req.headers.get('Sec-Fetch-Site')\n if (\n (fetchDestination && fetchDestination !== 'document') ||\n (fetchSite && fetchSite !== 'same-origin')\n ) {\n return new Response(null, { status: 403 })\n }\n\n const form = new URLSearchParams(await req.text!())\n const consent = unseal<Consent>({ type: 'consent', req, value: form.get('consent') })\n const client = consent && unseal<Client>({ type: 'client', req, value: consent.clientID })\n const user = getBrowserUser(req)\n\n // The form is only valid for the user it was shown to\n if (\n !consent ||\n !client ||\n user?.id !== consent.userID ||\n user.collection !== consent.collection\n ) {\n return redirectToAuthorizeView({ params: { error: 'expired' }, req })\n }\n\n const { clientID, codeChallenge, redirectURI, state } = consent\n\n // Responses to the client name this server in `iss`, so clients that use several authorization\n // servers can tell which one answered\n if (form.get('decision') !== 'allow') {\n return redirect({\n params: { error: OAuthErrorCode.AccessDenied, iss: issuer, state },\n redirectURI,\n })\n }\n\n // Checked again since the Allow page was shown, so no tokens are issued to users who lost access\n if (!(await canUseMCP({ req }))) {\n return redirectToAuthorizeView({ params: { error: 'forbidden' }, req })\n }\n\n const code: Code = {\n clientID,\n codeChallenge,\n redirectURI,\n tokens: await getTokenHooks(req).issueToken({\n client: { name: client.name, redirectURI },\n req,\n }),\n }\n\n return redirect({\n params: {\n code: seal({ type: 'code', data: code, expiresInSeconds: 60, req }),\n iss: issuer,\n state,\n },\n redirectURI,\n })\n}\n\nconst token: PayloadHandler = async (req) => {\n const form = new URLSearchParams(await req.text!())\n const clientID = form.get('client_id')\n const grantType = form.get('grant_type')\n\n if (grantType !== 'authorization_code' && grantType !== 'refresh_token') {\n return Response.json(\n { error: grantType ? OAuthErrorCode.UnsupportedGrantType : OAuthErrorCode.InvalidRequest },\n { status: 400 },\n )\n }\n\n const requiredParams =\n grantType === 'refresh_token' ? ['refresh_token'] : ['code', 'code_verifier']\n\n if (!clientID || requiredParams.some((param) => !form.get(param))) {\n return Response.json({ error: OAuthErrorCode.InvalidRequest }, { status: 400 })\n }\n\n const tokens =\n grantType === 'refresh_token'\n ? await refresh({ clientID, form, req })\n : await redeemCode({ clientID, form, req })\n\n if (!tokens) {\n return Response.json({ error: OAuthErrorCode.InvalidGrant }, { status: 400 })\n }\n\n return Response.json(\n {\n access_token: tokens.accessToken,\n expires_in: tokens.expiresIn,\n refresh_token:\n tokens.refreshToken &&\n seal({\n type: 'refresh',\n data: { clientID, refreshToken: tokens.refreshToken } satisfies RefreshToken,\n req,\n }),\n token_type: 'Bearer',\n } satisfies OAuthTokens,\n { headers: { 'Cache-Control': 'no-store' } },\n )\n}\n\nconst redeemCode = async ({\n clientID,\n form,\n req,\n}: {\n clientID: string\n form: URLSearchParams\n req: PayloadRequest\n}): Promise<MCPOAuthTokens | null | undefined> => {\n const code = unseal<Code>({ type: 'code', req, value: form.get('code') })\n\n if (\n code?.clientID === clientID &&\n // OAuth 2.1 clients leave it out, since PKCE does its job. OAuth 2.0 clients send it, and it must\n // match then.\n (!form.has('redirect_uri') || form.get('redirect_uri') === code.redirectURI) &&\n // PKCE: only the client that started the sign-in knows the verifier\n createHash('sha256')\n .update(form.get('code_verifier') ?? '')\n .digest('base64url') === code.codeChallenge\n ) {\n // A code must only work once. Trading it also trades its refresh token, with no leeway, so\n // using the code again counts as a copied refresh token: it's refused, and the tokens revoked.\n const hooks = getTokenHooks(req)\n if (hooks.refreshToken && code.tokens.refreshToken) {\n return await hooks.refreshToken({\n refreshToken: code.tokens.refreshToken,\n req,\n reuseInterval: 0,\n })\n }\n\n return code.tokens\n }\n}\n\nconst refresh = async ({\n clientID,\n form,\n req,\n}: {\n clientID: string\n form: URLSearchParams\n req: PayloadRequest\n}): Promise<MCPOAuthTokens | null | undefined> => {\n const refreshToken = unseal<RefreshToken>({\n type: 'refresh',\n req,\n value: form.get('refresh_token'),\n })\n\n // Only the client a refresh token was issued to can use it\n if (refreshToken?.clientID === clientID) {\n return await getTokenHooks(req).refreshToken?.({\n refreshToken: refreshToken.refreshToken,\n req,\n })\n }\n}\n\n/** `issueToken` and `refreshToken`, or the defaults for Payload login tokens. */\nconst getTokenHooks = (req: PayloadRequest) => {\n const oauth = getPluginConfig({ config: req.payload.config }).oauth as MCPBuiltinOAuthConfig\n\n return oauth.issueToken\n ? { issueToken: oauth.issueToken, refreshToken: oauth.refreshToken }\n : { issueToken: issueLoginToken, refreshToken: refreshLoginToken }\n}\n\nconst redirect = ({\n params,\n redirectURI,\n}: {\n params: Record<string, null | string>\n redirectURI: string\n}): Response => {\n const location = new URL(redirectURI)\n\n for (const [key, value] of Object.entries(params)) {\n if (value) {\n location.searchParams.set(key, value)\n }\n }\n\n return new Response(null, { headers: { Location: location.href }, status: 302 })\n}\n\n/**\n * Accepts https, http to the user's own computer only, since the code would otherwise travel\n * unencrypted, and app schemes like `cursor://` that desktop apps register to receive the code.\n */\nconst isValidRedirectURI = (uri: unknown): boolean => {\n if (typeof uri !== 'string' || !URL.canParse(uri) || uri.includes('#')) {\n return false\n }\n\n const { hostname, protocol } = new URL(uri)\n\n if (protocol === 'http:') {\n return ['[::1]', '127.0.0.1', 'localhost'].includes(hostname)\n }\n\n // Browser schemes that run or show content instead of sending the code to an app\n return protocol !== 'javascript:' && protocol !== 'data:'\n}\n\n/** Sends the browser to `MCPAuthorizeView`, with the Allow form or the reason it can't show it. */\nconst redirectToAuthorizeView = ({\n params,\n req,\n}: {\n params: { consent: string } | { error: AuthorizeViewError }\n req: PayloadRequest\n}): Response => {\n const viewURL = formatAdminURL({\n adminRoute: req.payload.config.routes.admin,\n path: authorizeViewPath,\n })\n\n return new Response(null, {\n headers: { Location: `${viewURL}?${new URLSearchParams(params)}` },\n status: 302,\n })\n}\n"],"names":["OAuthErrorCode","createHash","formatAdminURL","getPluginConfig","seal","unseal","canUseMCP","getMCPResource","issueLoginToken","refreshLoginToken","authorizeViewPath","oauthServerEndpoints","disableAuth","handler","req","withIssuer","issuer","metadataResponse","method","path","Response","json","keys","register","authorize","approve","token","getIssuer","config","payload","oauth","type","undefined","status","getBrowserUser","headers","has","user","authorization_endpoint","authorization_response_iss_parameter_supported","code_challenge_methods_supported","grant_types_supported","id_token_signing_alg_values_supported","jwks_uri","registration_endpoint","response_types_supported","subject_types_supported","token_endpoint","token_endpoint_auth_methods_supported","client_name","redirect_uris","catch","Array","isArray","length","every","isValidRedirectURI","error","InvalidRedirectUri","client","name","redirectURIs","client_id","data","grant_types","response_types","token_endpoint_auth_method","url","URL","params","searchParams","clientID","get","value","redirectURI","includes","redirectToAuthorizeView","state","codeChallenge","loginURL","adminRoute","routes","admin","login","Location","encodeURIComponent","pathname","search","consent","collection","userID","id","expiresInSeconds","fetchDestination","fetchSite","form","URLSearchParams","text","redirect","AccessDenied","iss","code","tokens","getTokenHooks","issueToken","grantType","UnsupportedGrantType","InvalidRequest","requiredParams","some","param","refresh","redeemCode","InvalidGrant","access_token","accessToken","expires_in","expiresIn","refresh_token","refreshToken","token_type","update","digest","hooks","reuseInterval","location","key","Object","entries","set","href","uri","canParse","hostname","protocol","viewURL"],"mappings":"AAOA,SAASA,cAAc,QAAQ,+BAA8B;AAC7D,SAASC,UAAU,QAAQ,SAAQ;AACnC,SAASC,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,SAASC,IAAI,EAAEC,MAAM,QAAQ,mBAAkB;AAC/C,SAASC,SAAS,QAAQ,cAAa;AACvC,SAASC,cAAc,QAAQ,aAAY;AAC3C,SAASC,eAAe,EAAEC,iBAAiB,QAAQ,uBAAsB;AAuBzE,sEAAsE,GACtE,OAAO,MAAMC,oBAAoB,iBAAgB;AAOjD;;;;;;;;CAQC,GACD,OAAO,MAAMC,uBAAmC;IAC9C;QACEC,aAAa;QACbC,SAAS,CAACC,MAAQC,WAAWD,KAAK,CAACE,SAAWC,iBAAiBD;QAC/DE,QAAQ;QACR,4FAA4F;QAC5F,mEAAmE;QACnEC,MAAM;IACR;IACA;QACEP,aAAa;QACbC,SAAS,CAACC,MAAQC,WAAWD,KAAK,IAAMM,SAASC,IAAI,CAAC;oBAAEC,MAAM,EAAE;gBAAC;QACjEJ,QAAQ;QACRC,MAAM;IACR;IACA;QACEP,aAAa;QACbC,SAAS,CAACC,MAAQC,WAAWD,KAAK,IAAMS,SAAST;QACjDI,QAAQ;QACRC,MAAM;IACR;IACA;QACEN,SAAS,CAACC,MAAQC,WAAWD,KAAK,IAAMU,UAAUV;QAClDI,QAAQ;QACRC,MAAM;IACR;IACA;QACEN,SAAS,CAACC,MAAQC,WAAWD,KAAK,CAACE,SAAWS,QAAQ;oBAAET;oBAAQF;gBAAI;QACpEI,QAAQ;QACRC,MAAM;IACR;IACA;QACEP,aAAa;QACbC,SAAS,CAACC,MAAQC,WAAWD,KAAK,IAAMY,MAAMZ;QAC9CI,QAAQ;QACRC,MAAM;IACR;CACD,CAAA;AAED,8FAA8F,GAC9F,MAAMQ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'../views/Authorize/AllowButtons/index.js';
|
|
2
2
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAA"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAA"}
|
package/dist/exports/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["'use client'\n\nexport {}\n"],"names":[],"mappings":"AAAA;AAEA,
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["'use client'\n\nexport { AllowButtons } from '../views/Authorize/AllowButtons/index.js'\n"],"names":["AllowButtons"],"mappings":"AAAA;AAEA,SAASA,YAAY,QAAQ,2CAA0C"}
|