teams-mcp-server
Version:
Microsoft Teams MCP server with direct messaging support
76 lines (75 loc) • 2.9 kB
JavaScript
import { TeamsClientStateless } from '../api/teamsClientStateless.js';
import { getAccessToken } from '../utils/tokenHelper.js';
export function createListChatsStatelessTool() {
const teamsClient = new TeamsClientStateless();
return {
name: 'teams_list_chats',
description: 'List all chats for the authenticated user',
inputSchema: {
type: 'object',
properties: {
tokens: {
type: 'object',
properties: {
access_token: { type: ['string', 'null'] }
},
required: [],
description: 'OAuth tokens with access_token'
},
limit: {
type: 'number',
description: 'Maximum number of chats to return (1-50)',
minimum: 1,
maximum: 50,
default: 50
},
filter: {
type: ['string', 'null'],
description: 'OData filter expression (e.g., "chatType eq \'oneOnOne\'")'
}
},
required: []
},
handler: async (args) => {
try {
const accessToken = getAccessToken(args.tokens);
if (!accessToken) {
return {
content: [{
type: 'text',
text: 'Error: access_token is required in tokens parameter'
}]
};
}
const limit = args.limit || 50;
const filter = args.filter;
const chats = await teamsClient.listChats(accessToken, 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}`
}]
};
}
}
};
}