Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
mcp_server.h
Go to the documentation of this file.
1
8
9/*
10 * Copyright 2025 NXP
11 *
12 * SPDX-License-Identifier: Apache-2.0
13 */
14
15#ifndef ZEPHYR_INCLUDE_NET_MCP_SERVER_H_
16#define ZEPHYR_INCLUDE_NET_MCP_SERVER_H_
17
22
23#include <zephyr/kernel.h>
24#include <errno.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
39
47
52 char name[CONFIG_MCP_TOOL_NAME_MAX_LEN];
53 char input_schema[CONFIG_MCP_TOOL_SCHEMA_MAX_LEN];
54#ifdef CONFIG_MCP_TOOL_DESC
55 char description[CONFIG_MCP_TOOL_DESC_MAX_LEN];
56#endif
57#ifdef CONFIG_MCP_TOOL_TITLE
58 char title[CONFIG_MCP_TOOL_NAME_MAX_LEN];
59#endif
60#ifdef CONFIG_MCP_TOOL_OUTPUT_SCHEMA
61 char output_schema[CONFIG_MCP_TOOL_SCHEMA_MAX_LEN];
62#endif
63};
64
68typedef void *mcp_server_ctx_t;
69
93typedef int (*mcp_tool_callback_t)(enum mcp_tool_event_type event, const char *arguments,
94 const char *execution_token);
95
108
127
134
142
152 const struct mcp_tool_message *user_msg,
153 const char *execution_token);
154
165int mcp_server_add_tool(mcp_server_ctx_t server_ctx, const struct mcp_tool_record *tool_record);
166
180int mcp_server_remove_tool(mcp_server_ctx_t server_ctx, const char *tool_name);
181
196int mcp_server_is_execution_canceled(mcp_server_ctx_t server_ctx, const char *execution_token,
197 bool *is_canceled);
198
199#ifdef __cplusplus
200}
201#endif
202
203#endif /* ZEPHYR_INCLUDE_MCP_SERVER_H_ */
204
System error numbers.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:31
int mcp_server_remove_tool(mcp_server_ctx_t server_ctx, const char *tool_name)
Remove a tool from the server.
int mcp_server_add_tool(mcp_server_ctx_t server_ctx, const struct mcp_tool_record *tool_record)
Add a tool to the server.
void * mcp_server_ctx_t
Server context handle.
Definition mcp_server.h:68
mcp_tool_event_type
MCP Tool event type.
Definition mcp_server.h:43
int(* mcp_tool_callback_t)(enum mcp_tool_event_type event, const char *arguments, const char *execution_token)
Tool callback function.
Definition mcp_server.h:93
int mcp_server_start(mcp_server_ctx_t server_ctx)
Start the MCP Server.
mcp_server_ctx_t mcp_server_init(void)
Initialize the MCP Server.
mcp_tool_msg_type
MCP Tool message type.
Definition mcp_server.h:33
int mcp_server_submit_tool_message(mcp_server_ctx_t server_ctx, const struct mcp_tool_message *user_msg, const char *execution_token)
Submit a message from a tool (response/notification).
int mcp_server_is_execution_canceled(mcp_server_ctx_t server_ctx, const char *execution_token, bool *is_canceled)
Helper for checking the execution state of a tool.
@ MCP_TOOL_CALL_REQUEST
JSON-RPC request calling the tool.
Definition mcp_server.h:44
@ MCP_TOOL_CANCEL_REQUEST
Tool cancellation request.
Definition mcp_server.h:45
@ MCP_USR_TOOL_PING
Ping to signify the tool is alive to the MCP Core.
Definition mcp_server.h:37
@ MCP_USR_TOOL_RESPONSE
JSON-RPC response to a client request.
Definition mcp_server.h:34
@ MCP_USR_TOOL_NOTIFICATION
Tool to client notification.
Definition mcp_server.h:35
@ MCP_USR_TOOL_CANCEL_ACK
Cancellation acknowledgment to the MCP Core.
Definition mcp_server.h:36
Public kernel APIs.
Message sent from a tool (response/notification).
Definition mcp_server.h:121
void * data
Message data pointer.
Definition mcp_server.h:124
int length
Message length.
Definition mcp_server.h:123
bool is_error
Signifies if message is error.
Definition mcp_server.h:125
enum mcp_tool_msg_type type
Type of message.
Definition mcp_server.h:122
Tool metadata structure.
Definition mcp_server.h:51
char name[CONFIG_MCP_TOOL_NAME_MAX_LEN]
Tool name.
Definition mcp_server.h:52
char input_schema[CONFIG_MCP_TOOL_SCHEMA_MAX_LEN]
Tool input schema (JSON).
Definition mcp_server.h:53
Tool definition structure.
Definition mcp_server.h:103
atomic_t refcount
Internal refcount.
Definition mcp_server.h:105
mcp_tool_callback_t callback
Tool callback (tools/call).
Definition mcp_server.h:106
struct mcp_tool_metadata metadata
Tool metadata.
Definition mcp_server.h:104