togello-mcp-server 1.0.22 → 1.0.24
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 -3
- package/build/bearerToken.js +11 -0
- package/build/client.js +12 -13
- package/build/handlers/resource/activityItemListHandler.js +2 -1
- package/build/handlers/tool/createTaskHandler.js +2 -1
- package/build/handlers/tool/getActivityItemListHandler.js +2 -1
- package/build/handlers/tool/getTodoListHandler.js +2 -1
- package/build/handlers/tool/updateTaskHandler.js +2 -1
- package/build/index.js +54 -96
- package/build/mcpServer.js +86 -0
- package/build/remoteServer.js +98 -0
- package/build/upstreamTokenContext.js +8 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -29,9 +29,9 @@ https://togello.com/sign
|
|
|
29
29
|
|
|
30
30
|
### Tools
|
|
31
31
|
|
|
32
|
-
- get-tasks-list: TODO 機能で未完了のタスクを取得します。タスク UUID / タスク名 / 予定開始日時 / 予定終了日時 / 優先度 / カテゴリ を認識できます。
|
|
33
|
-
- create-task: TODO 機能で新しいタスクを作成します。タスク名(taskName)を指定する必要があります。カテゴリー UUID(categoryUUID)、予定開始日時(scheduledStartDate)、URL(url)もオプションで指定できます。
|
|
34
|
-
- update-task: TODO
|
|
32
|
+
- get-tasks-list: TODO 機能で未完了のタスクを取得します。タスク UUID / タスク名 / 詳細(detail) / 予定開始日時 / 予定終了日時 / 優先度 / カテゴリ を認識できます。
|
|
33
|
+
- create-task: TODO 機能で新しいタスクを作成します。タスク名(taskName)を指定する必要があります。カテゴリー UUID(categoryUUID)、予定開始日時(scheduledStartDate)、URL(url)、詳細(detail)もオプションで指定できます。
|
|
34
|
+
- update-task: TODO 機能でタスクを更新します。タスクの完了状態に加えて詳細(detail)も更新できます。get-tasks-list で取得したタスク UUID を指定する必要があります。
|
|
35
35
|
- get-todo-category-list: TODO 機能からカテゴリーリストを取得します。カテゴリー名 / カテゴリー UUID を認識できます。
|
|
36
36
|
- get-today-calendar: 連携している Google カレンダーの昨日/今日/明日の予定を取得します。予定名 / 開始日時 / 終了日時 を認識できます。
|
|
37
37
|
- get-activity-item-list: 統合機能からアクティビティ項目のリストを取得します。アクティビティ項目 UUID / 項目名 を認識できます。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function parseBearerToken(authorizationHeader) {
|
|
2
|
+
if (!authorizationHeader) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
const match = authorizationHeader.match(/^Bearer\s+(.+)$/i);
|
|
6
|
+
const token = match?.[1]?.trim();
|
|
7
|
+
if (!token) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
return token;
|
|
11
|
+
}
|
package/build/client.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { getUpstreamToken } from './upstreamTokenContext.js';
|
|
2
|
+
const API_BASE_URL = process.env.TOGELLO_API_BASE_URL ?? 'https://togello.api.toru-takagi.dev';
|
|
3
|
+
function getApiTokenOrThrow() {
|
|
4
|
+
const token = getUpstreamToken() ?? process.env.TOGELLO_API_TOKEN;
|
|
5
|
+
if (!token) {
|
|
6
|
+
throw new Error('API token not available from upstream context or TOGELLO_API_TOKEN environment variable');
|
|
7
|
+
}
|
|
8
|
+
return token;
|
|
9
|
+
}
|
|
2
10
|
export const httpClient = {
|
|
3
11
|
fetchURL: async ({ path }) => {
|
|
4
|
-
const token =
|
|
5
|
-
if (!token) {
|
|
6
|
-
throw new Error('environment variable TOGELLO_API_TOKEN is not set');
|
|
7
|
-
}
|
|
12
|
+
const token = getApiTokenOrThrow();
|
|
8
13
|
const url = `${API_BASE_URL}${path}`;
|
|
9
14
|
const response = await fetch(url, {
|
|
10
15
|
method: 'GET',
|
|
@@ -19,10 +24,7 @@ export const httpClient = {
|
|
|
19
24
|
return (await response.json());
|
|
20
25
|
},
|
|
21
26
|
postJson: async ({ path, body }) => {
|
|
22
|
-
const token =
|
|
23
|
-
if (!token) {
|
|
24
|
-
throw new Error('environment variable TOGELLO_API_TOKEN is not set');
|
|
25
|
-
}
|
|
27
|
+
const token = getApiTokenOrThrow();
|
|
26
28
|
const url = `${API_BASE_URL}${path}`;
|
|
27
29
|
const response = await fetch(url, {
|
|
28
30
|
method: 'POST',
|
|
@@ -43,10 +45,7 @@ export const httpClient = {
|
|
|
43
45
|
return JSON.parse(text);
|
|
44
46
|
},
|
|
45
47
|
putJson: async ({ path, body }) => {
|
|
46
|
-
const token =
|
|
47
|
-
if (!token) {
|
|
48
|
-
throw new Error('environment variable TOGELLO_API_TOKEN is not set');
|
|
49
|
-
}
|
|
48
|
+
const token = getApiTokenOrThrow();
|
|
50
49
|
const url = `${API_BASE_URL}${path}`;
|
|
51
50
|
const bodyString = body !== null ? JSON.stringify(body) : '{}';
|
|
52
51
|
const response = await fetch(url, {
|
|
@@ -4,6 +4,7 @@ export const activityItemListHandler = async (uri, _options) => {
|
|
|
4
4
|
const activityItemList = await httpClient.fetchURL({
|
|
5
5
|
path: '/v2/integration/activity-items',
|
|
6
6
|
});
|
|
7
|
+
const enabledActivityItemList = activityItemList.filter((item) => item.enabled === 'true');
|
|
7
8
|
return {
|
|
8
9
|
contents: [
|
|
9
10
|
{
|
|
@@ -15,7 +16,7 @@ export const activityItemListHandler = async (uri, _options) => {
|
|
|
15
16
|
{
|
|
16
17
|
type: 'text',
|
|
17
18
|
uri: uri.href,
|
|
18
|
-
text:
|
|
19
|
+
text: enabledActivityItemList
|
|
19
20
|
.map((item) => [item.activityItemUUID, item.itemName])
|
|
20
21
|
.join(','),
|
|
21
22
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { httpClient } from '../../client.js';
|
|
2
|
-
export const createTaskHandler = async ({ taskName, categoryUUID, scheduledStartDate, scheduledEndDate, url, }) => {
|
|
2
|
+
export const createTaskHandler = async ({ taskName, categoryUUID, scheduledStartDate, scheduledEndDate, url, detail, }) => {
|
|
3
3
|
try {
|
|
4
4
|
await httpClient.postJson({
|
|
5
5
|
path: '/v2/integration/todo',
|
|
@@ -9,6 +9,7 @@ export const createTaskHandler = async ({ taskName, categoryUUID, scheduledStart
|
|
|
9
9
|
scheduledStartDate: scheduledStartDate,
|
|
10
10
|
scheduledEndDate: scheduledEndDate,
|
|
11
11
|
url: url,
|
|
12
|
+
detail: detail,
|
|
12
13
|
},
|
|
13
14
|
});
|
|
14
15
|
return {
|
|
@@ -4,6 +4,7 @@ export const getActivityItemListHandler = async () => {
|
|
|
4
4
|
const activityItemList = await httpClient.fetchURL({
|
|
5
5
|
path: '/v2/integration/activity-items',
|
|
6
6
|
});
|
|
7
|
+
const enabledActivityItemList = activityItemList.filter((item) => item.enabled === 'true');
|
|
7
8
|
return {
|
|
8
9
|
content: [
|
|
9
10
|
{
|
|
@@ -13,7 +14,7 @@ export const getActivityItemListHandler = async () => {
|
|
|
13
14
|
},
|
|
14
15
|
{
|
|
15
16
|
type: 'text',
|
|
16
|
-
text:
|
|
17
|
+
text: enabledActivityItemList
|
|
17
18
|
.map((item) => [item.activityItemUUID, item.itemName])
|
|
18
19
|
.join(','),
|
|
19
20
|
},
|
|
@@ -13,7 +13,7 @@ export const getTodoListHandler = async ({ categoryUUIDs }) => {
|
|
|
13
13
|
{
|
|
14
14
|
type: 'text',
|
|
15
15
|
text: `The following is a single task represented in the order:
|
|
16
|
-
[todo uuid, label of the task, scheduled start date, scheduled end date, priority, category of the task, URL associated with the task]`,
|
|
16
|
+
[todo uuid, label of the task, detail of the task, scheduled start date, scheduled end date, priority, category of the task, URL associated with the task]`,
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
type: 'text',
|
|
@@ -25,6 +25,7 @@ export const getTodoListHandler = async ({ categoryUUIDs }) => {
|
|
|
25
25
|
.map((todo) => [
|
|
26
26
|
todo.todoUUID,
|
|
27
27
|
todo.label,
|
|
28
|
+
todo.detail,
|
|
28
29
|
todo.scheduledStartDate,
|
|
29
30
|
todo.scheduledEndDate,
|
|
30
31
|
todo.priorityNumber,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { httpClient } from '../../client.js';
|
|
2
|
-
export const updateTaskHandler = async ({ todoUUID, isCompleted, scheduledStartDate, scheduledEndDate, url, }) => {
|
|
2
|
+
export const updateTaskHandler = async ({ todoUUID, isCompleted, scheduledStartDate, scheduledEndDate, url, detail, }) => {
|
|
3
3
|
try {
|
|
4
4
|
await httpClient.putJson({
|
|
5
5
|
path: `/v2/integration/todo/${todoUUID}`,
|
|
@@ -8,6 +8,7 @@ export const updateTaskHandler = async ({ todoUUID, isCompleted, scheduledStartD
|
|
|
8
8
|
scheduledStartDate,
|
|
9
9
|
scheduledEndDate,
|
|
10
10
|
url,
|
|
11
|
+
detail,
|
|
11
12
|
},
|
|
12
13
|
});
|
|
13
14
|
return {
|
package/build/index.js
CHANGED
|
@@ -1,104 +1,62 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { createTaskHandler } from './handlers/tool/createTaskHandler.js';
|
|
7
|
-
import { getActivityItemListHandler } from './handlers/tool/getActivityItemListHandler.js';
|
|
8
|
-
import { getActivityLogListHandler } from './handlers/tool/getActivityLogListHandler.js';
|
|
9
|
-
import { getJapanCurrentTimeHandler } from './handlers/tool/getJapanCurrentTimeHandler.js';
|
|
10
|
-
import { getTodayCalendarHandler } from './handlers/tool/getTodayCalendarHandler.js';
|
|
11
|
-
import { getTodoCategoryListHandler } from './handlers/tool/getTodoCategoryListHandler.js';
|
|
12
|
-
import { getTodoListHandler } from './handlers/tool/getTodoListHandler.js';
|
|
13
|
-
import { startActivityLogHandler } from './handlers/tool/startActivityLogHandler.js';
|
|
14
|
-
import { updateTaskHandler } from './handlers/tool/updateTaskHandler.js';
|
|
15
|
-
const server = new McpServer({
|
|
16
|
-
name: 'togello',
|
|
17
|
-
version: '1.0.0',
|
|
18
|
-
capabilities: {
|
|
19
|
-
resources: {},
|
|
20
|
-
tools: {},
|
|
21
|
-
},
|
|
22
|
-
});
|
|
3
|
+
import { createMcpServer } from './mcpServer.js';
|
|
4
|
+
import { startRemoteServer } from './remoteServer.js';
|
|
23
5
|
async function main() {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
server.
|
|
59
|
-
todoUUID: z
|
|
60
|
-
.string()
|
|
61
|
-
.describe('Task UUID. Please specify the task uuid (todo uuid) obtained from get-tasks-list. You cannot use this tool without specifying it.'),
|
|
62
|
-
isCompleted: z
|
|
63
|
-
.boolean()
|
|
64
|
-
.describe('You can update the completion status of the task. If true, it is completed.'),
|
|
65
|
-
scheduledStartDate: z
|
|
66
|
-
.string()
|
|
67
|
-
.optional()
|
|
68
|
-
.describe('Scheduled start date in ISO format.If the user does not specify, the information obtained from get-tasks-list is passed.'),
|
|
69
|
-
scheduledEndDate: z
|
|
70
|
-
.string()
|
|
71
|
-
.optional()
|
|
72
|
-
.describe('Scheduled end date in ISO format.If the user does not specify, the information obtained from get-tasks-list is passed.'),
|
|
73
|
-
url: z
|
|
74
|
-
.string()
|
|
75
|
-
.optional()
|
|
76
|
-
.describe('Optional URL associated with the task.If the user does not specify, the information obtained from get-tasks-list is passed.'),
|
|
77
|
-
}, updateTaskHandler);
|
|
78
|
-
server.tool('get-todo-category-list', 'Retrieves the list of categories from the TODO feature. Recognizes category name / category UUID', {}, getTodoCategoryListHandler);
|
|
79
|
-
server.tool('get-today-calendar', 'Retrieves scheduled events for yesterday/today/tomorrow from the linked Google Calendar. Recognizes event name / start date and time / end date and time. ', {}, getTodayCalendarHandler);
|
|
80
|
-
server.tool('get-activity-item-list', 'Retrieves the list of activity items from the integration feature. Recognizes activity item UUID / item name', {}, getActivityItemListHandler);
|
|
81
|
-
server.tool('get-activity-log-list', 'Retrieves the list of activity logs from the integration feature. Since it is a record of what the person has done, if all the end dates are filled in, this person is not doing anything now. If there is one with a null end date, there should be at most one, and if there is one, it means that the person is doing it now. Recognizes activity log UUID / start date and time / end date and time / item name.', {}, getActivityLogListHandler);
|
|
82
|
-
server.tool('start-activity-log',
|
|
83
|
-
// 'Starts an activity log. If all the endDateTime of get-activity-log-list have values, it means that nothing is being done, so start-activity-log can be called.',
|
|
84
|
-
'Starts an activity log.', {
|
|
85
|
-
activityItemName: z
|
|
86
|
-
.string()
|
|
87
|
-
.describe('Activity log name. Please specify the itemName obtained from get-activity-item-list. You cannot specify a value that is not in itemName, so this tool cannot be used.'),
|
|
88
|
-
}, startActivityLogHandler);
|
|
89
|
-
server.tool('complete-activity-log',
|
|
90
|
-
// 'Completes an activity log. If all the endDateTime of get-activity-log-list have values, it means that nothing is being done, so start-activity-log can be called.',
|
|
91
|
-
'Completes an activity log.', {
|
|
92
|
-
activityLogUUID: z
|
|
93
|
-
.string()
|
|
94
|
-
.describe('Activity log UUID. Please specify the activityLogUUID obtained from get-activity-log-list. You cannot specify a value that is not in activityLogUUID, so this tool cannot be used.'),
|
|
95
|
-
}, completeActivityLogHandler);
|
|
96
|
-
server.tool('get-japan-current-time', 'Returns the current time in Japan (JST).', {}, getJapanCurrentTimeHandler);
|
|
97
|
-
await server.connect(transport);
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const firstArg = args[0];
|
|
8
|
+
const mode = (getArgValue(args, '--mode')
|
|
9
|
+
?? (!firstArg || firstArg.startsWith('--') ? undefined : firstArg)
|
|
10
|
+
?? process.env.TOGELLO_MCP_MODE
|
|
11
|
+
?? 'stdio').toLowerCase();
|
|
12
|
+
if (mode === 'remote') {
|
|
13
|
+
const host = getArgValue(args, '--host') ?? process.env.TOGELLO_MCP_HOST ?? '0.0.0.0';
|
|
14
|
+
const portString = getArgValue(args, '--port') ?? process.env.TOGELLO_MCP_PORT ?? '8081';
|
|
15
|
+
const authMode = parseRemoteAuthMode(getArgValue(args, '--auth-mode') ?? process.env.TOGELLO_MCP_AUTH_MODE);
|
|
16
|
+
const keepAliveMsString = process.env.TOGELLO_MCP_SSE_KEEPALIVE_MS;
|
|
17
|
+
const port = Number(portString);
|
|
18
|
+
if (!Number.isFinite(port) || !Number.isInteger(port) || port < 1 || port > 65535) {
|
|
19
|
+
throw new Error(`Invalid port: ${portString}`);
|
|
20
|
+
}
|
|
21
|
+
let keepAliveMs;
|
|
22
|
+
if (keepAliveMsString !== undefined) {
|
|
23
|
+
keepAliveMs = Number(keepAliveMsString);
|
|
24
|
+
if (!Number.isFinite(keepAliveMs) || keepAliveMs < 0) {
|
|
25
|
+
throw new Error(`Invalid TOGELLO_MCP_SSE_KEEPALIVE_MS: ${keepAliveMsString}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
await startRemoteServer({
|
|
29
|
+
host,
|
|
30
|
+
port,
|
|
31
|
+
authMode,
|
|
32
|
+
sseKeepAliveMs: keepAliveMs,
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (mode !== 'stdio') {
|
|
37
|
+
throw new Error(`Unknown mode: ${mode}`);
|
|
38
|
+
}
|
|
39
|
+
const server = createMcpServer();
|
|
40
|
+
await server.connect(new StdioServerTransport());
|
|
98
41
|
}
|
|
99
42
|
main().catch((error) => {
|
|
100
43
|
console.error('Fatal error in main():', error);
|
|
101
44
|
process.exit(1);
|
|
102
45
|
});
|
|
103
|
-
|
|
104
|
-
|
|
46
|
+
function getArgValue(args, key) {
|
|
47
|
+
const index = args.indexOf(key);
|
|
48
|
+
if (index === -1) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return args[index + 1];
|
|
52
|
+
}
|
|
53
|
+
function parseRemoteAuthMode(value) {
|
|
54
|
+
if (value === undefined) {
|
|
55
|
+
return 'passthrough';
|
|
56
|
+
}
|
|
57
|
+
const normalized = value.trim().toLowerCase();
|
|
58
|
+
if (normalized === 'passthrough' || normalized === 'env') {
|
|
59
|
+
return normalized;
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`Invalid TOGELLO_MCP_AUTH_MODE: ${value}`);
|
|
62
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { runWithUpstreamToken } from './upstreamTokenContext.js';
|
|
4
|
+
import { completeActivityLogHandler } from './handlers/tool/completeActivityLogHandler.js';
|
|
5
|
+
import { createTaskHandler } from './handlers/tool/createTaskHandler.js';
|
|
6
|
+
import { getActivityItemListHandler } from './handlers/tool/getActivityItemListHandler.js';
|
|
7
|
+
import { getActivityLogListHandler } from './handlers/tool/getActivityLogListHandler.js';
|
|
8
|
+
import { getJapanCurrentTimeHandler } from './handlers/tool/getJapanCurrentTimeHandler.js';
|
|
9
|
+
import { getTodayCalendarHandler } from './handlers/tool/getTodayCalendarHandler.js';
|
|
10
|
+
import { getTodoCategoryListHandler } from './handlers/tool/getTodoCategoryListHandler.js';
|
|
11
|
+
import { getTodoListHandler } from './handlers/tool/getTodoListHandler.js';
|
|
12
|
+
import { startActivityLogHandler } from './handlers/tool/startActivityLogHandler.js';
|
|
13
|
+
import { updateTaskHandler } from './handlers/tool/updateTaskHandler.js';
|
|
14
|
+
function withUpstreamToken(cb, resolveUpstreamToken) {
|
|
15
|
+
return async (args, extra) => {
|
|
16
|
+
const token = resolveUpstreamToken?.(extra.sessionId);
|
|
17
|
+
if (!token) {
|
|
18
|
+
return await cb(args, extra);
|
|
19
|
+
}
|
|
20
|
+
return await runWithUpstreamToken(token, () => cb(args, extra));
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function createMcpServer(options = {}) {
|
|
24
|
+
const server = new McpServer({
|
|
25
|
+
name: 'togello',
|
|
26
|
+
version: '1.0.0',
|
|
27
|
+
capabilities: {
|
|
28
|
+
resources: {},
|
|
29
|
+
tools: {},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
server.tool('get-tasks-list', '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', {
|
|
33
|
+
categoryUUIDs: z.array(z.string()).optional().describe('Filters tasks by specified category UUIDs.'),
|
|
34
|
+
}, withUpstreamToken(getTodoListHandler, options.resolveUpstreamToken));
|
|
35
|
+
server.tool('create-task', 'Creates a new task in the TODO feature.', {
|
|
36
|
+
taskName: z.string().describe('create task name'),
|
|
37
|
+
categoryUUID: z
|
|
38
|
+
.string()
|
|
39
|
+
.optional()
|
|
40
|
+
.describe('category UUID. category UUID of get-todo-category-list'),
|
|
41
|
+
scheduledStartDate: z.string().optional().describe('Scheduled start date in ISO format.'),
|
|
42
|
+
scheduledEndDate: z.string().optional().describe('Scheduled end date in ISO format.'),
|
|
43
|
+
url: z.string().optional().describe('Optional URL associated with the task.'),
|
|
44
|
+
detail: z.string().optional().describe('Optional detail associated with the task.'),
|
|
45
|
+
}, withUpstreamToken(createTaskHandler, options.resolveUpstreamToken));
|
|
46
|
+
server.tool('update-task', 'Updates a task in the TODO feature.', {
|
|
47
|
+
todoUUID: z
|
|
48
|
+
.string()
|
|
49
|
+
.describe('Task UUID. Please specify the task uuid (todo uuid) obtained from get-tasks-list. You cannot use this tool without specifying it.'),
|
|
50
|
+
isCompleted: z
|
|
51
|
+
.boolean()
|
|
52
|
+
.describe('Required. Updates the completion status of the task. If true, it is completed.'),
|
|
53
|
+
scheduledStartDate: z
|
|
54
|
+
.string()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe('Scheduled start date in ISO format. If the user does not specify, the information obtained from get-tasks-list is passed.'),
|
|
57
|
+
scheduledEndDate: z
|
|
58
|
+
.string()
|
|
59
|
+
.optional()
|
|
60
|
+
.describe('Scheduled end date in ISO format. If the user does not specify, the information obtained from get-tasks-list is passed.'),
|
|
61
|
+
url: z
|
|
62
|
+
.string()
|
|
63
|
+
.optional()
|
|
64
|
+
.describe('Optional URL associated with the task. If the user does not specify, the information obtained from get-tasks-list is passed.'),
|
|
65
|
+
detail: z
|
|
66
|
+
.string()
|
|
67
|
+
.optional()
|
|
68
|
+
.describe('Optional detail associated with the task. If the user does not specify, the information obtained from get-tasks-list is passed.'),
|
|
69
|
+
}, withUpstreamToken(updateTaskHandler, options.resolveUpstreamToken));
|
|
70
|
+
server.tool('get-todo-category-list', 'Retrieves the list of categories from the TODO feature. Recognizes category name / category UUID', {}, withUpstreamToken(getTodoCategoryListHandler, options.resolveUpstreamToken));
|
|
71
|
+
server.tool('get-today-calendar', 'Retrieves scheduled events for yesterday/today/tomorrow from the linked Google Calendar. Recognizes event name / start date and time / end date and time. ', {}, withUpstreamToken(getTodayCalendarHandler, options.resolveUpstreamToken));
|
|
72
|
+
server.tool('get-activity-item-list', 'Retrieves the list of activity items from the integration feature. Recognizes activity item UUID / item name', {}, withUpstreamToken(getActivityItemListHandler, options.resolveUpstreamToken));
|
|
73
|
+
server.tool('get-activity-log-list', 'Retrieves the list of activity logs from the integration feature. Since it is a record of what the person has done, if all the end dates are filled in, this person is not doing anything now. If there is one with a null end date, there should be at most one, and if there is one, it means that the person is doing it now. Recognizes activity log UUID / start date and time / end date and time / item name.', {}, withUpstreamToken(getActivityLogListHandler, options.resolveUpstreamToken));
|
|
74
|
+
server.tool('start-activity-log', 'Starts an activity log.', {
|
|
75
|
+
activityItemName: z
|
|
76
|
+
.string()
|
|
77
|
+
.describe('You must specify a valid itemName obtained from get-activity-item-list. This tool requires a pre-existing activity item.'),
|
|
78
|
+
}, withUpstreamToken(startActivityLogHandler, options.resolveUpstreamToken));
|
|
79
|
+
server.tool('complete-activity-log', 'Completes an activity log.', {
|
|
80
|
+
activityLogUUID: z
|
|
81
|
+
.string()
|
|
82
|
+
.describe('You must specify a valid activityLogUUID obtained from get-activity-log-list. This tool requires an existing activity log.'),
|
|
83
|
+
}, withUpstreamToken(completeActivityLogHandler, options.resolveUpstreamToken));
|
|
84
|
+
server.tool('get-japan-current-time', 'Returns the current time in Japan (JST).', {}, withUpstreamToken(getJapanCurrentTimeHandler, options.resolveUpstreamToken));
|
|
85
|
+
return server;
|
|
86
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
3
|
+
import { parseBearerToken } from './bearerToken.js';
|
|
4
|
+
import { createMcpServer } from './mcpServer.js';
|
|
5
|
+
export async function startRemoteServer(options) {
|
|
6
|
+
const ssePath = options.ssePath ?? '/sse';
|
|
7
|
+
const messagePath = options.messagePath ?? '/message';
|
|
8
|
+
const sessions = new Map();
|
|
9
|
+
const resolveUpstreamToken = (sessionId) => {
|
|
10
|
+
if (!sessionId) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return sessions.get(sessionId)?.upstreamToken;
|
|
14
|
+
};
|
|
15
|
+
const server = createServer(async (req, res) => {
|
|
16
|
+
try {
|
|
17
|
+
const requestUrl = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`);
|
|
18
|
+
if (req.method === 'GET' && requestUrl.pathname === ssePath) {
|
|
19
|
+
const upstreamToken = getUpstreamTokenForSse(req.headers.authorization, options.authMode);
|
|
20
|
+
if (options.authMode === 'passthrough' && !upstreamToken) {
|
|
21
|
+
res.writeHead(401).end('Unauthorized');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const transport = new SSEServerTransport(messagePath, res);
|
|
25
|
+
sessions.set(transport.sessionId, { transport, upstreamToken });
|
|
26
|
+
const mcpServer = createMcpServer({ resolveUpstreamToken });
|
|
27
|
+
let closed = false;
|
|
28
|
+
const keepAliveMs = options.sseKeepAliveMs;
|
|
29
|
+
const keepAliveTimer = keepAliveMs && keepAliveMs > 0
|
|
30
|
+
? setInterval(() => {
|
|
31
|
+
if (!res.writableEnded) {
|
|
32
|
+
res.write(':\n\n');
|
|
33
|
+
}
|
|
34
|
+
}, keepAliveMs)
|
|
35
|
+
: undefined;
|
|
36
|
+
transport.onclose = () => {
|
|
37
|
+
if (closed) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
closed = true;
|
|
41
|
+
sessions.delete(transport.sessionId);
|
|
42
|
+
if (keepAliveTimer) {
|
|
43
|
+
clearInterval(keepAliveTimer);
|
|
44
|
+
}
|
|
45
|
+
void mcpServer.close().catch(() => undefined);
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
await mcpServer.connect(transport);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (!closed) {
|
|
52
|
+
closed = true;
|
|
53
|
+
sessions.delete(transport.sessionId);
|
|
54
|
+
if (keepAliveTimer) {
|
|
55
|
+
clearInterval(keepAliveTimer);
|
|
56
|
+
}
|
|
57
|
+
void mcpServer.close().catch(() => undefined);
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (req.method === 'POST' && requestUrl.pathname === messagePath) {
|
|
64
|
+
const sessionId = requestUrl.searchParams.get('sessionId');
|
|
65
|
+
if (!sessionId) {
|
|
66
|
+
res.writeHead(400).end('Missing sessionId');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const session = sessions.get(sessionId);
|
|
70
|
+
if (!session) {
|
|
71
|
+
res.writeHead(404).end('Session not found');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await session.transport.handlePostMessage(req, res);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
res.writeHead(404).end('Not found');
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error('Remote server error:', error);
|
|
81
|
+
if (!res.headersSent) {
|
|
82
|
+
res.writeHead(500);
|
|
83
|
+
}
|
|
84
|
+
res.end('Internal server error');
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
await new Promise((resolve, reject) => {
|
|
88
|
+
server.once('error', reject);
|
|
89
|
+
server.listen(options.port, options.host, () => resolve());
|
|
90
|
+
});
|
|
91
|
+
console.log(`Remote MCP server listening on http://${options.host}:${options.port}${ssePath}`);
|
|
92
|
+
}
|
|
93
|
+
function getUpstreamTokenForSse(authorizationHeader, authMode) {
|
|
94
|
+
if (authMode === 'env') {
|
|
95
|
+
return process.env.TOGELLO_API_TOKEN;
|
|
96
|
+
}
|
|
97
|
+
return parseBearerToken(authorizationHeader);
|
|
98
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
const upstreamTokenStorage = new AsyncLocalStorage();
|
|
3
|
+
export async function runWithUpstreamToken(token, fn) {
|
|
4
|
+
return await upstreamTokenStorage.run({ token }, fn);
|
|
5
|
+
}
|
|
6
|
+
export function getUpstreamToken() {
|
|
7
|
+
return upstreamTokenStorage.getStore()?.token;
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "togello-mcp-server",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.24",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc && chmod 755 build/index.js",
|
|
8
|
+
"codex:preclone": "bash scripts/codex-cloud/preclone.sh",
|
|
8
9
|
"start": "node build/index.js",
|
|
9
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
11
|
},
|