master
c 91 lines 3.24 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 /**
4 * MCP Prompts Namespace
5 *
6 * The MCP Prompts namespace provides methods for managing prompts.
7 * In the MCP protocol, prompts are text templates that guide AI generation for specific tasks.
8 * Prompts are user-controlled interactions that leverage AI capabilities in predefined ways.
9 *
10 * Standard methods in the MCP specification:
11 *
12 * 1. prompts/list - Lists available prompts
13 * - Returns a collection of prompts the server offers
14 * - Includes prompt names, descriptions, and potentially argument information
15 * - Can be paginated for large prompt collections
16 *
17 * 2. prompts/get - Gets details about a specific prompt
18 * - Takes a prompt name and returns its full definition
19 * - Returns the prompt template, messages, and metadata
20 * - May include information about required arguments
21 *
22 * Prompts differ from tools in that they are:
23 * - More flexible and text-oriented
24 * - Designed for natural language processing
25 * - Often used for analysis and summarization
26 * - Usually invoked explicitly by users rather than by the model
27 *
28 * In the Netdata context, prompts might include:
29 * - Analyzing a time period of metrics for anomalies
30 * - Summarizing system health
31 * - Creating natural language explanations of charts
32 * - Helping users create custom alert configurations
33 * - Generating analysis reports
34 *
35 * Prompts typically use templating to insert user-provided context into predefined templates,
36 * making them powerful for specific analysis tasks while maintaining predictable outputs.
37 */
38
39 #include "mcp-prompts.h"
40
41 // Implementation of prompts/list (transport-agnostic)
42 static MCP_RETURN_CODE mcp_prompts_method_list(MCP_CLIENT *mcpc, struct json_object *params __maybe_unused, MCP_REQUEST_ID id __maybe_unused) {
43 if (!mcpc)
44 return MCP_RC_ERROR;
45
46 // Initialize success response
47 mcp_init_success_result(mcpc, id);
48
49 // Add an empty prompts array
50 buffer_json_member_add_array(mcpc->result, "prompts");
51 buffer_json_array_close(mcpc->result); // Close prompts array
52
53 // Close the result object
54 buffer_json_finalize(mcpc->result);
55
56 return MCP_RC_OK;
57 }
58
59 // Stub implementations for other prompts methods (transport-agnostic)
60
61 static MCP_RETURN_CODE mcp_prompts_method_get(MCP_CLIENT *mcpc, struct json_object *params __maybe_unused, MCP_REQUEST_ID id __maybe_unused) {
62 buffer_sprintf(mcpc->error, "Method 'prompts/get' not implemented yet");
63 return MCP_RC_NOT_IMPLEMENTED;
64 }
65
66
67
68
69
70 // Prompts namespace method dispatcher (transport-agnostic)
71 MCP_RETURN_CODE mcp_prompts_route(MCP_CLIENT *mcpc, const char *method, struct json_object *params, MCP_REQUEST_ID id) {
72 if (!mcpc || !method) return MCP_RC_INTERNAL_ERROR;
73
74 netdata_log_debug(D_MCP, "MCP prompts method: %s", method);
75
76 MCP_RETURN_CODE rc;
77
78 if (strcmp(method, "list") == 0) {
79 rc = mcp_prompts_method_list(mcpc, params, id);
80 }
81 else if (strcmp(method, "get") == 0) {
82 rc = mcp_prompts_method_get(mcpc, params, id);
83 }
84 else {
85 // Method not found in prompts namespace
86 buffer_sprintf(mcpc->error, "Method 'prompts/%s' not implemented yet", method);
87 rc = MCP_RC_NOT_IMPLEMENTED;
88 }
89
90 return rc;
91 }