mcp-server-rocketchat-threads 1.0.0
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/LICENSE +21 -0
- package/README.md +332 -0
- package/dist/api/client.d.ts +119 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +305 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +22 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/schemas.d.ts +10636 -0
- package/dist/api/schemas.d.ts.map +1 -0
- package/dist/api/schemas.js +267 -0
- package/dist/api/schemas.js.map +1 -0
- package/dist/api/types.d.ts +263 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +7 -0
- package/dist/api/types.js.map +1 -0
- package/dist/config/config.d.ts +37 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +79 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +21 -0
- package/dist/config/index.js.map +1 -0
- package/dist/di/container.d.ts +101 -0
- package/dist/di/container.d.ts.map +1 -0
- package/dist/di/container.js +214 -0
- package/dist/di/container.js.map +1 -0
- package/dist/di/index.d.ts +6 -0
- package/dist/di/index.d.ts.map +1 -0
- package/dist/di/index.js +12 -0
- package/dist/di/index.js.map +1 -0
- package/dist/formatters/index.d.ts +6 -0
- package/dist/formatters/index.d.ts.map +1 -0
- package/dist/formatters/index.js +22 -0
- package/dist/formatters/index.js.map +1 -0
- package/dist/formatters/message-formatter.d.ts +64 -0
- package/dist/formatters/message-formatter.d.ts.map +1 -0
- package/dist/formatters/message-formatter.js +161 -0
- package/dist/formatters/message-formatter.js.map +1 -0
- package/dist/formatters/response-builder.d.ts +60 -0
- package/dist/formatters/response-builder.d.ts.map +1 -0
- package/dist/formatters/response-builder.js +108 -0
- package/dist/formatters/response-builder.js.map +1 -0
- package/dist/guards/index.d.ts +12 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/index.js +42 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/guards/input-validator.d.ts +89 -0
- package/dist/guards/input-validator.d.ts.map +1 -0
- package/dist/guards/input-validator.js +266 -0
- package/dist/guards/input-validator.js.map +1 -0
- package/dist/guards/rate-limiter.d.ts +115 -0
- package/dist/guards/rate-limiter.d.ts.map +1 -0
- package/dist/guards/rate-limiter.js +226 -0
- package/dist/guards/rate-limiter.js.map +1 -0
- package/dist/guards/sanitizer.d.ts +35 -0
- package/dist/guards/sanitizer.d.ts.map +1 -0
- package/dist/guards/sanitizer.js +111 -0
- package/dist/guards/sanitizer.js.map +1 -0
- package/dist/guards/write-guard.d.ts +33 -0
- package/dist/guards/write-guard.d.ts.map +1 -0
- package/dist/guards/write-guard.js +90 -0
- package/dist/guards/write-guard.js.map +1 -0
- package/dist/http-server.d.ts +9 -0
- package/dist/http-server.d.ts.map +1 -0
- package/dist/http-server.js +190 -0
- package/dist/http-server.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +114 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/base.d.ts +85 -0
- package/dist/tools/base.d.ts.map +1 -0
- package/dist/tools/base.js +184 -0
- package/dist/tools/base.js.map +1 -0
- package/dist/tools/channel-tools.d.ts +18 -0
- package/dist/tools/channel-tools.d.ts.map +1 -0
- package/dist/tools/channel-tools.js +151 -0
- package/dist/tools/channel-tools.js.map +1 -0
- package/dist/tools/handler-utils.d.ts +75 -0
- package/dist/tools/handler-utils.d.ts.map +1 -0
- package/dist/tools/handler-utils.js +105 -0
- package/dist/tools/handler-utils.js.map +1 -0
- package/dist/tools/index.d.ts +17 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +40 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/message-tools.d.ts +20 -0
- package/dist/tools/message-tools.d.ts.map +1 -0
- package/dist/tools/message-tools.js +194 -0
- package/dist/tools/message-tools.js.map +1 -0
- package/dist/tools/thread-tools.d.ts +23 -0
- package/dist/tools/thread-tools.d.ts.map +1 -0
- package/dist/tools/thread-tools.js +243 -0
- package/dist/tools/thread-tools.js.map +1 -0
- package/dist/tools/user-tools.d.ts +14 -0
- package/dist/tools/user-tools.d.ts.map +1 -0
- package/dist/tools/user-tools.js +120 -0
- package/dist/tools/user-tools.js.map +1 -0
- package/dist/tools/write-tools.d.ts +15 -0
- package/dist/tools/write-tools.d.ts.map +1 -0
- package/dist/tools/write-tools.js +181 -0
- package/dist/tools/write-tools.js.map +1 -0
- package/dist/utils/cache.d.ts +47 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +116 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/error-handler.d.ts +64 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +148 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +33 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +50 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +118 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/time-parser.d.ts +37 -0
- package/dist/utils/time-parser.d.ts.map +1 -0
- package/dist/utils/time-parser.js +98 -0
- package/dist/utils/time-parser.js.map +1 -0
- package/dist/utils/token-counter.d.ts +42 -0
- package/dist/utils/token-counter.d.ts.map +1 -0
- package/dist/utils/token-counter.js +81 -0
- package/dist/utils/token-counter.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* User Tools
|
|
4
|
+
* Tools for looking up user information
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getMeTool = exports.listUsersTool = exports.lookupUserTool = void 0;
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const client_js_1 = require("../api/client.js");
|
|
10
|
+
const message_formatter_js_1 = require("../formatters/message-formatter.js");
|
|
11
|
+
const response_builder_js_1 = require("../formatters/response-builder.js");
|
|
12
|
+
const token_counter_js_1 = require("../utils/token-counter.js");
|
|
13
|
+
const base_js_1 = require("./base.js");
|
|
14
|
+
/**
|
|
15
|
+
* rocketchat_lookup_user
|
|
16
|
+
* Get user information by ID or username
|
|
17
|
+
*/
|
|
18
|
+
const lookupUserSchema = zod_1.z.object({
|
|
19
|
+
userId: zod_1.z.string().optional()
|
|
20
|
+
.describe('User ID (provide either userId or username)'),
|
|
21
|
+
username: zod_1.z.string().optional()
|
|
22
|
+
.describe('Username without @ (provide either userId or username)')
|
|
23
|
+
});
|
|
24
|
+
exports.lookupUserTool = (0, base_js_1.defineTool)('rocketchat_lookup_user', `Look up a Rocket.Chat user by ID or username.
|
|
25
|
+
|
|
26
|
+
Returns user information:
|
|
27
|
+
- User ID and username
|
|
28
|
+
- Display name
|
|
29
|
+
- Email (if visible)
|
|
30
|
+
- Status (online/away/busy/offline)
|
|
31
|
+
- Roles (admin, user, etc.)
|
|
32
|
+
|
|
33
|
+
Use this to get details about message authors or participants.
|
|
34
|
+
|
|
35
|
+
Examples:
|
|
36
|
+
- By ID: { "userId": "x3JG6uXJgE7YNHR3S" }
|
|
37
|
+
- By username: { "username": "john.doe" }`, lookupUserSchema, async (params) => {
|
|
38
|
+
if (!params.userId && !params.username) {
|
|
39
|
+
return (0, base_js_1.createErrorResult)(base_js_1.ErrorCodes.VALIDATION_ERROR, 'Missing user identifier', 'Either userId or username must be provided');
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const client = (0, client_js_1.getClient)();
|
|
43
|
+
const response = await client.getUserInfo(params.userId, params.username);
|
|
44
|
+
if (!response.success) {
|
|
45
|
+
const identifier = params.userId || params.username || '';
|
|
46
|
+
return (0, base_js_1.createErrorResult)(base_js_1.ErrorCodes.NOT_FOUND, 'User not found', `No user found with identifier "${identifier}"`);
|
|
47
|
+
}
|
|
48
|
+
const formatted = (0, message_formatter_js_1.formatUser)(response.user);
|
|
49
|
+
const result = (0, response_builder_js_1.buildSuccessResponse)(formatted);
|
|
50
|
+
return (0, base_js_1.createToolResult)(result);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return (0, base_js_1.createErrorResultFromException)(base_js_1.ErrorCodes.API_ERROR, 'Failed to lookup user', error);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* rocketchat_list_users
|
|
58
|
+
* List users with pagination
|
|
59
|
+
*/
|
|
60
|
+
const listUsersSchema = zod_1.z.object({
|
|
61
|
+
limit: zod_1.z.number().min(1).max(100).default(50).optional()
|
|
62
|
+
.describe('Maximum number of users to return (1-100, default: 50)'),
|
|
63
|
+
offset: zod_1.z.number().min(0).default(0).optional()
|
|
64
|
+
.describe('Number of users to skip for pagination')
|
|
65
|
+
});
|
|
66
|
+
exports.listUsersTool = (0, base_js_1.defineTool)('rocketchat_list_users', `List Rocket.Chat users with pagination.
|
|
67
|
+
|
|
68
|
+
Returns user list with basic information for each user.
|
|
69
|
+
Use rocketchat_lookup_user for detailed information about a specific user.
|
|
70
|
+
|
|
71
|
+
Examples:
|
|
72
|
+
- List users: {}
|
|
73
|
+
- Paginate: { "limit": 20, "offset": 40 }`, listUsersSchema, async (params) => {
|
|
74
|
+
try {
|
|
75
|
+
const client = (0, client_js_1.getClient)();
|
|
76
|
+
const limit = params.limit || 50;
|
|
77
|
+
const offset = params.offset || 0;
|
|
78
|
+
const response = await client.listUsers(limit, offset);
|
|
79
|
+
if (!response.success) {
|
|
80
|
+
return (0, base_js_1.createErrorResult)(base_js_1.ErrorCodes.API_ERROR, 'Failed to list users');
|
|
81
|
+
}
|
|
82
|
+
const formatted = (0, message_formatter_js_1.formatUsers)(response.users);
|
|
83
|
+
const { items, truncated } = token_counter_js_1.TokenCounter.truncateToFit(formatted);
|
|
84
|
+
const result = (0, response_builder_js_1.buildPaginatedResponse)(items, response.total, offset, truncated);
|
|
85
|
+
return (0, base_js_1.createToolResult)(result);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
return (0, base_js_1.createErrorResultFromException)(base_js_1.ErrorCodes.API_ERROR, 'Failed to list users', error);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* rocketchat_get_me
|
|
93
|
+
* Get current authenticated user information
|
|
94
|
+
*/
|
|
95
|
+
const getMeSchema = zod_1.z.object({});
|
|
96
|
+
exports.getMeTool = (0, base_js_1.defineTool)('rocketchat_get_me', `Get information about the current authenticated user.
|
|
97
|
+
|
|
98
|
+
Returns the user information for the account used to authenticate with the MCP server.
|
|
99
|
+
Useful for understanding the current context and permissions.
|
|
100
|
+
|
|
101
|
+
Example: {}`, getMeSchema, async () => {
|
|
102
|
+
try {
|
|
103
|
+
const client = (0, client_js_1.getClient)();
|
|
104
|
+
const response = await client.getMe();
|
|
105
|
+
if (!response.success) {
|
|
106
|
+
return (0, base_js_1.createErrorResult)(base_js_1.ErrorCodes.API_ERROR, 'Failed to get current user');
|
|
107
|
+
}
|
|
108
|
+
const formatted = (0, message_formatter_js_1.formatUser)(response.user);
|
|
109
|
+
const result = (0, response_builder_js_1.buildSuccessResponse)(formatted);
|
|
110
|
+
return (0, base_js_1.createToolResult)(result);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return (0, base_js_1.createErrorResultFromException)(base_js_1.ErrorCodes.API_ERROR, 'Failed to get current user', error);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
// Register tools
|
|
117
|
+
base_js_1.toolRegistry.register(exports.lookupUserTool);
|
|
118
|
+
base_js_1.toolRegistry.register(exports.listUsersTool);
|
|
119
|
+
base_js_1.toolRegistry.register(exports.getMeTool);
|
|
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AAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,IAAA,wCAA8B,EAAC,oBAAU,CAAC,SAAS,EAAE,4BAA4B,EAAE,KAAK,CAAC,CAAC;IACrG,CAAC;AACL,CAAC,CACJ,CAAC;AAEF,iBAAiB;AACjB,sBAAY,CAAC,QAAQ,CAAC,sBAAc,CAAC,CAAC;AACtC,sBAAY,CAAC,QAAQ,CAAC,qBAAa,CAAC,CAAC;AACrC,sBAAY,CAAC,QAAQ,CAAC,iBAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write Tools
|
|
3
|
+
* Tools for sending messages (requires explicit enablement)
|
|
4
|
+
*/
|
|
5
|
+
export declare const sendMessageTool: import("./base.js").ToolDefinition<{
|
|
6
|
+
roomId: string;
|
|
7
|
+
text: string;
|
|
8
|
+
threadId?: string | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const reactTool: import("./base.js").ToolDefinition<{
|
|
11
|
+
emoji: string;
|
|
12
|
+
messageId: string;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const getWriteStatusTool: import("./base.js").ToolDefinition<{}>;
|
|
15
|
+
//# sourceMappingURL=write-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-tools.d.ts","sourceRoot":"","sources":["../../src/tools/write-tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA8BH,eAAO,MAAM,eAAe;;;;EAwE3B,CAAC;AAaF,eAAO,MAAM,SAAS;;;EAyDrB,CAAC;AAQF,eAAO,MAAM,kBAAkB,wCAoC9B,CAAC"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Write Tools
|
|
4
|
+
* Tools for sending messages (requires explicit enablement)
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getWriteStatusTool = exports.reactTool = exports.sendMessageTool = void 0;
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const client_js_1 = require("../api/client.js");
|
|
10
|
+
const message_formatter_js_1 = require("../formatters/message-formatter.js");
|
|
11
|
+
const response_builder_js_1 = require("../formatters/response-builder.js");
|
|
12
|
+
const write_guard_js_1 = require("../guards/write-guard.js");
|
|
13
|
+
const sanitizer_js_1 = require("../guards/sanitizer.js");
|
|
14
|
+
const base_js_1 = require("./base.js");
|
|
15
|
+
/**
|
|
16
|
+
* rocketchat_send_message
|
|
17
|
+
* Send a message to a channel
|
|
18
|
+
*/
|
|
19
|
+
const sendMessageSchema = zod_1.z.object({
|
|
20
|
+
roomId: zod_1.z.string()
|
|
21
|
+
.describe('Channel/room ID to send message to'),
|
|
22
|
+
text: zod_1.z.string().min(1).max(10000)
|
|
23
|
+
.describe('Message text to send (max 10000 characters)'),
|
|
24
|
+
threadId: zod_1.z.string().optional()
|
|
25
|
+
.describe('Thread ID (tmid) to reply to. If provided, message will be a thread reply.')
|
|
26
|
+
});
|
|
27
|
+
exports.sendMessageTool = (0, base_js_1.defineTool)('rocketchat_send_message', `Send a message to a Rocket.Chat channel.
|
|
28
|
+
|
|
29
|
+
**IMPORTANT - Check First:**
|
|
30
|
+
1. Call rocketchat_get_write_status to verify write is enabled
|
|
31
|
+
2. If disabled, inform user that ROCKETCHAT_WRITE_ENABLED=true is required
|
|
32
|
+
|
|
33
|
+
**Requirements:**
|
|
34
|
+
- ROCKETCHAT_WRITE_ENABLED=true (server configuration)
|
|
35
|
+
- Room must be in whitelist (if configured) or not in blacklist
|
|
36
|
+
|
|
37
|
+
**Safety Features (automatic):**
|
|
38
|
+
- @all, @here, @channel mentions are neutralized to prevent mass notifications
|
|
39
|
+
- Messages to unauthorized rooms are blocked
|
|
40
|
+
- Message length limited to 10000 characters
|
|
41
|
+
|
|
42
|
+
**Error Handling:**
|
|
43
|
+
- "Write disabled": Server not configured for writes
|
|
44
|
+
- "Room not allowed": Room not in whitelist or is blacklisted
|
|
45
|
+
- "API error": Check roomId is valid
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
- Sent message details
|
|
49
|
+
- Whether sanitization was applied
|
|
50
|
+
- List of neutralized patterns (if any)
|
|
51
|
+
|
|
52
|
+
Examples:
|
|
53
|
+
- Send to channel: { "roomId": "GENERAL", "text": "Hello team!" }
|
|
54
|
+
- Reply to thread: { "roomId": "GENERAL", "text": "I agree", "threadId": "abc123" }`, sendMessageSchema, async (params) => {
|
|
55
|
+
// Check write permissions
|
|
56
|
+
const writeGuard = (0, write_guard_js_1.getWriteGuard)();
|
|
57
|
+
const writeCheck = writeGuard.checkWrite(params.roomId);
|
|
58
|
+
if (!writeCheck.allowed) {
|
|
59
|
+
return (0, base_js_1.createErrorResult)(base_js_1.ErrorCodes.WRITE_DISABLED, writeCheck.reason || 'Write operation not allowed', 'Write operations are controlled by ROCKETCHAT_WRITE_ENABLED and ROCKETCHAT_WRITE_ROOMS');
|
|
60
|
+
}
|
|
61
|
+
// Sanitize message text
|
|
62
|
+
const sanitizer = (0, sanitizer_js_1.getSanitizer)();
|
|
63
|
+
const sanitized = sanitizer.sanitize(params.text);
|
|
64
|
+
try {
|
|
65
|
+
const client = (0, client_js_1.getClient)();
|
|
66
|
+
const response = await client.sendMessage({
|
|
67
|
+
roomId: params.roomId,
|
|
68
|
+
text: sanitized.text,
|
|
69
|
+
tmid: params.threadId
|
|
70
|
+
});
|
|
71
|
+
if (!response.success) {
|
|
72
|
+
return (0, base_js_1.createErrorResult)(base_js_1.ErrorCodes.API_ERROR, 'Failed to send message');
|
|
73
|
+
}
|
|
74
|
+
const formatted = (0, message_formatter_js_1.formatMessages)([response.message])[0];
|
|
75
|
+
const result = (0, response_builder_js_1.buildSuccessResponse)({
|
|
76
|
+
message: formatted,
|
|
77
|
+
sanitized: sanitized.modified,
|
|
78
|
+
neutralizedPatterns: sanitized.neutralized
|
|
79
|
+
});
|
|
80
|
+
return (0, base_js_1.createToolResult)(result);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
return (0, base_js_1.createErrorResultFromException)(base_js_1.ErrorCodes.API_ERROR, 'Failed to send message', error);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* rocketchat_react
|
|
88
|
+
* Add a reaction to a message
|
|
89
|
+
*/
|
|
90
|
+
const reactSchema = zod_1.z.object({
|
|
91
|
+
messageId: zod_1.z.string()
|
|
92
|
+
.describe('Message ID to react to'),
|
|
93
|
+
emoji: zod_1.z.string()
|
|
94
|
+
.describe('Emoji to react with (e.g., ":thumbsup:", ":check:", ":eyes:")')
|
|
95
|
+
});
|
|
96
|
+
exports.reactTool = (0, base_js_1.defineTool)('rocketchat_react', `Add a reaction emoji to a message.
|
|
97
|
+
|
|
98
|
+
Requires ROCKETCHAT_WRITE_ENABLED=true.
|
|
99
|
+
|
|
100
|
+
Emoji format:
|
|
101
|
+
- With colons: ":thumbsup:"
|
|
102
|
+
- Without colons: "thumbsup" (will be normalized)
|
|
103
|
+
|
|
104
|
+
Common reactions:
|
|
105
|
+
- :thumbsup: - Agreement/approval
|
|
106
|
+
- :eyes: - Looking into it
|
|
107
|
+
- :white_check_mark: - Done/completed
|
|
108
|
+
- :hourglass: - In progress
|
|
109
|
+
- :question: - Needs clarification
|
|
110
|
+
|
|
111
|
+
Examples:
|
|
112
|
+
- Add thumbsup: { "messageId": "abc123", "emoji": ":thumbsup:" }
|
|
113
|
+
- Mark as done: { "messageId": "abc123", "emoji": "white_check_mark" }`, reactSchema, async (params) => {
|
|
114
|
+
// Reactions require write access
|
|
115
|
+
const writeGuard = (0, write_guard_js_1.getWriteGuard)();
|
|
116
|
+
if (!writeGuard.isEnabled()) {
|
|
117
|
+
return (0, base_js_1.createErrorResult)(base_js_1.ErrorCodes.WRITE_DISABLED, 'Write operations are disabled', 'Set ROCKETCHAT_WRITE_ENABLED=true to enable reactions');
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const client = (0, client_js_1.getClient)();
|
|
121
|
+
// Normalize emoji format
|
|
122
|
+
let emoji = params.emoji;
|
|
123
|
+
if (!emoji.startsWith(':'))
|
|
124
|
+
emoji = ':' + emoji;
|
|
125
|
+
if (!emoji.endsWith(':'))
|
|
126
|
+
emoji = emoji + ':';
|
|
127
|
+
const response = await client.reactToMessage(params.messageId, emoji);
|
|
128
|
+
if (!response.success) {
|
|
129
|
+
return (0, base_js_1.createErrorResult)(base_js_1.ErrorCodes.API_ERROR, 'Failed to add reaction');
|
|
130
|
+
}
|
|
131
|
+
const result = (0, response_builder_js_1.buildSuccessResponse)({
|
|
132
|
+
messageId: params.messageId,
|
|
133
|
+
emoji,
|
|
134
|
+
success: true
|
|
135
|
+
});
|
|
136
|
+
return (0, base_js_1.createToolResult)(result);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
return (0, base_js_1.createErrorResultFromException)(base_js_1.ErrorCodes.API_ERROR, 'Failed to add reaction', error);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
/**
|
|
143
|
+
* rocketchat_get_write_status
|
|
144
|
+
* Check if write operations are enabled and get configuration
|
|
145
|
+
*/
|
|
146
|
+
const getWriteStatusSchema = zod_1.z.object({});
|
|
147
|
+
exports.getWriteStatusTool = (0, base_js_1.defineTool)('rocketchat_get_write_status', `Check if write operations are enabled and get the current configuration.
|
|
148
|
+
|
|
149
|
+
**Call this BEFORE using rocketchat_send_message or rocketchat_react.**
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
- enabled: Whether write operations are allowed
|
|
153
|
+
- whitelist: Rooms where writes are allowed (if configured)
|
|
154
|
+
- blacklist: Rooms where writes are blocked
|
|
155
|
+
- description: Human-readable status summary
|
|
156
|
+
|
|
157
|
+
**Decision Tree:**
|
|
158
|
+
1. If enabled=false → Inform user writes are disabled
|
|
159
|
+
2. If enabled=true + whitelist → Check if target room is in whitelist
|
|
160
|
+
3. If enabled=true + no whitelist → All rooms allowed except blacklist
|
|
161
|
+
|
|
162
|
+
Example: {}`, getWriteStatusSchema, async () => {
|
|
163
|
+
const writeGuard = (0, write_guard_js_1.getWriteGuard)();
|
|
164
|
+
const config = writeGuard.getConfig();
|
|
165
|
+
const result = (0, response_builder_js_1.buildSuccessResponse)({
|
|
166
|
+
enabled: config.enabled,
|
|
167
|
+
whitelist: config.whitelist,
|
|
168
|
+
blacklist: config.blacklist,
|
|
169
|
+
description: config.enabled
|
|
170
|
+
? config.whitelist.length > 0
|
|
171
|
+
? `Write enabled for rooms: ${config.whitelist.join(', ')}`
|
|
172
|
+
: 'Write enabled for all rooms (except blacklisted)'
|
|
173
|
+
: 'Write operations are disabled'
|
|
174
|
+
});
|
|
175
|
+
return (0, base_js_1.createToolResult)(result);
|
|
176
|
+
});
|
|
177
|
+
// Register tools
|
|
178
|
+
base_js_1.toolRegistry.register(exports.sendMessageTool);
|
|
179
|
+
base_js_1.toolRegistry.register(exports.reactTool);
|
|
180
|
+
base_js_1.toolRegistry.register(exports.getWriteStatusTool);
|
|
181
|
+
//# sourceMappingURL=write-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-tools.js","sourceRoot":"","sources":["../../src/tools/write-tools.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6BAAwB;AACxB,gDAA6C;AAC7C,6EAAoE;AACpE,2EAAyE;AACzE,6DAAyD;AACzD,yDAAsD;AACtD,uCAOmB;AAEnB;;;GAGG;AACH,MAAM,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/B,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;SACb,QAAQ,CAAC,oCAAoC,CAAC;IACnD,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;SAC7B,QAAQ,CAAC,6CAA6C,CAAC;IAC5D,QAAQ,EAAE,OAAC,CAAC,M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,IAAI,CAAC,EAAE;gBAC3D,CAAC,CAAC,kDAAkD;YACxD,CAAC,CAAC,+BAA+B;KACxC,CAAC,CAAC;IAEH,OAAO,IAAA,0BAAgB,EAAC,MAAM,CAAC,CAAC;AACpC,CAAC,CACJ,CAAC;AAEF,iBAAiB;AACjB,sBAAY,CAAC,QAAQ,CAAC,uBAAe,CAAC,CAAC;AACvC,sBAAY,CAAC,QAAQ,CAAC,iBAAS,CAAC,CAAC;AACjC,sBAAY,CAAC,QAAQ,CAAC,0BAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LRU Cache implementation for API response caching
|
|
3
|
+
* Reduces redundant API calls and improves response time
|
|
4
|
+
*/
|
|
5
|
+
export declare class LRUCache<T> {
|
|
6
|
+
private cache;
|
|
7
|
+
private readonly maxSize;
|
|
8
|
+
private readonly ttlMs;
|
|
9
|
+
constructor(maxSize?: number, ttlMs?: number);
|
|
10
|
+
/**
|
|
11
|
+
* Get value from cache
|
|
12
|
+
*/
|
|
13
|
+
get(key: string): T | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Set value in cache
|
|
16
|
+
*/
|
|
17
|
+
set(key: string, value: T): void;
|
|
18
|
+
/**
|
|
19
|
+
* Check if key exists and is not expired
|
|
20
|
+
*/
|
|
21
|
+
has(key: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Delete entry from cache
|
|
24
|
+
*/
|
|
25
|
+
delete(key: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Clear all entries
|
|
28
|
+
*/
|
|
29
|
+
clear(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Get cache statistics
|
|
32
|
+
*/
|
|
33
|
+
getStats(): {
|
|
34
|
+
size: number;
|
|
35
|
+
maxSize: number;
|
|
36
|
+
ttlMs: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Remove expired entries
|
|
40
|
+
*/
|
|
41
|
+
prune(): number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create cache key from parameters
|
|
45
|
+
*/
|
|
46
|
+
export declare function createCacheKey(prefix: string, params: Record<string, unknown>): string;
|
|
47
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,qBAAa,QAAQ,CAAC,CAAC;IACnB,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,OAAO,GAAE,MAAY,EAAE,KAAK,GAAE,MAAe;IAMzD;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAqB/B;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAgBhC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAczB;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI5B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,QAAQ,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAQ5D;;OAEG;IACH,KAAK,IAAI,MAAM;CAalB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAOtF"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* LRU Cache implementation for API response caching
|
|
4
|
+
* Reduces redundant API calls and improves response time
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LRUCache = void 0;
|
|
8
|
+
exports.createCacheKey = createCacheKey;
|
|
9
|
+
class LRUCache {
|
|
10
|
+
cache;
|
|
11
|
+
maxSize;
|
|
12
|
+
ttlMs;
|
|
13
|
+
constructor(maxSize = 100, ttlMs = 300000) {
|
|
14
|
+
this.cache = new Map();
|
|
15
|
+
this.maxSize = maxSize;
|
|
16
|
+
this.ttlMs = ttlMs;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get value from cache
|
|
20
|
+
*/
|
|
21
|
+
get(key) {
|
|
22
|
+
const entry = this.cache.get(key);
|
|
23
|
+
if (!entry) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
// Check if expired
|
|
27
|
+
if (Date.now() - entry.timestamp > this.ttlMs) {
|
|
28
|
+
this.cache.delete(key);
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
// Update access count and move to end (most recently used)
|
|
32
|
+
entry.accessCount++;
|
|
33
|
+
this.cache.delete(key);
|
|
34
|
+
this.cache.set(key, entry);
|
|
35
|
+
return entry.value;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set value in cache
|
|
39
|
+
*/
|
|
40
|
+
set(key, value) {
|
|
41
|
+
// Remove oldest entries if at capacity
|
|
42
|
+
if (this.cache.size >= this.maxSize) {
|
|
43
|
+
const oldestKey = this.cache.keys().next().value;
|
|
44
|
+
if (oldestKey) {
|
|
45
|
+
this.cache.delete(oldestKey);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
this.cache.set(key, {
|
|
49
|
+
value,
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
accessCount: 1
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check if key exists and is not expired
|
|
56
|
+
*/
|
|
57
|
+
has(key) {
|
|
58
|
+
const entry = this.cache.get(key);
|
|
59
|
+
if (!entry) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (Date.now() - entry.timestamp > this.ttlMs) {
|
|
63
|
+
this.cache.delete(key);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Delete entry from cache
|
|
70
|
+
*/
|
|
71
|
+
delete(key) {
|
|
72
|
+
return this.cache.delete(key);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Clear all entries
|
|
76
|
+
*/
|
|
77
|
+
clear() {
|
|
78
|
+
this.cache.clear();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get cache statistics
|
|
82
|
+
*/
|
|
83
|
+
getStats() {
|
|
84
|
+
return {
|
|
85
|
+
size: this.cache.size,
|
|
86
|
+
maxSize: this.maxSize,
|
|
87
|
+
ttlMs: this.ttlMs
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Remove expired entries
|
|
92
|
+
*/
|
|
93
|
+
prune() {
|
|
94
|
+
const now = Date.now();
|
|
95
|
+
let removed = 0;
|
|
96
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
97
|
+
if (now - entry.timestamp > this.ttlMs) {
|
|
98
|
+
this.cache.delete(key);
|
|
99
|
+
removed++;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return removed;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.LRUCache = LRUCache;
|
|
106
|
+
/**
|
|
107
|
+
* Create cache key from parameters
|
|
108
|
+
*/
|
|
109
|
+
function createCacheKey(prefix, params) {
|
|
110
|
+
const sortedParams = Object.keys(params)
|
|
111
|
+
.sort()
|
|
112
|
+
.map(key => `${key}=${JSON.stringify(params[key])}`)
|
|
113
|
+
.join('&');
|
|
114
|
+
return `${prefix}:${sortedParams}`;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=cache.js.map
|
|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AK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC9C,IAAI,GAAG,GAAG,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;gBACrC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACvB,OAAO,EAAE,CAAC;YACd,CAAC;QACL,CAAC;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAhHD,4BAgHC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,MAA+B;IAC1E,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACnC,IAAI,EAAE;SACN,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;SACnD,IAAI,CAAC,GAAG,CAAC,CAAC;IAEf,OAAO,GAAG,MAAM,IAAI,YAAY,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized Error Handling Utilities
|
|
3
|
+
* Provides consistent error handling across all MCP tools
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Error codes used across the MCP server
|
|
7
|
+
*/
|
|
8
|
+
export declare const ErrorCodes: {
|
|
9
|
+
readonly API_ERROR: "API_ERROR";
|
|
10
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
11
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
12
|
+
readonly PERMISSION_DENIED: "PERMISSION_DENIED";
|
|
13
|
+
readonly RATE_LIMITED: "RATE_LIMITED";
|
|
14
|
+
readonly WRITE_DISABLED: "WRITE_DISABLED";
|
|
15
|
+
readonly ROOM_NOT_ALLOWED: "ROOM_NOT_ALLOWED";
|
|
16
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
17
|
+
};
|
|
18
|
+
export type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
|
|
19
|
+
/**
|
|
20
|
+
* Standardized error result structure
|
|
21
|
+
*/
|
|
22
|
+
export interface ErrorInfo {
|
|
23
|
+
code: ErrorCode;
|
|
24
|
+
message: string;
|
|
25
|
+
details?: string;
|
|
26
|
+
suggestion?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Extract a meaningful error message from any error type
|
|
30
|
+
*/
|
|
31
|
+
export declare function extractErrorMessage(error: unknown): string;
|
|
32
|
+
/**
|
|
33
|
+
* Extract error details (stack trace or additional info)
|
|
34
|
+
*/
|
|
35
|
+
export declare function extractErrorDetails(error: unknown): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Create an error info object from any error
|
|
38
|
+
*/
|
|
39
|
+
export declare function createErrorInfo(code: ErrorCode, defaultMessage: string, error?: unknown): ErrorInfo;
|
|
40
|
+
/**
|
|
41
|
+
* Map HTTP status codes to error codes
|
|
42
|
+
*/
|
|
43
|
+
export declare function httpStatusToErrorCode(status: number): ErrorCode;
|
|
44
|
+
/**
|
|
45
|
+
* Wrapper for async handler functions with consistent error handling
|
|
46
|
+
* @param handler - The async handler function to wrap
|
|
47
|
+
* @param errorCode - Default error code to use
|
|
48
|
+
* @param errorMessage - Default error message
|
|
49
|
+
* @returns A wrapped function that catches errors and returns error results
|
|
50
|
+
*/
|
|
51
|
+
export declare function withErrorHandling<TParams, TResult>(handler: (params: TParams) => Promise<TResult>, errorCode: ErrorCode, errorMessage: string): (params: TParams) => Promise<TResult | ErrorInfo>;
|
|
52
|
+
/**
|
|
53
|
+
* Helper to check if a result is an error info
|
|
54
|
+
*/
|
|
55
|
+
export declare function isErrorInfo(result: unknown): result is ErrorInfo;
|
|
56
|
+
/**
|
|
57
|
+
* Standard suggestions for common errors
|
|
58
|
+
*/
|
|
59
|
+
export declare const ErrorSuggestions: Record<ErrorCode, string>;
|
|
60
|
+
/**
|
|
61
|
+
* Add suggestion to error info based on error code
|
|
62
|
+
*/
|
|
63
|
+
export declare function enrichErrorInfo(errorInfo: ErrorInfo): ErrorInfo;
|
|
64
|
+
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/utils/error-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;CASb,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,OAAO,UAAU,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAW1D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAgBtE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC3B,IAAI,EAAE,SAAS,EACf,cAAc,EAAE,MAAM,EACtB,KAAK,CAAC,EAAE,OAAO,GAChB,SAAS,CASX;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAc/D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAC9C,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,EAC9C,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,MAAM,GACrB,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAQnD;AAED;;GAEG;AACH,wBAA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