Skip to main content
Glama
piekstra

Slack MCP Server

by piekstra

send_code_snippet

Send formatted code snippets to Slack channels with syntax highlighting, titles, and optional descriptions for clear technical communication.

Instructions

Send a formatted code snippet message.

Args: channel: Channel ID or name title: Code snippet title code: The code content language: Programming language for syntax highlighting (optional) description: Optional description thread_ts: Thread timestamp for replies (optional)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channelYes
titleYes
codeYes
languageNo
descriptionNo
thread_tsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'send_code_snippet' MCP tool. It constructs a Slack Block Kit message with a header, optional description, and formatted code block, then sends it to the specified channel. Includes registration via @mcp.tool() decorator. The function signature and docstring define the tool schema.
    @mcp.tool()
    async def send_code_snippet(
        channel: str,
        title: str,
        code: str,
        language: Optional[str] = None,
        description: Optional[str] = None,
        thread_ts: Optional[str] = None
    ) -> str:
        """
        Send a formatted code snippet message.
    
        Args:
            channel: Channel ID or name
            title: Code snippet title
            code: The code content
            language: Programming language for syntax highlighting (optional)
            description: Optional description
            thread_ts: Thread timestamp for replies (optional)
        """
        try:
            blocks = [BlockKitBuilder.header(title)]
            
            if description:
                blocks.append(BlockKitBuilder.section(description))
            
            blocks.append(BlockKitBuilder.code_block(code, language))
            
            fallback_text = f"{title}: {code[:100]}{'...' if len(code) > 100 else ''}"
            
            client = SlackClient()
            result = await client.send_message(channel, fallback_text, thread_ts, blocks)
            return json.dumps(result, indent=2)
        except Exception as e:
            return json.dumps({"error": str(e)}, indent=2)
  • Supporting method in BlockKitBuilder class that creates a Slack Block Kit section block containing a mrkdwn-formatted code snippet, used directly by the send_code_snippet handler.
    def code_block(code: str, language: Optional[str] = None) -> Dict[str, Any]:
        """Create a formatted code block."""
        formatted_code = f"```{language + chr(10) if language else ''}{code}```"
        return {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": formatted_code
            }
        }
Behavior2/5

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

No annotations are provided, so the description carries full burden. While 'send' implies a write operation, the description doesn't disclose important behavioral aspects: whether this requires specific permissions, if it's rate-limited, whether messages are editable/deletable after sending, or what happens if the channel doesn't exist. It mentions formatting but doesn't explain what 'formatted' entails beyond syntax highlighting.

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

Conciseness3/5

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

The description is appropriately sized with a clear purpose statement followed by parameter documentation. However, the structure could be more front-loaded with usage context, and the parameter explanations are somewhat terse without examples. Every sentence serves a purpose, but the overall presentation could be more polished.

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

Completeness3/5

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

Given the tool has an output schema (which handles return values), 0% schema description coverage, and no annotations, the description does an adequate job explaining parameters and basic purpose. However, for a messaging tool with multiple similar siblings and no behavioral context, it should provide more guidance on when to use it and what distinguishes it from other message-sending tools.

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

Parameters4/5

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

With 0% schema description coverage, the description compensates well by explaining all 6 parameters in the Args section. It clarifies what each parameter represents (e.g., 'channel: Channel ID or name', 'language: Programming language for syntax highlighting'), adds semantic meaning about optionality, and distinguishes between required and optional parameters. The only gap is not explaining parameter formats or constraints.

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 with a specific verb ('send') and resource ('formatted code snippet message'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'send_message' or 'send_formatted_message', which likely have overlapping functionality in the same messaging context.

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. With multiple sibling tools for sending messages (send_message, send_formatted_message, send_announcement, etc.), there's no indication of when a code snippet is preferred over other message types or what distinguishes this from general formatted messages.

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/piekstra/slack-mcp-server'

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