Skip to content

Commit fe9b060

Browse files
committed
additional examples and tests
1 parent 051883d commit fe9b060

File tree

12 files changed

+530
-2
lines changed

12 files changed

+530
-2
lines changed

.github/workflows/ci.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
## ==================================================================================
2+
## SPDX-License-Identifier: MIT
3+
## Copyright (c) 2025 Vinny Parla
4+
## File: .github/workflows/ci.yml
5+
## Purpose: Cross-platform CI running Docker-first tests and Windows native smoke
6+
## ==================================================================================
7+
name: CI
8+
9+
on:
10+
push:
11+
branches: [ main, master, develop, "release/*" ]
12+
pull_request:
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
docker-tests-ubuntu:
20+
name: Docker-first tests (Ubuntu)
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Build and run tests in Docker (Dockerfile.demo:test target)
30+
run: |
31+
docker buildx build \
32+
-f Dockerfile.demo \
33+
--target test \
34+
--progress=plain \
35+
--pull \
36+
--load \
37+
-t mcp-cpp-test .
38+
39+
docker-tests-macos:
40+
name: Docker-first tests (macOS)
41+
runs-on: macos-latest
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v4
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Build and run tests in Docker (Dockerfile.demo:test target)
50+
run: |
51+
docker buildx build \
52+
-f Dockerfile.demo \
53+
--target test \
54+
--progress=plain \
55+
--pull \
56+
--load \
57+
-t mcp-cpp-test .
58+
59+
docker-tests-windows:
60+
name: Docker-first tests (Windows)
61+
runs-on: windows-latest
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v4
65+
66+
- name: Set up Docker Buildx
67+
uses: docker/setup-buildx-action@v3
68+
69+
- name: Show Docker version/info
70+
run: |
71+
docker version
72+
docker info
73+
shell: bash
74+
75+
- name: Build and run tests in Docker (Dockerfile.demo:test target)
76+
run: |
77+
docker buildx build \
78+
-f Dockerfile.demo \
79+
--target test \
80+
--progress=plain \
81+
--pull \
82+
--load \
83+
-t mcp-cpp-test .
84+
shell: bash
85+
86+
windows-native-smoke:
87+
name: Windows native stdio smoke
88+
runs-on: windows-latest
89+
steps:
90+
- name: Checkout repository
91+
uses: actions/checkout@v4
92+
93+
- name: Configure (MSVC, Release)
94+
shell: pwsh
95+
run: |
96+
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DMCP_BUILD_EXAMPLES=ON -DMCP_BUILD_TESTS=OFF
97+
98+
- name: Build stdio_smoke
99+
shell: pwsh
100+
run: |
101+
cmake --build build --config Release --target stdio_smoke
102+
103+
- name: Run stdio_smoke
104+
shell: pwsh
105+
run: |
106+
./build/examples/stdio_smoke/Release/stdio_smoke.exe

.github/workflows/release.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build-artifacts:
13+
name: Build artifacts (Docker artifacts stage)
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Build artifacts to local folder
23+
run: |
24+
docker buildx build \
25+
--target artifacts \
26+
--output type=local,dest=./out \
27+
--progress=plain \
28+
--pull \
29+
.
30+
31+
- name: Upload build artifacts
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: mcp-cpp-artifacts
35+
path: |
36+
out/include/**
37+
out/lib/**
38+
out/bin/**
39+
40+
publish-release:
41+
name: Publish GitHub Release
42+
needs: build-artifacts
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Download artifacts
46+
uses: actions/download-artifact@v4
47+
with:
48+
name: mcp-cpp-artifacts
49+
path: out
50+
51+
- name: Create Release
52+
uses: softprops/action-gh-release@v2
53+
with:
54+
files: |
55+
out/**
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#==========================================================================================================
2+
# SPDX-License-Identifier: MIT
3+
# Copyright (c) 2025 Vinny Parla
4+
# File: CMakeLists.txt
5+
# Purpose: MCP C++ SDKS
6+
#==========================================================================================================
17
cmake_minimum_required(VERSION 3.20)
28

39
# Fail early if a lower standard is attempted
@@ -78,6 +84,8 @@ if(MCP_BUILD_EXAMPLES)
7884
add_subdirectory(examples/json_test)
7985
add_subdirectory(examples/mcp_client)
8086
add_subdirectory(examples/mcp_server)
87+
add_subdirectory(examples/stdio_smoke)
88+
add_subdirectory(examples/subscriptions_progress)
8189
endif()
8290

8391
# Tests (to be implemented in a later step)

docs/index.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,28 @@ Detailed per-interface API documentation:
5353
- Client API: [docs/api/client.md](./api/client.md)
5454
- Server API: [docs/api/server.md](./api/server.md)
5555
- Transport API: [docs/api/transport.md](./api/transport.md)
56+
57+
## Environment variables
58+
59+
These environment variables influence runtime/demo behavior. See [BUILD+TEST.MD](../BUILD+TEST.MD#demo-and-transport-options-env--factory-config) for examples.
60+
61+
- `MCP_STDIOTRANSPORT_TIMEOUT_MS`: Default request timeout for `StdioTransport` (milliseconds). `0` disables.
62+
- `MCP_STDIO_CONFIG`: Pass stdio transport options as a `key=value` list (e.g., `timeout_ms`, `idle_read_timeout_ms`, `write_timeout_ms`, `write_queue_max_bytes`).
63+
- `MCP_KEEPALIVE_MS`: Enable periodic server keepalive notifications in the demo.
64+
- `DEMO_COLOR`: Set to `0` to disable colored output in demo scripts.
65+
66+
## Examples
67+
68+
- `examples/mcp_server` and `examples/mcp_client`: Demo server and client wired over stdio (used by `scripts/run_demo.sh`).
69+
- `examples/subscriptions_progress`: Demonstrates per-URI resource subscriptions and server progress notifications using `InMemoryTransport`.
70+
- `examples/stdio_smoke`: Minimal Windows-native smoke that exercises `StdioTransport` start/stop paths.
71+
72+
## Coding style checklist
73+
74+
Follow the project style rules in `task.md` and the Google C++ Style Guide:
75+
76+
- Use C++20 and avoid busy loops; prefer async, futures/promises, and coroutines.
77+
- No third-party runtime deps; standard library and C-runtime only.
78+
- Every source file must include the SPDX header banner with filename and purpose.
79+
- Brace style and formatting per `task.md`; see Google C++ Style Guide for general rules: https://google.github.io/styleguide/cppguide.html#C++_Version
80+
- Add comprehensive GoogleTest coverage for new changes, including negative paths; register tests in `tests/CMakeLists.txt`.

examples/basic/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
#==========================================================================================================
2+
#==========================================================================================================
13
# SPDX-License-Identifier: MIT
2-
4+
# Copyright (c) 2025 Vinny Parla
5+
# File: examples/basic/CMakeLists.txt
6+
# Purpose: Basic example
7+
#==========================================================================================================
38
cmake_minimum_required(VERSION 3.20)
49

510
project(basic_example LANGUAGES CXX)

examples/mcp_client/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
#==========================================================================================================
12
# SPDX-License-Identifier: MIT
3+
# Copyright (c) 2025 Vinny Parla
4+
# File: examples/mcp_client/CMakeLists.txt
5+
# Purpose: MCP C++ SDK client example
6+
#==========================================================================================================
27

38
cmake_minimum_required(VERSION 3.20)
49

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#==========================================================================================================
2+
# SPDX-License-Identifier: MIT
3+
# Copyright (c) 2025 Vinny Parla
4+
# File: examples/stdio_smoke/CMakeLists.txt
5+
# Purpose: Windows-native stdio smoke example (also builds on Linux/macOS)
6+
#==========================================================================================================
7+
8+
cmake_minimum_required(VERSION 3.20)
9+
10+
add_executable(stdio_smoke
11+
main.cpp
12+
)
13+
14+
# Link against the SDK static library
15+
target_link_libraries(stdio_smoke PRIVATE mcp_cpp)
16+
17+
target_compile_features(stdio_smoke PRIVATE cxx_std_20)
18+
19+
target_include_directories(stdio_smoke PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include)

examples/stdio_smoke/main.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//==========================================================================================================
2+
// SPDX-License-Identifier: MIT
3+
// Copyright (c) 2025 Vinny Parla
4+
// File: examples/stdio_smoke/main.cpp
5+
// Purpose: Windows-native stdio smoke test to exercise StdioTransport paths
6+
//==========================================================================================================
7+
8+
#include <chrono>
9+
#include <thread>
10+
#include <iostream>
11+
#include "mcp/StdioTransport.hpp"
12+
#include "logging/Logger.h"
13+
14+
int main() {
15+
using namespace mcp;
16+
Logger::setLogLevel(LogLevel::LOG_INFO_LEVEL);
17+
18+
StdioTransportFactory f;
19+
// Very short timeouts to traverse code paths quickly
20+
auto t = f.CreateTransport("timeout_ms=100; idle_read_timeout_ms=100; write_timeout_ms=100; write_queue_max_bytes=1024");
21+
22+
// Start and immediately close to exercise start/stop on native platform
23+
try {
24+
t->Start().get();
25+
} catch (...) {
26+
LOG_ERROR("Start failed");
27+
}
28+
std::this_thread::sleep_for(std::chrono::milliseconds(50));
29+
try {
30+
t->Close().get();
31+
} catch (...) {
32+
LOG_ERROR("Close failed");
33+
}
34+
35+
// If we reached here without crashing, declare success
36+
std::cout << "stdio_smoke: ok" << std::endl;
37+
return 0;
38+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#==========================================================================================================
2+
# SPDX-License-Identifier: MIT
3+
# Copyright (c) 2025 Vinny Parla
4+
# File: examples/subscriptions_progress/CMakeLists.txt
5+
# Purpose: Example demonstrating per-URI subscriptions and progress notifications
6+
#==========================================================================================================
7+
8+
cmake_minimum_required(VERSION 3.20)
9+
10+
add_executable(subscriptions_progress
11+
main.cpp
12+
)
13+
14+
target_link_libraries(subscriptions_progress PRIVATE mcp_cpp)
15+
16+
target_compile_features(subscriptions_progress PRIVATE cxx_std_20)
17+
18+
target_include_directories(subscriptions_progress PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include)

0 commit comments

Comments
 (0)