cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
mcp::server::ServerBuilder Class Reference

Fluent builder for constructing a configured Server. More...

#include <server.hpp>

Public Member Functions

ServerBuildername (std::string value)
 Sets the advertised server name.
 
ServerBuilderversion (std::string value)
 Sets the advertised server version.
 
ServerBuilderinstructions (std::string value)
 Sets the advertised server instructions.
 
ServerBuilderwith_capabilities (protocol::ServerCapabilities capabilities)
 Replaces the capabilities advertised during initialization.
 
ServerBuilderwith_transport (std::unique_ptr< Transport > transport)
 Adds a transport to be owned by the built server.
 
ServerBuilderwith_auth_provider (std::unique_ptr< AuthProvider > auth_provider)
 Sets the authentication provider owned by the built server.
 
ServerBuilderwith_rate_limiter (std::unique_ptr< RateLimiter > rate_limiter)
 Sets the rate limiter owned by the built server.
 
ServerBuilderwith_schema_validator (std::shared_ptr< const JsonSchemaValidator > validator)
 Sets the optional JSON Schema validator used by the built server.
 
ServerBuilderwith_task_manager (TaskOperationProcessorOptions options={})
 Enables the built-in SDK task processor on the built server.
 
ServerBuilderwith_task_manager (std::shared_ptr< TaskOperationProcessor > processor)
 Uses an explicit task processor on the built server.
 
ServerBuilderadd_tool (protocol::ToolDefinition definition, ToolHandler handler)
 Registers a tool definition and handler.
 
ServerBuilderadd_prompt (protocol::Prompt prompt, PromptHandler handler)
 Registers a prompt and handler.
 
ServerBuilderadd_resource (protocol::Resource resource, ResourceReadHandler handler)
 Registers a resource and read handler.
 
ServerBuilderadd_resource_template (protocol::ResourceTemplate resource_template)
 Registers a resource template.
 
template<class Router >
ServerBuilderwith_router (const Router &router)
 Applies a composable router object to this builder.
 
ServerBuilderon_completion (Server::JsonHandler handler)
 Sets the completion request handler.
 
ServerBuilderon_completion (Server::JsonContextHandler handler)
 
ServerBuilderon_completion (Server::JsonRequestContextHandler handler)
 
ServerBuilderon_sampling (Server::JsonHandler handler)
 Sets the sampling request handler.
 
ServerBuilderon_sampling (Server::JsonContextHandler handler)
 
ServerBuilderon_sampling (Server::JsonRequestContextHandler handler)
 
ServerBuilderon_logging (Server::LoggingHandler handler)
 Sets the logging notification handler.
 
ServerBuilderon_raw_request (Server::RawRequestHandler handler)
 Sets the raw request hook.
 
ServerBuilderon_raw_notification (Server::RawNotificationHandler handler)
 Sets the raw notification hook.
 
ServerBuilderon_custom_request (Server::RawRequestHandler handler)
 Sets the custom request handler.
 
ServerBuilderon_custom_notification (Server::RawNotificationHandler handler)
 Sets the custom notification handler.
 
ServerBuilderon_task_list (Server::TaskListHandler handler)
 Sets the task list handler.
 
ServerBuilderon_tools_list (Server::ToolsListHandler handler)
 Sets the tools/list handler.
 
ServerBuilderon_prompts_list (Server::PromptsListHandler handler)
 Sets the prompts/list handler.
 
ServerBuilderon_resources_list (Server::ResourcesListHandler handler)
 Sets the resources/list handler.
 
ServerBuilderon_resource_templates_list (Server::ResourceTemplatesListHandler handler)
 Sets the resources/templates/list handler.
 
ServerBuilderon_task_get (Server::TaskGetHandler handler)
 Sets the task get handler.
 
ServerBuilderon_task_cancel (Server::TaskCancelHandler handler)
 Sets the task cancel handler.
 
ServerBuilderon_task_result (Server::TaskResultHandler handler)
 Sets the task result handler.
 
ServerBuilderon_progress (Server::ProgressHandler handler)
 Sets the progress notification handler.
 
ServerBuilderon_roots_list_changed (Server::RootsListChangedHandler handler)
 Sets the roots-list-changed notification handler.
 
ServerBuilderon_tool_list_changed (Server::ListChangedHandler handler)
 Sets the tool-list-changed notification handler.
 
ServerBuilderon_prompt_list_changed (Server::ListChangedHandler handler)
 Sets the prompt-list-changed notification handler.
 
ServerBuilderon_resource_list_changed (Server::ListChangedHandler handler)
 Sets the resource-list-changed notification handler.
 
ServerBuilderon_resource_updated (Server::ResourceUpdatedHandler handler)
 Sets the resource-updated notification handler.
 
ServerBuilderwith_handler (ServerHandler handler)
 Installs every non-empty callback from a handler aggregate.
 
ServerBuilderwith_handler (const ServerHandlerInterface &handler)
 Installs callbacks from a borrowed contract-style handler.
 
ServerBuilderwith_handler (std::shared_ptr< const ServerHandlerInterface > handler)
 Installs callbacks from an owned contract-style handler.
 
core::Result< std::unique_ptr< Server > > build ()
 Builds a configured server.
 

Detailed Description

Fluent builder for constructing a configured Server.

Registrations are accumulated until build(). build() creates a Server, transfers owned transports/providers, registers tools, prompts, resources, and templates, then applies configured handler overrides.

Member Function Documentation

◆ add_prompt()

ServerBuilder & mcp::server::ServerBuilder::add_prompt ( protocol::Prompt  prompt,
PromptHandler  handler 
)

Registers a prompt and handler.

Parameters
promptPrompt metadata advertised by list_prompts().
handlerHandler invoked when the prompt is requested.

◆ add_resource()

ServerBuilder & mcp::server::ServerBuilder::add_resource ( protocol::Resource  resource,
ResourceReadHandler  handler 
)

Registers a resource and read handler.

Parameters
resourceResource metadata advertised by list_resources().
handlerHandler invoked when the resource URI is read.

◆ add_resource_template()

ServerBuilder & mcp::server::ServerBuilder::add_resource_template ( protocol::ResourceTemplate  resource_template)

Registers a resource template.

Parameters
resource_templateTemplate metadata advertised by list_resource_templates().

◆ add_tool()

ServerBuilder & mcp::server::ServerBuilder::add_tool ( protocol::ToolDefinition  definition,
ToolHandler  handler 
)

Registers a tool definition and handler.

Parameters
definitionTool metadata advertised by list_tools().
handlerHandler invoked when the tool is called.
Returns
Reference to this builder for chaining.
Note
The registration is applied during build(); duplicate or invalid names are reported in the build() result.

◆ build()

core::Result< std::unique_ptr< Server > > mcp::server::ServerBuilder::build ( )

Builds a configured server.

Returns
Owned server on success, or the first registration/configuration error.

◆ with_handler() [1/2]

ServerBuilder & mcp::server::ServerBuilder::with_handler ( const ServerHandlerInterface handler)

Installs callbacks from a borrowed contract-style handler.

The referenced handler must outlive the built server because installed callbacks delegate to it through a non-owning compatibility wrapper.

◆ with_handler() [2/2]

ServerBuilder & mcp::server::ServerBuilder::with_handler ( std::shared_ptr< const ServerHandlerInterface handler)

Installs callbacks from an owned contract-style handler.

The shared handler is retained by the built server callbacks.


The documentation for this class was generated from the following file: