Code Block

<mcp-code-block>

Code block component with copy button and optional line numbers. Optimized for AI chat interfaces.

AIWeb Component

Overview

Code block component with copy button and optional line numbers. Optimized for AI chat interfaces.

Preview

Preview
Loading components...

Import

javascript
// Import all components (recommended)
import '@mcpsystem/ui';

// Or import the class for TypeScript
import { McpCodeBlock } from '@mcpsystem/ui';

Basic Usage

html
<mcp-code-block language="javascript">
const greeting = "Hello, World!";
</mcp-code-block>

API Reference

Properties(4)

PropertyAttributeType
languagelanguagestring
filenamefilenamestring
showLineNumbersshow-line-numbersboolean
codecodestring

Slots(1)

SlotDescription
(default)Code content (plain text)

Events(1)

EventDetail
mcp-copy{ code: string }

CSS Parts(5)

Style internal elements using ::part() selector.

PartDescription
::part(container)The outer container
::part(header)The header with language/filename
::part(code)The code element
::part(copy-button)The copy button
::part(line-numbers)The line numbers gutter

CSS Custom Properties(6)

Customize appearance by setting these CSS variables.

PropertyDescription
--mcp-code-bgCode block background
--mcp-code-fgCode text color
--mcp-code-header-bgHeader background
--mcp-code-fontCode font family
--mcp-code-font-sizeCode font size
--mcp-code-radiusBorder radius

Examples

Basic Usage

Preview
Loading components...
html
<mcp-code-block language="javascript">
const greeting = "Hello, World!";
</mcp-code-block>

With Line Numbers

Preview
Loading components...
html
<mcp-code-block language="python" show-line-numbers>
    return "Hello, World!"
</mcp-code-block>

More Components