Skip to content

Commit 58d8fcc

Browse files
ci: Add Docker support
- Add .clang-tidy to check the code style and safety - Add DockerFile to this project. - Ignore some warnings.
1 parent 0a27940 commit 58d8fcc

File tree

12 files changed

+208
-24
lines changed

12 files changed

+208
-24
lines changed

.clang-tidy

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
Checks: '-*,
3+
clang-analyzer-core.*,
4+
clang-analyzer-cplusplus.*,
5+
modernize-redundant-void-arg,
6+
modernize-use-bool-literals,
7+
modernize-use-equals-default,
8+
modernize-use-nullptr,
9+
modernize-use-override,
10+
google-explicit-constructor,
11+
google-readability-casting,
12+
readability-braces-around-statements,
13+
readability-identifier-naming.ClassCase,
14+
readability-identifier-naming.StructCase,
15+
readability-identifier-naming.TypedefCase,
16+
readability-identifier-naming.EnumCase,
17+
readability-non-const-parameter,
18+
cert-dcl21-cpp,
19+
bugprone-undelegated-constructor,
20+
bugprone-macro-parentheses,
21+
bugprone-macro-repeated-side-effects,
22+
bugprone-forward-declaration-namespace,
23+
bugprone-bool-pointer-implicit-conversion,
24+
bugprone-misplaced-widening-cast,
25+
cppcoreguidelines-narrowing-conversions,
26+
cppcoreguidelines-pro-type-reinterpret-cast,
27+
misc-unconventional-assign-operator'
28+
WarningsAsErrors: ''
29+
HeaderFilterRegex: ''
30+
CheckOptions:
31+
- key: modernize-redundant-void-arg
32+
value: 'true'
33+
- key: modernize-use-bool-literals
34+
value: 'true'
35+
- key: modernize-use-equals-default
36+
value: 'true'
37+
- key: modernize-use-nullptr
38+
value: 'true'
39+
- key: modernize-use-override
40+
value: 'true'
41+
# Google
42+
- key: google-explicit-constructor
43+
value: 'true'
44+
- key: google-readability-casting
45+
value: 'true'
46+
47+
# Readability
48+
- key: readability-braces-around-statements
49+
value: 'true'
50+
- key: readability-identifier-naming.ClassCase
51+
value: 'CamelCase'
52+
- key: readability-identifier-naming.StructCase
53+
value: 'CamelCase'
54+
- key: readability-identifier-naming.TypedefCase
55+
value: 'CamelCase'
56+
- key: readability-identifier-naming.EnumCase
57+
value: 'CamelCase'
58+
- key: readability-non-const-parameter
59+
value: 'true'
60+
61+
# CERT
62+
- key: cert-dcl21-cpp
63+
value: 'true'
64+
65+
# Bugprone
66+
- key: bugprone-undelegated-constructor
67+
value: 'true'
68+
- key: bugprone-macro-parentheses
69+
value: 'true'
70+
- key: bugprone-macro-repeated-side-effects
71+
value: 'true'
72+
- key: bugprone-forward-declaration-namespace
73+
value: 'true'
74+
- key: bugprone-bool-pointer-implicit-conversion
75+
value: 'true'
76+
- key: bugprone-misplaced-widening-cast
77+
value: 'true'
78+
79+
# CppCoreGuidelines
80+
- key: cppcoreguidelines-narrowing-conversions
81+
value: 'true'
82+
- key: cppcoreguidelines-pro-type-reinterpret-cast
83+
value: 'true'
84+
85+
# Miscellaneous
86+
- key: misc-unconventional-assign-operator
87+
value: 'true'

.dockerignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*.git
2+
*.log
3+
*.md
4+
*.ini
5+
*.json
6+
*.png
7+
*.jpg
8+
*.sh
9+
*.pyc
10+
__pycache__
11+
.vscode
12+
.idea
13+
.cache
14+
logs
15+
certs
16+
17+
!README.md
18+
19+
!LICENSE
20+

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ mcp-server.log
1111
/.vs
1212
checks.json
1313
/certs
14-
*.exe
14+
*.exe
15+
checks.json

CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.23)
1+
cmake_minimum_required(VERSION 3.22)
22
project(MCPServer.cpp LANGUAGES CXX C VERSION 1.0.5.0)
33

44
if(UNIX AND NOT APPLE)
@@ -67,6 +67,8 @@ if(WIN32)
6767
add_compile_definitions(_WIN32_WINDOWS)
6868
endif()
6969

70+
add_compile_definitions(OPENSSL_API_COMPAT=30000)
71+
7072
# link mimalloc
7173
# target_link_libraries(mcp-server++ PRIVATE ${LINKED_LIBRARIES})
7274
if(MSVC)
@@ -201,6 +203,9 @@ endif()
201203
# CPack support for packaging
202204
include(cmake/CPackConfig.cmake)
203205

206+
# CPack RPM spec file
207+
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
208+
204209
# testing
205210
# Only build tests when including libs
206211
if(CPACK_INCLUDE_LIBS)
@@ -225,4 +230,8 @@ endif()
225230

226231
if(BUILD_EXAMPLES)
227232
add_subdirectory(examples)
228-
endif()
233+
endif()
234+
235+
set_target_properties(generate_cert PROPERTIES
236+
COMPILE_DEFINITIONS "OPENSSL_SUPPRESS_DEPRECATED"
237+
)

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM ubuntu:22.04 AS builder
2+
3+
RUN apt update && \
4+
apt install -y build-essential cmake git libssl-dev && \
5+
apt clean && \
6+
rm -rf /var/lib/apt/lists/*
7+
8+
WORKDIR /app
9+
10+
#RUN rm -rf /app/build
11+
12+
COPY . .
13+
14+
RUN mkdir -p build && \
15+
cd build && \
16+
cmake -DCMAKE_BUILD_TYPE=Release -DCPACK_INCLUDE_LIBS=OFF .. && \
17+
make -j$(nproc) && \
18+
strip bin/mcp-server++
19+
20+
# -----------------------------------------------------------------------------------#
21+
FROM debian:12-slim
22+
23+
RUN echo 'deb https://mirrors.ustc.edu.cn/debian bookworm main' > /etc/apt/sources.list && \
24+
echo 'deb https://mirrors.ustc.edu.cn/debian bookworm-updates main' >> /etc/apt/sources.list && \
25+
echo 'deb https://mirrors.ustc.edu.cn/debian-security bookworm-security main' >> /etc/apt/sources.list
26+
27+
RUN apt-get update && \
28+
apt-get install -y --no-install-recommends ca-certificates && \
29+
rm -rf /var/lib/apt/lists/*
30+
31+
RUN apt-get update && \
32+
apt-get install -y --no-install-recommends \
33+
libssl3 \
34+
ca-certificates && \
35+
apt-get clean && \
36+
rm -rf /var/lib/apt/lists/*
37+
38+
COPY --from=builder /app/build/bin/mcp-server++ /mcp-server++
39+
COPY config.ini.example /config.ini
40+
41+
RUN mkdir -p /logs /plugins
42+
43+
EXPOSE 6666 6667
44+
45+
CMD ["/mcp-server++"]

src/transport/http_handler.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -663,20 +663,17 @@ namespace mcp::transport {
663663
}
664664

665665
// Helper function: fully read and discard remaining request body (avoid buffer residue)
666-
asio::awaitable<void> HttpHandler::discard_remaining_request_body(
667-
std::shared_ptr<Session> session,
668-
const HttpRequest &req,
669-
size_t already_read) {// Note parameter name changed to "total bytes read"
666+
asio::awaitable<void> HttpHandler::discard_remaining_request_body(std::shared_ptr<Session> session, const HttpRequest &request, [[maybe_unused]] size_t already_read) {
670667
try {
671-
auto it = req.headers.find("Content-Length");
672-
if (it == req.headers.end()) {
668+
auto it = request.headers.find("Content-Length");
669+
if (it == request.headers.end()) {
673670
co_return;
674671
}
675672

676673
size_t content_len = std::stoull(it->second);
677674

678675
// Calculate already read body length
679-
size_t already_read_body = req.body.size();
676+
size_t already_read_body = request.body.size();
680677

681678
// Key: add underflow protection to avoid negative numbers (unsigned underflow)
682679
if (already_read_body >= content_len) {
@@ -705,20 +702,17 @@ namespace mcp::transport {
705702
}
706703

707704
// Helper function: fully read and discard remaining request body for SSL sessions (avoid buffer residue)
708-
asio::awaitable<void> HttpHandler::discard_remaining_request_body(
709-
std::shared_ptr<SslSession> session,
710-
const HttpRequest &req,
711-
size_t already_read) {// Note parameter name changed to "total bytes read"
705+
asio::awaitable<void> HttpHandler::discard_remaining_request_body(std::shared_ptr<SslSession> session, const HttpRequest &request, [[maybe_unused]] size_t already_read) {
712706
try {
713-
auto it = req.headers.find("Content-Length");
714-
if (it == req.headers.end()) {
707+
auto it = request.headers.find("Content-Length");
708+
if (it == request.headers.end()) {
715709
co_return;
716710
}
717711

718712
size_t content_len = std::stoull(it->second);
719713

720714
// Calculate already read body length
721-
size_t already_read_body = req.body.size();
715+
size_t already_read_body = request.body.size();
722716

723717
// Key: add underflow protection to avoid negative numbers (unsigned underflow)
724718
if (already_read_body >= content_len) {

src/transport/session.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace mcp::transport {
4040
* @param message The message to send
4141
* @param flush Whether to flush the data immediately
4242
*/
43-
virtual asio::awaitable<void> stream_write(const std::string &message, bool flush = true) {
43+
virtual asio::awaitable<void> stream_write(const std::string &message, [[maybe_unused]] bool flush = true) {
4444
// Default implementation just calls regular write
4545
co_await write(message);
4646
co_return;

src/transport/ssl_session.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ namespace mcp::transport {
188188
* @param message Data to send to client
189189
* @param flush Whether to flush the data immediately
190190
*/
191-
asio::awaitable<void> SslSession::stream_write(const std::string &message, bool flush) {
191+
asio::awaitable<void> SslSession::stream_write(const std::string &message, [[maybe_unused]] bool flush) {
192192
if (closed_ || !ssl_stream_.lowest_layer().is_open()) {
193193
MCP_DEBUG("Attempted stream write to closed SSL session (ID: {})", session_id_);
194194
co_return;

third_party/miniz/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
add_library(miniz STATIC miniz.c)
1+
add_library(miniz STATIC miniz.c)
2+
3+
target_compile_definitions(miniz PRIVATE MZ_USE_STDIO_FILEFUNC_64)

third_party/miniz/miniz.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
* THE SOFTWARE.
2525
*
2626
**************************************************************************/
27-
28-
29-
3027
typedef unsigned char mz_validate_uint16[sizeof(mz_uint16) == 2 ? 1 : -1];
3128
typedef unsigned char mz_validate_uint32[sizeof(mz_uint32) == 4 ? 1 : -1];
3229
typedef unsigned char mz_validate_uint64[sizeof(mz_uint64) == 8 ? 1 : -1];
@@ -3181,6 +3178,35 @@ static int mz_stat64(const char *path, struct __stat64 *buffer)
31813178
#define MZ_FREOPEN(p, m, s) freopen(p, m, s)
31823179
#define MZ_DELETE_FILE remove
31833180

3181+
#if defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
3182+
#ifndef _LARGEFILE64_SOURCE
3183+
#define _LARGEFILE64_SOURCE
3184+
#endif
3185+
#ifndef _FILE_OFFSET_BITS
3186+
#define _FILE_OFFSET_BITS 64
3187+
#endif
3188+
#endif
3189+
3190+
#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
3191+
/* Linux with large file support via _FILE_OFFSET_BITS=64 */
3192+
#ifndef MINIZ_NO_TIME
3193+
#include <utime.h>
3194+
#endif
3195+
#include <sys/stat.h>
3196+
#include <stdio.h>
3197+
3198+
#define MZ_FOPEN(f, m) fopen(f, m)
3199+
#define MZ_FCLOSE fclose
3200+
#define MZ_FREAD fread
3201+
#define MZ_FWRITE fwrite
3202+
#define MZ_FTELL64 ftello
3203+
#define MZ_FSEEK64 fseeko
3204+
#define MZ_FILE_STAT_STRUCT stat
3205+
#define MZ_FILE_STAT stat
3206+
#define MZ_FFLUSH fflush
3207+
#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
3208+
#define MZ_DELETE_FILE remove
3209+
31843210
#else
31853211
#pragma message("Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.")
31863212
#ifndef MINIZ_NO_TIME

0 commit comments

Comments
 (0)