Support markdown with your agent built with XMTP
Use the markdown content type to send rich formatted text messages with your agent. Markdown allows you to include headers, lists, tables, code blocks, and other formatting elements to create more engaging and structured messages.
Install the package
In some SDKs, the MarkdownCodec
is already included in the SDK. If not, you can install the package using the following command:
npm
npm i @xmtp/content-type-markdown
Configure the content type
After importing the package, you can register the codec.
Node
import {
ContentTypeMarkdown,
MarkdownCodec,
} from '@xmtp/content-type-markdown';
// Create the XMTP agent
const agent = await Agent.create(signer, {
env: 'dev',
codecs: [new MarkdownCodec()],
});
Send markdown content
With XMTP, markdown content is sent as a string containing markdown formatting:
Node
// Basic markdown message
const markdownContent = `## Welcome to XMTP
This is a **bold** message with *italic* text and \`inline code\`.
- Item 1
- Item 2
- Item 3`;
await ctx.conversation.send(markdownContent, ContentTypeMarkdown);
Supported markdown patterns
The markdown content type supports the following formatting patterns:
Headers
#
H1 headers##
H2 headers###
H3 headers####
H4 headers#####
H5 headers######
H6 headers
Text formatting
**bold text**
or__bold text__
*italic text*
or_italic text_
~~strikethrough text~~
- `inline code`
Lists
- Unordered lists with
-
,*
, or+
- Ordered lists with numbers
- Nested lists with proper indentation
Tables
- Standard markdown table syntax with
|
separators - Header rows with
---
separators
Code blocks
- Fenced code blocks with triple backticks
- Language-specific syntax highlighting
- Inline code with single backticks
Other elements
- Blockquotes with
>
- Horizontal rules with
---
- Links with
[text](url)
- Images with

Example usage
Node
const content = `## Results Summary
- **Total items:** ${count}
- *Status:* ${status}
- \`Processing time:\` ${duration}ms
### Next Steps
1. Review results
2. Update configuration
3. Deploy changes
| Metric | Value | Status |
|--------|-------|--------|
| Total | ${total} | ✅ |
| Active | ${active} | 🟡 |
| Errors | ${errors} | ❌ |
\`\`\`javascript
const agent = await Agent.create(signer, {
env: 'dev',
codecs: [new MarkdownCodec()],
});
\`\`\``;
await ctx.conversation.send(content, ContentTypeMarkdown);
Receive markdown content
Node
agent.on('message', async (ctx) => {
if (ctx.usesCodec(MarkdownCodec)) {
const markdownContent = ctx.message.content;
console.log('Received markdown:', markdownContent);
// Process the markdown content
// You can parse it, extract data, or display it formatted
}
});
Filter for markdown content
Node
// Check if the message contains markdown
if (ctx.usesCodec(MarkdownCodec)) {
const markdown: string = ctx.message.content;
// Handle markdown content
}