@tng-sh/mcp-server 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.
Files changed (46) hide show
  1. package/README.md +461 -0
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +189 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/init.d.ts +2 -0
  7. package/dist/init.d.ts.map +1 -0
  8. package/dist/init.js +113 -0
  9. package/dist/init.js.map +1 -0
  10. package/dist/tools/audit.d.ts +21 -0
  11. package/dist/tools/audit.d.ts.map +1 -0
  12. package/dist/tools/audit.js +204 -0
  13. package/dist/tools/audit.js.map +1 -0
  14. package/dist/tools/clones.d.ts +20 -0
  15. package/dist/tools/clones.d.ts.map +1 -0
  16. package/dist/tools/clones.js +202 -0
  17. package/dist/tools/clones.js.map +1 -0
  18. package/dist/tools/config.d.ts +30 -0
  19. package/dist/tools/config.d.ts.map +1 -0
  20. package/dist/tools/config.js +51 -0
  21. package/dist/tools/config.js.map +1 -0
  22. package/dist/tools/deadcode.d.ts +19 -0
  23. package/dist/tools/deadcode.d.ts.map +1 -0
  24. package/dist/tools/deadcode.js +223 -0
  25. package/dist/tools/deadcode.js.map +1 -0
  26. package/dist/tools/generate.d.ts +21 -0
  27. package/dist/tools/generate.d.ts.map +1 -0
  28. package/dist/tools/generate.js +186 -0
  29. package/dist/tools/generate.js.map +1 -0
  30. package/dist/tools/list.d.ts +18 -0
  31. package/dist/tools/list.d.ts.map +1 -0
  32. package/dist/tools/list.js +147 -0
  33. package/dist/tools/list.js.map +1 -0
  34. package/dist/tools/trace.d.ts +20 -0
  35. package/dist/tools/trace.d.ts.map +1 -0
  36. package/dist/tools/trace.js +194 -0
  37. package/dist/tools/trace.js.map +1 -0
  38. package/dist/tools/utils.d.ts +19 -0
  39. package/dist/tools/utils.d.ts.map +1 -0
  40. package/dist/tools/utils.js +143 -0
  41. package/dist/tools/utils.js.map +1 -0
  42. package/dist/tools/xray.d.ts +20 -0
  43. package/dist/tools/xray.d.ts.map +1 -0
  44. package/dist/tools/xray.js +187 -0
  45. package/dist/tools/xray.js.map +1 -0
  46. package/package.json +44 -0
package/README.md ADDED
@@ -0,0 +1,461 @@
1
+ # TNG MCP Server
2
+
3
+ > **Model Context Protocol server for TNG - Bring AI-powered test generation and code auditing to any AI assistant**
4
+
5
+ This MCP server exposes [TNG](https://tng.sh)'s test generation and code auditing capabilities to AI assistants like Claude Desktop, Cursor, Antigravity, and any other MCP-compatible tool.
6
+
7
+ ## What is MCP?
8
+
9
+ The [Model Context Protocol](https://modelcontextprotocol.io) allows AI assistants to interact with external tools and services. With this MCP server, you can ask your AI assistant questions like:
10
+
11
+ - *"Audit the `process_payment` method in `app/services/payment_processor.rb`"*
12
+ - *"Generate comprehensive tests for the UserController#create method"*
13
+ - *"What methods are defined in `app/models/user.rb`?"*
14
+
15
+ And the AI will use TNG automatically to provide detailed, actionable results.
16
+
17
+ ## Features
18
+
19
+ - **Method Auditing** - Deep analysis for bugs, security issues, and performance problems
20
+ - **Test Generation** - Automatic test creation for Ruby, Python, and JavaScript
21
+ - **Method Listing** - Quick overview of all methods in a file
22
+ - **X-Ray Visualization** - Generate Mermaid flowcharts to visualize method logic
23
+ - **Symbolic Trace** - Execution path analysis for debugging and understanding code flow
24
+ - **Clone Detection** - Find duplicate code with token-based, structural, and fuzzy matching
25
+ - **Dead Code Detection** - Identify unused imports, variables, functions, and unreachable code
26
+ - **Multi-Language Support** - Works with Ruby, Python, JavaScript/TypeScript
27
+ - **Universal Integration** - Works with any MCP-compatible AI assistant
28
+
29
+ ## Prerequisites
30
+
31
+ **IMPORTANT:** The TNG MCP server works just like the VSCode extension - it assumes you already have TNG installed and configured in your project.
32
+
33
+ ### Step 1: Install TNG in Your Project
34
+
35
+ Choose based on your project type:
36
+
37
+ #### For Ruby Projects
38
+ 1. Add to your `Gemfile`:
39
+ ```ruby
40
+ gem 'tng'
41
+ ```
42
+ 2. Run: `bundle install`
43
+ 3. Get API key from [tng.sh](https://tng.sh)
44
+ 4. Configure: `rails generate tng:install` or set `TNG_API_KEY` environment variable
45
+
46
+ ####For Python Projects
47
+ 1. Install TNG:
48
+ - **pip**: `pip install tng-python`
49
+ - **uv**: `uv add tng-python`
50
+ - **Poetry**: `poetry add tng-python`
51
+ 2. Get API key from [tng.sh](https://tng.sh)
52
+ 3. Configure: Run `tng init` or set `TNG_API_KEY` environment variable
53
+
54
+ #### For Node.js Projects
55
+ 1. Install TNG: `npm install tng-js`
56
+ 2. Get API key from [tng.sh](https://tng.sh)
57
+ 3. Configure: Set `TNG_API_KEY` in your `.env` file
58
+
59
+ ### Step 2: Install MCP Server
60
+
61
+ After TNG is working in your project:
62
+
63
+ ### Option 1: Install from npm (when published)
64
+
65
+ ```bash
66
+ npm install -g @tng-sh/mcp-server
67
+ ```
68
+
69
+ ### Option 2: Install from source (for development)
70
+
71
+ ```bash
72
+ cd /path/to/tng-mcp
73
+ npm install
74
+ npm run build
75
+ npm link
76
+ ```
77
+
78
+ ## Configuration
79
+
80
+ ### For Claude Desktop
81
+
82
+ Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
83
+
84
+ ```json
85
+ {
86
+ "mcpServers": {
87
+ "tng": {
88
+ "command": "tng-mcp"
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
94
+ ### For Cursor
95
+
96
+ Add to your project's `.cursor/mcp_config.json`:
97
+
98
+ ```json
99
+ {
100
+ "mcpServers": {
101
+ "tng": {
102
+ "command": "npx",
103
+ "args": ["-y", "@tng-sh/mcp-server"]
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ ### For Other MCP Clients
110
+
111
+ The server runs on stdio, so configure it as:
112
+
113
+ ```
114
+ Command: tng-mcp
115
+ ```
116
+
117
+ ### Environment Configuration (Ruby/Python/JS + Version Managers)
118
+
119
+ If you use version managers like **mise**, **asdf**, **rbenv**, **pyenv**, or **uv**, the MCP server might not find the correct language environment by default. You can fix this by adding environment variables to your MCP config.
120
+
121
+ The most reliable setup is to specify the TNG command per language, so mixed Ruby + JS + Python repos work correctly:
122
+
123
+ ```json
124
+ {
125
+ "mcpServers": {
126
+ "tng": {
127
+ "command": "tng-mcp",
128
+ "env": {
129
+ "TNG_COMMAND_RUBY": "bundle",
130
+ "TNG_COMMAND_RUBY_ARGS": "exec,tng",
131
+ "TNG_COMMAND_PYTHON": "uv",
132
+ "TNG_COMMAND_PYTHON_ARGS": "run,tng",
133
+ "TNG_COMMAND_JS": "npx",
134
+ "TNG_COMMAND_JS_ARGS": "-p,@tng-sh/js,tng",
135
+ "PATH": "/Users/USERNAME/.local/share/mise/shims:/usr/local/bin:/usr/bin:/bin"
136
+ }
137
+ }
138
+ }
139
+ }
140
+ ```
141
+
142
+ If you only use a single language, you can also set a global command:
143
+
144
+ ```json
145
+ {
146
+ "mcpServers": {
147
+ "tng": {
148
+ "command": "tng-mcp",
149
+ "env": {
150
+ "TNG_COMMAND": "bundle",
151
+ "TNG_COMMAND_ARGS": "exec,tng",
152
+ "PATH": "/usr/local/bin:/usr/bin:/bin"
153
+ }
154
+ }
155
+ }
156
+ }
157
+ ```
158
+
159
+ If you do not set any `TNG_COMMAND*` variables, the server will auto-detect based on file extension.
160
+
161
+ ```json
162
+ {
163
+ "mcpServers": {
164
+ "tng": {
165
+ "command": "tng-mcp",
166
+ "env": {
167
+ "PATH": "/Users/USERNAME/.local/share/mise/shims:/usr/local/bin:/usr/bin:/bin",
168
+ "GEM_HOME": "/Users/USERNAME/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0",
169
+ "GEM_PATH": "/Users/USERNAME/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0",
170
+ "PYTHONPATH": "/path/to/your/python/libs"
171
+ }
172
+ }
173
+ }
174
+ }
175
+ ```
176
+
177
+ This ensures that `bundle exec tng` or `uv run tng` use the correct version and find all installed gems/packages.
178
+
179
+ ## Usage Examples
180
+
181
+ Once configured, interact naturally with your AI assistant:
182
+
183
+ ### Audit a Method
184
+
185
+ ```
186
+ You: Audit the process_payment method in app/services/payment_processor.rb
187
+
188
+ AI: I'll audit that method for you.
189
+ [*calls audit_method tool*]
190
+
191
+ # Audit Results for PaymentProcessor#process_payment
192
+
193
+ ## Issues Found (3)
194
+
195
+ ### 1. Security - Severity: High
196
+ **Description:** Potential SQL injection vulnerability
197
+ **Location:** Line 52
198
+ **Suggested Fix:** Use parameterized queries instead of string interpolation
199
+ ...
200
+ ```
201
+
202
+ ## One-Time Setup Helper
203
+
204
+ Generate a ready-to-paste MCP config by running:
205
+
206
+ ```bash
207
+ npx @tng-sh/mcp-server init
208
+ ```
209
+
210
+ This prints configuration blocks for Claude, Cursor, ChatGPT Desktop, Antigravity, and OpenCode. Copy the block for your client and paste it into your MCP config file.
211
+
212
+ ### Generate Tests
213
+
214
+ ```
215
+ You: Generate tests for the User model's validate_email method
216
+
217
+ AI: I'll generate comprehensive tests for that method.
218
+ [*calls generate_test tool*]
219
+
220
+ ✅ Test Generated Successfully
221
+
222
+ **Test File:** test/models/user_test.rb
223
+ **Command to Run:** bundle exec rails test
224
+
225
+ ## Generated Test Code
226
+ ...
227
+ ```
228
+
229
+ ### Visualize with X-Ray
230
+
231
+ ```
232
+ You: Show me a flowchart of the authenticate_user method
233
+
234
+ AI: I'll generate an X-Ray visualization for that method.
235
+ [*calls xray_method tool*]
236
+
237
+ # X-Ray Visualization for UserController#authenticate_user
238
+
239
+ ## Mermaid Flowchart
240
+ ```mermaid
241
+ graph TD
242
+ A[Start] --> B{User exists?}
243
+ B -->|Yes| C[Check password]
244
+ B -->|No| D[Return error]
245
+ C -->|Valid| E[Create session]
246
+ C -->|Invalid| D
247
+ ```
248
+ ```
249
+
250
+ ### Trace Execution
251
+
252
+ ```
253
+ You: Trace the execution path of calculate_discount
254
+
255
+ AI: I'll generate a symbolic trace for that method.
256
+ [*calls trace_method tool*]
257
+
258
+ # Symbolic Trace for PricingService#calculate_discount
259
+
260
+ ### Step 1
261
+ **Action:** Initialize base_price from params
262
+ **Location:** Line 12
263
+ **State:** base_price = 100.0
264
+ ...
265
+ ```
266
+
267
+ ### Detect Code Clones
268
+
269
+ ```
270
+ You: Find duplicate code in app/services/report_generator.rb
271
+
272
+ AI: I'll check for code clones in that file.
273
+ [*calls detect_clones tool*]
274
+
275
+ # Clone Detection Results
276
+
277
+ **Detection Level:** All Levels (Comprehensive detection)
278
+ **Total Clone Groups Found:** 2
279
+
280
+ ### Clone Group 1 (structural)
281
+ **Similarity:** 95%
282
+ **Instances (3):**
283
+ 1. **Location:** Lines 45-52
284
+ 2. **Location:** Lines 78-85
285
+ 3. **Location:** Lines 112-119
286
+ ```
287
+
288
+ ### Find Dead Code
289
+
290
+ ```
291
+ You: Check for unused code in src/utils/helpers.js
292
+
293
+ AI: I'll analyze that file for dead code.
294
+ [*calls detect_deadcode tool*]
295
+
296
+ # Dead Code Analysis for src/utils/helpers.js
297
+
298
+ ## Summary
299
+ - **Total Issues:** 5
300
+ - **Unused Imports:** 2
301
+ - **Unused Functions:** 3
302
+
303
+ ### Unused Imports (2)
304
+ 1. **lodash**
305
+ - Location: Line 3
306
+ - Suggestion: Remove unused import
307
+ ```
308
+
309
+ ## Available Tools
310
+
311
+ The MCP server exposes six tools:
312
+
313
+ ### 1. `audit_method`
314
+
315
+ Audit a method for issues and behaviors.
316
+
317
+ **Parameters:**
318
+ - `file_path` (required) - Path to the source file
319
+ - `method_name` (required) - Name of the method to audit
320
+ - `test_type` (optional) - Component type for JS/Python (e.g., "react_component", "utility")
321
+
322
+ **Returns:**
323
+ - Detailed issues with severity levels
324
+ - Suggested fixes
325
+ - Behavioral analysis
326
+
327
+ ### 2. `generate_test`
328
+
329
+ Generate comprehensive tests for a method.
330
+
331
+ **Parameters:**
332
+ - `file_path` (required) - Path to the source file
333
+ - `method_name` (required) - Name of the method
334
+ - `test_type` (optional) - Test framework or component type hint
335
+
336
+ **Returns:**
337
+ - Generated test code
338
+ - Test file path
339
+ - Command to run tests
340
+
341
+ ### 3. `xray_method`
342
+
343
+ Generate X-Ray visualization (Mermaid flowchart) for a method.
344
+
345
+ **Parameters:**
346
+ - `file_path` (required) - Path to the source file
347
+ - `method_name` (required) - Name of the method to visualize
348
+
349
+ **Returns:**
350
+ - Mermaid flowchart diagram
351
+ - Visual representation of method logic flow
352
+
353
+ ### 4. `trace_method`
354
+
355
+ Generate symbolic trace execution path for a method.
356
+
357
+ **Parameters:**
358
+ - `file_path` (required) - Path to the source file
359
+ - `method_name` (required) - Name of the method to trace
360
+
361
+ **Returns:**
362
+ - Step-by-step execution path
363
+ - Variable states at each step
364
+ - Control flow analysis
365
+
366
+ ### 5. `detect_clones`
367
+
368
+ Detect code duplication within a file.
369
+
370
+ **Parameters:**
371
+ - `file_path` (required) - Path to the source file
372
+ - `level` (optional) - Detection level: "1" (token), "2" (structural), "3" (fuzzy), or "all" (default)
373
+
374
+ **Returns:**
375
+ - Clone groups with similarity scores
376
+ - Locations of duplicated code
377
+ - Refactoring recommendations
378
+
379
+ ### 6. `detect_deadcode`
380
+
381
+ Detect dead code in a file.
382
+
383
+ **Parameters:**
384
+ - `file_path` (required) - Path to the source file
385
+
386
+ **Returns:**
387
+ - Unused imports, variables, and functions
388
+ - Unreachable code blocks
389
+ - Cleanup recommendations
390
+
391
+ ## Development
392
+
393
+ ### Building
394
+
395
+ ```bash
396
+ npm install
397
+ npm run build
398
+ ```
399
+
400
+ ### Development Mode (with watch)
401
+
402
+ ```bash
403
+ npm run dev
404
+ ```
405
+
406
+ ### Testing the Server
407
+
408
+ You can test the MCP server using the MCP Inspector:
409
+
410
+ ```bash
411
+ npx @modelcontextprotocol/inspector tng-mcp
412
+ ```
413
+
414
+ Or test individual tools manually using the `mcp` CLI.
415
+
416
+ ## Troubleshooting
417
+
418
+ ### "TNG CLI not found"
419
+
420
+ Make sure you have TNG installed:
421
+
422
+ ```bash
423
+ # Check Ruby gem
424
+ gem list tng
425
+
426
+ # Check Python package
427
+ pip list | grep tng
428
+
429
+ # Check Node.js package
430
+ npm list -g | grep tng
431
+ ```
432
+
433
+ ### "Authentication failed"
434
+
435
+ Ensure you have run `tng init` (or the equivalent for your language) in your project to set up your API key. The MCP server uses your local TNG configuration.
436
+
437
+
438
+ ## Contributing
439
+
440
+ Contributions are welcome! Please:
441
+
442
+ 1. Fork the repository
443
+ 2. Create a feature branch
444
+ 3. Make your changes
445
+ 4. Add tests if applicable
446
+ 5. Submit a pull request
447
+
448
+ ## License
449
+
450
+ MIT License - see LICENSE file for details
451
+
452
+ ## Support
453
+
454
+ - **Documentation:** [tng.sh/docs](https://tng.sh/docs)
455
+ - **Issues:** [GitHub Issues](https://github.com/tng-sh/mcp-server/issues)
456
+ - **Discord:** [TNG Community](https://discord.gg/B8brEmjn8q)
457
+ - **Email:** support@tng.sh
458
+
459
+ ---
460
+
461
+ Made with ❤️ by [Binary Dreams LLC](https://tng.sh)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { z } from 'zod';
5
+ import { auditMethod } from './tools/audit.js';
6
+ import { generateTest } from './tools/generate.js';
7
+ import { xrayMethod } from './tools/xray.js';
8
+ import { traceMethod } from './tools/trace.js';
9
+ import { detectClones } from './tools/clones.js';
10
+ import { detectDeadCode } from './tools/deadcode.js';
11
+ import { runInit } from './init.js';
12
+ const server = new McpServer({
13
+ name: 'tng-mcp',
14
+ version: '1.0.0',
15
+ });
16
+ if (process.argv.includes('init')) {
17
+ const code = runInit();
18
+ process.exit(code);
19
+ }
20
+ // 1. Audit Method - AI-Powered Code Analysis
21
+ server.registerTool('audit_method', {
22
+ description: `Perform a comprehensive AI-powered audit of a specific method or function in your codebase. This tool analyzes code for:
23
+ - **Security vulnerabilities**: SQL injection, XSS, authentication issues, insecure data handling
24
+ - **Bugs and logic errors**: Edge cases, null pointer issues, race conditions, incorrect algorithms
25
+ - **Performance problems**: Inefficient loops, N+1 queries, memory leaks, unnecessary computations
26
+ - **Code quality issues**: Complexity, maintainability, anti-patterns, code smells
27
+ - **Behavioral analysis**: Understanding what the code does, its dependencies, and side effects
28
+
29
+ Use this when the user asks to "check", "analyze", "review", "audit", "find issues in", or "what's wrong with" code.
30
+
31
+ Returns: Detailed findings with severity levels (Critical/High/Medium/Low), descriptions, exact line locations, reasoning, and suggested fixes. Also includes behavioral insights about what the method does.
32
+
33
+ **How to use the results:**
34
+ 1. Summarize the most critical issues first (High/Critical severity)
35
+ 2. Explain each issue in plain language with context from the code
36
+ 3. Offer to show the suggested fixes or apply them directly to the file
37
+ 4. If no issues found, acknowledge the code quality and mention any positive behaviors observed
38
+ 5. Suggest follow-up actions: generate tests for edge cases, create documentation, or refactor for better maintainability
39
+
40
+ Supports: Ruby (Rails), Python, JavaScript/TypeScript (React, Node.js, Express), and more.`,
41
+ inputSchema: {
42
+ file_path: z.string().describe('Relative or absolute path to the source file (e.g., "app/services/payment_processor.rb", "src/utils/validator.ts")'),
43
+ method_name: z.string().describe('Name of the method/function to audit (e.g., "process_payment", "validateUser", "handleSubmit")'),
44
+ test_type: z.string().optional().describe('Component type - REQUIRED for JavaScript/Python: "utility", "react_component", "express_handler", "django_view", etc. Ignored for Ruby/Rails.'),
45
+ }
46
+ }, async (args) => await auditMethod(args));
47
+ // 2. Generate Test - AI Test Generation
48
+ server.registerTool('generate_test', {
49
+ description: `Generate comprehensive, production-ready tests for a specific method or function using AI. This tool:
50
+ - **Automatically detects** the appropriate test framework (RSpec, Jest, Pytest, Mocha, etc.)
51
+ - **Creates complete test files** with proper imports, setup, teardown, and test structure
52
+ - **Covers multiple scenarios**: Happy path, edge cases, error handling, boundary conditions
53
+ - **Includes assertions** for return values, side effects, state changes, and error conditions
54
+ - **Adds mocking/stubbing** for external dependencies, API calls, database queries
55
+ - **Follows best practices** for the detected framework and language
56
+
57
+ Use this when the user asks to "write tests", "generate tests", "create specs", "test this code", or "add test coverage".
58
+
59
+ Returns: Complete test file code with test count, file path where it should be saved, and the command to run the tests.
60
+
61
+ **How to use the results:**
62
+ 1. Show the generated test code in a code block with proper syntax highlighting
63
+ 2. Explain what scenarios the tests cover (happy path, edge cases, errors)
64
+ 3. Provide the file path where the test should be saved
65
+ 4. Show the command to run the tests (e.g., "npm test", "pytest", "rspec")
66
+ 5. Offer to save the test file directly or let the user review it first
67
+ 6. Suggest running the tests to verify they pass, or offer to fix any issues if they fail
68
+
69
+ Supports: Ruby (RSpec, Minitest), JavaScript/TypeScript (Jest, Mocha, Vitest), Python (Pytest, unittest), and more.`,
70
+ inputSchema: {
71
+ file_path: z.string().describe('Relative or absolute path to the source file to generate tests for'),
72
+ method_name: z.string().describe('Name of the method/function to generate tests for'),
73
+ test_type: z.string().optional().describe('Component type or test framework hint - REQUIRED for JS/Python: "utility", "react_component", "express_handler", etc.'),
74
+ }
75
+ }, async (args) => await generateTest(args));
76
+ // 3. X-Ray Visualization - Code Flow Diagrams
77
+ server.registerTool('xray_method', {
78
+ description: `Generate a visual X-Ray diagram (Mermaid flowchart) that maps out the logic flow of a specific method or function. This tool:
79
+ - **Creates flowcharts** showing decision points, loops, function calls, and control flow
80
+ - **Visualizes complexity** making it easy to understand what the code does at a glance
81
+ - **Identifies code paths** including conditional branches, error handling, and edge cases
82
+ - **Shows relationships** between different parts of the method
83
+
84
+ Use this when the user asks for a "diagram", "flowchart", "visual representation", "map out the logic", "show me how this works visually", or "xray".
85
+
86
+ Returns: Mermaid diagram code that can be rendered in Markdown-compatible viewers (GitHub, VS Code, etc.).
87
+
88
+ **How to use the results:**
89
+ 1. Display the Mermaid diagram code in a code block with \`\`\`mermaid syntax
90
+ 2. Explain the main flow and key decision points shown in the diagram
91
+ 3. Point out any complex branches or loops that might need attention
92
+ 4. Suggest using the diagram for documentation or code reviews
93
+ 5. If the diagram reveals high complexity, offer to audit the method for potential simplification
94
+
95
+ Supports: All languages - Ruby, Python, JavaScript/TypeScript, Go, and more.`,
96
+ inputSchema: {
97
+ file_path: z.string().describe('Relative or absolute path to the source file'),
98
+ method_name: z.string().describe('Name of the method/function to visualize'),
99
+ }
100
+ }, async (args) => await xrayMethod(args));
101
+ // 4. Trace Method - Symbolic Execution Analysis
102
+ server.registerTool('trace_method', {
103
+ description: `Generate a symbolic trace showing the step-by-step execution path through a method or function. This tool:
104
+ - **Simulates execution** with symbolic values to explore all possible code paths
105
+ - **Shows variable states** and how they change throughout execution
106
+ - **Identifies branches** and which conditions lead to which outcomes
107
+ - **Reveals execution order** of statements, function calls, and side effects
108
+ - **Helps debug** by showing exactly what happens when the code runs
109
+
110
+ Use this when the user asks to "trace", "step through", "show execution", "debug flow", "walk through the code", or "see what happens when this runs".
111
+
112
+ Returns: Detailed execution trace with line-by-line analysis, variable states, and decision points.
113
+
114
+ **How to use the results:**
115
+ 1. Present the trace in a clear, step-by-step format
116
+ 2. Highlight key decision points and branch conditions
117
+ 3. Explain how variables change throughout execution
118
+ 4. Point out any unexpected behavior or potential issues discovered
119
+ 5. Use the trace to answer specific debugging questions or explain complex logic
120
+ 6. Suggest areas where the code might benefit from simplification or better error handling
121
+
122
+ Supports: All languages - Ruby, Python, JavaScript/TypeScript, and more.`,
123
+ inputSchema: {
124
+ file_path: z.string().describe('Relative or absolute path to the source file'),
125
+ method_name: z.string().describe('Name of the method/function to trace'),
126
+ }
127
+ }, async (args) => await traceMethod(args));
128
+ // 5. Detect Clones - Code Duplication Detection
129
+ server.registerTool('detect_clones', {
130
+ description: `Detect code duplication (clones) within a file at multiple levels of similarity. This tool finds:
131
+ - **Type 1 (Exact clones)**: Identical code except for whitespace and comments
132
+ - **Type 2 (Renamed clones)**: Structurally identical code with different variable/function names
133
+ - **Type 3 (Near-miss clones)**: Similar code with minor modifications (statements added/removed)
134
+
135
+ Use this when the user asks to "find duplicates", "check for clones", "find repeated code", "detect copy-paste", or "find similar code".
136
+
137
+ Returns: List of clone pairs with similarity scores, exact line locations, and the duplicated code snippets.
138
+
139
+ **How to use the results:**
140
+ 1. Summarize the number and types of clones found
141
+ 2. Show the most significant duplications first (highest similarity or largest code blocks)
142
+ 3. Explain the impact of each duplication on maintainability
143
+ 4. Suggest refactoring strategies: extract to shared function, create a base class, use a loop, etc.
144
+ 5. Offer to help refactor the duplicated code into reusable components
145
+ 6. If no clones found, acknowledge good code organization
146
+
147
+ Supports: All languages - Ruby, Python, JavaScript/TypeScript, and more.`,
148
+ inputSchema: {
149
+ file_path: z.string().describe('Relative or absolute path to the source file to analyze for duplication'),
150
+ level: z.string().optional().describe('Clone detection level: "1" (exact), "2" (structural), "3" (fuzzy/near-miss), or "all" (default - detects all types)'),
151
+ }
152
+ }, async (args) => await detectClones(args));
153
+ // 6. Detect Dead Code - Unused Code Detection
154
+ server.registerTool('detect_deadcode', {
155
+ description: `Detect dead code and unused elements in a file, including:
156
+ - **Unused imports/requires**: Modules imported but never used
157
+ - **Unused variables**: Variables declared but never referenced
158
+ - **Unused functions**: Private/local functions that are never called
159
+ - **Unused parameters**: Function parameters that are never used in the function body
160
+ - **Unreachable code**: Code that can never be executed (after return, in impossible conditions)
161
+
162
+ Use this when the user asks to "find dead code", "find unused code", "check for unused imports", "clean up unused variables", or "find unreachable code".
163
+
164
+ Returns: List of unused/dead code elements with exact locations, types (import/variable/function), and suggestions for cleanup.
165
+
166
+ **How to use the results:**
167
+ 1. Categorize findings by type (unused imports, variables, functions, etc.)
168
+ 2. Explain why each element is considered unused
169
+ 3. Suggest safe removal of truly unused code
170
+ 4. Warn about potential false positives (e.g., variables used in eval, reflection, or external configs)
171
+ 5. Offer to remove the dead code automatically or show a cleaned-up version
172
+ 6. If the file is clean, acknowledge good code hygiene
173
+
174
+ Supports: Python, JavaScript/TypeScript, Ruby (coming soon).`,
175
+ inputSchema: {
176
+ file_path: z.string().describe('Relative or absolute path to the source file to analyze for dead code'),
177
+ }
178
+ }, async (args) => await detectDeadCode(args));
179
+ // Start the MCP server
180
+ async function main() {
181
+ const transport = new StdioServerTransport();
182
+ await server.connect(transport);
183
+ console.error('TNG MCP server running on stdio');
184
+ }
185
+ main().catch((error) => {
186
+ console.error('Fatal error running TNG MCP server:', error);
187
+ process.exit(1);
188
+ });
189
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IACzB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,OAAO;CACnB,CAAC,CAAC;AAEH,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC;AAED,6CAA6C;AAC7C,MAAM,CAA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AC,KAAK,CAAC,iCAAiC,CAAC,CAAC;AACrD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
package/dist/init.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function runInit(): number;
2
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAwGA,wBAAgB,OAAO,IAAI,MAAM,CAyBhC"}