|
Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
|
Files | |
| file | mcp_server.h |
| Model Context Protocol (MCP) Server API. | |
Data Structures | |
| struct | mcp_tool_metadata |
| Tool metadata structure. More... | |
| struct | mcp_tool_record |
| Tool definition structure. More... | |
| Message sent from a tool (response/notification). More... | |
Typedefs | |
| typedef void * | mcp_server_ctx_t |
| Server context handle. | |
| typedef int(* | mcp_tool_callback_t) (enum mcp_tool_event_type event, const char *arguments, const char *execution_token) |
| Tool callback function. | |
Enumerations | |
| enum | mcp_tool_msg_type { MCP_USR_TOOL_RESPONSE , MCP_USR_TOOL_NOTIFICATION , MCP_USR_TOOL_CANCEL_ACK , MCP_USR_TOOL_PING } |
| MCP Tool message type. More... | |
| enum | mcp_tool_event_type { MCP_TOOL_CALL_REQUEST , MCP_TOOL_CANCEL_REQUEST } |
| MCP Tool event type. More... | |
Functions | |
| mcp_server_ctx_t | mcp_server_init (void) |
| Initialize the MCP Server. | |
| int | mcp_server_start (mcp_server_ctx_t server_ctx) |
| Start the MCP Server. | |
| 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_add_tool (mcp_server_ctx_t server_ctx, const struct mcp_tool_record *tool_record) |
| Add a tool to the server. | |
| int | mcp_server_remove_tool (mcp_server_ctx_t server_ctx, const char *tool_name) |
| Remove a tool from the server. | |
| 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. | |
| typedef void* mcp_server_ctx_t |
#include <zephyr/net/mcp/mcp_server.h>
Server context handle.
| typedef int(* mcp_tool_callback_t) (enum mcp_tool_event_type event, const char *arguments, const char *execution_token) |
#include <zephyr/net/mcp/mcp_server.h>
Tool callback function.
| event | Type of tool event (call or cancel request) |
| arguments | JSON string with tool parameters |
| execution_token | Unique execution identifier (UUID string) |
Consider using heap allocation for large buffers to minimize stack usage.
This callback blocks an MCP server worker thread. For long-running operations, it is recommended to use your own thread pool to execute the work asynchronously and return quickly from this callback to avoid blocking the MCP server worker thread and potentially degrading server responsiveness.
It is up to the user application whether it allows concurrent executions of the same tool or not.
| enum mcp_tool_event_type |
#include <zephyr/net/mcp/mcp_server.h>
MCP Tool event type.
| Enumerator | |
|---|---|
| MCP_TOOL_CALL_REQUEST | JSON-RPC request calling the tool. |
| MCP_TOOL_CANCEL_REQUEST | Tool cancellation request. |
| enum mcp_tool_msg_type |
#include <zephyr/net/mcp/mcp_server.h>
MCP Tool message type.
| int mcp_server_add_tool | ( | mcp_server_ctx_t | server_ctx, |
| const struct mcp_tool_record * | tool_record ) |
#include <zephyr/net/mcp/mcp_server.h>
Add a tool to the server.
| server_ctx | Server context handle |
| tool_record | Tool definition with metadata and callback |
| -EINVAL | Invalid tool_record |
| -EEXIST | Tool name already exists |
| -ENOSPC | Registry full |
| mcp_server_ctx_t mcp_server_init | ( | void | ) |
#include <zephyr/net/mcp/mcp_server.h>
Initialize the MCP Server.
| int mcp_server_is_execution_canceled | ( | mcp_server_ctx_t | server_ctx, |
| const char * | execution_token, | ||
| bool * | is_canceled ) |
#include <zephyr/net/mcp/mcp_server.h>
Helper for checking the execution state of a tool.
| server_ctx | Server context handle |
| execution_token | Token representing the execution (UUID string) |
| is_canceled | Pointer to store cancellation state |
| -EINVAL | Invalid tool name |
| -ENOENT | Tool not found |
| int mcp_server_remove_tool | ( | mcp_server_ctx_t | server_ctx, |
| const char * | tool_name ) |
#include <zephyr/net/mcp/mcp_server.h>
Remove a tool from the server.
| server_ctx | Server context handle |
| tool_name | Name of tool to remove |
| -EINVAL | Invalid tool name |
| -ENOENT | Tool not found |
| -EBUSY | Tool is being executed and can't be removed (try again later) |
| int mcp_server_start | ( | mcp_server_ctx_t | server_ctx | ) |
#include <zephyr/net/mcp/mcp_server.h>
Start the MCP Server.
| server_ctx | Server context handle |
| int mcp_server_submit_tool_message | ( | mcp_server_ctx_t | server_ctx, |
| const struct mcp_tool_message * | user_msg, | ||
| const char * | execution_token ) |
#include <zephyr/net/mcp/mcp_server.h>
Submit a message from a tool (response/notification).
| server_ctx | Server context handle |
| user_msg | Application message to submit |
| execution_token | Execution token for tracking (UUID string) |