CMSIS-MCP  Version 0.0.0
Embedded MCP server with serial transport
 
Loading...
Searching...
No Matches
mcp.h
Go to the documentation of this file.
1
5
28
53#ifndef mcp_h
54#define mcp_h
55#include <stddef.h>
56#include <c_mcp_config.h>
57#ifdef __cplusplus
58extern "C" {
59#endif
60
72
75#define MCP_PARSE_ERROR (-32700)
78#define MCP_INVALID_REQUEST (-32600)
81#define MCP_METHOD_NOT_FOUND (-32601)
84#define MCP_INVALID_PARAMS (-32602)
87#define MCP_INTERNAL_ERROR (-32603)
90#define MCP_RESOURCE_NOT_FOUND (-32002)
91
94struct argument;
97struct tool;
100struct mcp_resource;
113typedef int (*mcp_resource_fn)(const char **returnMessage);
114
167extern struct mcp_resource *add_resource(const char *uri, const char *name,
168 const char *description, const char *mime_type, mcp_resource_fn callback);
178extern size_t mcp_resource_index_height(void);
188extern size_t mcp_resource_lookup_steps(void);
189
213typedef int (*mcp_tool_fn)(int argc, const char **returnMessage, const char **args);
227extern int set_tool_callback(struct tool *tool, mcp_tool_fn callback);
228
240extern struct tool *find_tool(const char *name);
252extern size_t mcp_tool_lookup_steps(void);
262extern size_t mcp_tool_index_height(void);
263
278extern int mcp_prepare(void);
293extern void *mcp_arena_alloc(size_t size);
308extern char *mcp_arena_strdup(const char *text);
318extern size_t mcp_arena_used(void);
330extern size_t mcp_arena_high_water(void);
345extern size_t mcp_heap_allocations(void);
346
363extern void dispatch(const char *line,int fd);
364
385typedef void (*mcp_send_fn)(const char *json, int fd);
403extern void dispatch_with_sender(const char *line, int fd, mcp_send_fn send);
434extern void add_argument(struct tool *tool,
435 const char *name,
436 enum type type,
437 const char *description);
438
513extern struct tool *add_tool(const char *name,
514 const char *description);
526extern void free_tools(void);
527
528#ifdef __cplusplus
529}
530#endif
531
532#endif
size_t mcp_resource_index_height(void)
Read the height of the resource-URI lookup index for diagnostics.
size_t mcp_tool_index_height(void)
Read the height of the tool-name lookup index for diagnostics.
size_t mcp_heap_allocations(void)
Count allocation attempts through the installed cJSON heap allocator.
size_t mcp_arena_high_water(void)
Read the arena's recorded high-water mark.
size_t mcp_arena_used(void)
Read current arena consumption, including alignment padding.
size_t mcp_resource_lookup_steps(void)
Read the comparison count of the latest resources/read lookup.
size_t mcp_tool_lookup_steps(void)
Read the comparison count of the latest tool-name lookup.
void(* mcp_send_fn)(const char *json, int fd)
Synchronous transport callback used by dispatch_with_sender().
Definition mcp.h:385
void dispatch_with_sender(const char *line, int fd, mcp_send_fn send)
Dispatch one JSON-RPC message through an application-provided sender.
void dispatch(const char *line, int fd)
Dispatch one JSON-RPC message through the default transport hook.
void * mcp_arena_alloc(size_t size)
Allocate aligned storage from the current request arena.
void free_tools(void)
Release tool/resource registries and cached responses; reopen registration.
int mcp_prepare(void)
Finish startup by caching discovery schemas and response templates.
char * mcp_arena_strdup(const char *text)
Copy a null-terminated string into the current request arena.
struct mcp_resource * add_resource(const char *uri, const char *name, const char *description, const char *mime_type, mcp_resource_fn callback)
Register an exact virtual URI and its read callback during startup.
int(* mcp_resource_fn)(const char **returnMessage)
Callback invoked when resources/read resolves a registered URI.
Definition mcp.h:113
int(* mcp_tool_fn)(int argc, const char **returnMessage, const char **args)
Callback invoked for a validated tools/call request.
Definition mcp.h:213
struct tool * add_tool(const char *name, const char *description)
Register a tool name and its client-visible description during startup.
void add_argument(struct tool *tool, const char *name, enum type type, const char *description)
Append one required argument to a tool's discovery schema.
int set_tool_callback(struct tool *tool, mcp_tool_fn callback)
Bind the callback invoked when a client calls a registered tool.
struct tool * find_tool(const char *name)
Look up a registered tool by exact, case-sensitive name.
type
JSON type used in a required argument's discovery schema.
Definition mcp.h:66
@ TYPE_STR
JSON string; callback receives decoded text.
Definition mcp.h:67
@ TYPE_FLOAT
Finite JSON number; callback receives numeric text.
Definition mcp.h:69
@ TYPE_BOOL
JSON boolean; callback receives "true" or "false".
Definition mcp.h:70
@ TYPE_INT
Finite integral JSON number; callback receives numeric text.
Definition mcp.h:68