pmcp 2.17.0

High-quality Rust SDK for Model Context Protocol (MCP) with full TypeScript SDK compatibility
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
name: CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1
  # Override .cargo/config.toml target-cpu=native to avoid SIGILL on CI runners
  RUSTFLAGS: ""
  # Pin matches .github/workflows/quality-badges.yml so badge and gate stay aligned (Phase 75 D-09).
  PMAT_VERSION: "3.15.0"

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v7

    - name: Free Disk Space
      uses: jlumbroso/free-disk-space@main
      with:
        # Remove large packages we don't need
        tool-cache: false
        android: true
        dotnet: true
        haskell: true
        large-packages: true
        docker-images: true
        swap-storage: true

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        components: rustfmt, clippy, llvm-tools-preview
    
    - name: Cache cargo
      uses: actions/cache@v6
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          target/
        key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
    
    - name: Install cargo-llvm-cov
      run: |
        if ! command -v cargo-llvm-cov &> /dev/null; then
          cargo install cargo-llvm-cov
        fi
    
    - name: Format check
      run: cargo fmt --all -- --check
    
    - name: Clippy
      run: |
        cargo clippy --all-targets --all-features -- \
          -D warnings \
          -A clippy::module_name_repetitions \
          -A clippy::must_use_candidate \
          -A clippy::missing_errors_doc \
          -A clippy::missing_const_for_fn \
          -A clippy::return_self_not_must_use \
          -A clippy::missing_fields_in_debug \
          -A clippy::uninlined_format_args \
          -A clippy::if_not_else \
          -A clippy::result_large_err \
          -A clippy::multiple_crate_versions \
          -A clippy::implicit_hasher \
          -A clippy::unused_async \
          -A clippy::cast_lossless \
          -A clippy::redundant_clone \
          -A clippy::redundant_closure_for_method_calls \
          -A clippy::significant_drop_tightening \
          -A clippy::missing_panics_doc \
          -A clippy::cast_possible_truncation \
          -A clippy::cast_precision_loss \
          -A clippy::option_if_let_else \
          -A clippy::derive_partial_eq_without_eq \
          -A clippy::redundant_else \
          -A clippy::match_same_arms
    
    - name: Build
      run: cargo build --all-features --verbose
    
    - name: Run tests
      run: cargo test --all-features --verbose -- --test-threads=1

    # NOTE: pmcp-package (workspace-EXCLUDED, own [workspace] table) is gated in
    # the `quality-gate` job via `make quality-gate` -> `pmcp-package-gate`
    # (fmt/clippy/test --manifest-path), which is the single source of truth and
    # is reused by the local `make quality-gate`. It is intentionally NOT
    # re-run here to avoid a duplicate from-scratch compile of the crate's tree.

    - name: Run doctests
      run: cargo test --doc --all-features --verbose
    
    - name: Check examples
      run: |
        # Build every registered example with its declared required-features.
        # Reading required-features from cargo metadata keeps this in sync with
        # Cargo.toml automatically, so future renames or feature changes don't
        # require workflow edits.
        cargo metadata --no-deps --format-version 1 \
          | python3 -c '
        import json, sys
        meta = json.load(sys.stdin)
        pkg = next(p for p in meta["packages"] if p["name"] == "pmcp")
        for t in pkg["targets"]:
            if "example" in t["kind"]:
                feats = ",".join(t.get("required-features") or [])
                print(f"{t[\"name\"]}|{feats}")
        ' | while IFS='|' read -r name feats; do
            if [[ -n "$feats" ]]; then
              echo "Checking example: $name (features: $feats)"
              cargo check --example "$name" --features "$feats"
            else
              echo "Checking example: $name (no required features)"
              cargo check --example "$name" --features http
            fi
          done

    - name: Clean up before coverage
      run: |
        echo "Disk usage before cleanup:"
        df -h
        echo "Cleaning cargo build artifacts..."
        cargo clean
        echo "Disk usage after cleanup:"
        df -h

    - name: Run coverage
      run: cargo llvm-cov --all-features --lcov --output-path lcov.info

  feature-flags:
    name: Feature Flag Verification
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v7

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        components: clippy

    - name: Cache cargo
      uses: actions/cache@v6
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          target/
        key: ${{ runner.os }}-cargo-feature-flags-${{ hashFiles('**/Cargo.lock') }}

    - name: Verify feature flag combinations
      run: make test-feature-flags

  quality-gate:
    name: Quality Gate
    runs-on: ubuntu-latest
    # Phase 75 Wave 5 / D-07: when adding PMAT here, pin via `cargo install pmat --version =3.15.0 --locked`
    # The pin matches .github/workflows/quality-badges.yml so badge and gate
    # semantics stay aligned. See .planning/phases/75-fix-pmat-issues/
    # 75-W0-SPIKE-RESULTS.md for the empirical justification (D-09).
    steps:
    - uses: actions/checkout@v7

    - name: Free Disk Space
      uses: jlumbroso/free-disk-space@main
      with:
        # Remove large packages we don't need
        tool-cache: false
        android: true
        dotnet: true
        haskell: true
        large-packages: true
        docker-images: true
        swap-storage: true

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        components: rustfmt, clippy
    
    - name: Cache cargo
      uses: actions/cache@v6
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
        key: ${{ runner.os }}-cargo-quality-${{ hashFiles('**/Cargo.lock') }}

    - name: Install quality tools
      run: |
        if ! command -v cargo-llvm-cov &> /dev/null; then
          cargo install cargo-llvm-cov
        fi
        if ! command -v cargo-nextest &> /dev/null; then
          # Why: cargo-nextest 0.9.133+ embeds a `locked-tripwire` build-time
          # compile_error! that aborts unless `--locked` is passed. Without
          # this flag CI fails with "Nextest does not support being installed
          # without --locked." See https://nexte.st/docs/installation/from-source/
          cargo install --locked cargo-nextest
        fi
        # Force install latest cargo-audit to support CVSS 4.0
        cargo install cargo-audit --force

    - name: Install cargo-deny (make quality-gate chains purity-check, which needs it)
      uses: taiki-e/install-action@v2
      with:
        # Pinned: the Makefile purity-check Layer 2 invocation uses cargo-deny
        # 0.18.3's CLI ordering (`check --config deny.toml bans`). Newer cargo-deny
        # moved `--config` to a global flag (before `check`) and rejects the old
        # form with a usage error, silently breaking the gate. Pin like PMAT_VERSION.
        tool: cargo-deny@0.18.3

    - name: Check disk space before quality gate
      run: df -h

    - name: Check rustdoc zero-warnings
      run: make doc-check

    - name: Run quality gate
      run: make quality-gate

    - name: Install PMAT (cache-aware; reused across runs via ~/.cargo/bin)
      run: |
        if ! command -v pmat &>/dev/null || ! pmat --version | grep -qE "^pmat ${PMAT_VERSION}$"; then
          cargo install pmat --version "=${PMAT_VERSION}" --locked
        fi

    - name: Run PMAT quality gate (complexity only — see CONTEXT.md D-01 / D-11-B)
      run: pmat quality-gate --fail-on-violation --checks complexity

    # Phase 109 Plan 08 (D-18): contract-first compliance for the team-servers
    # bindings. `comply-ci` is FAIL-CLOSED (no `command -v pmat` guard) so a CI
    # without pmat fails rather than passing vacuously; it runs the mandated
    # `pmat comply check --path .` report and makes team-servers binding drift
    # gate-blocking via a deterministic source-resolution check. Runs here AFTER
    # PMAT is installed. `comply-negative` proves a broken binding is rejected.
    - name: Run team-servers contract compliance (fail-closed)
      run: make comply-ci

    - name: Assert broken-binding rejection (negative compliance test)
      run: make comply-negative

    - name: Check disk space after quality gate
      run: df -h

  benchmarks:
    name: Benchmarks
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v7
    
    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
    
    - name: Cache cargo
      uses: actions/cache@v6
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          target/
        key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
    
    - name: Run benchmarks
      run: cargo bench --all-features --no-run

  msrv:
    name: Minimum Supported Rust Version (1.91)
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v7

    - name: Install Rust 1.91
      uses: dtolnay/rust-toolchain@1.91
    
    - name: Cache cargo
      uses: actions/cache@v6
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          target/
        key: ${{ runner.os }}-cargo-msrv-${{ hashFiles('**/Cargo.lock') }}
    
    - name: Check MSRV
      run: cargo check --all-features

  # Phase 91 (WBRT-04) purity gate — fail-closed, per-crate, per-feature.
  # Proves the Excel reader (umya/quick-xml/calamine) and the JS stack
  # (swc_*/pmcp-code-mode) can never enter the reader-free served trees.
  # `make purity-check` already loops crate × feature, fails closed, and runs the
  # crate-local cargo-deny [bans] (Layer 2) — so cargo-deny must be installed here.
  purity-check:
    name: Purity Gate
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v7

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable

    - name: Cache cargo
      uses: actions/cache@v6
      with:
        # No ~/.cargo/bin/ here — taiki-e/install-action fetches a prebuilt
        # cargo-deny in seconds and caches it itself; restore-keys keeps the
        # registry warm across Cargo.lock bumps.
        path: |
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
        key: ${{ runner.os }}-cargo-purity-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |
          ${{ runner.os }}-cargo-purity-

    - name: Install cargo-deny (Layer 2 backstop)
      uses: taiki-e/install-action@v2
      with:
        # Pinned to match the Makefile purity-check Layer 2 CLI form (see the
        # quality-gate job's install step for the full rationale). Newer cargo-deny
        # relocated `--config` and breaks `check --config deny.toml bans`.
        tool: cargo-deny@0.18.3

    - name: Run purity gate (per-crate, per-feature, fail-closed; Layers 1+2)
      run: make purity-check

  # Phase 108 (D-13) pmcp-agent target matrix. Two independent guarantees:
  #  1. The LOOP + SEAMS + config path compiles for wasm32 under DEFAULT features
  #     (no url-connector/reqwest/StreamableHttpTransport). The agent-as-server
  #     adapter + SamplingSource are native-only (they ride native-only pmcp APIs)
  #     and are `cfg`-excluded on wasm32, so this gate proves target-cleanliness of
  #     the loop/seam path, NOT adapter-on-wasm.
  #  2. The feature-gated HTTP sources (openai-compat/anthropic) AND the native-only
  #     UrlConnectorClientFactory (url-connector) compile on native.
  pmcp-agent-targets:
    name: pmcp-agent target matrix (wasm32 default + native features)
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v7

    - name: Install Rust (+ wasm32 target)
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: wasm32-unknown-unknown

    - name: Cache cargo
      uses: actions/cache@v6
      with:
        path: |
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          target/
        key: ${{ runner.os }}-cargo-pmcp-agent-targets-${{ hashFiles('**/Cargo.lock') }}

    - name: Build pmcp-agent for wasm32 (DEFAULT features — loop + seams + config)
      run: |
        rustup target add wasm32-unknown-unknown
        cargo build -p pmcp-agent --target wasm32-unknown-unknown

    - name: Build pmcp-agent native (HTTP sources + URL connector)
      run: cargo build -p pmcp-agent --features openai-compat,anthropic,url-connector

  # Unified gate — single required check for org ruleset.
  # Reports as "gate" to match the org ruleset's required status check.
  gate:
    runs-on: ubuntu-latest
    needs: [test, quality-gate, purity-check, pmcp-agent-targets]
    if: always()
    steps:
      - name: Evaluate required checks
        env:
          TEST_RESULT: ${{ needs.test.result }}
          QG_RESULT: ${{ needs.quality-gate.result }}
          PURITY_RESULT: ${{ needs.purity-check.result }}
          AGENT_TARGETS_RESULT: ${{ needs.pmcp-agent-targets.result }}
        run: |
          if [[ "$TEST_RESULT" != "success" ]] || \
             [[ "$QG_RESULT" != "success" ]] || \
             [[ "$PURITY_RESULT" != "success" ]] || \
             [[ "$AGENT_TARGETS_RESULT" != "success" ]]; then
            echo "Required checks failed: test=$TEST_RESULT, quality-gate=$QG_RESULT, purity-check=$PURITY_RESULT, pmcp-agent-targets=$AGENT_TARGETS_RESULT"
            exit 1
          fi
          echo "All required checks passed."