Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions slack-mcp/server/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export interface SlackChannel {
is_member: boolean;
created: number;
creator: string;
user?: string;
topic?: {
value: string;
creator: string;
Expand Down
24 changes: 23 additions & 1 deletion slack-mcp/server/slack/handlers/eventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
addReaction,
removeReaction,
deleteMessage,
getUserInfo,
} from "../../lib/slack-client.ts";
import type {
SlackEvent,
Expand Down Expand Up @@ -845,8 +846,29 @@ async function handleDirectMessage(
await removeReaction(channel, ts, "eyes");
}

// Resolve sender name so the LLM knows who it's talking to
let senderText = text;
try {
const userInfo = await getUserInfo(user);
const senderName = userInfo
? userInfo.profile?.display_name || userInfo.real_name || userInfo.name
: null;
if (senderName) {
senderText = `[Mensagem de ${senderName}]\n${text}`;
console.log(`[EventHandler] DM sender resolved: ${senderName}`);
}
} catch (err) {
console.warn(`[EventHandler] Failed to resolve DM sender name:`, err);
}

console.log(`[EventHandler] Building LLM messages for DM...`);
const messages = await buildLLMMessages(channel, text, ts, undefined, media);
const messages = await buildLLMMessages(
channel,
senderText,
ts,
undefined,
media,
);
console.log(`[EventHandler] LLM messages built: ${messages.length} messages`);
messages.forEach((msg, i) => {
console.log(
Expand Down
76 changes: 76 additions & 0 deletions slack-mcp/server/tools/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getChannelMembers,
openDM,
inviteToChannel,
getUserInfo,
} from "../lib/slack-client.ts";

/**
Expand Down Expand Up @@ -98,6 +99,80 @@ export const createListChannelsTool = (_env: Env) =>
},
});

/**
* List all direct message conversations
*/
export const createListDMsTool = (_env: Env) =>
createTool({
id: "SLACK_LIST_DMS",
description:
"List all direct message conversations the bot has. Returns channel IDs that can be used with SLACK_GET_CHANNEL_HISTORY to read DM messages.",
annotations: { readOnlyHint: true },
inputSchema: z
.object({
limit: z
.number()
.optional()
.default(100)
.describe("Maximum number of DMs to return"),
})
.strict(),
outputSchema: z
.object({
success: z.boolean(),
dms: z.array(
z.object({
channel_id: z.string(),
user_id: z.string(),
user_name: z.string(),
}),
),
error: z.string().optional(),
})
.strict(),
execute: async ({ context }: { context: unknown }) => {
const input = context as { limit?: number };

try {
const channels = await listChannels({
types: "im",
limit: input.limit,
skipCache: true,
});

const imChannels = channels.filter((c) => c.is_im && c.user);

const dms = await Promise.all(
imChannels.map(async (c) => {
const userInfo = await getUserInfo(c.user!);
const userName = userInfo
? userInfo.profile?.display_name ||
userInfo.real_name ||
userInfo.name
: "(unknown user)";

return {
channel_id: c.id,
user_id: c.user!,
user_name: userName,
};
}),
);

return {
success: true,
dms,
};
} catch (error) {
return {
success: false,
dms: [],
error: error instanceof Error ? error.message : String(error),
};
}
},
});

/**
* Get channel info
*/
Expand Down Expand Up @@ -356,6 +431,7 @@ export const createInviteToChannelTool = (_env: Env) =>
*/
export const channelTools = [
createListChannelsTool,
createListDMsTool,
createGetChannelInfoTool,
createJoinChannelTool,
createGetChannelMembersTool,
Expand Down
7 changes: 0 additions & 7 deletions slack-mcp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true,
/* Path Aliases */
"baseUrl": ".",
"paths": {
"server/*": [
"./server/*"
]
},
/* Types */
"types": [
"@types/node"
Expand Down
Loading