smart-coding-mcp 1.0.0

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,287 @@
1
+ # Project Structure
2
+
3
+ This document outlines the modular architecture of Smart Coding MCP.
4
+
5
+ ## Directory Structure
6
+
7
+ ```
8
+ smart-coding-mcp/
9
+ ├── index.js # Main entry point, MCP server setup
10
+ ├── package.json # Package configuration
11
+ ├── config.json # User configuration
12
+ ├── LICENSE # MIT License
13
+ ├── README.md # Project documentation
14
+ ├── EXAMPLES.md # Usage examples
15
+ ├── .gitignore # Git ignore rules
16
+
17
+ ├── lib/ # Core libraries
18
+ │ ├── config.js # Configuration loader
19
+ │ ├── cache.js # Embeddings cache management
20
+ │ └── utils.js # Shared utilities (chunking, similarity)
21
+
22
+ ├── features/ # Pluggable features
23
+ │ ├── hybrid-search.js # Semantic search feature
24
+ │ ├── index-codebase.js # Code indexing feature
25
+ │ └── clear-cache.js # Cache management feature
26
+
27
+ └── scripts/ # Utility scripts
28
+ └── clear-cache.js # Cache management utility
29
+ ```
30
+
31
+ ## Module Responsibilities
32
+
33
+ ### index.js
34
+
35
+ - MCP server initialization
36
+ - Feature registry and orchestration
37
+ - Tool request routing
38
+ - Global state management (embedder, cache)
39
+
40
+ ### lib/config.js
41
+
42
+ - Loads and validates configuration from config.json
43
+ - Provides default configuration values
44
+ - Resolves file paths
45
+
46
+ ### lib/cache.js
47
+
48
+ - **EmbeddingsCache** class
49
+ - Manages persistence of embedding vectors
50
+ - File hash tracking for change detection
51
+ - Load/save operations for disk cache
52
+
53
+ ### lib/utils.js
54
+
55
+ - **cosineSimilarity()** - Vector similarity calculation
56
+ - **hashContent()** - MD5 hashing for change detection
57
+ - **smartChunk()** - Language-aware code chunking
58
+
59
+ ### features/hybrid-search.js
60
+
61
+ - **HybridSearch** class
62
+ - Combines semantic and exact matching
63
+ - Weighted scoring algorithm
64
+ - Result formatting with relevance scores
65
+ - MCP tool: `semantic_search`
66
+
67
+ ### features/index-codebase.js
68
+
69
+ - **CodebaseIndexer** class
70
+ - File discovery via glob patterns
71
+ - Incremental indexing
72
+ - File watcher for real-time updates
73
+ - MCP tool: `index_codebase`
74
+
75
+ ## Adding New Features
76
+
77
+ To extend with a new feature:
78
+
79
+ ### 1. Create Feature Module
80
+
81
+ Create `features/my-feature.js`:
82
+
83
+ ```javascript
84
+ export class MyFeature {
85
+ constructor(embedder, cache, config) {
86
+ this.embedder = embedder;
87
+ this.cache = cache;
88
+ this.config = config;
89
+ }
90
+
91
+ async execute(params) {
92
+ // Implementation
93
+ return {
94
+ /* results */
95
+ };
96
+ }
97
+ }
98
+
99
+ export function getToolDefinition(config) {
100
+ return {
101
+ name: "my_tool",
102
+ description: "What this tool does",
103
+ inputSchema: {
104
+ type: "object",
105
+ properties: {
106
+ param1: { type: "string", description: "..." },
107
+ },
108
+ required: ["param1"],
109
+ },
110
+ };
111
+ }
112
+
113
+ export async function handleToolCall(request, instance) {
114
+ const params = request.params.arguments;
115
+ const result = await instance.execute(params);
116
+
117
+ return {
118
+ content: [
119
+ {
120
+ type: "text",
121
+ text: JSON.stringify(result, null, 2),
122
+ },
123
+ ],
124
+ };
125
+ }
126
+ ```
127
+
128
+ ### 2. Register in index.js
129
+
130
+ ```javascript
131
+ import * as MyFeature from "./features/my-feature.js";
132
+
133
+ // In initialize():
134
+ const myFeature = new MyFeature.MyFeature(embedder, cache, config);
135
+
136
+ // Add to features array:
137
+ const features = [
138
+ // ... existing features
139
+ {
140
+ module: MyFeature,
141
+ instance: myFeature,
142
+ handler: MyFeature.handleToolCall,
143
+ },
144
+ ];
145
+ ```
146
+
147
+ ### 3. Done!
148
+
149
+ The feature will automatically:
150
+
151
+ - Be listed in MCP tool discovery
152
+ - Handle incoming tool requests
153
+ - Have access to embeddings and cache
154
+
155
+ ## Configuration Flow
156
+
157
+ 1. User creates/edits `config.json`
158
+ 2. `lib/config.js` loads configuration on startup
159
+ 3. Configuration merged with defaults
160
+ 4. Passed to all features via constructor
161
+
162
+ ## Data Flow
163
+
164
+ ### Indexing Flow
165
+
166
+ ```
167
+ User code files
168
+
169
+ glob pattern matching
170
+
171
+ smartChunk() - split into chunks
172
+
173
+ embedder - generate vectors
174
+
175
+ EmbeddingsCache - store in memory + disk
176
+ ```
177
+
178
+ ### Search Flow
179
+
180
+ ```
181
+ User query
182
+
183
+ embedder - query to vector
184
+
185
+ cosineSimilarity() - score all chunks
186
+
187
+ exact match boost - adjust scores
188
+
189
+ sort and filter - top N results
190
+
191
+ format output - markdown with syntax highlighting
192
+ ```
193
+
194
+ ## Performance Considerations
195
+
196
+ ### Caching Strategy
197
+
198
+ - **First Run**: Download model (~90MB), index all files, save cache
199
+ - **Subsequent Runs**: Load cache from disk, only index changed files
200
+ - **File Changes**: Incremental updates via file watcher
201
+
202
+ ### Memory Usage
203
+
204
+ Approximate memory usage:
205
+
206
+ - Base (Node.js + libraries): ~50MB
207
+ - Embedding model: ~100MB
208
+ - Vector store: ~10KB per code chunk
209
+ - Example: 1000 files × 20 chunks/file = ~200MB
210
+
211
+ ### Optimization Tips
212
+
213
+ - Reduce `chunkSize` for large codebases
214
+ - Disable `watchFiles` if not needed
215
+ - Use `excludePatterns` aggressively
216
+ - Limit `fileExtensions` to relevant types
217
+
218
+ ## Future Feature Ideas
219
+
220
+ Potential features to add following this architecture:
221
+
222
+ 1. **Code Complexity Analysis**
223
+
224
+ - Cyclomatic complexity scoring
225
+ - Technical debt detection
226
+
227
+ 2. **Pattern Detection**
228
+
229
+ - Anti-pattern identification
230
+ - Best practice recommendations
231
+
232
+ 3. **Documentation Generation**
233
+
234
+ - Auto-generate function docs
235
+ - README generation from code
236
+
237
+ 4. **Refactoring Suggestions**
238
+
239
+ - Code smell detection
240
+ - Automated fix suggestions
241
+
242
+ 5. **Test Coverage Analysis**
243
+
244
+ - Identify untested code paths
245
+ - Generate test templates
246
+
247
+ 6. **Dependency Analysis**
248
+ - Import/export graph
249
+ - Dead code detection
250
+
251
+ Each feature would follow the same pattern:
252
+
253
+ - Class in `features/` directory
254
+ - Access to embedder, cache, config
255
+ - MCP tool definition and handler
256
+ - Registration in feature array
257
+
258
+ ## Testing Strategy
259
+
260
+ Recommended testing approach:
261
+
262
+ 1. **Unit Tests**: lib/ modules
263
+
264
+ - Test utilities in isolation
265
+ - Mock dependencies
266
+
267
+ 2. **Integration Tests**: features/
268
+
269
+ - Test with sample codebases
270
+ - Verify MCP tool contracts
271
+
272
+ 3. **E2E Tests**: Full workflow
273
+ - Index → Search → Results
274
+ - File watching behavior
275
+ - Cache persistence
276
+
277
+ ## Error Handling
278
+
279
+ Each module follows defensive error handling:
280
+
281
+ - Config errors → use defaults
282
+ - File read errors → log and skip
283
+ - Embedding errors → retry or skip chunk
284
+ - Cache errors → log but continue
285
+ - Unknown tools → return helpful error message
286
+
287
+ All errors logged to stderr for MCP protocol compatibility.
@@ -0,0 +1,308 @@
1
+ # Contributing to Smart Coding MCP
2
+
3
+ Thank you for your interest in contributing! This document provides guidelines for contributing to the project.
4
+
5
+ ## Getting Started
6
+
7
+ ### Prerequisites
8
+
9
+ - Node.js 18 or higher
10
+ - npm or yarn
11
+ - Git
12
+
13
+ ### Setup Development Environment
14
+
15
+ ```bash
16
+ # Fork and clone the repository
17
+ git clone https://github.com/omar-haris/smart-coding-mcp.git
18
+ cd smart-coding-mcp
19
+
20
+ # Install dependencies
21
+ npm install
22
+
23
+ # Run in development mode
24
+ npm run dev
25
+ ```
26
+
27
+ ## Project Structure
28
+
29
+ See [ARCHITECTURE.md](./ARCHITECTURE.md) for detailed information about the modular architecture.
30
+
31
+ Key directories:
32
+
33
+ - `lib/` - Core libraries and utilities
34
+ - `features/` - Pluggable feature modules
35
+ - `scripts/` - Utility scripts
36
+
37
+ ## Development Guidelines
38
+
39
+ ### Code Style
40
+
41
+ - Use ES6+ JavaScript features
42
+ - Follow existing code patterns
43
+ - Use meaningful variable and function names
44
+ - Add comments for complex logic
45
+ - No emojis in code or documentation
46
+
47
+ ### File Organization
48
+
49
+ ```javascript
50
+ // Standard file structure for features:
51
+
52
+ // 1. Imports
53
+ import { dependency } from "package";
54
+
55
+ // 2. Class definition
56
+ export class FeatureName {
57
+ constructor(embedder, cache, config) {
58
+ // ...
59
+ }
60
+
61
+ async method() {
62
+ // ...
63
+ }
64
+ }
65
+
66
+ // 3. MCP tool definition
67
+ export function getToolDefinition(config) {
68
+ return {
69
+ /* ... */
70
+ };
71
+ }
72
+
73
+ // 4. Tool handler
74
+ export async function handleToolCall(request, instance) {
75
+ // ...
76
+ }
77
+ ```
78
+
79
+ ### Error Handling
80
+
81
+ ```javascript
82
+ // Always handle errors gracefully
83
+ try {
84
+ // operation
85
+ } catch (error) {
86
+ console.error("[Module] Error description:", error.message);
87
+ // Continue execution or return default value
88
+ }
89
+ ```
90
+
91
+ ### Logging
92
+
93
+ Use `console.error()` for all logs (MCP protocol requirement):
94
+
95
+ ```javascript
96
+ console.error("[FeatureName] Informational message");
97
+ console.error("[FeatureName] Warning:", details);
98
+ console.error("[FeatureName] Error:", error.message);
99
+ ```
100
+
101
+ ## Adding New Features
102
+
103
+ ### Step-by-Step Guide
104
+
105
+ 1. **Create Feature File**
106
+
107
+ Create `features/your-feature.js`:
108
+
109
+ ```javascript
110
+ export class YourFeature {
111
+ constructor(embedder, cache, config) {
112
+ this.embedder = embedder;
113
+ this.cache = cache;
114
+ this.config = config;
115
+ }
116
+
117
+ async execute(params) {
118
+ // Implementation
119
+ return { result: "data" };
120
+ }
121
+ }
122
+
123
+ export function getToolDefinition(config) {
124
+ return {
125
+ name: "your_tool",
126
+ description: "Clear description of what the tool does",
127
+ inputSchema: {
128
+ type: "object",
129
+ properties: {
130
+ param: {
131
+ type: "string",
132
+ description: "Parameter description",
133
+ },
134
+ },
135
+ required: ["param"],
136
+ },
137
+ };
138
+ }
139
+
140
+ export async function handleToolCall(request, instance) {
141
+ const params = request.params.arguments;
142
+ const result = await instance.execute(params);
143
+
144
+ return {
145
+ content: [
146
+ {
147
+ type: "text",
148
+ text: JSON.stringify(result, null, 2),
149
+ },
150
+ ],
151
+ };
152
+ }
153
+ ```
154
+
155
+ 2. **Register Feature**
156
+
157
+ Update `index.js`:
158
+
159
+ ```javascript
160
+ import * as YourFeature from "./features/your-feature.js";
161
+
162
+ // In initialize():
163
+ const yourFeature = new YourFeature.YourFeature(embedder, cache, config);
164
+
165
+ // Add to features array:
166
+ features.push({
167
+ module: YourFeature,
168
+ instance: yourFeature,
169
+ handler: YourFeature.handleToolCall,
170
+ });
171
+ ```
172
+
173
+ 3. **Test Your Feature**
174
+
175
+ - Test with sample codebase
176
+ - Verify MCP tool contract
177
+ - Check error handling
178
+ - Validate output format
179
+
180
+ 4. **Document Your Feature**
181
+
182
+ - Add to README.md features section
183
+ - Create examples in EXAMPLES.md
184
+ - Update ARCHITECTURE.md if needed
185
+
186
+ ## Pull Request Process
187
+
188
+ 1. **Fork the repository**
189
+
190
+ 2. **Create a feature branch**
191
+
192
+ ```bash
193
+ git checkout -b feature/your-feature-name
194
+ ```
195
+
196
+ 3. **Make your changes**
197
+
198
+ - Follow code style guidelines
199
+ - Add appropriate comments
200
+ - Test thoroughly
201
+
202
+ 4. **Commit your changes**
203
+
204
+ ```bash
205
+ git add .
206
+ git commit -m "Add feature: description"
207
+ ```
208
+
209
+ Follow commit message conventions:
210
+
211
+ - `Add feature: description` - New features
212
+ - `Fix: description` - Bug fixes
213
+ - `Update: description` - Updates to existing code
214
+ - `Docs: description` - Documentation changes
215
+
216
+ 5. **Push to your fork**
217
+
218
+ ```bash
219
+ git push origin feature/your-feature-name
220
+ ```
221
+
222
+ 6. **Create Pull Request**
223
+
224
+ - Provide clear description of changes
225
+ - Reference any related issues
226
+ - Include examples of usage
227
+ - Explain testing performed
228
+
229
+ ## Testing
230
+
231
+ ### Manual Testing
232
+
233
+ ```bash
234
+ # Test with a sample project
235
+ cd /path/to/test/project
236
+ node /path/to/smart-coding-mcp/index.js
237
+
238
+ # In another terminal, send MCP requests
239
+ ```
240
+
241
+ ### Testing MCP Tools
242
+
243
+ Create a test script:
244
+
245
+ ```javascript
246
+ // test-tool.js
247
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
248
+ // ... setup and test your tool
249
+ ```
250
+
251
+ ## Configuration Changes
252
+
253
+ If adding new configuration options:
254
+
255
+ 1. Update `lib/config.js` with new default values
256
+ 2. Document in README.md
257
+ 3. Add examples to EXAMPLES.md
258
+ 4. Consider backward compatibility
259
+
260
+ ## Documentation
261
+
262
+ All documentation should:
263
+
264
+ - Be clear and concise
265
+ - Include code examples
266
+ - Avoid emojis
267
+ - Use proper markdown formatting
268
+ - Be kept up-to-date with code changes
269
+
270
+ ## Code Review Checklist
271
+
272
+ Before submitting a PR, verify:
273
+
274
+ - [ ] Code follows project style guidelines
275
+ - [ ] No console.log (use console.error for MCP)
276
+ - [ ] Error handling is implemented
277
+ - [ ] Configuration changes are documented
278
+ - [ ] README.md is updated if needed
279
+ - [ ] No breaking changes without discussion
280
+ - [ ] Comments explain complex logic
281
+ - [ ] No emojis in code or documentation
282
+
283
+ ## Feature Ideas
284
+
285
+ Looking for ideas? Consider implementing:
286
+
287
+ - Code complexity analysis
288
+ - Pattern detection and anti-pattern identification
289
+ - Documentation generation
290
+ - Refactoring suggestions
291
+ - Test coverage analysis
292
+ - Dependency graph visualization
293
+ - Performance profiling integration
294
+ - Multi-language translation support
295
+
296
+ ## Questions and Support
297
+
298
+ - **Issues**: Use GitHub Issues for bugs and feature requests
299
+ - **Discussions**: Use GitHub Discussions for questions
300
+ - **Email**: Contact Omar Haris via LinkedIn
301
+
302
+ ## License
303
+
304
+ By contributing, you agree that your contributions will be licensed under the MIT License.
305
+
306
+ ---
307
+
308
+ Thank you for contributing to Smart Coding MCP!
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Omar Haris
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.