@slbdn/mcp-tester 1.4.3 → 1.5.3

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 (66) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +49 -0
  3. package/dist/ai/provider.d.ts +145 -0
  4. package/dist/ai/provider.d.ts.map +1 -0
  5. package/dist/ai/provider.js +428 -0
  6. package/dist/ai/provider.js.map +1 -0
  7. package/dist/cli/index.js +214 -14
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/generate-cases.d.ts +113 -0
  10. package/dist/generate-cases.d.ts.map +1 -0
  11. package/dist/generate-cases.js +565 -0
  12. package/dist/generate-cases.js.map +1 -0
  13. package/dist/generate-tests.d.ts +52 -1
  14. package/dist/generate-tests.d.ts.map +1 -1
  15. package/dist/generate-tests.js +208 -81
  16. package/dist/generate-tests.js.map +1 -1
  17. package/dist/index.d.ts +3 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/matchers.d.ts +31 -21
  22. package/dist/matchers.d.ts.map +1 -1
  23. package/dist/matchers.js.map +1 -1
  24. package/dist/templates/full-stack/.github/workflows/test.yml +34 -0
  25. package/dist/templates/full-stack/README.md +73 -0
  26. package/dist/templates/full-stack/examples/mock-server.js +115 -0
  27. package/dist/templates/full-stack/jest.config.js +39 -0
  28. package/dist/templates/full-stack/package.json +31 -0
  29. package/dist/templates/full-stack/scripts/generate-tests.ts +32 -0
  30. package/dist/templates/full-stack/scripts/generate-types.ts +28 -0
  31. package/dist/templates/full-stack/src/server.ts +78 -0
  32. package/dist/templates/full-stack/tests/helpers.ts +29 -0
  33. package/dist/templates/full-stack/tests/parallel.test.ts +44 -0
  34. package/dist/templates/full-stack/tests/server.test.ts +36 -0
  35. package/dist/templates/full-stack/tests/tools.test.ts +61 -0
  36. package/dist/templates/full-stack/tsconfig.json +19 -0
  37. package/dist/templates/minimal-jest/README.md +42 -0
  38. package/dist/templates/minimal-jest/examples/mock-server.js +62 -0
  39. package/dist/templates/minimal-jest/jest.config.js +24 -0
  40. package/dist/templates/minimal-jest/package.json +24 -0
  41. package/dist/templates/minimal-jest/tests/server.test.ts +64 -0
  42. package/dist/templates/minimal-jest/tsconfig.json +19 -0
  43. package/dist/templates/standard-jest/.github/workflows/test.yml +32 -0
  44. package/dist/templates/standard-jest/README.md +44 -0
  45. package/dist/templates/standard-jest/examples/mock-server.js +122 -0
  46. package/dist/templates/standard-jest/jest.config.js +39 -0
  47. package/dist/templates/standard-jest/package.json +27 -0
  48. package/dist/templates/standard-jest/tests/helpers.ts +43 -0
  49. package/dist/templates/standard-jest/tests/prompts.test.ts +37 -0
  50. package/dist/templates/standard-jest/tests/resources.test.ts +37 -0
  51. package/dist/templates/standard-jest/tests/server.test.ts +30 -0
  52. package/dist/templates/standard-jest/tests/tools.test.ts +87 -0
  53. package/dist/templates/standard-jest/tsconfig.json +19 -0
  54. package/docs/advanced.md +424 -0
  55. package/docs/ai-generation.md +211 -0
  56. package/docs/api-reference.md +819 -0
  57. package/docs/cicd.md +289 -0
  58. package/docs/cli.md +225 -0
  59. package/docs/examples.md +300 -0
  60. package/docs/nodejs-compatibility.md +81 -0
  61. package/docs/releases.md +413 -0
  62. package/docs/starter-templates.md +110 -0
  63. package/docs/testing.md +443 -0
  64. package/docs/troubleshooting.md +139 -0
  65. package/jest.d.ts +43 -0
  66. package/package.json +5 -2
package/docs/cicd.md ADDED
@@ -0,0 +1,289 @@
1
+ # CI/CD Integration
2
+
3
+ Using MCP Tester in continuous integration pipelines.
4
+
5
+ ## GitHub Actions
6
+
7
+ Create `.github/workflows/test.yml`:
8
+
9
+ ```yaml
10
+ name: Test MCP Server
11
+
12
+ on:
13
+ push:
14
+ branches: [main, develop]
15
+ pull_request:
16
+ branches: [main, develop]
17
+
18
+ jobs:
19
+ test:
20
+ runs-on: ubuntu-latest
21
+
22
+ strategy:
23
+ matrix:
24
+ node-version: [20, 22]
25
+
26
+ steps:
27
+ - name: Checkout code
28
+ uses: actions/checkout@v5
29
+
30
+ - name: Setup Node.js ${{ matrix.node-version }}
31
+ uses: actions/setup-node@v5
32
+ with:
33
+ node-version: ${{ matrix.node-version }}
34
+ cache: 'npm'
35
+
36
+ - name: Install dependencies
37
+ run: npm ci
38
+
39
+ - name: Build TypeScript
40
+ run: npm run build
41
+
42
+ - name: Run tests
43
+ run: npm test
44
+
45
+ coverage:
46
+ runs-on: ubuntu-latest
47
+
48
+ steps:
49
+ - name: Checkout code
50
+ uses: actions/checkout@v5
51
+
52
+ - name: Setup Node.js
53
+ uses: actions/setup-node@v5
54
+ with:
55
+ node-version: '20'
56
+ cache: 'npm'
57
+
58
+ - name: Install dependencies
59
+ run: npm ci
60
+
61
+ - name: Build TypeScript
62
+ run: npm run build
63
+
64
+ - name: Run tests with coverage
65
+ run: npm run test:coverage
66
+
67
+ - name: Upload coverage to Codecov
68
+ uses: codecov/codecov-action@v5
69
+ with:
70
+ files: ./coverage/lcov.info
71
+ flags: unittests
72
+ name: codecov-umbrella
73
+ fail_ci_if_error: false
74
+ verbose: true
75
+
76
+ - name: Generate coverage summary
77
+ id: coverage
78
+ run: |
79
+ SUMMARY=$(cat coverage/coverage-summary.json 2>/dev/null || echo '{}')
80
+ STATEMENTS=$(echo "$SUMMARY" | jq -r '.total.statements.pct // "N/A"')
81
+ BRANCHES=$(echo "$SUMMARY" | jq -r '.total.branches.pct // "N/A"')
82
+ FUNCTIONS=$(echo "$SUMMARY" | jq -r '.total.functions.pct // "N/A"')
83
+ LINES=$(echo "$SUMMARY" | jq -r '.total.lines.pct // "N/A"')
84
+
85
+ echo "statements=$STATEMENTS" >> $GITHUB_OUTPUT
86
+ echo "branches=$BRANCHES" >> $GITHUB_OUTPUT
87
+ echo "functions=$FUNCTIONS" >> $GITHUB_OUTPUT
88
+ echo "lines=$LINES" >> $GITHUB_OUTPUT
89
+
90
+ {
91
+ echo "## 📊 Test Coverage Report"
92
+ echo ""
93
+ echo "| Metric | Coverage |"
94
+ echo "|--------|----------|"
95
+ echo "| Statements | ${STATEMENTS}% |"
96
+ echo "| Branches | ${BRANCHES}% |"
97
+ echo "| Functions | ${FUNCTIONS}% |"
98
+ echo "| Lines | ${LINES}% |"
99
+ echo ""
100
+ echo "Thresholds: Statements ≥67% · Branches ≥61% · Functions ≥60% · Lines ≥67%"
101
+ } > coverage-comment.md
102
+
103
+ - name: Comment PR with coverage
104
+ if: github.event_name == 'pull_request'
105
+ uses: marocchino/sticky-pull-request-comment@v2
106
+ with:
107
+ header: coverage
108
+ path: coverage-comment.md
109
+
110
+ lint:
111
+ runs-on: ubuntu-latest
112
+
113
+ steps:
114
+ - name: Checkout code
115
+ uses: actions/checkout@v5
116
+
117
+ - name: Setup Node.js
118
+ uses: actions/setup-node@v5
119
+ with:
120
+ node-version: '20'
121
+ cache: 'npm'
122
+
123
+ - name: Install dependencies
124
+ run: npm ci
125
+
126
+ - name: Run linter
127
+ run: npm run lint
128
+
129
+ - name: Check formatting
130
+ run: npm run format:check
131
+
132
+ security:
133
+ runs-on: ubuntu-latest
134
+
135
+ steps:
136
+ - name: Checkout code
137
+ uses: actions/checkout@v5
138
+
139
+ - name: Setup Node.js
140
+ uses: actions/setup-node@v5
141
+ with:
142
+ node-version: '20'
143
+ cache: 'npm'
144
+
145
+ - name: Install dependencies
146
+ run: npm ci
147
+
148
+ - name: Run security audit
149
+ run: npm audit --audit-level=moderate
150
+ ```
151
+
152
+ ### How It Works
153
+
154
+ | Job | Purpose | Node Version |
155
+ |-----|---------|---------------|
156
+ | `test` | Run full test suite, upload HTML test report | Matrix: 20, 22 |
157
+ | `coverage` | Generate coverage report, upload to Codecov, comment on PRs | 20 |
158
+ | `lint` | ESLint + Prettier checks | 20 |
159
+ | `security` | npm audit for vulnerabilities | 20 |
160
+
161
+ ### PR Coverage Comments
162
+
163
+ Every pull request receives an automated coverage comment like:
164
+
165
+ > ## 📊 Test Coverage Report
166
+ >
167
+ > | Metric | Coverage |
168
+ > |--------|----------|
169
+ > | Statements | 68% |
170
+ > | Branches | 61% |
171
+ > | Functions | 60% |
172
+ > | Lines | 68% |
173
+ >
174
+ > Thresholds: Statements ≥67% · Branches ≥61% · Functions ≥60% · Lines ≥67%
175
+
176
+ The comment updates on each push (using `sticky-pull-request-comment` with a `header` key).
177
+
178
+ ### HTML Test Reports
179
+
180
+ Every CI run uploads an HTML test report as a downloadable artifact:
181
+
182
+ - Generated by `jest-html-reporters` on every `npm test` run
183
+ - Saved to `reports/test-report.html`
184
+ - Uploaded per Node version (`test-report-node-20`, `test-report-node-22`)
185
+ - Retained for 14 days
186
+ - Includes: collapsible test tree, timing per test, failure details with stack traces
187
+
188
+ To view locally:
189
+
190
+ ```bash
191
+ npm test # generates reports/test-report.html
192
+ open reports/test-report.html # macOS
193
+ ```
194
+
195
+ ### Coverage Thresholds
196
+
197
+ Jest enforces minimum coverage thresholds in `jest.config.js`:
198
+
199
+ | File | Stmts | Branch | Func | Lines |
200
+ |------|-------|--------|------|-------|
201
+ | Global | 67% | 61% | 60% | 67% |
202
+ | `assert.ts` | 96% | 87% | 100% | 96% |
203
+ | `matchers.ts` | 68% | 28% | 42% | 64% |
204
+ | `MCPClient.ts` | 68% | 54% | 75% | 68% |
205
+ | `logger.ts` | 84% | 82% | 94% | 83% |
206
+ | `masking.ts` | 100% | 88% | 100% | 100% |
207
+ | `errors.ts` | 100% | 100% | 100% | 100% |
208
+ | `env.ts` | 80% | 100% | 60% | 87% |
209
+ | `mock-server.ts` | 96% | 64% | 94% | 96% |
210
+
211
+ If coverage drops below these thresholds, the `test:coverage` command will exit with an error — failing the CI build.
212
+
213
+ ## CircleCI
214
+
215
+ Create `.circleci/config.yml`:
216
+
217
+ ```yaml
218
+ version: 2.1
219
+ jobs:
220
+ test:
221
+ docker:
222
+ - image: cimg/node:20
223
+ steps:
224
+ - checkout
225
+ - run: npm ci
226
+ - run: npm run build
227
+ - run: npm test
228
+
229
+ coverage:
230
+ docker:
231
+ - image: cimg/node:20
232
+ steps:
233
+ - checkout
234
+ - run: npm ci
235
+ - run: npm run build
236
+ - run: npm run test:coverage
237
+ - store_artifacts:
238
+ path: coverage
239
+ destination: coverage
240
+
241
+ workflows:
242
+ version: 2
243
+ test_and_coverage:
244
+ jobs:
245
+ - test
246
+ - coverage
247
+ ```
248
+
249
+ ## Jenkins
250
+
251
+ Create `Jenkinsfile`:
252
+
253
+ ```groovy
254
+ pipeline {
255
+ agent any
256
+ stages {
257
+ stage('Test') {
258
+ steps {
259
+ sh 'npm ci'
260
+ sh 'npm run build'
261
+ sh 'npm test'
262
+ }
263
+ }
264
+ stage('Coverage') {
265
+ steps {
266
+ sh 'npm run test:coverage'
267
+ publishHTML(target: [
268
+ reportDir: 'coverage/lcov-report',
269
+ reportFiles: 'index.html',
270
+ reportName: 'Coverage'
271
+ ])
272
+ }
273
+ }
274
+ }
275
+ }
276
+ ```
277
+
278
+ ## Using the CLI in CI
279
+
280
+ ```bash
281
+ # Quick smoke test
282
+ npx @slbdn/mcp-tester test node ./server.js
283
+
284
+ # List tools and verify
285
+ npx @slbdn/mcp-tester list-tools node ./server.js --json
286
+
287
+ # Call a tool and check result
288
+ npx @slbdn/mcp-tester call-tool health-check node ./server.js --json
289
+ ```
package/docs/cli.md ADDED
@@ -0,0 +1,225 @@
1
+ # CLI Tool
2
+
3
+ MCP Tester includes a CLI for quick server testing without writing code.
4
+
5
+ Install globally or use via npx:
6
+
7
+ ```bash
8
+ npx @slbdn/mcp-tester test node ./server.js
9
+ ```
10
+
11
+ ## Transports
12
+
13
+ The CLI supports three transport types:
14
+
15
+ ### Stdio (default)
16
+
17
+ Pass the command and arguments as positional args:
18
+
19
+ ```bash
20
+ mcp-tester test node ./server.js
21
+ mcp-tester list-tools node ./server.js --json
22
+ ```
23
+
24
+ ### HTTP (Streamable HTTP)
25
+
26
+ Pass the URL as the first argument (auto-detected), or use `--transport http --url`:
27
+
28
+ ```bash
29
+ # Auto-detect: URL as first arg
30
+ mcp-tester test http://localhost:3000/mcp
31
+ mcp-tester list-tools http://localhost:3000/mcp --json
32
+
33
+ # Explicit
34
+ mcp-tester test --transport http --url http://localhost:3000/mcp
35
+
36
+ # With headers
37
+ mcp-tester test --transport http --url https://api.example.com/mcp --headers '{"Authorization":"Bearer token"}'
38
+ ```
39
+
40
+ ### SSE (legacy)
41
+
42
+ ```bash
43
+ mcp-tester test --transport sse --url http://localhost:3000/sse
44
+ ```
45
+
46
+ ## Commands
47
+
48
+ ### `test` — Test Server Connection
49
+
50
+ Connects to the server and lists all capabilities.
51
+
52
+ ```bash
53
+ mcp-tester test node ./server.js
54
+ ```
55
+
56
+ ### `list-tools` (alias: `lt`)
57
+
58
+ List all available tools.
59
+
60
+ ```bash
61
+ mcp-tester list-tools node ./server.js
62
+ mcp-tester lt node ./server.js --json
63
+ ```
64
+
65
+ ### `call-tool` (alias: `ct`)
66
+
67
+ Call a tool with optional JSON parameters.
68
+
69
+ ```bash
70
+ mcp-tester call-tool echo node ./server.js --params '{"message":"Hello"}'
71
+ mcp-tester ct echo node ./server.js --params '{"message":"World"}' --json
72
+ ```
73
+
74
+ ### `read-resource` (alias: `rr`)
75
+
76
+ Read a resource by URI.
77
+
78
+ ```bash
79
+ mcp-tester read-resource text://example node ./server.js
80
+ mcp-tester rr text://example node ./server.js --json
81
+ ```
82
+
83
+ ### `get-prompt` (alias: `gp`)
84
+
85
+ Get a prompt with optional JSON arguments.
86
+
87
+ ```bash
88
+ mcp-tester get-prompt greet node ./server.js --args '{"name":"Alice"}'
89
+ mcp-tester gp greet node ./server.js --args '{"name":"Bob"}' --json
90
+ ```
91
+
92
+ ## Global Options
93
+
94
+ | Option | Short | Default | Description |
95
+ |--------|-------|---------|-------------|
96
+ | `--timeout <ms>` | `-t` | 30000 | Request timeout |
97
+ | `--verbose` | `-v` | off | Enable debug output |
98
+ | `--log-level <level>` | `-l` | info | Log level (debug/info/warn/error) |
99
+ | `--json` | | off | Output as JSON (commands that support it) |
100
+
101
+ ### `generate` (alias: `gen`) — Generate Test Files
102
+
103
+ Connect to a server, inspect all capabilities, and generate a ready-to-run test file.
104
+
105
+ ```bash
106
+ # Generate Jest test file
107
+ mcp-tester generate node ./server.js -o server.test.ts
108
+
109
+ # Generate Vitest test file
110
+ mcp-tester gen node ./server.js --framework vitest -o server.test.ts
111
+
112
+ # Skip specific sections
113
+ mcp-tester generate node ./server.js --no-resources --no-prompts -o tools-only.test.ts
114
+
115
+ # Deterministic edge cases (offline)
116
+ mcp-tester generate node ./server.js --edge-cases -o edge.test.ts
117
+
118
+ # AI-suggested cases (OpenAI-compatible; Ollama needs no key on localhost)
119
+ mcp-tester generate node ./server.js --ai-generate --ai-model llama3 \
120
+ --ai-base-url http://localhost:11434/v1 -o ai.test.ts
121
+
122
+ # Dry-run derived cases against the live server
123
+ mcp-tester generate node ./server.js --edge-cases --verify -o edge.test.ts
124
+
125
+ # Print to stdout (no file)
126
+ mcp-tester generate node ./server.js
127
+ ```
128
+
129
+ **Options:**
130
+
131
+ | Option | Default | Description |
132
+ |--------|---------|-------------|
133
+ | `-o, --output <file>` | stdout | Output file path |
134
+ | `--framework <fw>` | `jest` | Test framework (`jest` or `vitest`) |
135
+ | `--description <desc>` | auto | Test suite description |
136
+ | `--no-tools` | | Skip tool tests |
137
+ | `--no-resources` | | Skip resource tests |
138
+ | `--no-prompts` | | Skip prompt tests |
139
+ | `--no-matchers` | | Skip custom matchers import |
140
+ | `--edge-cases` | off | Add schema-derived boundary/invalid test cases (offline) |
141
+ | `--ai-generate` | off | Edge cases + AI-suggested cases (env: `MCP_TESTER_AI_API_KEY`) |
142
+ | `--ai-model <model>` | `gpt-4o-mini` | AI model name |
143
+ | `--ai-base-url <url>` | `https://api.openai.com/v1` | OpenAI-compatible API base URL |
144
+ | `--require-ai` | off | Fail instead of falling back when AI is unavailable |
145
+ | `--verify` | off | Dry-run derived cases against the live server and annotate mismatches |
146
+
147
+ See [AI-Assisted Test Generation](./ai-generation.md) for the full workflow.
148
+
149
+ ### `generate-types` (alias: `gen-types`) — Generate TypeScript Types
150
+
151
+ Connect to a server, read tool schemas, and generate typed `.d.ts` declarations.
152
+
153
+ ```bash
154
+ # Generate and save to file
155
+ mcp-tester generate-types node ./server.js -o server.d.ts
156
+
157
+ # Print to stdout
158
+ mcp-tester generate-types node ./server.js
159
+
160
+ # Skip resource/prompt types
161
+ mcp-tester generate-types node ./server.js --no-resources --no-prompts -o types.d.ts
162
+ ```
163
+
164
+ **Options:**
165
+
166
+ | Option | Default | Description |
167
+ |--------|---------|-------------|
168
+ | `-o, --output <file>` | stdout | Output file path |
169
+ | `--module-name <name>` | `@slbdn/mcp-tester` | Module name for import hints |
170
+ | `--no-resources` | | Skip resource URI types |
171
+ | `--no-prompts` | | Skip prompt argument types |
172
+
173
+ **Generated types:**
174
+
175
+ | Type | Description |
176
+ |------|-------------|
177
+ | `{ToolName}Args` | Typed interface per tool (e.g., `EchoArgs`, `AddArgs`) |
178
+ | `ToolName` | Union of all tool names (e.g., `'echo' \| 'add'`) |
179
+ | `ToolArgsMap` | Lookup map: `ToolArgsMap['add']` → `AddArgs` |
180
+ | `ToolCall` | Discriminated union: `{ name: 'add'; arguments: AddArgs }` |
181
+ | `ResourceUri` | Union of all resource URIs |
182
+ | `{PromptName}Args` | Typed interface per prompt |
183
+ | `PromptName` | Union of all prompt names |
184
+ | `PromptArgsMap` | Lookup map for prompt arguments |
185
+ | `ServerCapabilities` | Overview interface with typed arrays |
186
+
187
+ **Usage with generated types:**
188
+
189
+ ```typescript
190
+ import type { ToolArgsMap, ToolName } from './server.d.ts';
191
+
192
+ const result = await client.callTool({
193
+ name: 'add',
194
+ arguments: { a: 1, b: 2 } as ToolArgsMap['add'],
195
+ });
196
+ ```
197
+
198
+ ## Global Options
199
+
200
+ | Option | Short | Default | Description |
201
+ |--------|-------|---------|-------------|
202
+ | `--timeout <ms>` | `-t` | 30000 | Request timeout |
203
+ | `--verbose` | `-v` | off | Enable debug output |
204
+ | `--log-level <level>` | `-l` | info | Log level (debug/info/warn/error) |
205
+ | `--json` | | off | Output as JSON (commands that support it) |
206
+
207
+ ## Output Format
208
+
209
+ Default output is human-readable with emojis. Use `--json` for machine-readable output:
210
+
211
+ ```bash
212
+ mcp-tester lt node ./server.js --json
213
+ ```
214
+
215
+ ```json
216
+ {
217
+ "tools": [
218
+ {
219
+ "name": "echo",
220
+ "description": "Echo back the input",
221
+ "inputSchema": { ... }
222
+ }
223
+ ]
224
+ }
225
+ ```