Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fastmcpp is a C++ port of the Python [fastmcp](https://github.com/jlowin/fastmcp
- Resources and prompts support.
- Resource templates with URI pattern matching.
- JSON Schema validation.
- McpApp high-level application class.
- FastMCP high-level application class.
- ProxyApp for backend server proxying.
- ServerSession for bidirectional communication, sampling, and server-initiated notifications.
- Built-in middleware: Logging, Timing, Caching, RateLimiting, ErrorHandling.
Expand Down
18 changes: 9 additions & 9 deletions include/fastmcpp/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace fastmcpp
struct MountedApp
{
std::string prefix; // Prefix for tools/prompts (e.g., "weather")
class McpApp* app; // Non-owning pointer to mounted app
class FastMCP* app; // Non-owning pointer to mounted app
};

/// Proxy-mounted app with prefix (proxy mode)
Expand All @@ -31,15 +31,15 @@ struct ProxyMountedApp

/// MCP Application - bundles server metadata with managers
///
/// Similar to Python's FastMCP class. Provides:
/// Equivalent to Python's FastMCP class. Provides:
/// - Server metadata (name, version, icons, etc.)
/// - Tool, Resource, and Prompt managers
/// - App mounting support with prefixes
///
/// Usage:
/// ```cpp
/// McpApp main_app("MainApp", "1.0");
/// McpApp weather_app("WeatherApp", "1.0");
/// FastMCP main_app("MainApp", "1.0");
/// FastMCP weather_app("WeatherApp", "1.0");
///
/// // Register tools on sub-app
/// weather_app.tools().register_tool(get_forecast_tool);
Expand All @@ -49,13 +49,13 @@ struct ProxyMountedApp
///
/// // Tools accessible as "weather_get_forecast"
/// ```
class McpApp
class FastMCP
{
public:
/// Construct app with metadata
explicit McpApp(std::string name = "fastmcpp_app", std::string version = "1.0.0",
std::optional<std::string> website_url = std::nullopt,
std::optional<std::vector<Icon>> icons = std::nullopt);
explicit FastMCP(std::string name = "fastmcpp_app", std::string version = "1.0.0",
std::optional<std::string> website_url = std::nullopt,
std::optional<std::vector<Icon>> icons = std::nullopt);

// Metadata accessors
const std::string& name() const
Expand Down Expand Up @@ -125,7 +125,7 @@ class McpApp
/// @param app The app to mount (must outlive this app in direct mode)
/// @param prefix Optional prefix (empty string = no prefix)
/// @param as_proxy If true, mount in proxy mode (uses MCP handler for communication)
void mount(McpApp& app, const std::string& prefix = "", bool as_proxy = false);
void mount(FastMCP& app, const std::string& prefix = "", bool as_proxy = false);

/// Get list of directly mounted apps
const std::vector<MountedApp>& mounted() const
Expand Down
12 changes: 6 additions & 6 deletions include/fastmcpp/mcp/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace fastmcpp
{
class McpApp; // Forward declaration
class FastMCP; // Forward declaration
class ProxyApp; // Forward declaration
} // namespace fastmcpp

Expand Down Expand Up @@ -58,9 +58,9 @@ make_mcp_handler(const std::string& server_name, const std::string& version,
const resources::ResourceManager& resources, const prompts::PromptManager& prompts,
const std::unordered_map<std::string, std::string>& descriptions = {});

// MCP handler from McpApp - supports mounted apps with aggregation
// MCP handler from FastMCP - supports mounted apps with aggregation
// Uses app's aggregated lists and routing for mounted sub-apps
std::function<fastmcpp::Json(const fastmcpp::Json&)> make_mcp_handler(const McpApp& app);
std::function<fastmcpp::Json(const fastmcpp::Json&)> make_mcp_handler(const FastMCP& app);

// MCP handler from ProxyApp - supports proxying to backend server
// Uses app's aggregated lists (local + remote) and routing
Expand All @@ -73,11 +73,11 @@ using SessionAccessor = std::function<std::shared_ptr<server::ServerSession>(con
/// The session_accessor callback is used to get ServerSession for sampling requests.
/// Session ID is extracted from params._meta.session_id (injected by SSE server).
std::function<fastmcpp::Json(const fastmcpp::Json&)>
make_mcp_handler_with_sampling(const McpApp& app, SessionAccessor session_accessor);
make_mcp_handler_with_sampling(const FastMCP& app, SessionAccessor session_accessor);

/// Convenience: create handler from McpApp + SseServerWrapper
/// Convenience: create handler from FastMCP + SseServerWrapper
/// Uses the SSE server's get_session() method as the session accessor.
std::function<fastmcpp::Json(const fastmcpp::Json&)>
make_mcp_handler_with_sampling(const McpApp& app, server::SseServerWrapper& sse_server);
make_mcp_handler_with_sampling(const FastMCP& app, server::SseServerWrapper& sse_server);

} // namespace fastmcpp::mcp
34 changes: 17 additions & 17 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
namespace fastmcpp
{

McpApp::McpApp(std::string name, std::string version, std::optional<std::string> website_url,
std::optional<std::vector<Icon>> icons)
FastMCP::FastMCP(std::string name, std::string version, std::optional<std::string> website_url,
std::optional<std::vector<Icon>> icons)
: server_(std::move(name), std::move(version), std::move(website_url), std::move(icons))
{
}

void McpApp::mount(McpApp& app, const std::string& prefix, bool as_proxy)
void FastMCP::mount(FastMCP& app, const std::string& prefix, bool as_proxy)
{
if (as_proxy)
{
Expand All @@ -40,22 +40,22 @@ void McpApp::mount(McpApp& app, const std::string& prefix, bool as_proxy)
// Prefix Utilities
// =========================================================================

std::string McpApp::add_prefix(const std::string& name, const std::string& prefix)
std::string FastMCP::add_prefix(const std::string& name, const std::string& prefix)
{
if (prefix.empty())
return name;
return prefix + "_" + name;
}

std::pair<std::string, std::string> McpApp::strip_prefix(const std::string& name)
std::pair<std::string, std::string> FastMCP::strip_prefix(const std::string& name)
{
auto pos = name.find('_');
if (pos == std::string::npos)
return {"", name};
return {name.substr(0, pos), name.substr(pos + 1)};
}

std::string McpApp::add_resource_prefix(const std::string& uri, const std::string& prefix)
std::string FastMCP::add_resource_prefix(const std::string& uri, const std::string& prefix)
{
if (prefix.empty())
return uri;
Expand All @@ -73,7 +73,7 @@ std::string McpApp::add_resource_prefix(const std::string& uri, const std::strin
return scheme + "://" + prefix + "/" + path;
}

std::string McpApp::strip_resource_prefix(const std::string& uri, const std::string& prefix)
std::string FastMCP::strip_resource_prefix(const std::string& uri, const std::string& prefix)
{
if (prefix.empty())
return uri;
Expand All @@ -93,7 +93,7 @@ std::string McpApp::strip_resource_prefix(const std::string& uri, const std::str
return uri;
}

bool McpApp::has_resource_prefix(const std::string& uri, const std::string& prefix)
bool FastMCP::has_resource_prefix(const std::string& uri, const std::string& prefix)
{
if (prefix.empty())
return true; // Empty prefix matches everything
Expand All @@ -112,7 +112,7 @@ bool McpApp::has_resource_prefix(const std::string& uri, const std::string& pref
// Aggregated Lists
// =========================================================================

std::vector<std::pair<std::string, const tools::Tool*>> McpApp::list_all_tools() const
std::vector<std::pair<std::string, const tools::Tool*>> FastMCP::list_all_tools() const
{
std::vector<std::pair<std::string, const tools::Tool*>> result;

Expand Down Expand Up @@ -153,7 +153,7 @@ std::vector<std::pair<std::string, const tools::Tool*>> McpApp::list_all_tools()
return result;
}

std::vector<client::ToolInfo> McpApp::list_all_tools_info() const
std::vector<client::ToolInfo> FastMCP::list_all_tools_info() const
{
std::vector<client::ToolInfo> result;

Expand Down Expand Up @@ -200,7 +200,7 @@ std::vector<client::ToolInfo> McpApp::list_all_tools_info() const
return result;
}

std::vector<resources::Resource> McpApp::list_all_resources() const
std::vector<resources::Resource> FastMCP::list_all_resources() const
{
std::vector<resources::Resource> result;

Expand Down Expand Up @@ -247,7 +247,7 @@ std::vector<resources::Resource> McpApp::list_all_resources() const
return result;
}

std::vector<resources::ResourceTemplate> McpApp::list_all_templates() const
std::vector<resources::ResourceTemplate> FastMCP::list_all_templates() const
{
std::vector<resources::ResourceTemplate> result;

Expand Down Expand Up @@ -293,7 +293,7 @@ std::vector<resources::ResourceTemplate> McpApp::list_all_templates() const
return result;
}

std::vector<std::pair<std::string, const prompts::Prompt*>> McpApp::list_all_prompts() const
std::vector<std::pair<std::string, const prompts::Prompt*>> FastMCP::list_all_prompts() const
{
std::vector<std::pair<std::string, const prompts::Prompt*>> result;

Expand Down Expand Up @@ -335,7 +335,7 @@ std::vector<std::pair<std::string, const prompts::Prompt*>> McpApp::list_all_pro
// Routing
// =========================================================================

Json McpApp::invoke_tool(const std::string& name, const Json& args) const
Json FastMCP::invoke_tool(const std::string& name, const Json& args) const
{
// Try local tools first
try
Expand Down Expand Up @@ -437,7 +437,7 @@ Json McpApp::invoke_tool(const std::string& name, const Json& args) const
throw NotFoundError("tool not found: " + name);
}

resources::ResourceContent McpApp::read_resource(const std::string& uri, const Json& params) const
resources::ResourceContent FastMCP::read_resource(const std::string& uri, const Json& params) const
{
// Try local resources first
try
Expand Down Expand Up @@ -562,8 +562,8 @@ resources::ResourceContent McpApp::read_resource(const std::string& uri, const J
throw NotFoundError("resource not found: " + uri);
}

std::vector<prompts::PromptMessage> McpApp::get_prompt(const std::string& name,
const Json& args) const
std::vector<prompts::PromptMessage> FastMCP::get_prompt(const std::string& name,
const Json& args) const
{
// Try local prompts first
try
Expand Down
8 changes: 4 additions & 4 deletions src/mcp/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,8 @@ make_mcp_handler(const std::string& server_name, const std::string& version,
};
}

// McpApp handler - supports mounted apps with aggregation
std::function<fastmcpp::Json(const fastmcpp::Json&)> make_mcp_handler(const McpApp& app)
// FastMCP handler - supports mounted apps with aggregation
std::function<fastmcpp::Json(const fastmcpp::Json&)> make_mcp_handler(const FastMCP& app)
{
return [&app](const fastmcpp::Json& message) -> fastmcpp::Json
{
Expand Down Expand Up @@ -1525,7 +1525,7 @@ static std::string extract_session_id(const fastmcpp::Json& params)
}

std::function<fastmcpp::Json(const fastmcpp::Json&)>
make_mcp_handler_with_sampling(const McpApp& app, SessionAccessor session_accessor)
make_mcp_handler_with_sampling(const FastMCP& app, SessionAccessor session_accessor)
{
return [&app, session_accessor](const fastmcpp::Json& message) -> fastmcpp::Json
{
Expand Down Expand Up @@ -1831,7 +1831,7 @@ make_mcp_handler_with_sampling(const McpApp& app, SessionAccessor session_access
}

std::function<fastmcpp::Json(const fastmcpp::Json&)>
make_mcp_handler_with_sampling(const McpApp& app, server::SseServerWrapper& sse_server)
make_mcp_handler_with_sampling(const FastMCP& app, server::SseServerWrapper& sse_server)
{
return make_mcp_handler_with_sampling(app, [&sse_server](const std::string& session_id)
{ return sse_server.get_session(session_id); });
Expand Down
Loading
Loading