Skip to content

Commit 6054c94

Browse files
committed
Restore constructor backward compatibility for instructions
1 parent 25fd671 commit 6054c94

5 files changed

Lines changed: 70 additions & 2 deletions

File tree

examples/server_metadata.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ int main()
4747

4848
std::cout << "2. Creating server with full metadata...\n";
4949

50-
// Server constructor signature (v2.13.0+):
51-
// Server(name, version, website_url, icons, strict_input_validation)
50+
// Server constructor signatures:
51+
// Preferred: Server(name, version, website_url, icons, instructions, strict_input_validation)
52+
// Legacy-compatible: Server(name, version, website_url, icons, strict_input_validation)
5253
auto server = std::make_shared<server::Server>("example_server", // name (required)
5354
"1.2.3", // version (required)
5455
"https://example.com", // website_url (optional)

include/fastmcpp/app.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "fastmcpp/tools/manager.hpp"
99

1010
#include <chrono>
11+
#include <initializer_list>
1112
#include <memory>
1213
#include <optional>
1314
#include <string>
@@ -117,6 +118,16 @@ class FastMCP
117118
std::optional<std::string> instructions = std::nullopt,
118119
std::vector<std::shared_ptr<providers::Provider>> providers = {},
119120
int list_page_size = 0, bool dereference_schemas = true);
121+
/// Backward-compatible constructor overload (legacy parameter order).
122+
FastMCP(std::string name, std::string version, std::optional<std::string> website_url,
123+
std::optional<std::vector<Icon>> icons,
124+
std::vector<std::shared_ptr<providers::Provider>> providers,
125+
int list_page_size = 0, bool dereference_schemas = true);
126+
/// Backward-compatible constructor overload for `{}` provider arguments.
127+
FastMCP(std::string name, std::string version, std::optional<std::string> website_url,
128+
std::optional<std::vector<Icon>> icons,
129+
std::initializer_list<std::shared_ptr<providers::Provider>> providers,
130+
int list_page_size = 0, bool dereference_schemas = true);
120131

121132
// Metadata accessors
122133
const std::string& name() const

include/fastmcpp/server/server.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace fastmcpp::server
1818
/// - version: Server version (optional)
1919
/// - website_url: Optional URL to server website
2020
/// - icons: Optional list of icons for UI display
21+
/// - instructions: Optional instructions shown during initialize
2122
/// - strict_input_validation: Flag for input validation behavior (optional)
2223
class Server
2324
{
@@ -36,6 +37,13 @@ class Server
3637
strict_input_validation_(std::move(strict_input_validation))
3738
{
3839
}
40+
/// Backward-compatible constructor overload (legacy parameter order).
41+
Server(std::string name, std::string version, std::optional<std::string> website_url,
42+
std::optional<std::vector<fastmcpp::Icon>> icons, bool strict_input_validation)
43+
: Server(std::move(name), std::move(version), std::move(website_url), std::move(icons),
44+
std::nullopt, strict_input_validation)
45+
{
46+
}
3947

4048
// Route registration
4149
void route(const std::string& name, Handler h)

src/app.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ FastMCP::FastMCP(std::string name, std::string version, std::optional<std::strin
3232
throw ValidationError("provider cannot be null");
3333
}
3434

35+
FastMCP::FastMCP(std::string name, std::string version, std::optional<std::string> website_url,
36+
std::optional<std::vector<Icon>> icons,
37+
std::vector<std::shared_ptr<providers::Provider>> providers, int list_page_size,
38+
bool dereference_schemas)
39+
: FastMCP(std::move(name), std::move(version), std::move(website_url), std::move(icons),
40+
std::nullopt, std::move(providers), list_page_size, dereference_schemas)
41+
{
42+
}
43+
44+
FastMCP::FastMCP(std::string name, std::string version, std::optional<std::string> website_url,
45+
std::optional<std::vector<Icon>> icons,
46+
std::initializer_list<std::shared_ptr<providers::Provider>> providers,
47+
int list_page_size, bool dereference_schemas)
48+
: FastMCP(std::move(name), std::move(version), std::move(website_url), std::move(icons),
49+
std::nullopt, std::vector<std::shared_ptr<providers::Provider>>(providers),
50+
list_page_size, dereference_schemas)
51+
{
52+
}
53+
3554
namespace
3655
{
3756
fastmcpp::Json schema_from_schema_or_simple(const fastmcpp::Json& schema_or_simple)

tests/mcp/test_instructions.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,34 @@ static void test_server_accessors()
256256
std::cout << " PASS\n";
257257
}
258258

259+
// ============================================================================
260+
// 11. Backward-compatible constructor parameter order
261+
// ============================================================================
262+
static void test_legacy_constructor_compatibility()
263+
{
264+
std::cout << "test_legacy_constructor_compatibility...\n";
265+
266+
std::vector<std::shared_ptr<providers::Provider>> providers;
267+
FastMCP app_with_vector("legacy_app_vector", "1.0.0", std::nullopt, std::nullopt, providers, 3,
268+
false);
269+
assert(!app_with_vector.instructions().has_value());
270+
assert(app_with_vector.list_page_size() == 3);
271+
assert(!app_with_vector.dereference_schemas());
272+
273+
FastMCP app_with_braces("legacy_app_braces", "1.0.0", std::nullopt, std::nullopt, {}, 0,
274+
false);
275+
assert(!app_with_braces.instructions().has_value());
276+
assert(app_with_braces.list_page_size() == 0);
277+
assert(!app_with_braces.dereference_schemas());
278+
279+
server::Server legacy_srv("legacy_srv", "1.0.0", std::nullopt, std::nullopt, true);
280+
assert(!legacy_srv.instructions().has_value());
281+
assert(legacy_srv.strict_input_validation().has_value());
282+
assert(*legacy_srv.strict_input_validation());
283+
284+
std::cout << " PASS\n";
285+
}
286+
259287
int main()
260288
{
261289
test_bare_handler_with_instructions();
@@ -268,6 +296,7 @@ int main()
268296
test_proxy_instructions();
269297
test_proxy_set_instructions();
270298
test_server_accessors();
299+
test_legacy_constructor_compatibility();
271300

272301
std::cout << "All instructions tests passed\n";
273302
return 0;

0 commit comments

Comments
 (0)