togello-mcp-server 1.0.32 → 1.0.34
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/README.md +3 -1
- package/build/remoteServer.js +51 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,9 @@ https://your-domain.example/mcp
|
|
|
51
51
|
|
|
52
52
|
ChatGPT developer mode can add remote MCP servers that use SSE. For production ChatGPT apps or connectors, use `passthrough` auth or a deployment that authenticates each user separately before forwarding requests to Togello.
|
|
53
53
|
|
|
54
|
-
Remote mode
|
|
54
|
+
Remote mode serves OAuth authorization server metadata from `/.well-known/oauth-authorization-server` and `/.well-known/oauth-authorization-server/mcp` using the Togello OAuth issuer configured with `TOGELLO_OAUTH_ISSUER` or `TOGELLO_API_BASE_URL`.
|
|
55
|
+
|
|
56
|
+
Remote OAuth clients that connect to `/mcp` should discover protected resource metadata at `/.well-known/oauth-protected-resource/mcp`. That metadata returns `resource` as the full MCP endpoint URL, such as `https://your-domain.example/mcp`. Unauthenticated `/mcp` requests include a `WWW-Authenticate` challenge whose `resource_metadata` value points to that `/mcp` metadata path.
|
|
55
57
|
|
|
56
58
|
The configured OAuth issuer must be an origin URL without a path component.
|
|
57
59
|
|
package/build/remoteServer.js
CHANGED
|
@@ -30,11 +30,34 @@ export async function startRemoteServer(options) {
|
|
|
30
30
|
const oauthIssuer = trimTrailingSlash(options.oauthIssuer);
|
|
31
31
|
validatePathlessOAuthIssuer(oauthIssuer);
|
|
32
32
|
const protectedResourceMetadataUrl = `${publicBaseUrl}${protectedResourceMetadataPath}`;
|
|
33
|
-
const
|
|
33
|
+
const mcpResourceUrl = `${publicBaseUrl}${mcpPath}`;
|
|
34
|
+
const mcpProtectedResourceMetadataPath = `${protectedResourceMetadataPath}${mcpPath}`;
|
|
35
|
+
const mcpProtectedResourceMetadataUrl = `${publicBaseUrl}${mcpProtectedResourceMetadataPath}`;
|
|
36
|
+
const authorizationServerMetadata = buildAuthorizationServerMetadata(oauthIssuer);
|
|
34
37
|
const authorizationServerMetadataPaths = new Set([
|
|
35
38
|
authorizationServerMetadataPath,
|
|
36
39
|
`${authorizationServerMetadataPath}${mcpPath}`,
|
|
37
40
|
]);
|
|
41
|
+
const protectedResourceMetadataByPath = new Map([
|
|
42
|
+
[
|
|
43
|
+
protectedResourceMetadataPath,
|
|
44
|
+
{
|
|
45
|
+
resource: publicBaseUrl,
|
|
46
|
+
authorization_servers: [oauthIssuer],
|
|
47
|
+
scopes_supported: supportedScopes,
|
|
48
|
+
bearer_methods_supported: ['header'],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
mcpProtectedResourceMetadataPath,
|
|
53
|
+
{
|
|
54
|
+
resource: mcpResourceUrl,
|
|
55
|
+
authorization_servers: [oauthIssuer],
|
|
56
|
+
scopes_supported: supportedScopes,
|
|
57
|
+
bearer_methods_supported: ['header'],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
]);
|
|
38
61
|
const openaiAppsChallengeToken = options.openaiAppsChallengeToken?.trim();
|
|
39
62
|
const sseSessions = new Map();
|
|
40
63
|
const streamableSessions = new Map();
|
|
@@ -64,22 +87,18 @@ export async function startRemoteServer(options) {
|
|
|
64
87
|
return;
|
|
65
88
|
}
|
|
66
89
|
if (req.method === 'GET') {
|
|
67
|
-
|
|
90
|
+
writeJsonResponse(res, authorizationServerMetadata);
|
|
68
91
|
return;
|
|
69
92
|
}
|
|
70
93
|
}
|
|
71
|
-
|
|
94
|
+
const protectedResourceMetadata = protectedResourceMetadataByPath.get(requestUrl.pathname);
|
|
95
|
+
if (protectedResourceMetadata) {
|
|
72
96
|
if (req.method === 'OPTIONS') {
|
|
73
97
|
writeOptionsResponse(res);
|
|
74
98
|
return;
|
|
75
99
|
}
|
|
76
100
|
if (req.method === 'GET') {
|
|
77
|
-
writeJsonResponse(res,
|
|
78
|
-
resource: publicBaseUrl,
|
|
79
|
-
authorization_servers: [oauthIssuer],
|
|
80
|
-
scopes_supported: supportedScopes,
|
|
81
|
-
bearer_methods_supported: ['header'],
|
|
82
|
-
});
|
|
101
|
+
writeJsonResponse(res, protectedResourceMetadata);
|
|
83
102
|
return;
|
|
84
103
|
}
|
|
85
104
|
}
|
|
@@ -92,7 +111,7 @@ export async function startRemoteServer(options) {
|
|
|
92
111
|
req,
|
|
93
112
|
res,
|
|
94
113
|
authMode: options.authMode,
|
|
95
|
-
protectedResourceMetadataUrl,
|
|
114
|
+
protectedResourceMetadataUrl: mcpProtectedResourceMetadataUrl,
|
|
96
115
|
resolveUpstreamToken,
|
|
97
116
|
sessions: streamableSessions,
|
|
98
117
|
});
|
|
@@ -192,6 +211,15 @@ async function handleStreamableHttpRequest({ req, res, authMode, protectedResour
|
|
|
192
211
|
writeJsonRpcError(res, 404, 'Session not found');
|
|
193
212
|
return;
|
|
194
213
|
}
|
|
214
|
+
const upstreamToken = getUpstreamToken(req.headers.authorization, authMode);
|
|
215
|
+
if (authMode === 'passthrough' && !upstreamToken) {
|
|
216
|
+
res
|
|
217
|
+
.writeHead(401, {
|
|
218
|
+
'WWW-Authenticate': `Bearer resource_metadata="${protectedResourceMetadataUrl}"`,
|
|
219
|
+
})
|
|
220
|
+
.end('Unauthorized');
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
195
223
|
if (req.method !== 'POST') {
|
|
196
224
|
writeJsonRpcError(res, 405, 'Method not allowed');
|
|
197
225
|
return;
|
|
@@ -212,15 +240,6 @@ async function handleStreamableHttpRequest({ req, res, authMode, protectedResour
|
|
|
212
240
|
writeJsonRpcError(res, 400, 'Bad Request: Missing or invalid initialize request');
|
|
213
241
|
return;
|
|
214
242
|
}
|
|
215
|
-
const upstreamToken = getUpstreamToken(req.headers.authorization, authMode);
|
|
216
|
-
if (authMode === 'passthrough' && !upstreamToken) {
|
|
217
|
-
res
|
|
218
|
-
.writeHead(401, {
|
|
219
|
-
'WWW-Authenticate': `Bearer resource_metadata="${protectedResourceMetadataUrl}"`,
|
|
220
|
-
})
|
|
221
|
-
.end('Unauthorized');
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
243
|
const transport = new StreamableHTTPServerTransport({
|
|
225
244
|
sessionIdGenerator: () => randomUUID(),
|
|
226
245
|
onsessioninitialized: (initializedSessionId) => {
|
|
@@ -269,6 +288,19 @@ function validatePathlessOAuthIssuer(oauthIssuer) {
|
|
|
269
288
|
throw new Error(`Remote OAuth issuer must not include a path: ${oauthIssuer}`);
|
|
270
289
|
}
|
|
271
290
|
}
|
|
291
|
+
function buildAuthorizationServerMetadata(oauthIssuer) {
|
|
292
|
+
return {
|
|
293
|
+
issuer: oauthIssuer,
|
|
294
|
+
authorization_endpoint: `${oauthIssuer}/oauth/authorize`,
|
|
295
|
+
token_endpoint: `${oauthIssuer}/oauth/token`,
|
|
296
|
+
registration_endpoint: `${oauthIssuer}/oauth/register`,
|
|
297
|
+
scopes_supported: supportedScopes,
|
|
298
|
+
response_types_supported: ['code'],
|
|
299
|
+
grant_types_supported: ['authorization_code', 'refresh_token'],
|
|
300
|
+
code_challenge_methods_supported: ['S256'],
|
|
301
|
+
token_endpoint_auth_methods_supported: ['none', 'client_secret_post'],
|
|
302
|
+
};
|
|
303
|
+
}
|
|
272
304
|
function writeJsonResponse(res, body) {
|
|
273
305
|
res.writeHead(200, {
|
|
274
306
|
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
|
@@ -279,14 +311,6 @@ function writeJsonResponse(res, body) {
|
|
|
279
311
|
});
|
|
280
312
|
res.end(JSON.stringify(body));
|
|
281
313
|
}
|
|
282
|
-
function writeRedirectResponse(res, location) {
|
|
283
|
-
res.writeHead(302, {
|
|
284
|
-
...authorizationServerMetadataCorsHeaders,
|
|
285
|
-
'Cache-Control': 'no-store',
|
|
286
|
-
Location: location,
|
|
287
|
-
});
|
|
288
|
-
res.end();
|
|
289
|
-
}
|
|
290
314
|
function writeAuthorizationServerMetadataOptionsResponse(res) {
|
|
291
315
|
res.writeHead(204, authorizationServerMetadataCorsHeaders);
|
|
292
316
|
res.end();
|
package/package.json
CHANGED