mcp-leftpad
Version:
An MCP server that exposes left-pad as a tool
35 lines (31 loc) • 962 B
JavaScript
// Import the required modules
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { z } from 'zod';
// Create an MCP server
const server = new McpServer({
name: 'mcp-leftpad',
version: '1.0.0'
});
// Add the left-pad tool
server.tool(
'left-pad',
{
str: z.string().describe('The string to pad'),
length: z.number().describe('The target length of the padded string'),
padStr: z.string().optional().describe('The string to pad with')
},
async ({ str, length, padStr = ' ' }) => ({
content: [{
type: 'text',
text: str.padStart(length, padStr)
}]
})
);
// Start receiving messages on stdin and sending messages on stdout
const transport = new StdioServerTransport();
server.connect(transport).catch(error => {
console.error('Error starting MCP server:', error);
process.exit(1);
});