trip-test 0.1.1

Contract testing & regression safety for MCP servers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
# Tripwire — Contract Testing for MCP Servers

[![Crates.io](https://img.shields.io/crates/v/trip-test.svg)](https://crates.io/crates/trip-test)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust 1.70+](https://img.shields.io/badge/rust-1.70+-orange.svg)](https://www.rust-lang.org/)

Contract testing and regression safety for Model Context Protocol (MCP) servers. Catch breaking changes before they ship.

## The Problem

MCP servers expose tools that AI agents depend on. A schema change breaks every agent that depends on it — **silently**, with no build-time error or test failure. It surfaces later as a 500 error or refused tool call in production.

**Example:** Rename a required parameter from `limit` to `max_results`.
- Old agents call: `search(q="test", limit=10)` → ❌ fails
- No CI warning
- No regression test catches it
- Agents break in production

## The Solution

Tripwire treats MCP server contracts like REST APIs. Record a baseline, detect breaking changes in CI, fail PRs automatically.

Think of it as **Postman + Jest snapshots, but for MCP servers**.

## Quick Start

### Installation

**Via Cargo:**

```bash
cargo install trip-test
```

**Via Homebrew (coming soon):**

```bash
brew install trip-test
```

**From source:**

```bash
git clone https://github.com/arjav1528/trip-test
cd trip-test
cargo install --path .
```

### Basic Usage

**1. Connect to your server and list tools:**

```bash
trip-test connect --server "python -m my_mcp_server"
```

Output:
```
Connecting to: python -m my_mcp_server

Tools:
  - search (Search records)
    inputs: { q: string, limit: integer, }
  - fetch (Fetch a record)
    inputs: { id: string, }
```

**2. Record a baseline snapshot:**

```bash
trip-test record --server "python -m my_mcp_server" --out baseline.trip-test.json
```

Interactive prompts guide you to invoke a few tools. Captures tool schemas + responses.

**3. Check for regressions:**

```bash
trip-test check --snapshot baseline.trip-test.json --server "python -m my_mcp_server"
```

Replays recorded exchanges. Passes if behavior matches.

```
Results: 2 passed, 0 failed
```

**4. Detect breaking changes:**

```bash
trip-test diff --baseline baseline.trip-test.json --server "python -m my_mcp_server"
```

Compares contracts. Classifies changes.

```
🚨 BREAKING CHANGES:
  • search: Parameter 'limit' removed (was required: true)
  • search: Parameter 'max_results' added (required: true)

⚠️  NON-BREAKING CHANGES:
  • search: Description updated

Overall Verdict: BREAKING
```

## CLI Commands

### `connect`

List all tools and their schemas from a server.

```bash
trip-test connect --server "python -m my_server"
```

### `call`

Invoke a single tool and see the exchange.

```bash
trip-test call \
  --server "python -m my_server" \
  --tool search \
  --args '{"q":"acme","limit":10}'
```

Output:
```json
{
  "results": [...],
  "total": 42
}
```

### `record`

Interactively record tool calls into a snapshot file.

```bash
trip-test record --server "python -m my_server" --out baseline.trip-test.json
```

Prompts you to select tools and invoke them. Captures input + output. Saves to JSON.

### `check`

Replay a snapshot and verify the server still matches.

```bash
trip-test check --snapshot baseline.trip-test.json --server "python -m my_server"
```

Exit code: `0` if all pass, `1` if any fail.

### `diff`

Compare baseline contract vs live server. Classify changes.

```bash
trip-test diff --baseline baseline.trip-test.json --server "python -m my_server"
```

Output: BREAKING, NON-BREAKING, or ADDITIVE changes.

Exit code: `0` if safe, `1` if breaking.

### Global Flags

- `--verbose` or `-v` — Enable debug output
- `--help` or `-h` — Show usage
- `--version` — Print version
- `--config <file>` — Load settings from TOML file

## Configuration

### TOML Configuration File

Create `trip-test.toml` in your project root to avoid repeating flags:

```toml
[snapshot]
# Path to your baseline snapshot file (relative to repo root)
baseline = "contracts/baseline.trip-test.json"

[server]
# Command to start your MCP server
# Can be any command that spawns an MCP server:
#   - Python: "python -m my_package"
#   - Node.js: "node src/index.js"
#   - Rust: "./target/release/my-server"
#   - Docker: "docker run my-image"
command = "python -m my_mcp_server"

# Timeout for server operations (milliseconds)
timeout_ms = 5000

[diff]
# Whether to treat additive changes (new tools/params) as warnings
treat_additive_as_warning = false

# Whether to treat non-breaking changes (descriptions) as warnings
treat_non_breaking_as_warning = false
```

Then just run:

```bash
trip-test diff --config trip-test.toml
```

### Configuration Examples

**Python server with virtual environment:**

```toml
[server]
command = "python -m venv/bin/python -m my_server"
```

**Node.js server with npm script:**

```toml
[server]
command = "npm run start:mcp"
```

**Rust server (local development):**

```toml
[server]
command = "cargo run --release -- --stdio"
```

**Docker container:**

```toml
[server]
command = "docker run --rm my-mcp-server:latest"
```

**With environment variables:**

```toml
[server]
# Unix/Linux/Mac
command = "env RUST_LOG=debug ./target/release/server"

# Or use shell directly
command = "bash -c 'export RUST_LOG=debug && ./target/release/server'"
```

**Multiple servers (use separate config files):**

```bash
# test-server-v1.toml
trip-test diff --config test-server-v1.toml

# test-server-v2.toml
trip-test diff --config test-server-v2.toml
```

## Snapshot File Format

Snapshots are JSON files that capture a contract baseline.

```json
{
  "formatVersion": 1,
  "meta": {
    "name": "my-server-baseline",
    "recordedAt": "2026-08-09T12:00:00Z",
    "serverName": "my-server",
    "serverVersion": "1.0.0"
  },
  "toolCatalog": [
    {
      "name": "search",
      "description": "Search records",
      "inputSchema": {
        "type": "object",
        "properties": {
          "q": { "type": "string" },
          "limit": { "type": "integer" }
        },
        "required": ["q", "limit"]
      }
    }
  ],
  "exchanges": [
    {
      "id": "ex-001",
      "tool": "search",
      "input": { "q": "acme", "limit": 10 },
      "matchMode": "structural",
      "expected": {
        "isError": false,
        "content": [{ "type": "text", "text": "..." }]
      }
    }
  ]
}
```

Version-control this file. It's your regression baseline.

## CI/CD Integration

This section shows how to integrate trip-test into your existing CI/CD pipeline.

### GitHub Actions

#### Basic Setup

Create `.github/workflows/trip-test.yml` in any MCP server repository:

```yaml
name: Tripwire Contract Check

on:
  pull_request:
    paths:
      - 'src/**'
      - 'Cargo.toml'
      - '.github/workflows/trip-test.yml'
  push:
    branches: [main]

jobs:
  contract-check:
    name: Check MCP Contract
    runs-on: ubuntu-latest
    
    steps:
      # 1. Checkout code
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      # 2. Setup Rust (if building Rust server)
      - uses: dtolnay/rust-toolchain@stable
      - uses: swatinem/rust-cache@v2

      # 3. Build server
      - name: Build MCP server
        run: cargo build --release

      # 4. Install trip-test
      - name: Install trip-test
        run: cargo install trip-test

      # 5. Run contract check
      - name: Check contract
        id: check
        run: |
          trip-test diff \
            --baseline contracts/baseline.trip-test.json \
            --server "./target/release/my-server" \
            --format json > report.json || true
          cat report.json

      # 6. Comment on PR
      - name: Post PR comment
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const fs = require('fs');
            const report = JSON.parse(fs.readFileSync('report.json'));
            
            let comment = '## 🔍 Tripwire Contract Check\n\n';
            
            if (report.overall_verdict === 'BREAKING') {
              comment += '### ❌ **Breaking Changes Detected**\n\n';
              comment += 'The following breaking changes were found:\n\n';
              comment += '| Tool | Change | Details |\n';
              comment += '|------|--------|----------|\n';
              report.breaking_changes.forEach(c => {
                comment += `| \`${c.tool_name}\` | ${c.change_type} | ${c.details} |\n`;
              });
            } else {
              comment += '### ✅ **Contract is Safe**\n\n';
              comment += 'No breaking changes detected.\n\n';
            }
            
            if (report.non_breaking_changes.length > 0) {
              comment += '\n### ⚠️ Non-Breaking Changes\n\n';
              comment += '| Tool | Change | Details |\n';
              comment += '|------|--------|----------|\n';
              report.non_breaking_changes.forEach(c => {
                comment += `| \`${c.tool_name}\` | ${c.change_type} | ${c.details} |\n`;
              });
            }
            
            if (report.additive_changes.length > 0) {
              comment += '\n### ✨ Additive Changes\n\n';
              comment += '| Tool | Change | Details |\n';
              comment += '|------|--------|----------|\n';
              report.additive_changes.forEach(c => {
                comment += `| \`${c.tool_name}\` | ${c.change_type} | ${c.details} |\n`;
              });
            }
            
            comment += '\n---\n';
            comment += `**Verdict:** \`${report.overall_verdict}\`\n`;
            
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: comment
            });

      # 7. Fail if breaking changes
      - name: Enforce contract safety
        if: always()
        run: |
          if grep -q '"overall_verdict": "BREAKING"' report.json; then
            echo "❌ Breaking changes detected! PR check failed."
            exit 1
          fi
```

#### For Python Servers

```yaml
name: Tripwire Contract Check (Python)

on: [pull_request, push]

jobs:
  contract-check:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.11'
          cache: 'pip'
      
      - name: Install dependencies
        run: |
          pip install -e .
          pip install mcp
      
      - name: Install trip-test
        run: cargo install trip-test
      
      - name: Check contract
        run: |
          trip-test diff \
            --config trip-test.toml \
            --format json > report.json || true
      
      - name: Post result
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const report = JSON.parse(fs.readFileSync('report.json'));
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `## Tripwire Check\n\nVerdict: **${report.overall_verdict}**`
            });
      
      - name: Enforce safety
        run: |
          if grep -q '"overall_verdict": "BREAKING"' report.json; then
            exit 1
          fi
```

#### For Node.js Servers

```yaml
name: Tripwire Contract Check (Node.js)

on: [pull_request, push]

jobs:
  contract-check:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Node
        uses: actions/setup-node@v3
        with:
          node-version: '18'
          cache: 'npm'
      
      - name: Install dependencies
        run: npm ci
      
      - name: Build
        run: npm run build
      
      - name: Install trip-test
        run: cargo install trip-test
      
      - name: Check contract
        run: |
          trip-test diff \
            --config trip-test.toml \
            --format json > report.json || true
      
      - name: Post result
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const report = JSON.parse(fs.readFileSync('report.json'));
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `## Tripwire Check\n\nVerdict: **${report.overall_verdict}**`
            });
      
      - name: Enforce safety
        run: |
          if grep -q '"overall_verdict": "BREAKING"' report.json; then
            exit 1
          fi
```

### GitLab CI

```yaml
contract-check:
  image: rust:latest
  
  before_script:
    - apt-get update && apt-get install -y python3
    - cargo install trip-test
  
  script:
    # Build your server (adjust for your build system)
    - cargo build --release
    
    # Run contract check
    - trip-test diff --config trip-test.toml --format json > report.json || true
    
    # Check for breaking changes
    - |
      if grep -q '"overall_verdict": "BREAKING"' report.json; then
        echo "❌ Breaking changes detected!"
        cat report.json
        exit 1
      else
        echo "✅ Contract is safe"
      fi
  
  artifacts:
    paths:
      - report.json
    expire_in: 30 days
```

### Generic CI (Jenkins, CircleCI, etc.)

The core pattern is:

```bash
# 1. Build server
<your-build-command>

# 2. Install trip-test (if not cached)
cargo install trip-test

# 3. Run check
trip-test diff --config trip-test.toml --format json > report.json || true

# 4. Parse report
if grep -q '"overall_verdict": "BREAKING"' report.json; then
  echo "❌ Contract violation!"
  cat report.json
  exit 1
fi

# 5. Optional: upload report
<your-artifact-upload>
```

### Integration Checklist

When adding trip-test to an existing MCP server:

- [ ] Create `trip-test.toml` with correct server command
- [ ] Create `contracts/` directory
- [ ] Record baseline: `trip-test record --server "..." --out contracts/baseline.trip-test.json`
- [ ] Commit `contracts/baseline.trip-test.json` and `trip-test.toml`
- [ ] Add CI workflow (GitHub Actions / GitLab CI / etc.)
- [ ] Test locally: `trip-test diff --config trip-test.toml`
- [ ] Open a test PR with intentional breaking change
- [ ] Verify CI fails and posts comment
- [ ] Revert test change
- [ ] Merge and ship ✅

### Example: Adding Tripwire to Existing Showpad MCP Server

```bash
# 1. Clone server
git clone https://github.com/showpad/mcp-showql
cd mcp-showql

# 2. Install trip-test
cargo install trip-test

# 3. Create config
cat > trip-test.toml << 'EOF'
[snapshot]
baseline = "contracts/baseline.trip-test.json"

[server]
command = "cargo run --release -- --stdio"
timeout_ms = 5000
EOF

# 4. Create contracts directory
mkdir -p contracts

# 5. Record baseline (interactively)
trip-test record --server "cargo run --release -- --stdio" --out contracts/baseline.trip-test.json

# 6. Verify
trip-test diff --config trip-test.toml

# 7. Commit
git add trip-test.toml contracts/baseline.trip-test.json
git commit -m "chore: add MCP contract testing with trip-test"

# 8. Add GitHub Actions
cat > .github/workflows/contract-check.yml << 'EOF'
name: Tripwire Contract Check
on: [pull_request]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo install trip-test
      - run: trip-test diff --config trip-test.toml --format json > report.json || true
      - run: |
          if grep -q '"overall_verdict": "BREAKING"' report.json; then
            exit 1
          fi
EOF

# 9. Push and open PR
git push origin add-trip-test
```

### Troubleshooting CI Integration

**CI fails to build server:**
- Check that build command in `trip-test.toml` works locally
- Ensure all build dependencies are in CI environment
- For Python: verify venv/dependencies
- For Node.js: verify npm install runs
- For Rust: verify Cargo.toml exists

**CI fails to install trip-test:**
- Add `rustup` if not present: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`
- Or pre-build trip-test as a cached artifact
- Or use: `pip install trip-test` (if available)

**Report not found:**
- Check that server command in config works
- Verify baseline snapshot exists: `contracts/baseline.trip-test.json`
- Run locally first: `trip-test diff --config trip-test.toml`

**PR comment not posting:**
- Ensure GitHub token has `issues:write` permission
- Check that issue/PR number is correct
- Verify repository is not private (or token has private repo access)

## Testing Your MCP Server

### Complete Testing Workflow

This section walks you through a complete testing setup from scratch.

#### Step 1: Installation

```bash
# Clone your MCP server repository
git clone https://github.com/your-org/my-mcp-server
cd my-mcp-server

# Install trip-test
cargo install trip-test

# Or, if you have Homebrew:
brew install trip-test
```

#### Step 2: Create Project Structure

```bash
# Create a contracts directory for snapshots
mkdir -p contracts

# Create initial trip-test config
cat > trip-test.toml << 'EOF'
[snapshot]
baseline = "contracts/baseline.trip-test.json"

[server]
command = "python -m my_mcp_server"
timeout_ms = 5000

[diff]
treat_additive_as_warning = false
treat_non_breaking_as_warning = false
EOF
```

#### Step 3: Test Server Connection

Verify your server works:

```bash
# List all tools exposed by your server
trip-test connect --server "python -m my_mcp_server"
```

Expected output:
```
Connecting to: python -m my_mcp_server

Tools:
  - search (Search records)
    inputs: { q: string, limit: integer, }
  - fetch (Fetch a record by ID)
    inputs: { id: string, }
  - create (Create a new record)
    inputs: { title: string, content: string, }
```

If this fails, check:
- Is your server command correct? (Try running it manually)
- Does your server implement the MCP `initialize` handshake?
- Are tools properly advertised with `inputSchema`?

#### Step 4: Test Individual Tool Calls

Before recording, test each tool manually:

```bash
# Test the search tool
trip-test call \
  --server "python -m my_mcp_server" \
  --tool search \
  --args '{"q":"acme","limit":10}'

# Test the fetch tool
trip-test call \
  --server "python -m my_mcp_server" \
  --tool fetch \
  --args '{"id":"123"}'
```

This verifies:
- Tools are callable
- Arguments are accepted
- Responses are valid JSON
- No runtime errors

#### Step 5: Record Baseline Snapshot

Once individual tools work, record the baseline:

```bash
# Interactively record exchanges
trip-test record --server "python -m my_mcp_server" --out contracts/baseline.trip-test.json
```

The tool will:
1. Connect to your server
2. List all tools
3. Prompt you to select tools to test
4. Ask for input arguments for each
5. Record the request and response
6. Save everything to `baseline.trip-test.json`

Example session:
```
Connected to: python -m my_mcp_server
Tools available:
 1. search (Search records)
 2. fetch (Fetch a record by ID)

Enter tool number to record (or 0 to finish): 1
Enter arguments as JSON: {"q":"test","limit":5}
Calling search...
Result: {"results":[...],"total":42}
✓ Exchange recorded!

Enter tool number to record (or 0 to finish): 2
Enter arguments as JSON: {"id":"123"}
Calling fetch...
Result: {"id":"123","title":"...","content":"..."}
✓ Exchange recorded!

Enter tool number to record (or 0 to finish): 0
Snapshot saved to: contracts/baseline.trip-test.json
```

#### Step 6: Inspect the Snapshot

View what was recorded:

```bash
# Pretty-print the snapshot
cat contracts/baseline.trip-test.json | jq .

# Or use your editor
code contracts/baseline.trip-test.json
```

The snapshot captures:
- Tool schemas (names, descriptions, input parameters)
- Recorded exchanges (what you called, what you got back)
- Metadata (when recorded, server version)

#### Step 7: Commit Baseline

Lock in your contract:

```bash
git add contracts/baseline.trip-test.json trip-test.toml
git commit -m "baseline: record MCP contract v1.0"
git push
```

### Testing Workflow Scenarios

#### Scenario 1: Developer Makes Safe Change

```bash
# Developer adds an optional parameter (safe)
# Edits server code and rebuilds
python -m build

# Run contract check
trip-test check --config trip-test.toml

# Output:
# Replaying ex-001: search
#   Input: {"q": "test", "limit": 5}
#   ✓ PASS
#
# Results: 1 passed, 0 failed
```

**CI will pass** ✅

#### Scenario 2: Developer Makes Breaking Change

```bash
# Developer renames a required parameter
# Before: search(q, limit)
# After: search(q, max_results)

# Developer commits and opens PR
git commit -m "api: rename limit → max_results"
git push origin feature-branch

# CI automatically runs
trip-test diff --config trip-test.toml

# Output:
# 🚨 BREAKING CHANGES:
#   • search: Parameter 'limit' removed (was required: true)
#   • search: Parameter 'max_results' added (required: true)
#
# Overall Verdict: BREAKING
```

**CI will fail** ❌ and **block the PR**

**Resolution options:**

Option A: Fix the breaking change
```bash
# Revert to old parameter name
git revert HEAD
git push

# CI passes on new commit
```

Option B: Intentionally break the contract
```bash
# Update baseline to reflect new contract
trip-test record --server "python -m my_mcp_server" --out contracts/baseline.trip-test.json

# Commit the new baseline
git add contracts/baseline.trip-test.json
git commit -m "api: rename limit → max_results (breaking change)"

# New baseline is now locked in
# Future PRs will compare against this
```

#### Scenario 3: Detect Non-Breaking Change

```bash
# Developer improves tool descriptions
# Before: "Search records"
# After: "Search records by query (case-insensitive)"

trip-test diff --config trip-test.toml

# Output:
# ⚠️  NON-BREAKING CHANGES:
#   • search: Description changed
#
# Overall Verdict: SAFE (no breaking changes)
```

**CI will pass** ✅

### Real Server Examples

#### Python MCP Server (with venv)

```bash
# Create venv
python -m venv venv
source venv/bin/activate
pip install mcp

# Test connection
trip-test connect --server "python -m my_mcp_server"

# Config file
cat > trip-test.toml << 'EOF'
[server]
command = "python -m my_mcp_server"
EOF
```

#### Node.js MCP Server

```bash
# Install dependencies
npm install

# Build if needed
npm run build

# Test connection
trip-test connect --server "node dist/index.js"

# Config file
cat > trip-test.toml << 'EOF'
[server]
command = "node dist/index.js"
EOF
```

#### Rust MCP Server

```bash
# Build in release mode for performance
cargo build --release

# Test connection
trip-test connect --server "./target/release/my-server"

# Config file with proper invocation
cat > trip-test.toml << 'EOF'
[server]
command = "./target/release/my-server --stdio"
EOF
```

#### Docker Container

```bash
# Build your MCP server image
docker build -t my-mcp-server .

# Test connection
trip-test connect --server "docker run --rm my-mcp-server"

# Config file
cat > trip-test.toml << 'EOF'
[server]
command = "docker run --rm my-mcp-server"
EOF
```

#### Testing Multiple Versions

Keep separate configs for different versions:

```bash
# test-v1.toml
cat > test-v1.toml << 'EOF'
[snapshot]
baseline = "contracts/baseline-v1.trip-test.json"

[server]
command = "git checkout v1.0.0 && cargo build --release && ./target/release/server"
EOF

# test-v2.toml
cat > test-v2.toml << 'EOF'
[snapshot]
baseline = "contracts/baseline-v2.trip-test.json"

[server]
command = "git checkout main && cargo build --release && ./target/release/server"
EOF

# Test both
trip-test diff --config test-v1.toml
trip-test diff --config test-v2.toml
```

### Testing Against Example Servers

Tripwire ships with example MCP servers for learning:

```bash
# Clone trip-test
git clone https://github.com/arjav1528/trip-test
cd trip-test

# Build example servers
cargo build --examples

# Test against basic example
trip-test connect --server "./target/debug/examples/test-server"

# Record baseline from example
trip-test record \
  --server "./target/debug/examples/test-server" \
  --out example-baseline.trip-test.json

# Test against modified example
trip-test diff \
  --baseline example-baseline.trip-test.json \
  --server "./target/debug/examples/test-server-modified"

# Expected output: BREAKING changes detected ❌
```

## How It Works

### Architecture

```
┌──────────────────┐
│   Your CLI       │
│  (trip-test)      │
└────────┬─────────┘
         │ JSON-RPC (stdio)
┌────────▼─────────┐
│  Your MCP Server │
│  (any language)  │
└──────────────────┘
```

1. **Connect**: Spawn your MCP server as a subprocess
2. **Handshake**: Perform MCP `initialize` protocol
3. **List**: Fetch all tools + input schemas
4. **Call**: Invoke tools with your args
5. **Record**: Save exchanges to snapshot JSON
6. **Diff**: Compare baseline schema vs live schema
7. **Classify**: Mark each change as breaking/non-breaking/additive

### Change Classification Rules

| Change | Class | Example |
|---|---|---|
| Tool removed | **BREAKING** | `search` tool deleted |
| Tool added | **ADDITIVE** | New `fetch` tool added |
| Required param removed | **BREAKING** | `limit` param removed |
| Required param added | **BREAKING** | New required `max_results` |
| Optional param added | **ADDITIVE** | Optional `sort` param added |
| Type narrowed | **BREAKING** | `string``enum` |
| Type widened | **NON-BREAKING** | `enum``string` |
| Enum value removed | **BREAKING** | Removed option "asc" |
| Enum value added | **NON-BREAKING** | Added option "desc" |
| Description changed | **NON-BREAKING** | Help text updated |

## Output Formats

### Pretty (default)

```bash
trip-test diff --baseline baseline.trip-test.json --server "python -m my_server"
```

Human-readable terminal output with colors.

### JSON (for CI)

```bash
trip-test diff --baseline baseline.trip-test.json --server "python -m my_server" --format json
```

Machine-readable JSON:

```json
{
  "overall_verdict": "BREAKING",
  "breaking_changes": [
    {
      "tool_name": "search",
      "change_type": "Parameter removed",
      "details": "Parameter 'limit' was removed (was required: true)",
      "class": "BREAKING"
    }
  ],
  "non_breaking_changes": [...],
  "additive_changes": [...]
}
```

## Limitations & Known Issues

**MVP Scope (current):**
- Supports **stdio transport only** (spawn subprocess)
- Flat + one level of nested schema changes (handles most cases)
- No `$ref` resolution (document workaround)
- No credential management (pass headers via `--header` flag planned)
- No output schema validation (input schemas only)

**Planned (Phase 2+):**
- HTTP transport (remote servers)
- Web UI (interactive tool browser)
- Watch mode (alert on drift)
- Snapshot registry (share baselines)
- Test generation (auto-generate snapshots from schemas)

## Contributing

We welcome contributions! See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.

### Local Development

```bash
# Clone repo
git clone https://github.com/arjav1528/trip-test
cd trip-test

# Build
cargo build

# Test against example server
cargo build --example test-server
cargo run -- connect --server "./target/debug/examples/test-server"

# Run tests
cargo test

# Lint
cargo clippy

# Format
cargo fmt
```

### Project Structure

```
trip-test/
├── src/
│   ├── main.rs           # CLI entry point
│   ├── lib.rs            # Public API
│   ├── mcp.rs            # MCP protocol client
│   ├── snapshot.rs       # Snapshot file format
│   ├── diff.rs           # Diff engine & classification
│   ├── config.rs         # TOML configuration
│   └── logger.rs         # Logging utilities
├── examples/
│   ├── test-server.rs    # Dummy MCP server for testing
│   └── test-server-modified.rs
├── .github/workflows/
│   └── trip-test.yml      # CI workflow
├── Cargo.toml
├── LICENSE
└── README.md
```

## License

MIT License — see [LICENSE](./LICENSE) for details.

## Acknowledgments

Inspired by:
- [Postman]https://www.postman.com/ — API testing
- [Jest snapshots]https://jestjs.io/docs/snapshot-testing — regression detection
- [OpenAPI/Swagger]https://swagger.io/ — schema-first design

## Support

- **GitHub Issues**: [Report bugs or request features]https://github.com/arjav1528/trip-test/issues
- **Discussions**: [Ask questions]https://github.com/arjav1528/trip-test/discussions
- **Documentation**: [Full docs]https://docs.rs/trip-test

## Roadmap

- [x] Core MVP (snapshot + diff + CI)
- [x] GitHub Actions integration
- [x] JSON output for CI/CD
- [x] Configuration file support
- [x] Published on crates.io
- [ ] HTTP transport support
- [ ] Web UI dashboard
- [ ] Watch mode & alerts
- [ ] Snapshot registry
- [ ] Test generation

---

**Made with ❤️ for MCP developers**

Questions? Open an [issue](https://github.com/arjav1528/trip-test/issues) or [discussion](https://github.com/arjav1528/trip-test/discussions).