@jhl8041/dooray-mcp 0.1.6 → 0.1.7
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.
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Upload Attachment Tool
|
|
3
|
-
* Upload a file attachment to a task
|
|
3
|
+
* Upload a file attachment to a task using curl
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
export declare const uploadAttachmentSchema: z.ZodObject<{
|
|
7
7
|
projectId: z.ZodString;
|
|
8
8
|
taskId: z.ZodString;
|
|
9
|
-
|
|
10
|
-
fileContent: z.ZodString;
|
|
11
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
|
9
|
+
filePath: z.ZodString;
|
|
12
10
|
}, "strip", z.ZodTypeAny, {
|
|
13
11
|
projectId: string;
|
|
14
12
|
taskId: string;
|
|
15
|
-
|
|
16
|
-
fileContent: string;
|
|
17
|
-
mimeType?: string | undefined;
|
|
13
|
+
filePath: string;
|
|
18
14
|
}, {
|
|
19
15
|
projectId: string;
|
|
20
16
|
taskId: string;
|
|
21
|
-
|
|
22
|
-
fileContent: string;
|
|
23
|
-
mimeType?: string | undefined;
|
|
17
|
+
filePath: string;
|
|
24
18
|
}>;
|
|
25
19
|
export type UploadAttachmentInput = z.infer<typeof uploadAttachmentSchema>;
|
|
26
20
|
export declare function uploadAttachmentHandler(args: UploadAttachmentInput): Promise<{
|
|
@@ -50,15 +44,7 @@ export declare const uploadAttachmentTool: {
|
|
|
50
44
|
type: string;
|
|
51
45
|
description: string;
|
|
52
46
|
};
|
|
53
|
-
|
|
54
|
-
type: string;
|
|
55
|
-
description: string;
|
|
56
|
-
};
|
|
57
|
-
fileContent: {
|
|
58
|
-
type: string;
|
|
59
|
-
description: string;
|
|
60
|
-
};
|
|
61
|
-
mimeType: {
|
|
47
|
+
filePath: {
|
|
62
48
|
type: string;
|
|
63
49
|
description: string;
|
|
64
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-attachment.d.ts","sourceRoot":"","sources":["../../../src/tools/projects/upload-attachment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"upload-attachment.d.ts","sourceRoot":"","sources":["../../../src/tools/projects/upload-attachment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,eAAO,MAAM,sBAAsB;;;;;;;;;;;;EAIjC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE3E,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,qBAAqB;;;;;;;;;;;;GA4FxE;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;CAqChC,CAAC"}
|
|
@@ -1,42 +1,90 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Upload Attachment Tool
|
|
4
|
-
* Upload a file attachment to a task
|
|
4
|
+
* Upload a file attachment to a task using curl
|
|
5
5
|
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
10
|
exports.uploadAttachmentTool = exports.uploadAttachmentSchema = void 0;
|
|
8
11
|
exports.uploadAttachmentHandler = uploadAttachmentHandler;
|
|
9
12
|
const zod_1 = require("zod");
|
|
10
|
-
const
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
14
|
+
const util_1 = require("util");
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
17
|
const errors_js_1 = require("../../utils/errors.js");
|
|
18
|
+
const logger_js_1 = require("../../utils/logger.js");
|
|
19
|
+
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
12
20
|
exports.uploadAttachmentSchema = zod_1.z.object({
|
|
13
21
|
projectId: zod_1.z.string().describe('Project ID'),
|
|
14
22
|
taskId: zod_1.z.string().describe('Task ID (post ID)'),
|
|
15
|
-
|
|
16
|
-
fileContent: zod_1.z.string().describe('Base64 encoded file content'),
|
|
17
|
-
mimeType: zod_1.z.string().optional().describe('MIME type of the file (e.g., "image/png", "application/pdf"). Auto-detected if not provided.'),
|
|
23
|
+
filePath: zod_1.z.string().describe('Absolute path to the file to upload'),
|
|
18
24
|
});
|
|
19
25
|
async function uploadAttachmentHandler(args) {
|
|
20
26
|
try {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
27
|
+
const apiToken = process.env.DOORAY_API_TOKEN;
|
|
28
|
+
if (!apiToken) {
|
|
29
|
+
throw new Error('DOORAY_API_TOKEN environment variable is required');
|
|
30
|
+
}
|
|
31
|
+
// Verify file exists
|
|
32
|
+
if (!fs_1.default.existsSync(args.filePath)) {
|
|
33
|
+
throw new Error(`File not found: ${args.filePath}`);
|
|
34
|
+
}
|
|
35
|
+
const fileName = path_1.default.basename(args.filePath);
|
|
36
|
+
const baseUrl = process.env.DOORAY_API_BASE_URL || 'https://api.dooray.com';
|
|
37
|
+
const apiUrl = `${baseUrl}/project/v1/projects/${args.projectId}/posts/${args.taskId}/files`;
|
|
38
|
+
// Step 1: Make initial request to get 307 redirect location
|
|
39
|
+
logger_js_1.logger.debug(`Upload step 1: POST ${apiUrl}`);
|
|
40
|
+
const step1Command = `curl -s -X POST '${apiUrl}' \
|
|
41
|
+
--header 'Authorization: dooray-api ${apiToken}' \
|
|
42
|
+
--form 'file=@"${args.filePath}"' \
|
|
43
|
+
-w '\\n%{http_code}\\n%{redirect_url}' \
|
|
44
|
+
-o /dev/null`;
|
|
45
|
+
const step1Result = await execAsync(step1Command);
|
|
46
|
+
const step1Lines = step1Result.stdout.trim().split('\n');
|
|
47
|
+
const httpCode = step1Lines[step1Lines.length - 2];
|
|
48
|
+
const redirectUrl = step1Lines[step1Lines.length - 1];
|
|
49
|
+
logger_js_1.logger.debug(`Step 1 response: HTTP ${httpCode}, redirect: ${redirectUrl}`);
|
|
50
|
+
let result;
|
|
51
|
+
if (httpCode === '307' && redirectUrl) {
|
|
52
|
+
// Step 2: Follow redirect and upload to file server
|
|
53
|
+
logger_js_1.logger.debug(`Upload step 2: POST ${redirectUrl}`);
|
|
54
|
+
const step2Command = `curl -s -X POST '${redirectUrl}' \
|
|
55
|
+
--header 'Authorization: dooray-api ${apiToken}' \
|
|
56
|
+
--form 'file=@"${args.filePath}"'`;
|
|
57
|
+
const step2Result = await execAsync(step2Command);
|
|
58
|
+
const response = JSON.parse(step2Result.stdout);
|
|
59
|
+
if (!response.header?.isSuccessful) {
|
|
60
|
+
throw new Error(response.header?.resultMessage || 'Upload failed');
|
|
61
|
+
}
|
|
62
|
+
result = response.result;
|
|
63
|
+
}
|
|
64
|
+
else if (httpCode === '200' || httpCode === '201') {
|
|
65
|
+
// Direct upload succeeded (no redirect)
|
|
66
|
+
const directCommand = `curl -s -X POST '${apiUrl}' \
|
|
67
|
+
--header 'Authorization: dooray-api ${apiToken}' \
|
|
68
|
+
--form 'file=@"${args.filePath}"'`;
|
|
69
|
+
const directResult = await execAsync(directCommand);
|
|
70
|
+
const response = JSON.parse(directResult.stdout);
|
|
71
|
+
if (!response.header?.isSuccessful) {
|
|
72
|
+
throw new Error(response.header?.resultMessage || 'Upload failed');
|
|
73
|
+
}
|
|
74
|
+
result = response.result;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
throw new Error(`Unexpected HTTP status: ${httpCode}`);
|
|
78
|
+
}
|
|
32
79
|
return {
|
|
33
80
|
content: [
|
|
34
81
|
{
|
|
35
82
|
type: 'text',
|
|
36
83
|
text: JSON.stringify({
|
|
37
84
|
success: true,
|
|
38
|
-
fileId: result.
|
|
39
|
-
|
|
85
|
+
fileId: result.id,
|
|
86
|
+
fileName: fileName,
|
|
87
|
+
message: `File "${fileName}" successfully uploaded to task.`,
|
|
40
88
|
}, null, 2),
|
|
41
89
|
},
|
|
42
90
|
],
|
|
@@ -61,24 +109,18 @@ exports.uploadAttachmentTool = {
|
|
|
61
109
|
**Required Parameters:**
|
|
62
110
|
- projectId: The project ID
|
|
63
111
|
- taskId: The task ID (post ID) to attach the file to
|
|
64
|
-
-
|
|
65
|
-
- fileContent: Base64 encoded file content
|
|
66
|
-
|
|
67
|
-
**Optional Parameters:**
|
|
68
|
-
- mimeType: MIME type (e.g., "image/png", "application/pdf"). Auto-detected if not provided.
|
|
112
|
+
- filePath: Absolute path to the file to upload (e.g., "/Users/name/document.pdf")
|
|
69
113
|
|
|
70
114
|
**Example:**
|
|
71
115
|
{
|
|
72
116
|
"projectId": "123456",
|
|
73
117
|
"taskId": "789012",
|
|
74
|
-
"
|
|
75
|
-
"fileContent": "iVBORw0KGgoAAAANSUhEUgAA...",
|
|
76
|
-
"mimeType": "image/png"
|
|
118
|
+
"filePath": "/Users/nhn/Downloads/report.pdf"
|
|
77
119
|
}
|
|
78
120
|
|
|
79
121
|
**Returns:** File ID of the uploaded attachment.
|
|
80
122
|
|
|
81
|
-
**Note:** The
|
|
123
|
+
**Note:** The file must exist at the specified path. Maximum file size depends on Dooray's server limits.`,
|
|
82
124
|
inputSchema: {
|
|
83
125
|
type: 'object',
|
|
84
126
|
properties: {
|
|
@@ -90,20 +132,12 @@ exports.uploadAttachmentTool = {
|
|
|
90
132
|
type: 'string',
|
|
91
133
|
description: 'Task ID (post ID) to attach the file to',
|
|
92
134
|
},
|
|
93
|
-
|
|
94
|
-
type: 'string',
|
|
95
|
-
description: 'Name of the file to upload',
|
|
96
|
-
},
|
|
97
|
-
fileContent: {
|
|
98
|
-
type: 'string',
|
|
99
|
-
description: 'Base64 encoded file content',
|
|
100
|
-
},
|
|
101
|
-
mimeType: {
|
|
135
|
+
filePath: {
|
|
102
136
|
type: 'string',
|
|
103
|
-
description: '
|
|
137
|
+
description: 'Absolute path to the file to upload',
|
|
104
138
|
},
|
|
105
139
|
},
|
|
106
|
-
required: ['projectId', 'taskId', '
|
|
140
|
+
required: ['projectId', 'taskId', 'filePath'],
|
|
107
141
|
},
|
|
108
142
|
};
|
|
109
143
|
//# sourceMappingURL=upload-attachment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-attachment.js","sourceRoot":"","sources":["../../../src/tools/projects/upload-attachment.ts"],"names":[],"mappings":";AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"upload-attachment.js","sourceRoot":"","sources":["../../../src/tools/projects/upload-attachment.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAoBH,0DA4FC;AA9GD,6BAAwB;AACxB,iDAAqC;AACrC,+BAAiC;AACjC,gDAAwB;AACxB,4CAAoB;AACpB,qDAAoD;AACpD,qDAA+C;AAE/C,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC;AAErB,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC;IAC5C,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IAChD,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;CACrE,CAAC,CAAC;AAII,KAAK,UAAU,uBAAuB,CAAC,IAA2B;IACvE,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;QAC9C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,mDA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