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

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
            }
        }

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