togello-mcp-server 1.0.31 → 1.0.33

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 CHANGED
@@ -51,6 +51,12 @@ 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 redirects OAuth authorization server metadata discovery paths at `/.well-known/oauth-authorization-server` and `/.well-known/oauth-authorization-server/mcp` to 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.
57
+
58
+ The configured OAuth issuer must be an origin URL without a path component.
59
+
54
60
  For OpenAI Apps domain verification, set `TOGELLO_MCP_OPENAI_APPS_CHALLENGE_TOKEN` to the verification token. Remote mode then serves it from `/.well-known/openai-apps-challenge` as `text/plain`. If both `TOGELLO_MCP_OPENAI_APPS_CHALLENGE_TOKEN` and `OPENAI_APPS_CHALLENGE_TOKEN` are set, the Togello-scoped variable takes precedence.
55
61
 
56
62
  ## Tools
@@ -5,6 +5,12 @@ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/
5
5
  import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
6
6
  import { parseBearerToken } from './bearerToken.js';
7
7
  import { createMcpServer } from './mcpServer.js';
8
+ const authorizationServerMetadataPath = '/.well-known/oauth-authorization-server';
9
+ const authorizationServerMetadataCorsHeaders = {
10
+ 'Access-Control-Allow-Headers': 'Content-Type, Authorization, MCP-Protocol-Version, mcp-protocol-version',
11
+ 'Access-Control-Allow-Methods': 'GET, OPTIONS',
12
+ 'Access-Control-Allow-Origin': '*',
13
+ };
8
14
  const protectedResourceMetadataPath = '/.well-known/oauth-protected-resource';
9
15
  const openaiAppsChallengePath = '/.well-known/openai-apps-challenge';
10
16
  const maxRequestBodyBytes = 1_000_000;
@@ -21,8 +27,37 @@ export async function startRemoteServer(options) {
21
27
  const ssePath = options.ssePath ?? '/sse';
22
28
  const messagePath = options.messagePath ?? '/message';
23
29
  const publicBaseUrl = trimTrailingSlash(options.publicBaseUrl);
24
- const oauthIssuer = options.oauthIssuer;
30
+ const oauthIssuer = trimTrailingSlash(options.oauthIssuer);
31
+ validatePathlessOAuthIssuer(oauthIssuer);
25
32
  const protectedResourceMetadataUrl = `${publicBaseUrl}${protectedResourceMetadataPath}`;
33
+ const mcpResourceUrl = `${publicBaseUrl}${mcpPath}`;
34
+ const mcpProtectedResourceMetadataPath = `${protectedResourceMetadataPath}${mcpPath}`;
35
+ const mcpProtectedResourceMetadataUrl = `${publicBaseUrl}${mcpProtectedResourceMetadataPath}`;
36
+ const authorizationServerMetadataUrl = `${oauthIssuer}${authorizationServerMetadataPath}`;
37
+ const authorizationServerMetadataPaths = new Set([
38
+ authorizationServerMetadataPath,
39
+ `${authorizationServerMetadataPath}${mcpPath}`,
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
+ ]);
26
61
  const openaiAppsChallengeToken = options.openaiAppsChallengeToken?.trim();
27
62
  const sseSessions = new Map();
28
63
  const streamableSessions = new Map();
@@ -46,18 +81,24 @@ export async function startRemoteServer(options) {
46
81
  return;
47
82
  }
48
83
  }
49
- if (requestUrl.pathname === protectedResourceMetadataPath) {
84
+ if (authorizationServerMetadataPaths.has(requestUrl.pathname)) {
85
+ if (req.method === 'OPTIONS') {
86
+ writeAuthorizationServerMetadataOptionsResponse(res);
87
+ return;
88
+ }
89
+ if (req.method === 'GET') {
90
+ writeRedirectResponse(res, authorizationServerMetadataUrl);
91
+ return;
92
+ }
93
+ }
94
+ const protectedResourceMetadata = protectedResourceMetadataByPath.get(requestUrl.pathname);
95
+ if (protectedResourceMetadata) {
50
96
  if (req.method === 'OPTIONS') {
51
97
  writeOptionsResponse(res);
52
98
  return;
53
99
  }
54
100
  if (req.method === 'GET') {
55
- writeJsonResponse(res, {
56
- resource: publicBaseUrl,
57
- authorization_servers: [oauthIssuer],
58
- scopes_supported: supportedScopes,
59
- bearer_methods_supported: ['header'],
60
- });
101
+ writeJsonResponse(res, protectedResourceMetadata);
61
102
  return;
62
103
  }
63
104
  }
@@ -70,7 +111,7 @@ export async function startRemoteServer(options) {
70
111
  req,
71
112
  res,
72
113
  authMode: options.authMode,
73
- protectedResourceMetadataUrl,
114
+ protectedResourceMetadataUrl: mcpProtectedResourceMetadataUrl,
74
115
  resolveUpstreamToken,
75
116
  sessions: streamableSessions,
76
117
  });
@@ -170,6 +211,15 @@ async function handleStreamableHttpRequest({ req, res, authMode, protectedResour
170
211
  writeJsonRpcError(res, 404, 'Session not found');
171
212
  return;
172
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
+ }
173
223
  if (req.method !== 'POST') {
174
224
  writeJsonRpcError(res, 405, 'Method not allowed');
175
225
  return;
@@ -190,15 +240,6 @@ async function handleStreamableHttpRequest({ req, res, authMode, protectedResour
190
240
  writeJsonRpcError(res, 400, 'Bad Request: Missing or invalid initialize request');
191
241
  return;
192
242
  }
193
- const upstreamToken = getUpstreamToken(req.headers.authorization, authMode);
194
- if (authMode === 'passthrough' && !upstreamToken) {
195
- res
196
- .writeHead(401, {
197
- 'WWW-Authenticate': `Bearer resource_metadata="${protectedResourceMetadataUrl}"`,
198
- })
199
- .end('Unauthorized');
200
- return;
201
- }
202
243
  const transport = new StreamableHTTPServerTransport({
203
244
  sessionIdGenerator: () => randomUUID(),
204
245
  onsessioninitialized: (initializedSessionId) => {
@@ -241,6 +282,12 @@ async function handleStreamableHttpRequest({ req, res, authMode, protectedResour
241
282
  function trimTrailingSlash(url) {
242
283
  return url.replace(/\/+$/, '');
243
284
  }
285
+ function validatePathlessOAuthIssuer(oauthIssuer) {
286
+ const { pathname } = new URL(oauthIssuer);
287
+ if (pathname !== '/') {
288
+ throw new Error(`Remote OAuth issuer must not include a path: ${oauthIssuer}`);
289
+ }
290
+ }
244
291
  function writeJsonResponse(res, body) {
245
292
  res.writeHead(200, {
246
293
  'Access-Control-Allow-Headers': 'Content-Type, Authorization',
@@ -251,6 +298,18 @@ function writeJsonResponse(res, body) {
251
298
  });
252
299
  res.end(JSON.stringify(body));
253
300
  }
301
+ function writeRedirectResponse(res, location) {
302
+ res.writeHead(302, {
303
+ ...authorizationServerMetadataCorsHeaders,
304
+ 'Cache-Control': 'no-store',
305
+ Location: location,
306
+ });
307
+ res.end();
308
+ }
309
+ function writeAuthorizationServerMetadataOptionsResponse(res) {
310
+ res.writeHead(204, authorizationServerMetadataCorsHeaders);
311
+ res.end();
312
+ }
254
313
  function writeTextResponse(res, body) {
255
314
  res.writeHead(200, {
256
315
  'Access-Control-Allow-Origin': '*',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "togello-mcp-server",
4
- "version": "1.0.31",
4
+ "version": "1.0.33",
5
5
  "description": "MCP server for Togello tasks, calendar memos, calendar events, and activity logs.",
6
6
  "main": "build/index.js",
7
7
  "scripts": {