teams-mcp-server
Version:
Microsoft Teams MCP server with direct messaging support
79 lines (78 loc) • 3.01 kB
JavaScript
import { TeamsClientStateless } from '../api/teamsClientStateless.js';
import { getAccessToken } from '../utils/tokenHelper.js';
export function createSendMessageStatelessTool() {
const teamsClient = new TeamsClientStateless();
return {
name: 'teams_send_message',
description: 'Send a message to a Teams chat',
inputSchema: {
type: 'object',
properties: {
tokens: {
type: 'object',
properties: {
access_token: { type: ['string', 'null'] }
},
required: [],
description: 'OAuth tokens with access_token'
},
chatId: {
type: 'string',
description: 'ID of the chat to send the message to'
},
content: {
type: 'string',
description: 'Content of the message'
},
contentType: {
type: 'string',
enum: ['text', 'html'],
description: 'Type of content (text or HTML)',
default: 'text'
}
},
required: ['tokens', 'chatId', 'content']
},
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 = {
chatId: args.chatId,
content: args.content,
contentType: args.contentType || 'text'
};
const message = await teamsClient.sendMessage(accessToken, args.chatId, request);
return {
content: [{
type: 'text',
text: JSON.stringify({
success: true,
message: {
id: message.id,
from: message.from?.user?.displayName || 'Unknown',
content: message.body?.content,
timestamp: new Date(message.createdDateTime).toLocaleString()
}
}, null, 2)
}]
};
}
catch (error) {
return {
content: [{
type: 'text',
text: `Failed to send message: ${error.message}`
}]
};
}
}
};
}