togello-mcp-server 1.0.27 → 1.0.28
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
|
@@ -29,7 +29,7 @@ Use this for desktop clients and local developer tools that launch MCP servers o
|
|
|
29
29
|
|
|
30
30
|
## Remote MCP
|
|
31
31
|
|
|
32
|
-
Remote mode exposes
|
|
32
|
+
Remote mode exposes a Streamable HTTP endpoint at `/mcp`. It also keeps the legacy SSE endpoint at `/sse` and message endpoint at `/message` for older MCP clients.
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
35
|
TOGELLO_MCP_MODE=remote \
|
|
@@ -42,7 +42,7 @@ npm start
|
|
|
42
42
|
Connect remote MCP clients to:
|
|
43
43
|
|
|
44
44
|
```text
|
|
45
|
-
https://your-domain.example/
|
|
45
|
+
https://your-domain.example/mcp
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
`passthrough` auth expects each remote client request to send its own Togello API token as an `Authorization: Bearer ...` header. Use this mode for published remote MCP servers.
|
|
@@ -13,6 +13,7 @@ export const getTodoListHandler = async ({ categoryUUIDs, }) => {
|
|
|
13
13
|
tasks: tasks.map((todo) => ({
|
|
14
14
|
todoUUID: todo.todoUUID,
|
|
15
15
|
label: todo.label,
|
|
16
|
+
status: todo.status,
|
|
16
17
|
detail: todo.detail,
|
|
17
18
|
scheduledStartDate: todo.scheduledStartDate,
|
|
18
19
|
scheduledEndDate: todo.scheduledEndDate,
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { httpClient } from '../../client.js';
|
|
2
2
|
import { errorToolResponse, jsonToolResponse } from './toolResponse.js';
|
|
3
|
-
export const updateTaskHandler = async ({ todoUUID, isCompleted, scheduledStartDate, scheduledEndDate, url, detail, }) => {
|
|
3
|
+
export const updateTaskHandler = async ({ todoUUID, isCompleted, status, scheduledStartDate, scheduledEndDate, url, detail, }) => {
|
|
4
4
|
try {
|
|
5
|
+
if (isCompleted === undefined &&
|
|
6
|
+
status === undefined &&
|
|
7
|
+
scheduledStartDate === undefined &&
|
|
8
|
+
scheduledEndDate === undefined &&
|
|
9
|
+
url === undefined &&
|
|
10
|
+
detail === undefined) {
|
|
11
|
+
return errorToolResponse('At least one update field is required');
|
|
12
|
+
}
|
|
13
|
+
if (isCompleted !== undefined && status !== undefined) {
|
|
14
|
+
return errorToolResponse('Specify either isCompleted or status, not both');
|
|
15
|
+
}
|
|
5
16
|
await httpClient.putJson({
|
|
6
17
|
path: `/v2/integration/todo/${encodeURIComponent(todoUUID)}`,
|
|
7
18
|
body: {
|
|
8
19
|
isCompleted,
|
|
20
|
+
status,
|
|
9
21
|
scheduledStartDate,
|
|
10
22
|
scheduledEndDate,
|
|
11
23
|
url,
|
|
@@ -15,6 +27,7 @@ export const updateTaskHandler = async ({ todoUUID, isCompleted, scheduledStartD
|
|
|
15
27
|
return jsonToolResponse({
|
|
16
28
|
todoUUID,
|
|
17
29
|
isCompleted,
|
|
30
|
+
status,
|
|
18
31
|
updated: true,
|
|
19
32
|
});
|
|
20
33
|
}
|
package/build/mcpServer.js
CHANGED
|
@@ -43,7 +43,7 @@ export function createMcpServer(options = {}) {
|
|
|
43
43
|
},
|
|
44
44
|
});
|
|
45
45
|
server.registerTool('get-tasks-list', {
|
|
46
|
-
description: 'Retrieves incomplete tasks from the TODO feature. Recognizes task uuid / task name / detail / scheduled start date and time / scheduled end date and time / priority / category',
|
|
46
|
+
description: 'Retrieves incomplete tasks from the TODO feature. Recognizes task uuid / task name / status / detail / scheduled start date and time / scheduled end date and time / priority / category',
|
|
47
47
|
inputSchema: {
|
|
48
48
|
categoryUUIDs: z
|
|
49
49
|
.array(z.string())
|
|
@@ -87,23 +87,28 @@ export function createMcpServer(options = {}) {
|
|
|
87
87
|
.describe('Task UUID. Please specify the task uuid (todo uuid) obtained from get-tasks-list. You cannot use this tool without specifying it.'),
|
|
88
88
|
isCompleted: z
|
|
89
89
|
.boolean()
|
|
90
|
-
.
|
|
90
|
+
.optional()
|
|
91
|
+
.describe('Optional. Backward-compatible completion update. true marks the task done. false preserves existing TODO or DOING tasks and reopens DONE tasks to TODO.'),
|
|
92
|
+
status: z
|
|
93
|
+
.enum(['TODO', 'DOING', 'DONE'])
|
|
94
|
+
.optional()
|
|
95
|
+
.describe('Optional. Updates the todo status directly. Use this to switch tasks between TODO, DOING, and DONE.'),
|
|
91
96
|
scheduledStartDate: z
|
|
92
97
|
.string()
|
|
93
98
|
.optional()
|
|
94
|
-
.describe('Scheduled start date in ISO format. If
|
|
99
|
+
.describe('Scheduled start date in ISO format. If omitted, the current value is kept.'),
|
|
95
100
|
scheduledEndDate: z
|
|
96
101
|
.string()
|
|
97
102
|
.optional()
|
|
98
|
-
.describe('Scheduled end date in ISO format. If
|
|
103
|
+
.describe('Scheduled end date in ISO format. If omitted, the current value is kept.'),
|
|
99
104
|
url: z
|
|
100
105
|
.string()
|
|
101
106
|
.optional()
|
|
102
|
-
.describe('Optional URL associated with the task. If
|
|
107
|
+
.describe('Optional URL associated with the task. If omitted, the current value is kept.'),
|
|
103
108
|
detail: z
|
|
104
109
|
.string()
|
|
105
110
|
.optional()
|
|
106
|
-
.describe('Optional detail associated with the task. If
|
|
111
|
+
.describe('Optional detail associated with the task. If omitted, the current value is kept.'),
|
|
107
112
|
},
|
|
108
113
|
}, withUpstreamToken(updateTaskHandler, options.resolveUpstreamToken, options.requireUpstreamToken));
|
|
109
114
|
server.registerTool('get-calendar-date-memo', {
|
package/build/remoteServer.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
1
2
|
import { createServer } from 'node:http';
|
|
2
3
|
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
4
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
5
|
+
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
3
6
|
import { parseBearerToken } from './bearerToken.js';
|
|
4
7
|
import { createMcpServer } from './mcpServer.js';
|
|
5
8
|
const protectedResourceMetadataPath = '/.well-known/oauth-protected-resource';
|
|
9
|
+
const maxRequestBodyBytes = 1_000_000;
|
|
6
10
|
const supportedScopes = [
|
|
7
11
|
'offline_access',
|
|
8
12
|
'tasks:read',
|
|
@@ -12,17 +16,20 @@ const supportedScopes = [
|
|
|
12
16
|
'calendar:read',
|
|
13
17
|
];
|
|
14
18
|
export async function startRemoteServer(options) {
|
|
19
|
+
const mcpPath = options.mcpPath ?? '/mcp';
|
|
15
20
|
const ssePath = options.ssePath ?? '/sse';
|
|
16
21
|
const messagePath = options.messagePath ?? '/message';
|
|
17
22
|
const publicBaseUrl = trimTrailingSlash(options.publicBaseUrl);
|
|
18
23
|
const oauthIssuer = options.oauthIssuer;
|
|
19
24
|
const protectedResourceMetadataUrl = `${publicBaseUrl}${protectedResourceMetadataPath}`;
|
|
20
|
-
const
|
|
25
|
+
const sseSessions = new Map();
|
|
26
|
+
const streamableSessions = new Map();
|
|
21
27
|
const resolveUpstreamToken = (sessionId) => {
|
|
22
28
|
if (!sessionId) {
|
|
23
29
|
return undefined;
|
|
24
30
|
}
|
|
25
|
-
return
|
|
31
|
+
return (streamableSessions.get(sessionId)?.upstreamToken ??
|
|
32
|
+
sseSessions.get(sessionId)?.upstreamToken);
|
|
26
33
|
};
|
|
27
34
|
const server = createServer(async (req, res) => {
|
|
28
35
|
try {
|
|
@@ -42,8 +49,23 @@ export async function startRemoteServer(options) {
|
|
|
42
49
|
return;
|
|
43
50
|
}
|
|
44
51
|
}
|
|
52
|
+
if (requestUrl.pathname === mcpPath) {
|
|
53
|
+
if (req.method === 'OPTIONS') {
|
|
54
|
+
writeMcpOptionsResponse(res);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
await handleStreamableHttpRequest({
|
|
58
|
+
req,
|
|
59
|
+
res,
|
|
60
|
+
authMode: options.authMode,
|
|
61
|
+
protectedResourceMetadataUrl,
|
|
62
|
+
resolveUpstreamToken,
|
|
63
|
+
sessions: streamableSessions,
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
45
67
|
if (req.method === 'GET' && requestUrl.pathname === ssePath) {
|
|
46
|
-
const upstreamToken =
|
|
68
|
+
const upstreamToken = getUpstreamToken(req.headers.authorization, options.authMode);
|
|
47
69
|
if (options.authMode === 'passthrough' && !upstreamToken) {
|
|
48
70
|
res
|
|
49
71
|
.writeHead(401, {
|
|
@@ -53,7 +75,7 @@ export async function startRemoteServer(options) {
|
|
|
53
75
|
return;
|
|
54
76
|
}
|
|
55
77
|
const transport = new SSEServerTransport(messagePath, res);
|
|
56
|
-
|
|
78
|
+
sseSessions.set(transport.sessionId, { transport, upstreamToken });
|
|
57
79
|
const mcpServer = createMcpServer({
|
|
58
80
|
resolveUpstreamToken,
|
|
59
81
|
requireUpstreamToken: options.authMode === 'passthrough',
|
|
@@ -72,7 +94,7 @@ export async function startRemoteServer(options) {
|
|
|
72
94
|
return;
|
|
73
95
|
}
|
|
74
96
|
closed = true;
|
|
75
|
-
|
|
97
|
+
sseSessions.delete(transport.sessionId);
|
|
76
98
|
if (keepAliveTimer) {
|
|
77
99
|
clearInterval(keepAliveTimer);
|
|
78
100
|
}
|
|
@@ -84,7 +106,7 @@ export async function startRemoteServer(options) {
|
|
|
84
106
|
catch (error) {
|
|
85
107
|
if (!closed) {
|
|
86
108
|
closed = true;
|
|
87
|
-
|
|
109
|
+
sseSessions.delete(transport.sessionId);
|
|
88
110
|
if (keepAliveTimer) {
|
|
89
111
|
clearInterval(keepAliveTimer);
|
|
90
112
|
}
|
|
@@ -100,7 +122,7 @@ export async function startRemoteServer(options) {
|
|
|
100
122
|
res.writeHead(400).end('Missing sessionId');
|
|
101
123
|
return;
|
|
102
124
|
}
|
|
103
|
-
const session =
|
|
125
|
+
const session = sseSessions.get(sessionId);
|
|
104
126
|
if (!session) {
|
|
105
127
|
res.writeHead(404).end('Session not found');
|
|
106
128
|
return;
|
|
@@ -122,7 +144,87 @@ export async function startRemoteServer(options) {
|
|
|
122
144
|
server.once('error', reject);
|
|
123
145
|
server.listen(options.port, options.host, () => resolve());
|
|
124
146
|
});
|
|
125
|
-
console.log(`Remote MCP server listening on http://${options.host}:${options.port}${
|
|
147
|
+
console.log(`Remote MCP server listening on http://${options.host}:${options.port}${mcpPath}`);
|
|
148
|
+
}
|
|
149
|
+
async function handleStreamableHttpRequest({ req, res, authMode, protectedResourceMetadataUrl, resolveUpstreamToken, sessions, }) {
|
|
150
|
+
writeMcpCorsHeaders(res);
|
|
151
|
+
const sessionId = getHeaderValue(req.headers['mcp-session-id']);
|
|
152
|
+
const existingSession = sessionId ? sessions.get(sessionId) : undefined;
|
|
153
|
+
if (existingSession) {
|
|
154
|
+
await existingSession.transport.handleRequest(req, res);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (sessionId) {
|
|
158
|
+
writeJsonRpcError(res, 404, 'Session not found');
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (req.method !== 'POST') {
|
|
162
|
+
writeJsonRpcError(res, 405, 'Method not allowed');
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
let body;
|
|
166
|
+
try {
|
|
167
|
+
body = await readJsonBody(req);
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
if (error instanceof RequestBodyTooLargeError) {
|
|
171
|
+
writeJsonRpcError(res, 413, 'Payload too large');
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
writeJsonRpcError(res, 400, 'Bad Request: Invalid JSON body');
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (!includesInitializeRequest(body)) {
|
|
178
|
+
writeJsonRpcError(res, 400, 'Bad Request: Missing or invalid initialize request');
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const upstreamToken = getUpstreamToken(req.headers.authorization, authMode);
|
|
182
|
+
if (authMode === 'passthrough' && !upstreamToken) {
|
|
183
|
+
res
|
|
184
|
+
.writeHead(401, {
|
|
185
|
+
'WWW-Authenticate': `Bearer resource_metadata="${protectedResourceMetadataUrl}"`,
|
|
186
|
+
})
|
|
187
|
+
.end('Unauthorized');
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const transport = new StreamableHTTPServerTransport({
|
|
191
|
+
sessionIdGenerator: () => randomUUID(),
|
|
192
|
+
onsessioninitialized: (initializedSessionId) => {
|
|
193
|
+
sessions.set(initializedSessionId, {
|
|
194
|
+
transport,
|
|
195
|
+
upstreamToken,
|
|
196
|
+
closeMcpServer: () => mcpServer.close(),
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
onsessionclosed: async (closedSessionId) => {
|
|
200
|
+
const session = sessions.get(closedSessionId);
|
|
201
|
+
sessions.delete(closedSessionId);
|
|
202
|
+
await session?.closeMcpServer().catch(() => undefined);
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
const mcpServer = createMcpServer({
|
|
206
|
+
resolveUpstreamToken,
|
|
207
|
+
requireUpstreamToken: authMode === 'passthrough',
|
|
208
|
+
});
|
|
209
|
+
transport.onclose = () => {
|
|
210
|
+
const initializedSessionId = transport.sessionId;
|
|
211
|
+
if (initializedSessionId) {
|
|
212
|
+
sessions.delete(initializedSessionId);
|
|
213
|
+
}
|
|
214
|
+
void mcpServer.close().catch(() => undefined);
|
|
215
|
+
};
|
|
216
|
+
try {
|
|
217
|
+
await mcpServer.connect(transport);
|
|
218
|
+
await transport.handleRequest(req, res, body);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
const initializedSessionId = transport.sessionId;
|
|
222
|
+
if (initializedSessionId) {
|
|
223
|
+
sessions.delete(initializedSessionId);
|
|
224
|
+
}
|
|
225
|
+
await mcpServer.close().catch(() => undefined);
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
126
228
|
}
|
|
127
229
|
function trimTrailingSlash(url) {
|
|
128
230
|
return url.replace(/\/+$/, '');
|
|
@@ -145,7 +247,62 @@ function writeOptionsResponse(res) {
|
|
|
145
247
|
});
|
|
146
248
|
res.end();
|
|
147
249
|
}
|
|
148
|
-
function
|
|
250
|
+
function writeMcpCorsHeaders(res) {
|
|
251
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
252
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, Mcp-Session-Id, mcp-session-id, Last-Event-ID, mcp-protocol-version');
|
|
253
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
|
|
254
|
+
res.setHeader('Access-Control-Expose-Headers', 'Mcp-Session-Id, mcp-session-id, mcp-protocol-version');
|
|
255
|
+
}
|
|
256
|
+
function writeMcpOptionsResponse(res) {
|
|
257
|
+
writeMcpCorsHeaders(res);
|
|
258
|
+
res.writeHead(204);
|
|
259
|
+
res.end();
|
|
260
|
+
}
|
|
261
|
+
function writeJsonRpcError(res, httpStatus, message) {
|
|
262
|
+
res.writeHead(httpStatus, {
|
|
263
|
+
'Content-Type': 'application/json',
|
|
264
|
+
});
|
|
265
|
+
res.end(JSON.stringify({
|
|
266
|
+
jsonrpc: '2.0',
|
|
267
|
+
error: {
|
|
268
|
+
code: -32000,
|
|
269
|
+
message,
|
|
270
|
+
},
|
|
271
|
+
id: null,
|
|
272
|
+
}));
|
|
273
|
+
}
|
|
274
|
+
function getHeaderValue(header) {
|
|
275
|
+
if (Array.isArray(header)) {
|
|
276
|
+
return header[0];
|
|
277
|
+
}
|
|
278
|
+
return header;
|
|
279
|
+
}
|
|
280
|
+
async function readJsonBody(req) {
|
|
281
|
+
const chunks = [];
|
|
282
|
+
let totalBytes = 0;
|
|
283
|
+
for await (const chunk of req) {
|
|
284
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
285
|
+
totalBytes += buffer.byteLength;
|
|
286
|
+
if (totalBytes > maxRequestBodyBytes) {
|
|
287
|
+
throw new RequestBodyTooLargeError();
|
|
288
|
+
}
|
|
289
|
+
chunks.push(buffer);
|
|
290
|
+
}
|
|
291
|
+
const rawBody = Buffer.concat(chunks).toString('utf8').trim();
|
|
292
|
+
if (!rawBody) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
return JSON.parse(rawBody);
|
|
296
|
+
}
|
|
297
|
+
function includesInitializeRequest(body) {
|
|
298
|
+
if (Array.isArray(body)) {
|
|
299
|
+
return body.some((item) => isInitializeRequest(item));
|
|
300
|
+
}
|
|
301
|
+
return isInitializeRequest(body);
|
|
302
|
+
}
|
|
303
|
+
class RequestBodyTooLargeError extends Error {
|
|
304
|
+
}
|
|
305
|
+
function getUpstreamToken(authorizationHeader, authMode) {
|
|
149
306
|
if (authMode === 'env') {
|
|
150
307
|
return process.env.TOGELLO_API_TOKEN;
|
|
151
308
|
}
|
package/package.json
CHANGED