teams-mcp-server
Version:
Microsoft Teams MCP server with direct messaging support
104 lines (103 loc) • 4.09 kB
JavaScript
import { TeamsClientStateless } from '../api/teamsClientStateless.js';
import { getAccessToken } from '../utils/tokenHelper.js';
export function createChatStatelessTool() {
const teamsClient = new TeamsClientStateless();
return {
name: 'teams_create_chat',
description: 'Create a new Teams chat (one-on-one or group)',
inputSchema: {
type: 'object',
properties: {
tokens: {
type: 'object',
properties: {
access_token: { type: ['string', 'null'] }
},
required: [],
description: 'OAuth tokens with access_token'
},
chatType: {
type: 'string',
enum: ['oneOnOne', 'group'],
description: 'Type of chat to create'
},
members: {
type: 'array',
description: 'List of members to add to the chat',
items: {
type: 'object',
properties: {
email: {
type: 'string',
description: 'Email address of the user to add'
},
role: {
type: 'string',
enum: ['owner', 'guest'],
description: 'Role of the member in the chat',
default: 'owner'
}
},
required: ['email']
},
minItems: 1
},
topic: {
type: 'string',
description: 'Topic/name for the chat (only for group chats)'
}
},
required: ['tokens', 'chatType', 'members']
},
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 request = {
chatType: args.chatType,
members: args.members,
topic: args.topic
};
if (request.chatType === 'oneOnOne' && request.members.length !== 1) {
return {
content: [{
type: 'text',
text: 'Error: One-on-one chats must have exactly 1 other member'
}]
};
}
const chat = await teamsClient.createChat(accessToken, request);
return {
content: [{
type: 'text',
text: JSON.stringify({
success: true,
chat: {
id: chat.id,
type: chat.chatType,
topic: chat.topic || `${chat.chatType} chat`,
webUrl: chat.webUrl,
created: new Date(chat.createdDateTime).toLocaleString()
}
}, null, 2)
}]
};
}
catch (error) {
return {
content: [{
type: 'text',
text: `Failed to create chat: ${error.message}`
}]
};
}
}
};
}