Skip to main content
Glama
seo-rii

oxlint-mcp

by seo-rii

lint-files

Analyze JavaScript and TypeScript code for errors and style issues. Provide absolute file paths to identify problems and improve code quality through automated linting.

Instructions

Lint files using Oxlint. You must provide a list of absolute file paths to the files you want to lint. The absolute file paths should be in the correct format for your operating system (e.g., forward slashes on Unix-like systems, backslashes on Windows).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathsYes

Implementation Reference

  • The handler for the "lint-files" MCP tool. It spawns the oxlint process, parses its JSON output, normalizes diagnostic information, and formats it for the MCP response.
    async ({ filePaths }) => {
    	const type = /** @type {const} */ ("text");
    	const oxlintEntryPath = require.resolve("oxlint");
    	const oxlintBinPath = path.resolve(
    		path.dirname(oxlintEntryPath),
    		"../bin/oxlint",
    	);
    	const { stdout, stderr, exitCode } = await new Promise((resolve, reject) => {
    		let collectedStdout = "";
    		let collectedStderr = "";
    		const child = spawn(
    			process.execPath,
    			[oxlintBinPath, "--format", "json", ...filePaths],
    			{
    				cwd: process.cwd(),
    				env: process.env,
    				stdio: ["ignore", "pipe", "pipe"],
    			},
    		);
    
    		child.stdout.setEncoding("utf8");
    		child.stdout.on("data", data => {
    			collectedStdout += data;
    		});
    
    		child.stderr.setEncoding("utf8");
    		child.stderr.on("data", data => {
    			collectedStderr += data;
    		});
    
    		child.on("error", reject);
    		child.on("close", (code, signal) => {
    			if (signal) {
    				reject(
    					new Error(`oxlint process was terminated by signal: ${signal}`),
    				);
    				return;
    			}
    
    			resolve({
    				stdout: collectedStdout,
    				stderr: collectedStderr,
    				exitCode: code ?? 1,
    			});
    		});
    	});
    
    	let parsedOutput;
    	try {
    		parsedOutput = JSON.parse(stdout);
    	} catch (error) {
    		throw new Error(
    			["Failed to parse Oxlint JSON output.", stdout, stderr]
    				.filter(Boolean)
    				.join("\n\n"),
    			{ cause: error },
    		);
    	}
    
    	const diagnostics = Array.isArray(parsedOutput.diagnostics)
    		? parsedOutput.diagnostics
    		: [];
    	const normalizedFilePaths = filePaths.map(filePath => path.resolve(filePath));
    	const normalizedFilePathSet = new Set(normalizedFilePaths);
    	/** @type {Map<string, Array<any>>} */
    	const diagnosticsByFilePath = new Map(
    		normalizedFilePaths.map(filePath => [filePath, []]),
    	);
    
    	for (const diagnostic of diagnostics) {
    		if (!diagnostic || typeof diagnostic !== "object") {
    			continue;
    		}
    
    		const diagnosticFilePath =
    			typeof diagnostic.filename === "string"
    				? path.resolve(diagnostic.filename)
    				: "";
    		if (!diagnosticFilePath) {
    			continue;
    		}
    
    		if (!diagnosticsByFilePath.has(diagnosticFilePath)) {
    			diagnosticsByFilePath.set(diagnosticFilePath, []);
    		}
    		const diagnosticsForFile = diagnosticsByFilePath.get(diagnosticFilePath);
    		if (diagnosticsForFile) {
    			diagnosticsForFile.push(diagnostic);
    		}
    	}
    
    	const additionalFilePaths = [];
    	for (const diagnosticFilePath of diagnosticsByFilePath.keys()) {
    		if (!normalizedFilePathSet.has(diagnosticFilePath)) {
    			additionalFilePaths.push(diagnosticFilePath);
    		}
    	}
    
    	const results = [...normalizedFilePaths, ...additionalFilePaths].map(filePath => {
    		/** @type {Array<any>} */
    		const fileDiagnostics = diagnosticsByFilePath.get(filePath) ?? [];
    		let errorCount = 0;
    		let fatalErrorCount = 0;
    		let warningCount = 0;
    
    		const messages = fileDiagnostics.map(diagnostic => {
    			const severity = diagnostic.severity === "error" ? 2 : 1;
    			const isFatal = severity === 2 && typeof diagnostic.code !== "string";
    			if (severity === 2) {
    				errorCount += 1;
    			}
    			if (severity === 1) {
    				warningCount += 1;
    			}
    			if (isFatal) {
    				fatalErrorCount += 1;
    			}
    
    			const firstLabel =
    				Array.isArray(diagnostic.labels) && diagnostic.labels.length > 0
    					? diagnostic.labels[0]
    					: null;
    			const span =
    				firstLabel && typeof firstLabel === "object" && firstLabel.span
    					? firstLabel.span
    					: null;
    
    			return {
    				ruleId: typeof diagnostic.code === "string" ? diagnostic.code : null,
    				severity,
    				fatal: isFatal,
    				message:
    					typeof diagnostic.message === "string"
    						? diagnostic.message
    						: "Unknown oxlint diagnostic message.",
    				line: span && typeof span.line === "number" ? span.line : 1,
    				column: span && typeof span.column === "number" ? span.column : 1,
    			};
    		});
    
    		return {
    			filePath,
    			messages,
    			suppressedMessages: [],
    			errorCount,
    			fatalErrorCount,
    			warningCount,
    			fixableErrorCount: 0,
    			fixableWarningCount: 0,
    			usedDeprecatedRules: [],
    		};
    	});
    
    	const content = results.map(result => ({
    		type,
    		text: JSON.stringify(result),
    	}));
    
    	content.unshift({
    		type,
    		text: "Here are the results of running Oxlint on the provided files. Before doing anything else, you must display the full list to the user:",
    	});
    	if (stderr.trim()) {
    		content.push({
    			type,
    			text: `Oxlint stderr output:\n${stderr.trim()}`,
    		});
    	}
    	if (exitCode !== 0 && exitCode !== 1) {
    		content.push({
    			type,
    			text: `Oxlint exited with an unexpected code: ${exitCode}`,
    		});
    	}
    	content.push({
    		type,
    		text: "If the user asked to fix any issues found, proceed in fixing them. If the user did not ask to fix issues found, you must ask the user for confirmation before attempting to fix the issues found.",
    	});
    
    	return {
    		content,
    	};
    },
  • Registration of the "lint-files" tool within the McpServer instance, including the description and input schema.
    mcpServer.registerTool(
    	"lint-files",
    	{
    		description:
    			"Lint files using Oxlint. You must provide a list of absolute file paths to the files you want to lint. The absolute file paths should be in the correct format for your operating system (e.g., forward slashes on Unix-like systems, backslashes on Windows).",
    		inputSchema: filePathsSchema,
    	},
    	async ({ filePaths }) => {
    		const type = /** @type {const} */ ("text");
    		const oxlintEntryPath = require.resolve("oxlint");
    		const oxlintBinPath = path.resolve(
    			path.dirname(oxlintEntryPath),
    			"../bin/oxlint",
    		);
    		const { stdout, stderr, exitCode } = await new Promise((resolve, reject) => {
    			let collectedStdout = "";
    			let collectedStderr = "";
    			const child = spawn(
    				process.execPath,
    				[oxlintBinPath, "--format", "json", ...filePaths],
    				{
    					cwd: process.cwd(),
    					env: process.env,
    					stdio: ["ignore", "pipe", "pipe"],
    				},
    			);
    
    			child.stdout.setEncoding("utf8");
    			child.stdout.on("data", data => {
    				collectedStdout += data;
    			});
    
    			child.stderr.setEncoding("utf8");
    			child.stderr.on("data", data => {
    				collectedStderr += data;
    			});
    
    			child.on("error", reject);
    			child.on("close", (code, signal) => {
    				if (signal) {
    					reject(
    						new Error(`oxlint process was terminated by signal: ${signal}`),
    					);
    					return;
    				}
    
    				resolve({
    					stdout: collectedStdout,
    					stderr: collectedStderr,
    					exitCode: code ?? 1,
    				});
    			});
    		});
    
    		let parsedOutput;
    		try {
    			parsedOutput = JSON.parse(stdout);
    		} catch (error) {
    			throw new Error(
    				["Failed to parse Oxlint JSON output.", stdout, stderr]
    					.filter(Boolean)
    					.join("\n\n"),
    				{ cause: error },
    			);
    		}
    
    		const diagnostics = Array.isArray(parsedOutput.diagnostics)
    			? parsedOutput.diagnostics
    			: [];
    		const normalizedFilePaths = filePaths.map(filePath => path.resolve(filePath));
    		const normalizedFilePathSet = new Set(normalizedFilePaths);
    		/** @type {Map<string, Array<any>>} */
    		const diagnosticsByFilePath = new Map(
    			normalizedFilePaths.map(filePath => [filePath, []]),
    		);
    
    		for (const diagnostic of diagnostics) {
    			if (!diagnostic || typeof diagnostic !== "object") {
    				continue;
    			}
    
    			const diagnosticFilePath =
    				typeof diagnostic.filename === "string"
    					? path.resolve(diagnostic.filename)
    					: "";
    			if (!diagnosticFilePath) {
    				continue;
    			}
    
    			if (!diagnosticsByFilePath.has(diagnosticFilePath)) {
    				diagnosticsByFilePath.set(diagnosticFilePath, []);
    			}
    			const diagnosticsForFile = diagnosticsByFilePath.get(diagnosticFilePath);
    			if (diagnosticsForFile) {
    				diagnosticsForFile.push(diagnostic);
    			}
    		}
    
    		const additionalFilePaths = [];
    		for (const diagnosticFilePath of diagnosticsByFilePath.keys()) {
    			if (!normalizedFilePathSet.has(diagnosticFilePath)) {
    				additionalFilePaths.push(diagnosticFilePath);
    			}
    		}
    
    		const results = [...normalizedFilePaths, ...additionalFilePaths].map(filePath => {
    			/** @type {Array<any>} */
    			const fileDiagnostics = diagnosticsByFilePath.get(filePath) ?? [];
    			let errorCount = 0;
    			let fatalErrorCount = 0;
    			let warningCount = 0;
    
    			const messages = fileDiagnostics.map(diagnostic => {
    				const severity = diagnostic.severity === "error" ? 2 : 1;
    				const isFatal = severity === 2 && typeof diagnostic.code !== "string";
    				if (severity === 2) {
    					errorCount += 1;
    				}
    				if (severity === 1) {
    					warningCount += 1;
    				}
    				if (isFatal) {
    					fatalErrorCount += 1;
    				}
    
    				const firstLabel =
    					Array.isArray(diagnostic.labels) && diagnostic.labels.length > 0
    						? diagnostic.labels[0]
    						: null;
    				const span =
    					firstLabel && typeof firstLabel === "object" && firstLabel.span
    						? firstLabel.span
    						: null;
    
    				return {
    					ruleId: typeof diagnostic.code === "string" ? diagnostic.code : null,
    					severity,
    					fatal: isFatal,
    					message:
    						typeof diagnostic.message === "string"
    							? diagnostic.message
    							: "Unknown oxlint diagnostic message.",
    					line: span && typeof span.line === "number" ? span.line : 1,
    					column: span && typeof span.column === "number" ? span.column : 1,
    				};
    			});
    
    			return {
    				filePath,
    				messages,
    				suppressedMessages: [],
    				errorCount,
    				fatalErrorCount,
    				warningCount,
    				fixableErrorCount: 0,
    				fixableWarningCount: 0,
    				usedDeprecatedRules: [],
    			};
    		});
    
    		const content = results.map(result => ({
    			type,
    			text: JSON.stringify(result),
    		}));
    
    		content.unshift({
    			type,
    			text: "Here are the results of running Oxlint on the provided files. Before doing anything else, you must display the full list to the user:",
    		});
    		if (stderr.trim()) {
    			content.push({
    				type,
    				text: `Oxlint stderr output:\n${stderr.trim()}`,
    			});
    		}
    		if (exitCode !== 0 && exitCode !== 1) {
    			content.push({
    				type,
    				text: `Oxlint exited with an unexpected code: ${exitCode}`,
    			});
    		}
    		content.push({
    			type,
    			text: "If the user asked to fix any issues found, proceed in fixing them. If the user did not ask to fix issues found, you must ask the user for confirmation before attempting to fix the issues found.",
    		});
    
    		return {
    			content,
    		};
    	},
    );
  • Definition of the input schema for the "lint-files" tool, requiring a non-empty array of file paths.
    const filePathsSchema = {
    	filePaths: z.array(z.string().min(1)).nonempty(),
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the need for absolute file paths and OS-specific formatting, but fails to disclose key behavioral traits such as what the linting process entails (e.g., error reporting, output format), whether it modifies files, performance implications, or any rate limits. This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, starting with the core purpose. Both sentences add value: the first states the action, and the second specifies parameter requirements. There's no unnecessary information, though it could be slightly more structured (e.g., bullet points for constraints).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (1 parameter, no output schema, no annotations), the description is partially complete. It covers the basic purpose and parameter semantics but lacks details on behavioral traits, output expectations, and usage scenarios. Without annotations or output schema, more context on what linting returns would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful context beyond the input schema, which has 0% coverage. It explains that 'filePaths' must be absolute paths in OS-specific format, clarifying the parameter's purpose and constraints. However, it doesn't detail what constitutes valid file paths or examples beyond slashes, leaving some ambiguity.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Lint files using Oxlint.' It specifies the verb ('lint') and resource ('files'), though it doesn't differentiate from siblings as none exist. However, it could be more specific about what 'lint' entails (e.g., checking for errors, style issues).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides some usage context by specifying that absolute file paths are required and must be in the correct OS format. However, it lacks explicit guidance on when to use this tool versus alternatives (e.g., other linters or file-checking tools), and there's no mention of prerequisites or typical scenarios for linting.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/seo-rii/oxlint-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server