The Diagnostics module provides language-agnostic error and warning detection across multiple programming languages. It automatically identifies the appropriate diagnostic tool for your project and returns structured, actionable error information.
Instead of manually running different linters and compilers for each language, the Diagnostics module:
cargo checkCargo.tomltsc (TypeScript), eslint (ESLint)tsconfig.json or .eslintrc.*pylint, flake8, mypy.py files, requirements.txt, setup.pygcc, clang.c, .cpp, .h files, CMakeLists.txt, MakefileGet errors and warnings for files or entire projects.
Parameters:
path (string, required) - Path to file or project directoryseverity (array, optional) - Filter by severity: ["error", "warning", "info"]tool (string, optional) - Force specific tool: "cargo", "tsc", "eslint", "pylint", etc.fix (boolean, optional) - Attempt automatic fixes where possible (default: false)Example - Auto-detect:
{
"name": "diagnostics_get",
"arguments": {
"path": "./src"
}
}
Example - Specific Tool:
{
"name": "diagnostics_get",
"arguments": {
"path": "./src",
"tool": "eslint",
"severity": ["error", "warning"]
}
}
Example - With Auto-fix:
{
"name": "diagnostics_get",
"arguments": {
"path": "./src/main.ts",
"tool": "eslint",
"fix": true
}
}
The tool returns a structured response with all diagnostics:
{
"project_type": "typescript",
"tool_used": "tsc",
"total_errors": 3,
"total_warnings": 5,
"diagnostics": [
{
"file": "src/main.ts",
"line": 42,
"column": 15,
"severity": "error",
"code": "TS2322",
"message": "Type 'string' is not assignable to type 'number'",
"suggestion": "Change variable type to string or convert the value"
},
{
"file": "src/utils.ts",
"line": 10,
"column": 5,
"severity": "warning",
"code": "TS6133",
"message": "Unused variable 'unused'",
"suggestion": "Remove unused variable or prefix with underscore"
}
],
"execution_time_ms": 1234
}
Common Errors Detected:
{
"file": "src/main.rs",
"severity": "error",
"code": "E0308",
"message": "mismatched types",
"details": "expected `i32`, found `&str`"
}
Borrow Checker:
{
"file": "src/lib.rs",
"severity": "error",
"code": "E0502",
"message": "cannot borrow `x` as mutable because it is also borrowed as immutable"
}
Type Errors:
{
"file": "src/app.ts",
"severity": "error",
"code": "TS2339",
"message": "Property 'foo' does not exist on type 'MyType'"
}
Strict Null Checks:
{
"file": "src/utils.ts",
"severity": "error",
"code": "TS2531",
"message": "Object is possibly 'null'"
}
Syntax Errors:
{
"file": "main.py",
"severity": "error",
"code": "E0001",
"message": "invalid syntax"
}
Style Violations:
{
"file": "utils.py",
"severity": "warning",
"code": "C0103",
"message": "Variable name doesn't conform to snake_case naming style"
}
Run diagnostics before committing code:
// 1. Get current git status
{"name": "git_status", "arguments": {"path": "."}}
// 2. Run diagnostics on changed files
{"name": "diagnostics_get", "arguments": {"path": "./src"}}
// 3. Block commit if errors found
// 4. Auto-fix warnings if possible
{"name": "diagnostics_get", "arguments": {"path": "./src", "fix": true}}
Validate code in CI pipelines:
{
"name": "diagnostics_get",
"arguments": {
"path": ".",
"severity": ["error"]
}
}
// Exit with error if any diagnostics found
Provide real-time feedback:
// Watch for file changes
{"name": "fs_watch", "arguments": {"path": "./src", "events": ["modify"]}}
// Run diagnostics on change
{"name": "diagnostics_get", "arguments": {"path": "./src/modified_file.ts"}}
Automated code quality checks:
// 1. Get diff of changes
{"name": "git_diff", "arguments": {"path": ".", "staged": false}}
// 2. Run diagnostics on entire project
{"name": "diagnostics_get", "arguments": {"path": "."}}
// 3. Compare with baseline to find new issues
The module uses the following priority for auto-detection:
Check for config files:
Cargo.toml → Rusttsconfig.json → TypeScript.eslintrc.* → JavaScript/TypeScriptpyproject.toml, setup.py → PythonCMakeLists.txt, Makefile → C/C++Analyze file extensions:
.rs → Rust.ts, .tsx → TypeScript.js, .jsx → JavaScript.py → Python.c, .cpp, .h → C/C++Check for tool availability:
{
"error": {
"code": -32001,
"message": "Diagnostic tool not found: tsc",
"suggestion": "Install TypeScript: npm install -g typescript"
}
}
{
"error": {
"code": -32002,
"message": "Could not detect project type for path: ./unknown",
"suggestion": "Specify tool explicitly using 'tool' parameter"
}
}
{
"error": {
"code": -32003,
"message": "Diagnostic tool crashed",
"stdout": "...",
"stderr": "..."
}
}
For large projects, run diagnostics on specific files:
// Instead of checking entire project
{"name": "diagnostics_get", "arguments": {"path": "."}}
// Check only modified files
{"name": "diagnostics_get", "arguments": {"path": "./src/modified_file.ts"}}
The module caches diagnostic results for unchanged files:
For multi-language projects, diagnostics run in parallel:
// Runs TypeScript and Python checks concurrently
{"name": "diagnostics_get", "arguments": {"path": "./mixed_project"}}
Configure diagnostic tools via environment variables:
# Rust
export RUSTFLAGS="-D warnings" # Treat warnings as errors
# TypeScript
export TSC_FLAGS="--strict" # Enable strict mode
# Python
export PYLINT_RCFILE=".pylintrc" # Custom config file
# ESLint
export ESLINT_CONFIG=".eslintrc.json"
Check diagnostics before committing:
// 1. Stage files
{"name": "git_status", "arguments": {"path": "."}}
// 2. Run diagnostics
{"name": "diagnostics_get", "arguments": {"path": ".", "severity": ["error"]}}
// 3. If no errors, proceed with commit
{"name": "git_commit", "arguments": {"message": "feat: add feature"}}
Auto-fix and save:
// 1. Run diagnostics with fix
{"name": "diagnostics_get", "arguments": {"path": "./src", "fix": true}}
// 2. Create snapshot before applying fixes
{"name": "fs_snapshot", "arguments": {"path": "./src"}}
// 3. Apply fixes (done automatically by diagnostic tool)
Run in CI pipeline:
{
"name": "silent_script",
"arguments": {
"script": "#!/bin/bash\nresult=$(poly-mcp diagnostics_get ./src)\nif [ $? -ne 0 ]; then exit 1; fi",
"timeout": 300
}
}
Integrate into your development workflow:
Focus on errors first, then tackle warnings for code quality.
.eslintrc, pylintrc, etc. for project-specific rulesConfigure tool-specific ignore rules:
ESLint:
/* eslint-disable no-unused-vars */
Pylint:
# pylint: disable=unused-variable
Rust:
#[allow(dead_code)]
Ensure consistent tool versions across environments:
# Lock versions
npm install --save-dev typescript@5.0.0
pip install pylint==2.17.0
Use absolute paths to avoid resolution problems:
{
"name": "diagnostics_get",
"arguments": {
"path": "/absolute/path/to/project"
}
}