UNPKG

markdown-editor-mcp

Version:

MCP server for markdown editing and management

23 lines (22 loc) 1.05 kB
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import process from "node:process"; /** * Extended StdioServerTransport that filters out non-JSON messages. * This prevents the "Watching /" error from crashing the server. */ export class FilteredStdioServerTransport extends StdioServerTransport { constructor() { // Create a proxy for stdout that only allows valid JSON to pass through const originalStdoutWrite = process.stdout.write; process.stdout.write = function (buffer) { // Only intercept string output that doesn't look like JSON if (typeof buffer === 'string' && !buffer.trim().startsWith('{')) { return true; //process.stderr.write(buffer); } return originalStdoutWrite.apply(process.stdout, arguments); }; super(); // Log initialization to stderr to avoid polluting the JSON stream process.stderr.write(`[desktop-commander] Initialized FilteredStdioServerTransport\n`); } }