html_encode
Convert special characters in text to HTML entities for safe web display and proper browser rendering.
Instructions
Encode special characters in a string to HTML entities.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | The string to HTML-encode |
Implementation Reference
- src/tools/encoding.ts:77-90 (handler)The handler for the html_encode tool is defined within the server.tool registration call in src/tools/encoding.ts. It takes a string input and replaces special characters with their corresponding HTML entities.
server.tool( "html_encode", "Encode special characters in a string to HTML entities.", { input: z.string().describe("The string to HTML-encode") }, async ({ input }) => { const encoded = input .replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">") .replace(/"/g, """) .replace(/'/g, "'"); return { content: [{ type: "text" as const, text: encoded }] }; } );