base64_encode
Convert text to Base64 encoding for secure data representation or transmission.
Instructions
encode text to base64
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | text to encode |
Implementation Reference
- src/service/base64.ts:30-47 (handler)The handler function for the 'base64_encode' MCP tool, registered via server.tool(). Takes a 'content' string parameter, calls Base64Util.encode() to convert it to base64, and returns the result as text content.
server.tool( "base64_encode", "encode text to base64", { content: z.string().describe("text to encode"), }, async ({ content }) => { const result = Base64Util.encode(content); return { content: [ { type: "text", text: result, }, ], }; } ); - src/service/base64.ts:10-12 (helper)The Base64Util.encode() helper method that performs the actual base64 encoding using Buffer.from(input).toString('base64').
static encode(input: string): string { return Buffer.from(input).toString('base64'); } - src/service/base64.ts:33-35 (schema)The input schema for the base64_encode tool, defining a single required 'content' parameter of type string (using Zod) described as 'text to encode'.
{ content: z.string().describe("text to encode"), }, - src/service/base64.ts:28-68 (registration)The registerBase64Tool() function that registers both 'base64_encode' and 'base64_decode' tools on the McpServer instance.
export function registerBase64Tool(server: McpServer) { // Base64 Encode server.tool( "base64_encode", "encode text to base64", { content: z.string().describe("text to encode"), }, async ({ content }) => { const result = Base64Util.encode(content); return { content: [ { type: "text", text: result, }, ], }; } ); // Base64 Decode server.tool( "base64_decode", "decode base64 to text", { content: z.string().describe("base64 text to decode"), }, async ({ content }) => { const result = Base64Util.decode(content); return { content: [ { type: "text", text: result, }, ], }; } ); } - src/index.ts:6-6 (registration)Import statement for registerBase64Tool from the base64 service module.
import { registerBase64Tool } from "./service/base64.js";