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
| Name | Required | Description | Default |
|---|---|---|---|
| channel | Yes | ||
| code | Yes | ||
| description | No | ||
| language | No | ||
| thread_ts | No | ||
| title | Yes |
Implementation Reference
- slack_mcp/server.py:943-978 (handler)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)
- slack_mcp/server.py:693-702 (helper)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 } }