mcp-cpp-server 0.2.2

A high-performance Model Context Protocol (MCP) server for C++ code analysis using clangd LSP integration
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
name: Release

on:
  push:
    tags:
      - "v*" # Trigger on version tags like v0.1.0, v1.0.0, etc.

permissions:
  contents: write # Required for creating releases
  packages: write # Required for publishing packages

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  # Comprehensive checks for release - run in parallel where possible
  rust-checks:
    name: Rust Comprehensive Checks
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.version.outputs.version }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

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

      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-rust-checks-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-rust-checks-cargo-registry-
            ${{ runner.os }}-cargo-registry-

      - name: Cache cargo build
        uses: actions/cache@v4
        with:
          path: target
          key: ${{ runner.os }}-rust-checks-cargo-build-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-rust-checks-cargo-build-
            ${{ runner.os }}-cargo-build-

      - name: Check formatting
        run: cargo fmt --all -- --check

      - name: Run clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Run unit tests
        run: cargo test --verbose

      - name: Build debug
        run: cargo build --verbose

      - name: Build release
        run: cargo build --release --verbose

      - name: Verify package can be built
        run: cargo package --no-verify

      - name: Run security audit
        run: |
          cargo install cargo-audit || true
          cargo audit

      - name: Extract version
        id: version
        run: |
          CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
          echo "version=$CARGO_VERSION" >> $GITHUB_OUTPUT
          echo "Extracted version: $CARGO_VERSION"

      - name: Cache release binary
        uses: actions/cache@v4
        with:
          path: target/release/mcp-cpp-server
          key: ${{ runner.os }}-release-binary-${{ hashFiles('**/Cargo.lock') }}-${{ github.sha }}

  # Cross-platform binary builds
  build-binaries:
    name: Build Cross-Platform Binaries
    needs: [rust-checks]
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            binary: mcp-cpp-server
            name: mcp-cpp-server-linux-x86_64
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            binary: mcp-cpp-server
            name: mcp-cpp-server-linux-aarch64
          - target: x86_64-apple-darwin
            os: macos-latest
            binary: mcp-cpp-server
            name: mcp-cpp-server-macos-x86_64
          - target: aarch64-apple-darwin
            os: macos-latest
            binary: mcp-cpp-server
            name: mcp-cpp-server-macos-aarch64
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Install cross-compilation tools
        run: |
          case "${{ matrix.target }}" in
            "aarch64-unknown-linux-gnu")
              sudo apt-get update
              sudo apt-get install -y gcc-aarch64-linux-gnu
              echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
              ;;
            "x86_64-apple-darwin"|"aarch64-apple-darwin")
              # macOS builds run on macos-latest with universal support
              echo "Native macOS build"
              ;;
            "x86_64-unknown-linux-gnu")
              # Native Linux build
              echo "Native Linux build"
              ;;
            *)
              echo "Unknown target: ${{ matrix.target }}"
              exit 1
              ;;
          esac

      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-${{ matrix.target }}-build-binaries-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.target }}-build-binaries-cargo-registry-
            ${{ runner.os }}-cargo-registry-

      - name: Cache cargo build
        uses: actions/cache@v4
        with:
          path: target
          key: ${{ runner.os }}-${{ matrix.target }}-build-binaries-cargo-build-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.target }}-build-binaries-cargo-build-
            ${{ runner.os }}-cargo-build-

      - name: Build binary
        run: cargo build --release --target ${{ matrix.target }}

      - name: Verify binary exists
        run: |
          if [ ! -f "target/${{ matrix.target }}/release/${{ matrix.binary }}" ]; then
            echo "Error: Binary not found after build"
            echo "Expected: target/${{ matrix.target }}/release/${{ matrix.binary }}"
            echo "Contents of target/${{ matrix.target }}/release/:"
            ls -la target/${{ matrix.target }}/release/ || echo "Directory does not exist"
            exit 1
          fi
          echo "Binary verified: target/${{ matrix.target }}/release/${{ matrix.binary }}"
          ls -la target/${{ matrix.target }}/release/${{ matrix.binary }}

      - name: Rename binary
        shell: bash
        run: |
          mkdir -p dist
          cp target/${{ matrix.target }}/release/${{ matrix.binary }} dist/${{ matrix.name }}

      - name: Verify renamed binary
        run: |
          if [ ! -f "dist/${{ matrix.name }}" ]; then
            echo "Error: Renamed binary not found"
            echo "Expected: dist/${{ matrix.name }}"
            echo "Contents of dist/:"
            ls -la dist/ || echo "Directory does not exist"
            exit 1
          fi
          echo "Renamed binary verified: dist/${{ matrix.name }}"
          ls -la dist/${{ matrix.name }}

      - name: Upload binary artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.name }}
          path: dist/${{ matrix.name }}
          retention-days: 1

  cpp-checks:
    name: C++ Build Check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y build-essential cmake

      - name: Cache CMake build
        uses: actions/cache@v4
        with:
          path: test/test-project/build
          key: ${{ runner.os }}-release-cmake-${{ hashFiles('test/test-project/CMakeLists.txt', 'test/test-project/**/*.cpp', 'test/test-project/**/*.h') }}
          restore-keys: |
            ${{ runner.os }}-release-cmake-
            ${{ runner.os }}-cmake-

      - name: Configure CMake
        working-directory: test/test-project
        run: cmake -B build -S .

      - name: Build C++ test project
        working-directory: test/test-project
        run: cmake --build build

  ts-checks:
    name: TypeScript Comprehensive Checks
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "18"
          cache: "npm"
          cache-dependency-path: test/e2e/package-lock.json

      - name: Install dependencies
        working-directory: test/e2e
        run: npm ci

      - name: Check formatting
        working-directory: test/e2e
        run: npm run format:check

      - name: Run linting
        working-directory: test/e2e
        run: npm run lint

      - name: Run TypeScript framework tests
        working-directory: test/e2e
        run: npm run test:framework

  # E2E Integration Tests - depends on all other checks
  e2e-integration:
    name: E2E Integration Tests
    runs-on: ubuntu-latest
    needs: [rust-checks, cpp-checks, ts-checks]
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "18"
          cache: "npm"
          cache-dependency-path: test/e2e/package-lock.json

      - name: Install C++ dependencies
        run: |
          sudo apt-get update
          # Get Ubuntu codename dynamically
          UBUNTU_CODENAME=$(lsb_release -cs)
          echo "Detected Ubuntu codename: $UBUNTU_CODENAME"
          # Add LLVM repository using modern method
          curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/llvm-archive-keyring.gpg
          echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-20 main" | sudo tee /etc/apt/sources.list.d/llvm.list
          sudo apt-get update
          sudo apt-get install -y build-essential cmake clangd-20

      - name: Verify clangd installation
        run: |
          if ! command -v clangd-20 &> /dev/null; then
            echo "Error: clangd-20 not found in PATH"
            exit 1
          fi
          echo "clangd-20 version:"
          clangd-20 --version
          echo "clangd-20 path: $(which clangd-20)"

      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-e2e-integration-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-e2e-integration-cargo-registry-
            ${{ runner.os }}-cargo-registry-

      - name: Restore release binary
        uses: actions/cache@v4
        with:
          path: target/release/mcp-cpp-server
          key: ${{ runner.os }}-release-binary-${{ hashFiles('**/Cargo.lock') }}-${{ github.sha }}

      - name: Build if binary not cached
        run: |
          if [ ! -f target/release/mcp-cpp-server ]; then
            echo "Binary not found in cache, building..."
            cargo build --release
          else
            echo "Using cached binary"
          fi

      - name: Build C++ test project
        working-directory: test/test-project
        run: |
          cmake -B build -S .
          cmake --build build
        env:
          CLANGD_PATH: /usr/bin/clangd-20

      - name: Install E2E test dependencies
        working-directory: test/e2e
        run: npm ci

      - name: Run E2E integration tests
        working-directory: test/e2e
        run: npm run test:e2e
        env:
          MCP_SERVER_PATH: ../../target/release/mcp-cpp-server
          TEST_PROJECT_PATH: ../test-project
          CLANGD_PATH: /usr/bin/clangd-20

  # Version verification
  version-check:
    name: Version Verification
    runs-on: ubuntu-latest
    needs: rust-checks
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Verify tag matches Cargo.toml version
        run: |
          CARGO_VERSION="${{ needs.rust-checks.outputs.version }}"
          TAG_VERSION=${GITHUB_REF#refs/tags/v}
          echo "Cargo.toml version: $CARGO_VERSION"
          echo "Git tag version: $TAG_VERSION"
          if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
            echo "Error: Version mismatch between Cargo.toml ($CARGO_VERSION) and git tag ($TAG_VERSION)"
            exit 1
          fi
          echo "Version verification passed: $CARGO_VERSION"

  # Publish to crates.io - only after successful GitHub release
  publish-crates:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs: [create-github-release]
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

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

      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-publish-crates-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-publish-crates-cargo-registry-
            ${{ runner.os }}-cargo-registry-

      - name: Publish to crates.io
        run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  # Create GitHub release first - crates.io publish depends on this
  create-github-release:
    name: Create GitHub Release
    runs-on: ubuntu-latest
    needs:
      [
        rust-checks,
        cpp-checks,
        ts-checks,
        e2e-integration,
        version-check,
        build-binaries,
      ]
    permissions:
      contents: write
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Extract changelog for this version
        id: changelog
        uses: ffurrer2/extract-release-notes@v2

      - name: Download all binary artifacts
        uses: actions/download-artifact@v4
        with:
          path: dist
          pattern: mcp-cpp-server-*

      - name: List downloaded artifacts
        run: |
          echo "Downloaded artifacts:"
          find dist -type f -name "mcp-cpp-server-*" -exec ls -la {} \;

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: |
            dist/*/mcp-cpp-server-*
          body: |
            ${{ steps.changelog.outputs.release_notes }}

            ---

            ### 🔍 What's Tested
            - ✅ All unit tests passed
            - ✅ Code formatting and linting checks
            - ✅ Comprehensive E2E integration tests
            - ✅ C++ test project compatibility
            - ✅ TypeScript tooling compatibility
            - ✅ Security audit passed

            ### 📦 Installation Options

            #### From crates.io
            ```bash
            cargo install mcp-cpp-server
            ```

            #### Download Binary
            Choose the appropriate binary for your platform:
            - **Linux x86_64**: `mcp-cpp-server-linux-x86_64`
            - **Linux ARM64**: `mcp-cpp-server-linux-aarch64`
            - **macOS x86_64**: `mcp-cpp-server-macos-x86_64`
            - **macOS ARM64**: `mcp-cpp-server-macos-aarch64`

            ### 🚀 Usage
            See the [README](https://github.com/mpsm/mcp-cpp#readme) for detailed usage instructions.

            ### 🛠️ CLI Tool
            Use the Python CLI tool for easy interaction:
            ```bash
            python3 tools/mcp-cli.py --help
            ```
          draft: false
          prerelease: false
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}