Skip to content

Commit 43cc365

Browse files
committed
networking: lifecycle
Basic steps towards lifecycle handling, starting with initialization Signed-off-by: David Piskula <david.piskula@nxp.com>
1 parent 1ed381d commit 43cc365

File tree

10 files changed

+854
-30
lines changed

10 files changed

+854
-30
lines changed

include/zephyr/net/mcp/mcp_server.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,30 @@
1313
extern "C" {
1414
#endif
1515

16+
struct mcp_message_msg {
17+
uint32_t token;
18+
/* More fields will be added later */
19+
};
20+
1621
/**
1722
* @brief Initialize the MCP Server.
1823
*
1924
*/
2025
int mcp_server_init(void);
2126

27+
/**
28+
* @brief Start the MCP Server.
29+
*
30+
*/
31+
int mcp_server_start(void);
32+
33+
/**
34+
* @brief Queues a response to the MCP Server library, which takes care of sending it to
35+
* the MCP Client.
36+
*
37+
*/
38+
int mcp_queue_response(void);
39+
2240
#ifdef __cplusplus
2341
}
2442
#endif

samples/net/mcp/mcp_server_hello_world/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
2727

2828
# Sufficient stack size for HTTP + JSON processing
2929
CONFIG_MAIN_STACK_SIZE=4096
30+
CONFIG_HEAP_MEM_POOL_SIZE=16384

samples/net/mcp/mcp_server_hello_world/src/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ LOG_MODULE_REGISTER(mcp_sample_hello, LOG_LEVEL_INF);
1313
int main(void)
1414
{
1515
printk("Hello World\n\r");
16+
printk("Initializing...\n\r");
1617
mcp_server_init();
18+
printk("Starting...\n\r");
19+
mcp_server_start();
1720
return 0;
1821
}

subsys/net/lib/mcp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
zephyr_library()
55

6+
zephyr_library_sources_ifdef(CONFIG_MCP_SERVER mcp_common.c)
67
zephyr_library_sources_ifdef(CONFIG_MCP_SERVER mcp_server.c)
78
zephyr_library_sources_ifdef(CONFIG_MCP_SERVER mcp_transport.c)
89
zephyr_library_sources_ifdef(CONFIG_MCP_SERVER mcp_json.c)

subsys/net/lib/mcp/Kconfig

Lines changed: 150 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,159 @@ menuconfig MCP_SERVER
55
bool "Model Context Protocol (MCP) Server support"
66
depends on NETWORKING && HTTP_SERVER && JSON_LIBRARY
77
help
8-
Enable support for MCP Server functionality.
8+
Support for MCP Server functionality.
99

1010
if MCP_SERVER
1111

12+
config HTTP_SERVER_MAX_CLIENTS
13+
int "Max number of HTTP/2 clients"
14+
default 3
15+
range 1 100
16+
help
17+
This setting determines the maximum number of HTTP/2 clients that the server can handle at once.
18+
19+
config HTTP_SERVER_MAX_STREAMS
20+
int "Max number of HTTP/2 streams"
21+
default 3
22+
range 1 100
23+
help
24+
This setting determines the maximum number of HTTP/2 streams for each client.
25+
26+
config MCP_SERVER_INFO_NAME_MAX_LEN
27+
int "Maximum server info name length"
28+
default 64
29+
help
30+
Maximum length for the server name field in serverInfo.
31+
32+
config MCP_SERVER_INFO_NAME
33+
string "Server name"
34+
default "Zephyr MCP Server"
35+
help
36+
The name of the MCP server reported in serverInfo.
37+
38+
config MCP_SERVER_INFO_VERSION_MAX_LEN
39+
int "Maximum server info version length"
40+
default 16
41+
help
42+
Maximum length for the server version field in serverInfo.
43+
44+
config MCP_SERVER_INFO_VERSION
45+
string "Server version"
46+
default "1.0.0"
47+
help
48+
The version of the MCP server reported in serverInfo.
49+
50+
config MCP_SERVER_INFO_TITLE
51+
bool "Include server title in serverInfo"
52+
default n
53+
help
54+
Include optional title field in the serverInfo section.
55+
56+
if MCP_SERVER_INFO_TITLE
57+
58+
config MCP_SERVER_INFO_TITLE_MAX_LEN
59+
int "Maximum server info title length"
60+
default 64
61+
help
62+
Maximum length for the server title field in serverInfo.
63+
64+
config MCP_SERVER_INFO_TITLE_VALUE
65+
string "Server title"
66+
default "Zephyr MCP Server"
67+
help
68+
The title of the MCP server reported in serverInfo.
69+
70+
endif # MCP_SERVER_INFO_TITLE
71+
72+
config MCP_SERVER_INFO_INSTRUCTIONS
73+
bool "Include server instructions in serverInfo"
74+
default n
75+
help
76+
Include optional instructions field in the serverInfo section.
77+
78+
if MCP_SERVER_INFO_INSTRUCTIONS
79+
80+
config MCP_SERVER_INFO_INSTRUCTIONS_MAX_LEN
81+
int "Maximum server info instructions length"
82+
default 256
83+
help
84+
Maximum length for the server instructions field in serverInfo.
85+
86+
config MCP_SERVER_INFO_INSTRUCTIONS_VALUE
87+
string "Server instructions"
88+
default "This is a Zephyr-based MCP server providing tool capabilities."
89+
help
90+
The instructions for the MCP server reported in serverInfo.
91+
92+
endif # MCP_SERVER_INFO_INSTRUCTIONS
93+
94+
config MCP_TOOLS_CAPABILITY
95+
bool "Tools capability"
96+
default y
97+
help
98+
Tools capability in the MCP server. This allows the server
99+
to register and execute tools via tools/list and tools/call methods.
100+
101+
if MCP_TOOLS_CAPABILITY
102+
103+
config MCP_MAX_TOOLS
104+
int "Maximum number of registered tools"
105+
default 4
106+
107+
config MCP_TOOL_NAME_MAX_LEN
108+
int "Maximum tool name length"
109+
default 32
110+
help
111+
Maximum length for tool name and title fields.
112+
113+
config MCP_TOOL_DESC
114+
bool "Include tool description in tools/list response"
115+
default n
116+
help
117+
Include optional description field in the tools/list response.
118+
119+
if MCP_TOOL_DESC
120+
121+
config MCP_TOOL_DESC_MAX_LEN
122+
int "Maximum tool description length"
123+
default 256
124+
help
125+
Maximum length for tool description field.
126+
127+
endif # MCP_TOOL_DESC
128+
129+
config MCP_TOOL_SCHEMA_MAX_LEN
130+
int "Maximum input/output schema length"
131+
default 512
132+
help
133+
Maximum length for tool input and output schema fields.
134+
135+
config MCP_TOOL_INPUT_ARGS_MAX_LEN
136+
int "Maximum input argument length"
137+
default 512
138+
help
139+
Maximum length for tool input arguments RPC field.
140+
141+
config MCP_TOOL_TITLE
142+
bool "Include tool title field"
143+
default n
144+
help
145+
Include optional title field for tools. Adds memory overhead.
146+
147+
config MCP_TOOL_OUTPUT_SCHEMA
148+
bool "Include tool output schema field"
149+
default n
150+
help
151+
Include optional output schema field for tools. Adds memory overhead.
152+
153+
config MCP_TOOL_RESULT_MAX_LEN
154+
int "Maximum tool execution result length"
155+
default 256
156+
help
157+
Maximum length for tool execution result.
158+
159+
endif # MCP_TOOLS_CAPABILITY
160+
12161
module = MCP
13162
module-str = MCP Server
14163
source "subsys/logging/Kconfig.template.log_config"

subsys/net/lib/mcp/mcp_common.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/logging/log.h>
9+
#include "mcp_common.h"
10+
11+
void *mcp_alloc(size_t size)
12+
{
13+
return k_malloc(size);
14+
}
15+
16+
void mcp_free(void *ptr)
17+
{
18+
k_free(ptr);
19+
}

0 commit comments

Comments
 (0)