cxxmcp 1.2.8
C++ MCP SDK
Loading...
Searching...
No Matches
authoring.hpp
Go to the documentation of this file.
1// Copyright (c) 2025 [caomengxuan666]
2
3#pragma once
4
7
8#include <cstdint>
9#include <memory>
10#include <stdexcept>
11#include <string>
12#include <string_view>
13#include <type_traits>
14#include <utility>
15
16#include "cxxmcp/config.hpp"
19
20namespace mcp::server {
21
22namespace detail {
23
24template <class T, class = void>
25struct has_tool_title : std::false_type {};
26
27template <class T>
28struct has_tool_title<T, std::void_t<decltype(T::title)>> : std::true_type {};
29
30template <class T, class = void>
31struct has_tool_description : std::false_type {};
32
33template <class T>
34struct has_tool_description<T, std::void_t<decltype(T::description)>>
35 : std::true_type {};
36
37template <class T, class = void>
38struct has_tool_definition : std::false_type {};
39
40template <class T>
42 T, std::void_t<decltype(std::declval<const T&>().definition())>>
43 : std::true_type {};
44
45template <class Tool, class Text>
46inline std::string static_tool_text(Text value) {
47 if constexpr (std::is_convertible_v<Text, std::string_view>) {
48 return std::string(std::string_view(value));
49 } else {
50 return std::string(value);
51 }
52}
53
54} // namespace detail
55
57template <class Args, class Result, class Handler>
59 protocol::ToolDefinition definition;
60 Handler handler;
61};
62
64template <class Args, class Result>
66 public:
67 explicit TypedToolBuilder(std::string name) {
68 definition_ = protocol::tool_definition(std::move(name))
69 .input_schema(protocol::tool_input_schema_for<Args>())
70 .build();
71 detail::apply_default_output_schema<Result>(definition_);
72 }
73
75 : definition_(std::move(definition)) {}
76
77 TypedToolBuilder& title(std::string value) {
78 definition_.title = std::move(value);
79 return *this;
80 }
81
82 TypedToolBuilder& description(std::string value) {
83 definition_.description = std::move(value);
84 return *this;
85 }
86
87 TypedToolBuilder& input_schema(protocol::Json schema) {
88 definition_.input_schema = std::move(schema);
89 return *this;
90 }
91
92 template <class T>
93 TypedToolBuilder& input() {
94 return input_schema(protocol::tool_input_schema_for<T>());
95 }
96
97 TypedToolBuilder& output_schema(protocol::Json schema) {
98 definition_.output_schema = std::move(schema);
99 definition_.output_schema_present = true;
100 return *this;
101 }
102
103 template <class T>
104 TypedToolBuilder& output() {
105 return output_schema(protocol::tool_output_schema_for<T>());
106 }
107
108 TypedToolBuilder& streaming(bool value = true) {
109 definition_.streaming = value;
110 return *this;
111 }
112
113 TypedToolBuilder& icon(protocol::Icon value) {
114 definition_.icons.push_back(std::move(value));
115 return *this;
116 }
117
118 TypedToolBuilder& task_support(protocol::TaskSupport value) {
119 if (!definition_.execution.has_value()) {
120 definition_.execution = protocol::ToolExecution{};
121 }
122 definition_.execution->task_support = value;
123 return *this;
124 }
125
126 TypedToolBuilder& execution(protocol::ToolExecution value) {
127 definition_.execution = std::move(value);
128 return *this;
129 }
130
131 TypedToolBuilder& annotations(protocol::Json value) {
132 definition_.annotations = std::move(value);
133 return *this;
134 }
135
136 TypedToolBuilder& meta(protocol::Json value) {
137 definition_.meta = std::move(value);
138 return *this;
139 }
140
141 template <class Handler>
142 TypedToolRegistration<Args, Result, Handler> handler(Handler value) {
143 detail::require_callable(value, "tool");
144 detail::require_unambiguous_tool_handler<Handler, Args>();
145 return TypedToolRegistration<Args, Result, Handler>{std::move(definition_),
146 std::move(value)};
147 }
148
149 private:
150 protocol::ToolDefinition definition_;
151};
152
154template <class Args, class Result>
155inline TypedToolBuilder<Args, Result> tool(std::string name) {
156 return TypedToolBuilder<Args, Result>(std::move(name));
157}
158
165template <class Tool>
166inline auto tool(Tool value) {
167 using Args = typename Tool::Args;
168 using Result = typename Tool::Result;
169 auto definition = [&]() {
171 return value.definition();
172 } else {
173 auto built =
174 protocol::tool_definition(detail::static_tool_text<Tool>(Tool::name))
175 .build();
177 built.title = detail::static_tool_text<Tool>(Tool::title);
178 }
180 built.description = detail::static_tool_text<Tool>(Tool::description);
181 }
182 return built;
183 }
184 }();
185 if (definition.input_schema.empty()) {
186 definition.input_schema = protocol::tool_input_schema_for<Args>();
187 }
188 detail::apply_default_output_schema<Result>(definition);
189 TypedToolBuilder<Args, Result> builder(std::move(definition));
190 return builder.handler(std::move(value));
191}
192
195template <class Tool>
196inline auto tool() {
197 return tool(Tool{});
198}
199
201template <class Args, class Handler>
203 protocol::Prompt prompt;
204 Handler handler;
205};
206
208template <class Args>
210 public:
211 explicit TypedPromptBuilder(protocol::Prompt prompt)
212 : prompt_(std::move(prompt)) {}
213
214 explicit TypedPromptBuilder(std::string name) {
215 prompt_ = protocol::prompt_definition(std::move(name)).build();
216 }
217
218 TypedPromptBuilder& title(std::string value) {
219 prompt_.title = std::move(value);
220 return *this;
221 }
222
223 TypedPromptBuilder& description(std::string value) {
224 prompt_.description = std::move(value);
225 return *this;
226 }
227
228 TypedPromptBuilder& argument(std::string name, bool required = false,
229 std::string description = {}) {
231 argument.name = std::move(name);
232 argument.required = required;
233 argument.required_present = true;
234 argument.description = std::move(description);
235 prompt_.arguments.push_back(std::move(argument));
236 return *this;
237 }
238
240 prompt_.icons.push_back(std::move(value));
241 return *this;
242 }
243
244 TypedPromptBuilder& annotations(protocol::Json value) {
245 prompt_.annotations = std::move(value);
246 return *this;
247 }
248
250 prompt_.meta = std::move(value);
251 return *this;
252 }
253
254 template <class Handler>
255 TypedPromptRegistration<Args, Handler> handler(Handler value) {
256 detail::require_callable(value, "prompt");
257 detail::require_unambiguous_typed_context_handler<Handler, Args,
258 PromptContext>("prompt");
259 return TypedPromptRegistration<Args, Handler>{std::move(prompt_),
260 std::move(value)};
261 }
262
263 private:
264 protocol::Prompt prompt_;
265};
266
267template <class Args>
268inline TypedPromptBuilder<Args> prompt(std::string name) {
269 return TypedPromptBuilder<Args>(std::move(name));
270}
271
272template <class Args>
273inline TypedPromptBuilder<Args> prompt(protocol::Prompt prompt) {
274 return TypedPromptBuilder<Args>(std::move(prompt));
275}
276
278template <class Args, class Handler>
280 protocol::Resource resource;
281 Handler handler;
282};
283
285template <class Args>
287 public:
289 : resource_(std::move(resource)) {}
290
291 TypedResourceBuilder(std::string uri, std::string name) {
292 resource_ =
293 protocol::resource_definition(std::move(uri), std::move(name)).build();
294 }
295
296 TypedResourceBuilder& title(std::string value) {
297 resource_.title = std::move(value);
298 return *this;
299 }
300
301 TypedResourceBuilder& description(std::string value) {
302 resource_.description = std::move(value);
303 return *this;
304 }
305
306 TypedResourceBuilder& mime_type(std::string value) {
307 resource_.mime_type = std::move(value);
308 return *this;
309 }
310
311 TypedResourceBuilder& size(std::int64_t value) {
312 resource_.size = value;
313 return *this;
314 }
315
317 resource_.icons.push_back(std::move(value));
318 return *this;
319 }
320
321 TypedResourceBuilder& annotations(protocol::Json value) {
322 resource_.annotations = std::move(value);
323 return *this;
324 }
325
327 resource_.meta = std::move(value);
328 return *this;
329 }
330
331 template <class Handler>
332 TypedResourceRegistration<Args, Handler> handler(Handler value) {
333 detail::require_callable(value, "resource");
334 detail::require_unambiguous_typed_context_handler<Handler, Args,
336 "resource");
337 return TypedResourceRegistration<Args, Handler>{std::move(resource_),
338 std::move(value)};
339 }
340
341 private:
342 protocol::Resource resource_;
343};
344
345template <class Args>
346inline TypedResourceBuilder<Args> resource(std::string uri, std::string name) {
347 return TypedResourceBuilder<Args>(std::move(uri), std::move(name));
348}
349
350template <class Args>
351inline TypedResourceBuilder<Args> resource(protocol::Resource resource) {
352 return TypedResourceBuilder<Args>(std::move(resource));
353}
354
355inline protocol::ResourceTemplateBuilder resource_template(
356 std::string uri_template, std::string name) {
357 return protocol::resource_template_definition(std::move(uri_template),
358 std::move(name));
359}
360
365class App {
366 public:
368 class Builder {
369 public:
371 Builder& name(std::string value);
372
374 Builder& version(std::string value);
375
377 Builder& instructions(std::string value);
378
381
382#if defined(CXXMCP_ENABLE_HTTP)
387 Builder& streamable_http(std::string host, std::uint16_t port,
388 std::string path = "/mcp");
389
394 Builder& legacy_sse(std::string host, std::uint16_t port,
395 std::string path = "/mcp");
396#endif
397
400 Builder& transport(std::unique_ptr<Transport> value);
401
404
407 std::shared_ptr<const JsonSchemaValidator> validator);
408
418 template <class Args, class Result, class Handler>
419 Builder& tool(std::string name, Handler handler);
420
422 template <class Args, class Result, class Handler>
423 Builder& tool(protocol::ToolDefinition definition, Handler handler);
424
426 template <class Args, class Result, class Handler>
428
431
439 template <class Args, class Handler>
440 Builder& prompt(std::string name, Handler handler);
441
442 template <class Handler>
443 Builder& prompt(std::string name, Handler handler);
444
447
456 template <class Args, class Handler>
457 Builder& resource(std::string name, Handler handler);
458
459 template <class Handler>
460 Builder& resource(std::string name, Handler handler);
461
464
472 template <class Handler>
473 Builder& resource_template(std::string name, Handler handler);
474
477
479 template <class Handler>
480 Builder& completion(Handler handler);
481
483 template <class Handler>
484 Builder& sampling(Handler handler);
485
487 template <class Handler>
488 Builder& logging(Handler handler);
489
494 template <class Handler>
495 Builder& raw_request(Handler handler);
496
499
501 int run();
502
503 private:
504 ServerBuilder builder_;
505 };
506
508 CXXMCP_COMPAT_DEPRECATED("use ServerPeer::builder() instead")
509 static Builder builder();
510};
511
512template <class Args, class Result, class Handler>
513App::Builder& App::Builder::tool(std::string name, Handler handler) {
514 detail::require_callable(handler, "tool");
515 detail::require_unambiguous_tool_handler<Handler, Args>();
516 auto definition = protocol::tool_definition(std::move(name))
517 .input_schema(protocol::tool_input_schema_for<Args>())
518 .build();
519 detail::apply_default_output_schema<Result>(definition);
520 return tool<Args, Result>(std::move(definition), std::move(handler));
521}
522
523template <class Args, class Result, class Handler>
525 Handler handler) {
526 detail::require_callable(handler, "tool");
527 detail::require_unambiguous_tool_handler<Handler, Args>();
528 if (definition.input_schema.empty()) {
529 definition.input_schema = protocol::tool_input_schema_for<Args>();
530 }
531 detail::apply_default_output_schema<Result>(definition);
532 return tool(
533 std::move(definition),
534 [handler = std::move(handler)](
535 const ToolContext& context) -> core::Result<protocol::ToolResult> {
536 try {
537 auto args = detail::argument_from_json<Args>(context.arguments);
538 auto handled =
539 detail::invoke_tool_handler(handler, std::move(args), context);
540 if constexpr (detail::is_result<decltype(handled)>::value) {
541 if (!handled) {
542 return mcp::core::unexpected(handled.error());
543 }
544 return detail::value_to_tool_result(*handled);
545 } else {
546 return detail::value_to_tool_result(std::move(handled));
547 }
548 } catch (const std::exception& exception) {
549 return mcp::core::unexpected(core::Error{
550 static_cast<int>(protocol::ErrorCode::InvalidParams),
551 "failed to decode tool arguments",
552 exception.what(),
553 });
554 }
555 });
556}
557
558template <class Args, class Result, class Handler>
559App::Builder& App::Builder::tool(
560 TypedToolRegistration<Args, Result, Handler> registration) {
561 return tool<Args, Result>(std::move(registration.definition),
562 std::move(registration.handler));
563}
564
565template <class Args, class Handler>
566App::Builder& App::Builder::prompt(std::string name, Handler handler) {
567 detail::require_callable(handler, "prompt");
568 detail::require_unambiguous_typed_context_handler<Handler, Args,
569 PromptContext>("prompt");
570 protocol::Prompt prompt;
571 prompt.name = std::move(name);
572 return this->prompt(
573 std::move(prompt),
574 [handler = std::move(handler)](const PromptContext& context)
575 -> core::Result<protocol::PromptsGetResult> {
576 try {
577 auto args = context.arguments.get<Args>();
578 auto handled = detail::invoke_typed_context_handler(
579 handler, std::move(args), context);
580 if constexpr (detail::is_result<decltype(handled)>::value) {
581 if (!handled) {
582 return mcp::core::unexpected(handled.error());
583 }
584 return detail::value_to_prompt_result(*handled);
585 } else {
586 return detail::value_to_prompt_result(std::move(handled));
587 }
588 } catch (const std::exception& exception) {
589 return mcp::core::unexpected(core::Error{
590 static_cast<int>(protocol::ErrorCode::InvalidParams),
591 "failed to decode prompt arguments",
592 exception.what(),
593 });
594 }
595 });
596}
597
598template <class Handler>
599App::Builder& App::Builder::prompt(std::string name, Handler handler) {
600 detail::require_callable(handler, "prompt");
601 detail::require_unambiguous_prompt_handler<Handler>();
602 protocol::Prompt prompt;
603 prompt.name = std::move(name);
604 return this->prompt(
605 std::move(prompt),
606 [handler = std::move(handler)](const PromptContext& context)
607 -> core::Result<protocol::PromptsGetResult> {
608 try {
609 auto handled = detail::invoke_prompt_handler(handler, context);
610 if constexpr (detail::is_result<decltype(handled)>::value) {
611 if (!handled) {
612 return mcp::core::unexpected(handled.error());
613 }
614 return detail::value_to_prompt_result(*handled);
615 } else {
616 return detail::value_to_prompt_result(std::move(handled));
617 }
618 } catch (const std::exception& exception) {
619 return mcp::core::unexpected(core::Error{
620 static_cast<int>(protocol::ErrorCode::InvalidParams),
621 "failed to run prompt handler",
622 exception.what(),
623 });
624 }
625 });
626}
627
628template <class Args, class Handler>
629App::Builder& App::Builder::resource(std::string name, Handler handler) {
630 detail::require_callable(handler, "resource");
631 detail::require_unambiguous_typed_context_handler<Handler, Args,
632 ResourceContext>(
633 "resource");
634 protocol::Resource resource;
635 resource.uri = std::move(name);
636 resource.name = resource.uri;
637 return this->resource(
638 std::move(resource),
639 [handler = std::move(handler)](const ResourceContext& context)
640 -> core::Result<protocol::ResourcesReadResult> {
641 try {
642 auto args = context.params.get<Args>();
643 auto handled = detail::invoke_typed_context_handler(
644 handler, std::move(args), context);
645 if constexpr (detail::is_result<decltype(handled)>::value) {
646 if (!handled) {
647 return mcp::core::unexpected(handled.error());
648 }
649 return detail::value_to_resource_read_result(*handled, context.uri);
650 } else {
651 return detail::value_to_resource_read_result(std::move(handled),
652 context.uri);
653 }
654 } catch (const std::exception& exception) {
655 return mcp::core::unexpected(core::Error{
656 static_cast<int>(protocol::ErrorCode::InvalidParams),
657 "failed to decode resource parameters",
658 exception.what(),
659 });
660 }
661 });
662}
663
664template <class Handler>
665App::Builder& App::Builder::resource(std::string name, Handler handler) {
666 detail::require_callable(handler, "resource");
667 detail::require_unambiguous_resource_handler<Handler>();
668 protocol::Resource resource;
669 resource.uri = std::move(name);
670 resource.name = resource.uri;
671 if constexpr (std::is_invocable_v<Handler>) {
672 using Handled = decltype(handler());
673 if constexpr (std::is_same_v<std::decay_t<Handled>, protocol::Resource>) {
674 resource = handler();
675 }
676 }
677 return this->resource(
678 std::move(resource),
679 [handler = std::move(handler)](const ResourceContext& context)
680 -> core::Result<protocol::ResourcesReadResult> {
681 try {
682 auto handled = detail::invoke_resource_handler(handler, context);
683 if constexpr (std::is_same_v<std::decay_t<decltype(handled)>,
684 protocol::Resource>) {
685 return protocol::ResourcesReadResult{};
686 } else if constexpr (detail::is_result<decltype(handled)>::value) {
687 if (!handled) {
688 return mcp::core::unexpected(handled.error());
689 }
690 return detail::value_to_resource_read_result(*handled, context.uri);
691 } else {
692 return detail::value_to_resource_read_result(std::move(handled),
693 context.uri);
694 }
695 } catch (const std::exception& exception) {
696 return mcp::core::unexpected(core::Error{
697 static_cast<int>(protocol::ErrorCode::InvalidParams),
698 "failed to run resource handler",
699 exception.what(),
700 });
701 }
702 });
703}
704
705template <class Handler>
706App::Builder& App::Builder::resource_template(std::string name,
707 Handler handler) {
708 detail::require_callable(handler, "resource_template");
709 protocol::ResourceTemplate resource_template;
710 if constexpr (std::is_invocable_v<Handler>) {
711 auto handled = handler();
712 if constexpr (detail::is_result<decltype(handled)>::value) {
713 if (!handled) {
714 throw std::runtime_error(handled.error().message);
715 }
716 resource_template = *handled;
717 } else {
718 resource_template = std::move(handled);
719 }
720 } else if constexpr (std::is_invocable_v<Handler, std::string>) {
721 resource_template = handler({});
722 } else {
723 static_assert(
724 std::is_invocable_v<Handler>,
725 "resource_template handler must accept no arguments or string");
726 }
727 if (resource_template.name.empty()) {
728 resource_template.name = name;
729 }
730 if (resource_template.uri_template.empty()) {
731 resource_template.uri_template = std::move(name);
732 }
733 return this->resource_template(std::move(resource_template));
734}
735
736template <class Handler>
737App::Builder& App::Builder::completion(Handler handler) {
738 detail::require_callable(handler, "completion");
739 if constexpr (detail::is_typed_completion_handler_v<Handler>) {
740 detail::require_unambiguous_completion_handler<Handler>();
741 } else {
742 detail::require_unambiguous_json_extension_handler<Handler>();
743 }
744 builder_.on_completion(
745 [handler = std::move(handler)](const protocol::Json& request,
746 const SessionContext& context,
747 CancellationToken cancellation) mutable
748 -> core::Result<protocol::Json> {
749 if constexpr (detail::is_typed_completion_handler_v<Handler>) {
750 const auto params = protocol::complete_params_from_json(request);
751 if (!params) {
752 return mcp::core::unexpected(core::Error{
753 static_cast<int>(protocol::ErrorCode::InvalidParams),
754 params.error().message, params.error().detail, "protocol"});
755 }
756 CompletionContext completion_context;
757 static_cast<SessionContext&>(completion_context) = context;
758 completion_context.params = *params;
759 completion_context.cancellation = cancellation;
760 auto handled =
761 detail::invoke_completion_handler(handler, completion_context);
762 return detail::completion_response_to_json(std::move(handled));
763 } else {
764 auto handled = detail::invoke_json_extension_handler(
765 handler, request, context, cancellation);
766 if constexpr (detail::is_result<decltype(handled)>::value) {
767 return handled;
768 } else {
769 return detail::value_to_json(std::move(handled));
770 }
771 }
772 });
773 return *this;
774}
775
776template <class Handler>
777App::Builder& App::Builder::sampling(Handler handler) {
778 detail::require_callable(handler, "sampling");
779 detail::require_unambiguous_json_extension_handler<Handler>();
780 builder_.on_sampling(
781 [handler = std::move(handler)](const protocol::Json& request,
782 const SessionContext& context,
783 CancellationToken cancellation) mutable
784 -> core::Result<protocol::Json> {
785 auto handled = detail::invoke_json_extension_handler(
786 handler, request, context, cancellation);
787 if constexpr (detail::is_result<decltype(handled)>::value) {
788 return handled;
789 } else {
790 return detail::value_to_json(std::move(handled));
791 }
792 });
793 return *this;
794}
795
796template <class Handler>
797App::Builder& App::Builder::logging(Handler handler) {
798 detail::require_callable(handler, "logging");
799 builder_.on_logging([handler = std::move(handler)](std::string_view level,
800 std::string_view message) {
801 handler(level, message);
802 });
803 return *this;
804}
805
806template <class Handler>
807App::Builder& App::Builder::raw_request(Handler handler) {
808 detail::require_callable(handler, "raw_request");
809 builder_.on_raw_request([handler = std::move(handler)](
810 const protocol::JsonRpcRequest& request,
811 const SessionContext& context)
812 -> std::optional<protocol::JsonRpcResponse> {
813 (void)context;
814 if constexpr (std::is_same_v<std::decay_t<decltype(handler(request))>,
815 std::optional<protocol::JsonRpcResponse>>) {
816 return handler(request);
817 } else if constexpr (std::is_same_v<
818 std::decay_t<decltype(handler(request))>,
819 protocol::JsonRpcResponse>) {
820 return handler(request);
821 } else {
822 handler(request);
823 return std::nullopt;
824 }
825 });
826 return *this;
827}
828
829} // namespace mcp::server
TypedToolBuilder< Args, Result > tool(std::string name)
Starts a typed tool registration builder.
Definition authoring.hpp:155
Higher-level server builder with callable adapters.
Definition authoring.hpp:368
Builder & tool(std::string name, Handler handler)
Registers a tool using a typed argument adapter.
Builder & transport(std::unique_ptr< Transport > value)
Adds a caller-supplied transport.
Builder & tasks(TaskOperationProcessorOptions options={})
Enables server-side task processing for task-aware tools.
Builder & raw_request(Handler handler)
Registers a raw request hook adapter.
Builder & instructions(std::string value)
Sets the advertised server instructions.
Builder & completion(Handler handler)
Registers a completion request handler adapter.
Builder & resource_template(protocol::ResourceTemplate resource_template)
Registers a fully described resource template.
core::Result< std::unique_ptr< Server > > build()
Builds the configured server.
Builder & schema_validator(std::shared_ptr< const JsonSchemaValidator > validator)
Installs an optional JSON Schema validator.
Builder & sampling(Handler handler)
Registers a sampling request handler adapter.
Builder & tool(protocol::ToolDefinition definition, Handler handler)
Registers a typed callable using an explicit tool definition.
Builder & tool(TypedToolRegistration< Args, Result, Handler > registration)
Registers a typed tool registration built by mcp::server::tool().
int run()
Builds, starts, and runs the configured server application.
Builder & stdio()
Adds a stdio server transport.
Builder & prompt(std::string name, Handler handler)
Registers a prompt using a callable adapter.
Builder & resource_template(std::string name, Handler handler)
Registers a resource template using a callable adapter.
Builder & logging(Handler handler)
Registers a logging notification handler adapter.
Builder & prompt(protocol::Prompt prompt, PromptHandler handler)
Registers a fully described prompt and low-level handler.
Builder & resource(protocol::Resource resource, ResourceReadHandler handler)
Registers a fully described resource and low-level read handler.
Builder & tool(protocol::ToolDefinition definition, ToolHandler handler)
Registers a fully described tool and low-level handler.
Builder & resource(std::string name, Handler handler)
Registers a resource using a callable adapter.
Builder & version(std::string value)
Sets the advertised server version.
Builder & name(std::string value)
Sets the advertised server name.
Convenience entry point for compact server applications.
Definition authoring.hpp:365
static Builder builder()
Creates a new convenience server builder.
Fluent builder for constructing a configured Server.
Definition server.hpp:571
Fluent typed prompt builder for low-boilerplate server authoring.
Definition authoring.hpp:209
Fluent typed resource builder for low-boilerplate server authoring.
Definition authoring.hpp:286
Fluent typed tool builder for low-boilerplate server authoring.
Definition authoring.hpp:65
Public SDK configuration and compatibility markers.
#define CXXMCP_COMPAT_DEPRECATED(message)
Marks compatibility-only APIs as deprecated when explicitly enabled.
Definition config.hpp:39
Internal handler dispatch helpers for cxxmcp server authoring APIs.
std::function< core::Result< protocol::ToolResult >(const ToolContext &)> ToolHandler
Application callback that executes a tool.
Definition handler_types.hpp:21
std::function< core::Result< protocol::ResourcesReadResult >(const ResourceContext &)> ResourceReadHandler
Application callback that reads a resource.
Definition handler_types.hpp:32
std::function< core::Result< protocol::PromptsGetResult >(const PromptContext &)> PromptHandler
Application callback that renders a prompt.
Definition handler_types.hpp:26
nlohmann::json Json
JSON value type used by all protocol DTOs.
Definition types.hpp:28
tl::expected< T, Error > Result
Alias for the SDK result type.
Definition result.hpp:64
constexpr auto unexpected(E &&value)
Creates an unexpected result value for the active expected backend.
Definition result.hpp:24
High-level server compatibility API, builder, and convenience app API.
Icon descriptor used by tools, resources, resource templates, and prompts.
Definition types.hpp:160
Argument accepted by a prompt template.
Definition prompt.hpp:63
std::string name
Stable argument name used as a key in prompts/get arguments.
Definition prompt.hpp:67
bool required
Whether the caller must provide this argument.
Definition prompt.hpp:71
bool required_present
Whether required was explicitly present on the wire or configured.
Definition prompt.hpp:73
std::string description
Optional human-readable description.
Definition prompt.hpp:69
Prompt descriptor returned by prompts/list.
Definition prompt.hpp:83
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition prompt.hpp:97
std::string description
Optional human-readable description.
Definition prompt.hpp:89
std::vector< Icon > icons
Optional icon descriptors for client presentation.
Definition prompt.hpp:93
std::vector< PromptArgument > arguments
Prompt arguments accepted by this prompt.
Definition prompt.hpp:91
std::string title
Optional human-readable display title.
Definition prompt.hpp:85
Json annotations
Optional annotations for model or client presentation.
Definition prompt.hpp:95
URI template advertised by resources/templates/list.
Definition resource.hpp:127
Concrete resource advertised by resources/list.
Definition resource.hpp:28
std::string title
Optional human-readable display title.
Definition resource.hpp:30
std::string mime_type
Optional MIME type for the resource contents.
Definition resource.hpp:38
std::string description
Optional human-readable description.
Definition resource.hpp:36
Json annotations
Optional annotations for model or client presentation.
Definition resource.hpp:44
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition resource.hpp:46
std::optional< std::int64_t > size
Optional size hint in bytes when known.
Definition resource.hpp:40
std::vector< Icon > icons
Optional icon descriptors for client presentation.
Definition resource.hpp:42
Metadata describing a callable MCP tool.
Definition tool.hpp:213
Json input_schema
JSON Schema object describing accepted arguments.
Definition tool.hpp:221
std::optional< ToolExecution > execution
Optional execution configuration including task support mode.
Definition tool.hpp:231
Json output_schema
Optional JSON Schema object describing structured result content.
Definition tool.hpp:223
std::string title
Optional human-readable display title.
Definition tool.hpp:215
Json annotations
Optional raw annotations preserved for forward-compatible round trips.
Definition tool.hpp:235
std::vector< Icon > icons
Optional icon descriptors for client presentation.
Definition tool.hpp:229
bool output_schema_present
Whether output_schema was explicitly present on the wire or configured.
Definition tool.hpp:225
std::string description
Human-readable tool description.
Definition tool.hpp:219
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition tool.hpp:237
bool streaming
Whether the tool may stream partial results outside a single response.
Definition tool.hpp:227
Execution configuration advertised with a tool definition.
Definition tool.hpp:44
Invocation context passed to prompt handlers.
Definition context.hpp:56
Invocation context passed to resource read handlers.
Definition context.hpp:70
Options for the SDK server task processor.
Definition task_manager.hpp:35
Typed prompt registration produced by mcp::server::prompt().
Definition authoring.hpp:202
Typed resource registration produced by mcp::server::resource().
Definition authoring.hpp:279
Typed tool registration produced by mcp::server::tool().
Definition authoring.hpp:58
Definition authoring.hpp:38
Definition authoring.hpp:25
TaskSupport
Per-tool support mode for task-based invocation.
Definition tool.hpp:34