Skip to main content
Glama
piekstra

Slack MCP Server

by piekstra

send_code_snippet

Share formatted code snippets in Slack channels with syntax highlighting. Specify the channel, title, code, optional language, and description for clear 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
codeYes
descriptionNo
languageNo
thread_tsNo
titleYes

Implementation Reference

  • Primary handler function for the send_code_snippet tool. Decorated with @mcp.tool() for registration. Builds a Slack Block Kit message using a header, optional description, and code block, then sends it via SlackClient.
    @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)
  • Helper method in BlockKitBuilder class that formats the provided code into a Slack mrkdwn code block with optional language specifier, used directly in 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