textlint
Version:
The pluggable linting tool for natural language.
84 lines • 3.14 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.server = exports.connectStdioMcpServer = void 0;
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
const zod_1 = require("zod");
const read_pkg_up_1 = __importDefault(require("read-pkg-up"));
const index_js_1 = require("../index.js");
const version = read_pkg_up_1.default.sync({ cwd: __dirname }).pkg.version;
const server = new mcp_js_1.McpServer({
name: "textlint",
version
});
exports.server = server;
const makeLinterOptions = async () => {
const descriptor = await (0, index_js_1.loadTextlintrc)();
return {
descriptor
};
};
server.tool("lintFile", "Lint files using textlint", {
filePaths: zod_1.z.array(zod_1.z.string().min(1)).nonempty()
}, async ({ filePaths }) => {
const linterOptions = await makeLinterOptions();
const linter = (0, index_js_1.createLinter)(linterOptions);
const results = await linter.lintFiles(filePaths);
const content = results.map((result) => ({
type: "text",
text: JSON.stringify(result)
}));
return { content };
});
server.tool("lintText", "Lint text using textlint", {
text: zod_1.z.string().nonempty(),
stdinFilename: zod_1.z.string().nonempty()
}, async ({ text, stdinFilename }) => {
const linterOptions = await makeLinterOptions();
const linter = (0, index_js_1.createLinter)(linterOptions);
const result = await linter.lintText(text, stdinFilename);
const content = [
{
type: "text",
text: JSON.stringify(result)
}
];
return { content };
});
server.tool("getLintFixedFileContent", "Get lint-fixed content of files using textlint", {
filePaths: zod_1.z.array(zod_1.z.string().min(1)).nonempty()
}, async ({ filePaths }) => {
const linterOptions = await makeLinterOptions();
const linter = (0, index_js_1.createLinter)(linterOptions);
const results = await linter.fixFiles(filePaths);
const content = results.map((result) => ({
type: "text",
text: JSON.stringify(result)
}));
return { content };
});
server.tool("getLintFixedTextContent", "Get lint-fixed content of text using textlint", {
text: zod_1.z.string().nonempty(),
stdinFilename: zod_1.z.string().nonempty()
}, async ({ text, stdinFilename }) => {
const linterOptions = await makeLinterOptions();
const linter = (0, index_js_1.createLinter)(linterOptions);
const result = await linter.fixText(text, stdinFilename);
const content = [
{
type: "text",
text: JSON.stringify(result)
}
];
return { content };
});
const connectStdioMcpServer = async () => {
const transport = new stdio_js_1.StdioServerTransport();
await server.connect(transport);
return server;
};
exports.connectStdioMcpServer = connectStdioMcpServer;
//# sourceMappingURL=server.js.map