Prepare persistent metadata and manage bounded request storage.
More...
|
| int | mcp_prepare (void) |
| | Finish startup by caching discovery schemas and response templates.
|
| |
| void * | mcp_arena_alloc (size_t size) |
| | Allocate aligned storage from the current request arena.
|
| |
| char * | mcp_arena_strdup (const char *text) |
| | Copy a null-terminated string into the current request arena.
|
| |
| void | free_tools (void) |
| | Release tool/resource registries and cached responses; reopen registration.
|
| |
Prepare persistent metadata and manage bounded request storage.
◆ free_tools()
Release tool/resource registries and cached responses; reopen registration.
Invalidates all handles. Borrowed registration strings are not freed. Repeated calls are safe; a call during dispatch is ignored. Arena high-water and cJSON heap-allocation counters are not reset.
- Example
void free_tools(void)
Release tool/resource registries and cached responses; reopen registration.
◆ mcp_arena_alloc()
| void * mcp_arena_alloc |
( |
size_t | size | ) |
|
|
extern |
Allocate aligned storage from the current request arena.
- Parameters
-
| [in] | size | Number of bytes; must be greater than zero. |
- Returns
- Borrowed storage, or NULL outside dispatch, for zero size or exhaustion.
Aligns for the core's scalar types. Exhaustion marks the request as failed; dispatch sends a bounded internal error and subsequent requests can recover. No individual free: reset occurs after the synchronous sender returns.
- Example
void * mcp_arena_alloc(size_t size)
Allocate aligned storage from the current request arena.
- See also
- add_resource for formatted text and allocation/error checks.
◆ mcp_arena_strdup()
| char * mcp_arena_strdup |
( |
const char * | text | ) |
|
|
extern |
Copy a null-terminated string into the current request arena.
- Parameters
-
| [in] | text | Source string; NULL is permitted. |
- Returns
- Borrowed copy including its null terminator, or NULL for NULL input, exhaustion or a call outside dispatch.
Follows the lifetime/exhaustion rules of mcp_arena_alloc().
- Example
return 0;
char * mcp_arena_strdup(const char *text)
Copy a null-terminated string into the current request arena.
#define MCP_INTERNAL_ERROR
JSON-RPC internal error: allocation or callback failure (-32603).
Definition mcp.h:87
◆ mcp_prepare()
Finish startup by caching discovery schemas and response templates.
- Returns
- 0 on success, including repeated calls after successful preparation; -1 for allocation/registration failure or an active unprepared request.
Successful preparation closes registration until free_tools(). Dispatch also prepares on first use. Explicit preparation lets startup detect errors before accepting requests. Installs process-wide cJSON hooks and uses the heap, not the request arena.
- Example
int mcp_prepare(void)
Finish startup by caching discovery schemas and response templates.