teams-mcp-server
Version:
Microsoft Teams MCP server with direct messaging support
57 lines (56 loc) • 2.07 kB
JavaScript
export function createListChatsTool(teamsClient) {
return {
name: 'teams_list_chats',
description: 'List all chats for the authenticated user',
inputSchema: {
type: 'object',
properties: {
limit: {
type: 'number',
description: 'Maximum number of chats to return (1-50)',
minimum: 1,
maximum: 50,
default: 50
},
filter: {
type: 'string',
description: 'OData filter expression (e.g., "chatType eq \'oneOnOne\'")'
}
},
required: []
},
handler: async (args) => {
try {
await teamsClient.ensureAuthenticated();
const limit = args.limit || 50;
const filter = args.filter;
const chats = await teamsClient.listChats(limit, filter);
const formattedChats = chats.map(chat => ({
id: chat.id,
type: chat.chatType,
topic: chat.topic || `${chat.chatType} chat`,
created: new Date(chat.createdDateTime).toLocaleString(),
lastActivity: new Date(chat.lastUpdatedDateTime).toLocaleString(),
webUrl: chat.webUrl
}));
return {
content: [{
type: 'text',
text: JSON.stringify({
chats: formattedChats,
count: formattedChats.length
}, null, 2)
}]
};
}
catch (error) {
return {
content: [{
type: 'text',
text: `Failed to list chats: ${error.message}`
}]
};
}
}
};
}