Skip to main content
Glama

send_chat_message

Send formatted messages to Microsoft Teams chats with mentions and priority settings to communicate effectively within conversations.

Instructions

Send a message to a specific chat conversation. Supports text and markdown formatting, mentions, and importance levels.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chatIdYesChat ID
messageYesMessage content
importanceNoMessage importance
formatNoMessage format (text or markdown)
mentionsNoArray of @mentions to include in the message

Implementation Reference

  • The handler function that implements the core logic of the 'send_chat_message' tool. It handles message formatting (text/markdown), processes mentions by fetching user display names and generating HTML mention tags, builds the payload, and sends the POST request to Microsoft Graph API `/me/chats/{chatId}/messages`.
      async ({ chatId, message, importance = "normal", format = "text", mentions }) => {
        try {
          const client = await graphService.getClient();
    
          // Process message content based on format
          let content: string;
          let contentType: "text" | "html";
    
          if (format === "markdown") {
            content = await markdownToHtml(message);
            contentType = "html";
          } else {
            content = message;
            contentType = "text";
          }
    
          // Process @mentions if provided
          const mentionMappings: Array<{ mention: string; userId: string; displayName: string }> = [];
          if (mentions && mentions.length > 0) {
            // Convert provided mentions to mappings with display names
            for (const mention of mentions) {
              try {
                // Get user info to get display name
                const userResponse = await client
                  .api(`/users/${mention.userId}`)
                  .select("displayName")
                  .get();
                mentionMappings.push({
                  mention: mention.mention,
                  userId: mention.userId,
                  displayName: userResponse.displayName || mention.mention,
                });
              } catch (_error) {
                console.warn(
                  `Could not resolve user ${mention.userId}, using mention text as display name`
                );
                mentionMappings.push({
                  mention: mention.mention,
                  userId: mention.userId,
                  displayName: mention.mention,
                });
              }
            }
          }
    
          // Process mentions in HTML content
          let finalMentions: Array<{
            id: number;
            mentionText: string;
            mentioned: { user: { id: string } };
          }> = [];
          if (mentionMappings.length > 0) {
            const result = processMentionsInHtml(content, mentionMappings);
            content = result.content;
            finalMentions = result.mentions;
    
            // Ensure we're using HTML content type when mentions are present
            contentType = "html";
          }
    
          // Build message payload
          const messagePayload: any = {
            body: {
              content,
              contentType,
            },
            importance,
          };
    
          if (finalMentions.length > 0) {
            messagePayload.mentions = finalMentions;
          }
    
          const result = (await client
            .api(`/me/chats/${chatId}/messages`)
            .post(messagePayload)) as ChatMessage;
    
          // Build success message
          const successText = `āœ… Message sent successfully. Message ID: ${result.id}${
            finalMentions.length > 0
              ? `\nšŸ“± Mentions: ${finalMentions.map((m) => m.mentionText).join(", ")}`
              : ""
          }`;
    
          return {
            content: [
              {
                type: "text" as const,
                text: successText,
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: "text" as const,
                text: `āŒ Failed to send message: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • Zod input schema for the 'send_chat_message' tool defining parameters: chatId (required string), message (required string), importance (optional enum: normal/high/urgent), format (optional enum: text/markdown), mentions (optional array of objects with mention text and userId).
    {
      chatId: z.string().describe("Chat ID"),
      message: z.string().describe("Message content"),
      importance: z.enum(["normal", "high", "urgent"]).optional().describe("Message importance"),
      format: z.enum(["text", "markdown"]).optional().describe("Message format (text or markdown)"),
      mentions: z
        .array(
          z.object({
            mention: z
              .string()
              .describe("The @mention text (e.g., 'john.doe' or 'john.doe@company.com')"),
            userId: z.string().describe("Azure AD User ID of the mentioned user"),
          })
        )
        .optional()
        .describe("Array of @mentions to include in the message"),
    },
  • The server.tool() call that registers the 'send_chat_message' tool on the MCP server, providing the tool name, description, input schema, and handler function.
    server.tool(
      "send_chat_message",
      "Send a message to a specific chat conversation. Supports text and markdown formatting, mentions, and importance levels.",
      {
        chatId: z.string().describe("Chat ID"),
        message: z.string().describe("Message content"),
        importance: z.enum(["normal", "high", "urgent"]).optional().describe("Message importance"),
        format: z.enum(["text", "markdown"]).optional().describe("Message format (text or markdown)"),
        mentions: z
          .array(
            z.object({
              mention: z
                .string()
                .describe("The @mention text (e.g., 'john.doe' or 'john.doe@company.com')"),
              userId: z.string().describe("Azure AD User ID of the mentioned user"),
            })
          )
          .optional()
          .describe("Array of @mentions to include in the message"),
      },
      async ({ chatId, message, importance = "normal", format = "text", mentions }) => {
        try {
          const client = await graphService.getClient();
    
          // Process message content based on format
          let content: string;
          let contentType: "text" | "html";
    
          if (format === "markdown") {
            content = await markdownToHtml(message);
            contentType = "html";
          } else {
            content = message;
            contentType = "text";
          }
    
          // Process @mentions if provided
          const mentionMappings: Array<{ mention: string; userId: string; displayName: string }> = [];
          if (mentions && mentions.length > 0) {
            // Convert provided mentions to mappings with display names
            for (const mention of mentions) {
              try {
                // Get user info to get display name
                const userResponse = await client
                  .api(`/users/${mention.userId}`)
                  .select("displayName")
                  .get();
                mentionMappings.push({
                  mention: mention.mention,
                  userId: mention.userId,
                  displayName: userResponse.displayName || mention.mention,
                });
              } catch (_error) {
                console.warn(
                  `Could not resolve user ${mention.userId}, using mention text as display name`
                );
                mentionMappings.push({
                  mention: mention.mention,
                  userId: mention.userId,
                  displayName: mention.mention,
                });
              }
            }
          }
    
          // Process mentions in HTML content
          let finalMentions: Array<{
            id: number;
            mentionText: string;
            mentioned: { user: { id: string } };
          }> = [];
          if (mentionMappings.length > 0) {
            const result = processMentionsInHtml(content, mentionMappings);
            content = result.content;
            finalMentions = result.mentions;
    
            // Ensure we're using HTML content type when mentions are present
            contentType = "html";
          }
    
          // Build message payload
          const messagePayload: any = {
            body: {
              content,
              contentType,
            },
            importance,
          };
    
          if (finalMentions.length > 0) {
            messagePayload.mentions = finalMentions;
          }
    
          const result = (await client
            .api(`/me/chats/${chatId}/messages`)
            .post(messagePayload)) as ChatMessage;
    
          // Build success message
          const successText = `āœ… Message sent successfully. Message ID: ${result.id}${
            finalMentions.length > 0
              ? `\nšŸ“± Mentions: ${finalMentions.map((m) => m.mentionText).join(", ")}`
              : ""
          }`;
    
          return {
            content: [
              {
                type: "text" as const,
                text: successText,
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: "text" as const,
                text: `āŒ Failed to send message: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • src/index.ts:135-135 (registration)
    Invocation of registerChatTools(server, graphService) in the main MCP server setup, which registers all chat tools including 'send_chat_message'.
    registerChatTools(server, graphService);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions supported features (text/markdown formatting, mentions, importance levels) but lacks critical behavioral details: whether this requires specific permissions, if messages are editable/deletable after sending, rate limits, error conditions, or what happens on success. For a mutation tool with zero annotation coverage, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose and lists key features. There's no wasted text, but it could be slightly more structured by separating purpose from capabilities. It earns a 4 for being appropriately sized and clear.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (5 parameters, mutation operation) and lack of annotations or output schema, the description is incomplete. It doesn't address behavioral aspects like permissions, side effects, or response format, which are crucial for an AI agent to use it correctly. For a chat messaging tool with no structured safety or output info, this is insufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, meaning all parameters are documented in the schema itself. The description adds minimal value beyond the schema by listing supported features (formatting, mentions, importance) that correspond to parameters, but doesn't provide additional semantic context like examples or constraints. With high schema coverage, the baseline is 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Send a message to a specific chat conversation.' It specifies the action (send) and resource (message to chat conversation), distinguishing it from sibling tools like 'send_channel_message' which targets channels. However, it doesn't explicitly contrast with 'reply_to_channel_message' or other messaging tools, keeping it at 4 rather than 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose 'send_chat_message' over 'send_channel_message' or 'reply_to_channel_message', nor does it specify prerequisites like needing an existing chat. Without any usage context or exclusions, this scores a 2.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/floriscornel/teams-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server