mcp-server-lint 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vishal Habib
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-server-lint
3
+ Version: 0.2.0
4
+ Summary: Static analysis CLI that audits MCP (Model Context Protocol) server implementations for spec conformance and quality issues.
5
+ Author: Vishal Habib
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/vishalhabib99/mcp-doctor
8
+ Project-URL: Issues, https://github.com/vishalhabib99/mcp-doctor/issues
9
+ Keywords: mcp,model-context-protocol,agents,llm,linter,static-analysis
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Software Development :: Quality Assurance
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: tree-sitter>=0.23
20
+ Requires-Dist: tree-sitter-typescript>=0.23
21
+ Dynamic: license-file
22
+
23
+ # mcp-doctor
24
+
25
+ [![CI](https://github.com/vishalhabib99/mcp-doctor/actions/workflows/ci.yml/badge.svg)](https://github.com/vishalhabib99/mcp-doctor/actions/workflows/ci.yml)
26
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
27
+
28
+ A static analysis CLI that audits **MCP (Model Context Protocol) server** implementations for the things that actually break an agent calling them: missing tool descriptions, undocumented parameters, no error handling, no README coverage.
29
+
30
+ The MCP ecosystem is growing faster than the conventions around building a *good* server have settled. Most servers are hand-written in an afternoon and never checked against anything. `mcp-doctor` is a linter for that gap — point it at a repo, get a score and a concrete list of what to fix.
31
+
32
+ ```
33
+ $ mcp-doctor examples/bad_server
34
+ mcp-doctor report
35
+ Score: 13% Grade: F (2 tool(s) found)
36
+
37
+ [FAIL] do_thing (server.py:9)
38
+ ERROR Tool has no description. An agent cannot decide when to call this.
39
+ WARNING 2/2 parameters have no type annotation.
40
+ WARNING Parameters aren't documented in an Args: section — the model only sees names, not intent.
41
+ WARNING No try/except — an exception here will raise a raw traceback back through the MCP transport.
42
+ [FAIL] run (server.py:15)
43
+ ERROR Tool has no description. An agent cannot decide when to call this.
44
+ WARNING 1/1 parameters have no type annotation.
45
+ WARNING Parameters aren't documented in an Args: section — the model only sees names, not intent.
46
+ ERROR Bare 'except:' swallows all errors including cancellation — catch specific exceptions.
47
+
48
+ Repo-level
49
+ ERROR No README found.
50
+ WARNING No LICENSE file — undermines adoption.
51
+ WARNING No test files found.
52
+ WARNING No pyproject.toml/requirements.txt/setup.py — dependencies aren't pinned.
53
+ ```
54
+
55
+ ```
56
+ $ mcp-doctor examples/good_server
57
+ mcp-doctor report
58
+ Score: 100% Grade: A (1 tool(s) found)
59
+
60
+ [OK] get_forecast (server.py:9)
61
+ ```
62
+
63
+ ## Install
64
+
65
+ ```bash
66
+ pip install mcp-server-lint
67
+ ```
68
+
69
+ (The PyPI project is named `mcp-server-lint` — `mcp-doctor` and every close variant of it were already taken or blocked by PyPI's anti-typosquat check — but the installed command is still `mcp-doctor`.)
70
+
71
+ Or install straight from the repo:
72
+
73
+ ```bash
74
+ pip install git+https://github.com/vishalhabib99/mcp-doctor.git
75
+ ```
76
+
77
+ or clone it and install locally:
78
+
79
+ ```bash
80
+ git clone https://github.com/vishalhabib99/mcp-doctor.git
81
+ cd mcp-doctor
82
+ pip install -e .
83
+ ```
84
+
85
+ ## Usage
86
+
87
+ ```bash
88
+ mcp-doctor . # audit the current directory
89
+ mcp-doctor path/to/server # audit a specific path
90
+ mcp-doctor . --json # machine-readable output
91
+ mcp-doctor . --fail-under 80 # exit 1 if score drops below 80% — wire into CI
92
+ ```
93
+
94
+ ## GitHub Action
95
+
96
+ Gate PRs on server quality without installing anything yourself:
97
+
98
+ ```yaml
99
+ - uses: vishalhabib99/mcp-doctor@v1
100
+ with:
101
+ path: . # default: repo root
102
+ fail-under: 70 # default: 0 (report only, don't fail the build)
103
+ comment: true # default: true — posts/updates a PR comment with the report
104
+ ```
105
+
106
+ The report also gets written to the job summary either way. `@v1` tracks the latest `v1.x` release; pin an exact tag or commit SHA instead if you need stricter reproducibility.
107
+
108
+ ## What it checks
109
+
110
+ Audits both Python and TypeScript/JavaScript servers in the same repo. Python detects the FastMCP `@mcp.tool()` decorator style and the low-level SDK's `Tool(name=..., description=..., inputSchema=...)` style; TS/JS detects the official SDK's `server.registerTool(name, config, handler)` and `server.tool(name, description, schema, handler)` styles, including the common pattern where the config object or Zod schema is a same-file `const` reference rather than inline. The same checks apply either way — a description, per-parameter docs (`Args:`/`Field(description=...)` in Python, `.describe(...)` on each Zod field in TS), and a try/except (or try/catch).
111
+
112
+ **Per tool**:
113
+
114
+ | Check | Why it matters |
115
+ |---|---|
116
+ | Has a description | An agent picks tools by reading descriptions. No description, no calls. |
117
+ | Description isn't trivially short | A 3-character description is functionally the same as none. |
118
+ | Parameters are type-annotated | Untyped params usually mean the schema exposed to the model is untyped too. |
119
+ | Parameters are documented (`Args:` section, or schema `description` fields) | The model sees parameter names but not intent unless you spell it out. |
120
+ | Has error handling | FastMCP catches an unhandled exception and returns a structured error either way — this check is about message quality, not transport safety: a tool-level catch can raise a specific, actionable message instead of leaving the model with generic exception text. |
121
+ | No bare `except:` | Swallows everything, including cancellation — a real production bug pattern, not just a style nit. |
122
+
123
+ **Repo-level:**
124
+
125
+ - README exists, and mentions every tool you export
126
+ - LICENSE exists
127
+ - Tests exist
128
+ - Dependencies are declared (`pyproject.toml` / `requirements.txt` / `setup.py` / `package.json`)
129
+ - No hardcoded-looking API keys/secrets/tokens in source
130
+ - Tool names conform to the [spec's Tool Names guidance](https://modelcontextprotocol.io/specification/2026-07-28/server/tools#tool-names) (1–128 chars, `A-Z a-z 0-9 _ - .` only, unique within the server)
131
+
132
+ ## Real-world spot check
133
+
134
+ Run against three servers from the official [`modelcontextprotocol/servers`](https://github.com/modelcontextprotocol/servers) repo:
135
+
136
+ - **`src/fetch`** — **100% / A**. Clean.
137
+ - **`src/git`**, **`src/time`** — flagged as **parse errors**, not false passes. Both use Python `match` statements (3.10+ syntax); `mcp-doctor`'s AST parser follows the grammar of whatever Python interpreter runs it, so under Python 3.9 those files can't be parsed. Rather than silently skip them and report a misleadingly clean score, `mcp-doctor` surfaces this as an explicit error: *"N file(s) could not be parsed and were skipped."* Run it under Python ≥3.10 to analyze those files correctly.
138
+
139
+ Later spot-checked against 4 more real, in-the-wild servers (awslabs' `aws-documentation-mcp-server`, `mcp-google-ads`, `sv-excel-agent`, and Home Assistant's `ha-mcp`, an 88-tool server). That run caught two real precision bugs: the secret scanner was flagging test fixtures and identifier-style constant names (`SERVICE_GET_CALLER_TOKEN = "get_caller_token"`) as hardcoded credentials, and the param-docs check didn't recognize `Annotated[T, Field(description=...)]` — a completely valid, schema-level way to document a parameter — as documentation at all, since it only looked for a docstring `Args:` section. Both fixed.
140
+
141
+ A maintainer on `ha-mcp` reviewed the resulting report in detail and pushed back further, correctly: the param-docs check still missed descriptions reached through a shared, cross-file type alias (`Annotated[..., Field(description=...)]` assigned to a name and imported elsewhere) and prose under non-`Args:` headings (e.g. `**Parameters:**`, including bulleted `- param: ...` lines), and — more importantly — the error-handling check's own message was wrong. It claimed a missing try/except lets a raw traceback leak through the MCP transport; FastMCP's `call_tool` dispatcher actually wraps every call and converts any exception into a structured error regardless, which the pushback prompted me to verify directly against FastMCP's source. Both the alias/heading gaps and the error-handling message are now fixed — see [homeassistant-ai/ha-mcp#2324](https://github.com/homeassistant-ai/ha-mcp/issues/2324) for the full exchange.
142
+
143
+ The maintainer offered to leave a follow-up issue open if it were grounded in the actual spec and FastMCP's own guidelines rather than another pass of the same heuristics. Read the [current spec's Tools page](https://modelcontextprotocol.io/specification/2026-07-28/server/tools) end to end looking for exactly that: one concrete, checkable gap emerged — the normative **Tool Names** section (length, character set, uniqueness), which mcp-doctor didn't check at all — now added. Checked it against ha-mcp's real 88 tool names before claiming anything: all of them already comply, so this doesn't reopen anything there — it's a real gap closed for the next server that isn't as careful, not a finding to hand back.
144
+
145
+ ## Known limitations
146
+
147
+ - **AST-based, single-pass.** Tools constructed dynamically in a loop, or schemas built from something other than a dict literal or a `pydantic` `model_json_schema()` call, won't be fully introspected — you'll get the tool detected but a blind spot on its parameter-level checks rather than a false failure. A dynamic tool *name* (not a string literal, e.g. built in a loop) means the tool is skipped entirely rather than misattributed.
148
+ - **Parses with the running interpreter's grammar (Python side).** See the spot check above — run under a Python version that matches or exceeds the syntax used in the server you're auditing.
149
+ - **Doesn't follow delegation.** If a tool function immediately hands off to a helper that has its own try/except (or try/catch), the error-handling check only looks at the decorated function's own body and reports a false positive — it has no call-graph analysis.
150
+ - **TS/JS const resolution is same-file only.** Unlike the Python side's cross-file `Field` type-alias resolution, a TS config object or Zod schema referenced via an import from another file won't be resolved — only same-file `const` references.
151
+
152
+ ## Roadmap
153
+
154
+ - [x] TypeScript/JS server support (the official SDK's dominant language) — `registerTool`/`tool` styles, same-file const resolution
155
+ - [ ] Publish to PyPI
156
+ - [ ] `--fix` for the mechanical stuff (stub `Args:` sections, wrap in try/except)
157
+ - [ ] GitHub Action for one-line CI integration
158
+
159
+ ## Contributing
160
+
161
+ Issues and PRs welcome. The test suite (`pytest`) covers the analyzer directly and the CLI end-to-end against the fixtures in `examples/` — add a fixture case for anything you fix.
162
+
163
+ ## License
164
+
165
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,143 @@
1
+ # mcp-doctor
2
+
3
+ [![CI](https://github.com/vishalhabib99/mcp-doctor/actions/workflows/ci.yml/badge.svg)](https://github.com/vishalhabib99/mcp-doctor/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
+
6
+ A static analysis CLI that audits **MCP (Model Context Protocol) server** implementations for the things that actually break an agent calling them: missing tool descriptions, undocumented parameters, no error handling, no README coverage.
7
+
8
+ The MCP ecosystem is growing faster than the conventions around building a *good* server have settled. Most servers are hand-written in an afternoon and never checked against anything. `mcp-doctor` is a linter for that gap — point it at a repo, get a score and a concrete list of what to fix.
9
+
10
+ ```
11
+ $ mcp-doctor examples/bad_server
12
+ mcp-doctor report
13
+ Score: 13% Grade: F (2 tool(s) found)
14
+
15
+ [FAIL] do_thing (server.py:9)
16
+ ERROR Tool has no description. An agent cannot decide when to call this.
17
+ WARNING 2/2 parameters have no type annotation.
18
+ WARNING Parameters aren't documented in an Args: section — the model only sees names, not intent.
19
+ WARNING No try/except — an exception here will raise a raw traceback back through the MCP transport.
20
+ [FAIL] run (server.py:15)
21
+ ERROR Tool has no description. An agent cannot decide when to call this.
22
+ WARNING 1/1 parameters have no type annotation.
23
+ WARNING Parameters aren't documented in an Args: section — the model only sees names, not intent.
24
+ ERROR Bare 'except:' swallows all errors including cancellation — catch specific exceptions.
25
+
26
+ Repo-level
27
+ ERROR No README found.
28
+ WARNING No LICENSE file — undermines adoption.
29
+ WARNING No test files found.
30
+ WARNING No pyproject.toml/requirements.txt/setup.py — dependencies aren't pinned.
31
+ ```
32
+
33
+ ```
34
+ $ mcp-doctor examples/good_server
35
+ mcp-doctor report
36
+ Score: 100% Grade: A (1 tool(s) found)
37
+
38
+ [OK] get_forecast (server.py:9)
39
+ ```
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ pip install mcp-server-lint
45
+ ```
46
+
47
+ (The PyPI project is named `mcp-server-lint` — `mcp-doctor` and every close variant of it were already taken or blocked by PyPI's anti-typosquat check — but the installed command is still `mcp-doctor`.)
48
+
49
+ Or install straight from the repo:
50
+
51
+ ```bash
52
+ pip install git+https://github.com/vishalhabib99/mcp-doctor.git
53
+ ```
54
+
55
+ or clone it and install locally:
56
+
57
+ ```bash
58
+ git clone https://github.com/vishalhabib99/mcp-doctor.git
59
+ cd mcp-doctor
60
+ pip install -e .
61
+ ```
62
+
63
+ ## Usage
64
+
65
+ ```bash
66
+ mcp-doctor . # audit the current directory
67
+ mcp-doctor path/to/server # audit a specific path
68
+ mcp-doctor . --json # machine-readable output
69
+ mcp-doctor . --fail-under 80 # exit 1 if score drops below 80% — wire into CI
70
+ ```
71
+
72
+ ## GitHub Action
73
+
74
+ Gate PRs on server quality without installing anything yourself:
75
+
76
+ ```yaml
77
+ - uses: vishalhabib99/mcp-doctor@v1
78
+ with:
79
+ path: . # default: repo root
80
+ fail-under: 70 # default: 0 (report only, don't fail the build)
81
+ comment: true # default: true — posts/updates a PR comment with the report
82
+ ```
83
+
84
+ The report also gets written to the job summary either way. `@v1` tracks the latest `v1.x` release; pin an exact tag or commit SHA instead if you need stricter reproducibility.
85
+
86
+ ## What it checks
87
+
88
+ Audits both Python and TypeScript/JavaScript servers in the same repo. Python detects the FastMCP `@mcp.tool()` decorator style and the low-level SDK's `Tool(name=..., description=..., inputSchema=...)` style; TS/JS detects the official SDK's `server.registerTool(name, config, handler)` and `server.tool(name, description, schema, handler)` styles, including the common pattern where the config object or Zod schema is a same-file `const` reference rather than inline. The same checks apply either way — a description, per-parameter docs (`Args:`/`Field(description=...)` in Python, `.describe(...)` on each Zod field in TS), and a try/except (or try/catch).
89
+
90
+ **Per tool**:
91
+
92
+ | Check | Why it matters |
93
+ |---|---|
94
+ | Has a description | An agent picks tools by reading descriptions. No description, no calls. |
95
+ | Description isn't trivially short | A 3-character description is functionally the same as none. |
96
+ | Parameters are type-annotated | Untyped params usually mean the schema exposed to the model is untyped too. |
97
+ | Parameters are documented (`Args:` section, or schema `description` fields) | The model sees parameter names but not intent unless you spell it out. |
98
+ | Has error handling | FastMCP catches an unhandled exception and returns a structured error either way — this check is about message quality, not transport safety: a tool-level catch can raise a specific, actionable message instead of leaving the model with generic exception text. |
99
+ | No bare `except:` | Swallows everything, including cancellation — a real production bug pattern, not just a style nit. |
100
+
101
+ **Repo-level:**
102
+
103
+ - README exists, and mentions every tool you export
104
+ - LICENSE exists
105
+ - Tests exist
106
+ - Dependencies are declared (`pyproject.toml` / `requirements.txt` / `setup.py` / `package.json`)
107
+ - No hardcoded-looking API keys/secrets/tokens in source
108
+ - Tool names conform to the [spec's Tool Names guidance](https://modelcontextprotocol.io/specification/2026-07-28/server/tools#tool-names) (1–128 chars, `A-Z a-z 0-9 _ - .` only, unique within the server)
109
+
110
+ ## Real-world spot check
111
+
112
+ Run against three servers from the official [`modelcontextprotocol/servers`](https://github.com/modelcontextprotocol/servers) repo:
113
+
114
+ - **`src/fetch`** — **100% / A**. Clean.
115
+ - **`src/git`**, **`src/time`** — flagged as **parse errors**, not false passes. Both use Python `match` statements (3.10+ syntax); `mcp-doctor`'s AST parser follows the grammar of whatever Python interpreter runs it, so under Python 3.9 those files can't be parsed. Rather than silently skip them and report a misleadingly clean score, `mcp-doctor` surfaces this as an explicit error: *"N file(s) could not be parsed and were skipped."* Run it under Python ≥3.10 to analyze those files correctly.
116
+
117
+ Later spot-checked against 4 more real, in-the-wild servers (awslabs' `aws-documentation-mcp-server`, `mcp-google-ads`, `sv-excel-agent`, and Home Assistant's `ha-mcp`, an 88-tool server). That run caught two real precision bugs: the secret scanner was flagging test fixtures and identifier-style constant names (`SERVICE_GET_CALLER_TOKEN = "get_caller_token"`) as hardcoded credentials, and the param-docs check didn't recognize `Annotated[T, Field(description=...)]` — a completely valid, schema-level way to document a parameter — as documentation at all, since it only looked for a docstring `Args:` section. Both fixed.
118
+
119
+ A maintainer on `ha-mcp` reviewed the resulting report in detail and pushed back further, correctly: the param-docs check still missed descriptions reached through a shared, cross-file type alias (`Annotated[..., Field(description=...)]` assigned to a name and imported elsewhere) and prose under non-`Args:` headings (e.g. `**Parameters:**`, including bulleted `- param: ...` lines), and — more importantly — the error-handling check's own message was wrong. It claimed a missing try/except lets a raw traceback leak through the MCP transport; FastMCP's `call_tool` dispatcher actually wraps every call and converts any exception into a structured error regardless, which the pushback prompted me to verify directly against FastMCP's source. Both the alias/heading gaps and the error-handling message are now fixed — see [homeassistant-ai/ha-mcp#2324](https://github.com/homeassistant-ai/ha-mcp/issues/2324) for the full exchange.
120
+
121
+ The maintainer offered to leave a follow-up issue open if it were grounded in the actual spec and FastMCP's own guidelines rather than another pass of the same heuristics. Read the [current spec's Tools page](https://modelcontextprotocol.io/specification/2026-07-28/server/tools) end to end looking for exactly that: one concrete, checkable gap emerged — the normative **Tool Names** section (length, character set, uniqueness), which mcp-doctor didn't check at all — now added. Checked it against ha-mcp's real 88 tool names before claiming anything: all of them already comply, so this doesn't reopen anything there — it's a real gap closed for the next server that isn't as careful, not a finding to hand back.
122
+
123
+ ## Known limitations
124
+
125
+ - **AST-based, single-pass.** Tools constructed dynamically in a loop, or schemas built from something other than a dict literal or a `pydantic` `model_json_schema()` call, won't be fully introspected — you'll get the tool detected but a blind spot on its parameter-level checks rather than a false failure. A dynamic tool *name* (not a string literal, e.g. built in a loop) means the tool is skipped entirely rather than misattributed.
126
+ - **Parses with the running interpreter's grammar (Python side).** See the spot check above — run under a Python version that matches or exceeds the syntax used in the server you're auditing.
127
+ - **Doesn't follow delegation.** If a tool function immediately hands off to a helper that has its own try/except (or try/catch), the error-handling check only looks at the decorated function's own body and reports a false positive — it has no call-graph analysis.
128
+ - **TS/JS const resolution is same-file only.** Unlike the Python side's cross-file `Field` type-alias resolution, a TS config object or Zod schema referenced via an import from another file won't be resolved — only same-file `const` references.
129
+
130
+ ## Roadmap
131
+
132
+ - [x] TypeScript/JS server support (the official SDK's dominant language) — `registerTool`/`tool` styles, same-file const resolution
133
+ - [ ] Publish to PyPI
134
+ - [ ] `--fix` for the mechanical stuff (stub `Args:` sections, wrap in try/except)
135
+ - [ ] GitHub Action for one-line CI integration
136
+
137
+ ## Contributing
138
+
139
+ Issues and PRs welcome. The test suite (`pytest`) covers the analyzer directly and the CLI end-to-end against the fixtures in `examples/` — add a fixture case for anything you fix.
140
+
141
+ ## License
142
+
143
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,4 @@
1
+ from .analyzer import Report, ToolFinding, RepoIssue, analyze_repo
2
+
3
+ __all__ = ["Report", "ToolFinding", "RepoIssue", "analyze_repo"]
4
+ __version__ = "0.2.0"