code-sentinel-mcp 0.1.0 → 0.2.1

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.
Files changed (3) hide show
  1. package/README.md +246 -84
  2. package/build/index.js +45 -0
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -1,45 +1,67 @@
1
1
  # CodeSentinel MCP Server
2
2
 
3
- A code quality analysis MCP server that detects security issues, deceptive patterns, placeholders, and highlights code strengths.
3
+ A comprehensive code quality analysis server for the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/). CodeSentinel integrates with Claude Code and other MCP-compatible clients to detect security vulnerabilities, deceptive patterns, incomplete code, and highlight good practices.
4
+
5
+ ## Why CodeSentinel?
6
+
7
+ AI coding assistants can inadvertently introduce subtle issues: hardcoded secrets, empty catch blocks, TODO placeholders left behind, or patterns that hide errors. CodeSentinel acts as a quality gate, analyzing code for **93 distinct patterns** across 5 categories before issues reach production.
8
+
9
+ **Key differentiators:**
10
+ - **Verification-aware detection**: Many patterns include verification steps to reduce false positives
11
+ - **LLM-optimized output**: Structured JSON output designed for AI consumption and action
12
+ - **Balanced analysis**: Detects both issues AND strengths for fair code assessment
13
+ - **Multi-language support**: Works with TypeScript, JavaScript, Python, Go, Rust, Java, and more
4
14
 
5
15
  ## Features
6
16
 
7
- - 🔒 **Security Analysis**: Hardcoded secrets, SQL injection, XSS, insecure crypto, and more
8
- - 🎭 **Deceptive Pattern Detection**: Empty catch blocks, silent failures, error-hiding returns
9
- - 📝 **Placeholder Detection**: TODO/FIXME, lorem ipsum, test data, incomplete implementations
10
- - ⚠️ **Error & Code Smell Detection**: Type coercion, null references, async issues
11
- - 💪 **Strength Recognition**: Highlights good practices like typing, error handling, tests
12
- - 📊 **HTML Reports**: Beautiful visual reports with scores and suggestions
17
+ - **Security Analysis** (16 patterns): Hardcoded secrets, SQL injection, XSS, command injection, insecure crypto, disabled SSL, and more
18
+ - **Deceptive Pattern Detection** (17 patterns): Empty catch blocks, silent failures, error-hiding fallbacks, linter suppression
19
+ - **Placeholder Detection** (19 patterns): TODO/FIXME/HACK comments, lorem ipsum, test data, incomplete implementations
20
+ - **Error & Code Smell Detection** (18 patterns): Type coercion issues, null references, async anti-patterns, floating point comparison
21
+ - **Strength Recognition** (23 patterns): Highlights good practices like proper typing, error handling, testing patterns, documentation
22
+ - **HTML Reports**: Visual reports with quality scores and actionable suggestions
13
23
 
14
24
  ## Installation
15
25
 
26
+ ### From npm
27
+
16
28
  ```bash
17
- # Clone or copy the project
18
- cd code-sentinel
29
+ npm install -g code-sentinel-mcp
30
+ ```
19
31
 
20
- # Install dependencies
21
- npm install
32
+ ### From source
22
33
 
23
- # Build
34
+ ```bash
35
+ git clone https://github.com/your-username/code-sentinel.git
36
+ cd code-sentinel
37
+ npm install
24
38
  npm run build
25
39
  ```
26
40
 
27
41
  ## Usage with Claude Code
28
42
 
29
- Add to your Claude Code MCP configuration:
43
+ ### Quick setup
44
+
45
+ ```bash
46
+ claude mcp add code-sentinel -- npx code-sentinel-mcp
47
+ ```
48
+
49
+ ### Or if installed globally
30
50
 
31
51
  ```bash
32
- claude mcp add code-sentinel -- node /path/to/code-sentinel/build/index.js
52
+ claude mcp add code-sentinel -- code-sentinel
33
53
  ```
34
54
 
35
- Or manually add to your config:
55
+ ### Manual configuration
56
+
57
+ Add to your Claude Code MCP configuration file (`~/.claude/claude_desktop_config.json`):
36
58
 
37
59
  ```json
38
60
  {
39
61
  "mcpServers": {
40
62
  "code-sentinel": {
41
- "command": "node",
42
- "args": ["/path/to/code-sentinel/build/index.js"]
63
+ "command": "npx",
64
+ "args": ["code-sentinel-mcp"]
43
65
  }
44
66
  }
45
67
  }
@@ -48,21 +70,77 @@ Or manually add to your config:
48
70
  ## Available Tools
49
71
 
50
72
  ### `analyze_code`
51
- Full analysis returning structured JSON with all issues and strengths.
73
+ Full analysis returning structured JSON with all issues and strengths. Best for programmatic processing.
74
+
75
+ **Parameters:**
76
+ - `code` (string, required): The source code to analyze
77
+ - `filename` (string, required): Filename for language detection (e.g., "app.ts")
78
+
79
+ **Returns:** JSON object with issues, strengths, and summary statistics.
52
80
 
53
81
  ### `generate_report`
54
- Full analysis with HTML report output.
82
+ Full analysis with a visual HTML report. Best for human review.
83
+
84
+ **Parameters:**
85
+ - `code` (string, required): The source code to analyze
86
+ - `filename` (string, required): Filename for language detection
87
+
88
+ **Returns:** Markdown summary plus complete HTML report.
55
89
 
56
90
  ### `check_security`
57
- Security-focused analysis only.
91
+ Security-focused analysis only. Use when you specifically want to audit for vulnerabilities.
92
+
93
+ **Parameters:**
94
+ - `code` (string, required): The source code to check
95
+ - `filename` (string, required): Filename
96
+
97
+ **Returns:** List of security issues or confirmation of none found.
58
98
 
59
99
  ### `check_deceptive_patterns`
60
- Check for error-hiding and deceptive code patterns.
100
+ Check for code patterns that hide errors or create false confidence.
101
+
102
+ **Parameters:**
103
+ - `code` (string, required): The source code to check
104
+ - `filename` (string, required): Filename
105
+
106
+ **Returns:** List of deceptive patterns found.
61
107
 
62
108
  ### `check_placeholders`
63
- Find TODOs, dummy data, and incomplete code.
109
+ Find TODOs, dummy data, and incomplete implementations.
110
+
111
+ **Parameters:**
112
+ - `code` (string, required): The source code to check
113
+ - `filename` (string, required): Filename
114
+
115
+ **Returns:** List of placeholder code found.
116
+
117
+ ### `analyze_patterns`
118
+ Analyze code for architectural, design, and implementation patterns. Detects pattern usage, inconsistencies, and provides actionable suggestions.
119
+
120
+ **Parameters:**
121
+ - `code` (string, required): The source code to analyze
122
+ - `filename` (string, required): Filename for language detection
123
+ - `level` (string, optional): Pattern level to analyze:
124
+ - `architectural`: System structure patterns (layering, modules)
125
+ - `design`: Gang of Four patterns (Singleton, Factory, Observer)
126
+ - `code`: Implementation idioms (error handling, async patterns)
127
+ - `all`: All levels (default)
128
+ - `query` (string, optional): Natural language query to focus analysis (e.g., "how is error handling done?")
129
+
130
+ **Returns:** LLM-optimized JSON with detected patterns, inconsistencies, suggestions, and ready-to-execute action items.
131
+
132
+ ### `analyze_design_patterns`
133
+ Focused analysis of Gang of Four (GoF) design patterns. Best for understanding OOP structure.
134
+
135
+ **Parameters:**
136
+ - `code` (string, required): The source code to analyze
137
+ - `filename` (string, required): Filename for language detection
64
138
 
65
- ## Example Usage in Claude Code
139
+ **Returns:** Detected design patterns with confidence levels, locations, and implementation details.
140
+
141
+ ## Example Usage
142
+
143
+ Ask Claude to analyze code:
66
144
 
67
145
  ```
68
146
  Analyze this code for quality issues:
@@ -79,71 +157,155 @@ async function fetchData() {
79
157
  }
80
158
  ```
81
159
 
82
- Claude will automatically use CodeSentinel to analyze and report:
83
- - Critical: Hardcoded API key detected
84
- - High: Empty catch block (deceptive pattern)
85
- - Low: TODO comment found
160
+ CodeSentinel will detect:
161
+ - **Critical** (CS-SEC003): OpenAI API key hardcoded in source
162
+ - **High** (CS-DEC001): Empty catch block silently swallowing errors
163
+ - **Low** (CS-PH001): TODO comment indicating incomplete implementation
86
164
 
87
165
  ## Detection Categories
88
166
 
89
- ### Security Issues (SEC)
90
- - Hardcoded secrets (API keys, tokens, passwords)
91
- - SQL injection patterns
92
- - XSS vulnerabilities
93
- - Insecure random, weak crypto
94
- - Disabled SSL validation
95
- - Eval and dynamic code execution
96
-
97
- ### Deceptive Patterns (DEC)
98
- - Empty catch blocks
99
- - Silent promise rejections
100
- - Error-hiding fallbacks (|| [], || {})
101
- - Fake success responses
102
- - Excessive optional chaining
103
- - Linter suppression comments
104
-
105
- ### Placeholders (PH)
106
- - TODO/FIXME/HACK/XXX comments
107
- - Lorem ipsum text
108
- - Test emails and passwords
109
- - Debug console.log
110
- - Debugger statements
111
- - Not implemented errors
112
-
113
- ### Errors & Smells (ERR)
114
- - Loose equality (==)
115
- - Assignment in conditions
116
- - parseInt without radix
117
- - Array mutation during iteration
118
- - Floating point comparison
119
- - Await in constructor
120
-
121
- ## Scoring
122
-
123
- The quality score (0-100) is calculated based on:
124
- - Critical issues: -25 points each
125
- - High issues: -15 points each
126
- - Medium issues: -5 points each
127
- - Low issues: -1 point each
128
- - Strengths: +2 points each
129
-
130
- ## Extending
131
-
132
- Add new patterns by editing the analyzer files in `src/analyzers/`:
133
- - `security.ts` - Security vulnerability patterns
134
- - `deceptive.ts` - Error-hiding patterns
135
- - `placeholders.ts` - Incomplete code patterns
136
- - `errors.ts` - Code smell patterns
137
- - `strengths.ts` - Good practice patterns
138
-
139
- Each pattern includes:
140
- - `id`: Unique identifier (e.g., SEC001)
141
- - `pattern`: RegExp to match
142
- - `title`: Short description
143
- - `description`: Detailed explanation
144
- - `severity`: critical | high | medium | low
145
- - `suggestion`: How to fix (optional)
167
+ ### Security Issues (CS-SEC)
168
+ | ID | Pattern |
169
+ |:---|:--------|
170
+ | SEC001 | Hardcoded secrets (API keys, tokens, passwords) |
171
+ | SEC002 | GitHub tokens |
172
+ | SEC003 | OpenAI API keys |
173
+ | SEC004 | AWS access keys |
174
+ | SEC005-010 | SQL injection patterns |
175
+ | SEC011-015 | XSS vulnerabilities |
176
+ | SEC016 | Command injection (eval, exec) |
177
+
178
+ ### Deceptive Patterns (CS-DEC)
179
+ | ID | Pattern |
180
+ |:---|:--------|
181
+ | DEC001-003 | Empty/comment-only catch blocks |
182
+ | DEC010-012 | Silent promise rejections |
183
+ | DEC020-025 | Error-hiding fallbacks (|| [], || {}, ?? default) |
184
+ | DEC030+ | Linter suppression, fake success responses |
185
+
186
+ ### Placeholders (CS-PH)
187
+ | ID | Pattern |
188
+ |:---|:--------|
189
+ | PH001-005 | TODO/FIXME/HACK/XXX/NOTE comments |
190
+ | PH010-015 | Lorem ipsum, placeholder text |
191
+ | PH020-025 | Test/dummy data (test@example.com, password123) |
192
+ | PH030+ | console.log debugging, debugger statements |
193
+
194
+ ### Errors & Code Smells (CS-ERR)
195
+ | ID | Pattern |
196
+ |:---|:--------|
197
+ | ERR001-005 | Loose equality (==), type coercion issues |
198
+ | ERR010-015 | Null reference risks |
199
+ | ERR020-025 | Async anti-patterns |
200
+ | ERR030+ | parseInt without radix, array mutation in loops |
201
+
202
+ ### Strengths (CS-STR)
203
+ | ID | Pattern |
204
+ |:---|:--------|
205
+ | STR001-005 | TypeScript strict typing |
206
+ | STR010-015 | Proper error handling patterns |
207
+ | STR020-025 | Test coverage indicators |
208
+ | STR030+ | Documentation, input validation |
209
+
210
+ ## Scoring Algorithm
211
+
212
+ Quality score (0-100) calculated as:
213
+
214
+ ```
215
+ Score = 100 - (critical × 25) - (high × 15) - (medium × 5) - (low × 1) + (strengths × 2)
216
+ ```
217
+
218
+ | Severity | Point Deduction |
219
+ |:---------|:----------------|
220
+ | Critical | -25 points |
221
+ | High | -15 points |
222
+ | Medium | -5 points |
223
+ | Low | -1 point |
224
+ | Strength | +2 points (bonus) |
225
+
226
+ ## Supported Languages
227
+
228
+ CodeSentinel detects language from file extensions:
229
+
230
+ | Extension | Language |
231
+ |:----------|:---------|
232
+ | `.ts`, `.tsx` | TypeScript |
233
+ | `.js`, `.jsx` | JavaScript |
234
+ | `.py` | Python |
235
+ | `.go` | Go |
236
+ | `.rs` | Rust |
237
+ | `.java` | Java |
238
+ | `.kt` | Kotlin |
239
+ | `.swift` | Swift |
240
+ | `.cs` | C# |
241
+ | `.cpp`, `.c` | C/C++ |
242
+ | `.php` | PHP |
243
+ | `.vue` | Vue |
244
+ | `.svelte` | Svelte |
245
+
246
+ ## Extending CodeSentinel
247
+
248
+ Add custom patterns by editing files in `src/analyzers/`:
249
+
250
+ ```
251
+ src/analyzers/
252
+ ├── security.ts # Security vulnerability patterns
253
+ ├── deceptive.ts # Error-hiding patterns
254
+ ├── placeholders.ts # Incomplete code patterns
255
+ ├── errors.ts # Code smell patterns
256
+ └── strengths.ts # Good practice patterns
257
+ ```
258
+
259
+ Each pattern follows this structure:
260
+
261
+ ```typescript
262
+ {
263
+ id: 'CS-SEC001', // Unique ID with category prefix
264
+ pattern: /regex/g, // RegExp to match
265
+ title: 'Short description',
266
+ description: 'Detailed explanation',
267
+ severity: 'critical', // critical | high | medium | low | info
268
+ category: 'security',
269
+ suggestion: 'How to fix',
270
+ verification: { // Optional: reduce false positives
271
+ assumption: 'What we assume is true',
272
+ confirmIf: 'When to confirm as real issue',
273
+ falsePositiveIf: 'When to dismiss'
274
+ }
275
+ }
276
+ ```
277
+
278
+ ## Development
279
+
280
+ ```bash
281
+ # Install dependencies
282
+ npm install
283
+
284
+ # Build
285
+ npm run build
286
+
287
+ # Watch mode
288
+ npm run watch
289
+
290
+ # Test with MCP inspector
291
+ npm run inspector
292
+ ```
293
+
294
+ ## Contributing
295
+
296
+ Contributions welcome! Please:
297
+
298
+ 1. Fork the repository
299
+ 2. Create a feature branch
300
+ 3. Add patterns following the existing format
301
+ 4. Submit a pull request
146
302
 
147
303
  ## License
148
304
 
149
305
  MIT
306
+
307
+ ## Links
308
+
309
+ - [Model Context Protocol](https://modelcontextprotocol.io/)
310
+ - [Claude Code](https://claude.ai/code)
311
+ - [npm package](https://www.npmjs.com/package/code-sentinel-mcp)
package/build/index.js CHANGED
@@ -179,6 +179,51 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
179
179
  },
180
180
  required: ["code", "filename"]
181
181
  }
182
+ },
183
+ {
184
+ name: "analyze_patterns",
185
+ description: "Analyze code for architectural, design, and implementation patterns. Detects pattern usage, inconsistencies, and provides actionable suggestions for improvement. Returns LLM-optimized JSON with action items.",
186
+ inputSchema: {
187
+ type: "object",
188
+ properties: {
189
+ code: {
190
+ type: "string",
191
+ description: "The source code to analyze"
192
+ },
193
+ filename: {
194
+ type: "string",
195
+ description: "The filename (used to detect language)"
196
+ },
197
+ level: {
198
+ type: "string",
199
+ enum: ["architectural", "design", "code", "all"],
200
+ description: "Pattern level to analyze: 'architectural' (system structure), 'design' (GoF patterns), 'code' (implementation idioms), or 'all' (default)"
201
+ },
202
+ query: {
203
+ type: "string",
204
+ description: "Optional natural language query to focus analysis (e.g., 'how is error handling done?')"
205
+ }
206
+ },
207
+ required: ["code", "filename"]
208
+ }
209
+ },
210
+ {
211
+ name: "analyze_design_patterns",
212
+ description: "Focused analysis of Gang of Four (GoF) design patterns in code. Detects Singleton, Factory, Observer, Strategy, and other classic patterns with confidence levels and implementation details.",
213
+ inputSchema: {
214
+ type: "object",
215
+ properties: {
216
+ code: {
217
+ type: "string",
218
+ description: "The source code to analyze"
219
+ },
220
+ filename: {
221
+ type: "string",
222
+ description: "The filename (used to detect language)"
223
+ }
224
+ },
225
+ required: ["code", "filename"]
226
+ }
182
227
  }
183
228
  ]
184
229
  };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "code-sentinel-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
+ "mcpName": "io.github.salrad22/code-sentinel",
4
5
  "description": "MCP server for code quality analysis - security, errors, deceptive patterns, and placeholder detection",
5
6
  "private": false,
6
7
  "type": "module",