CMSIS-MCP  Version 0.0.0
Embedded MCP server with serial transport
 
Loading...
Searching...
No Matches
mcp.h File Reference

Public API for the portable C MCP server. More...

#include <stddef.h>
#include <c_mcp_config.h>

Go to the source code of this file.

Macros

#define MCP_PARSE_ERROR   (-32700)
 JSON-RPC parse error: malformed JSON (-32700).
 
#define MCP_INVALID_REQUEST   (-32600)
 JSON-RPC invalid request: malformed envelope (-32600).
 
#define MCP_METHOD_NOT_FOUND   (-32601)
 JSON-RPC method not found (-32601).
 
#define MCP_INVALID_PARAMS   (-32602)
 JSON-RPC invalid parameters: missing, extra or invalid input (-32602).
 
#define MCP_INTERNAL_ERROR   (-32603)
 JSON-RPC internal error: allocation or callback failure (-32603).
 
#define MCP_RESOURCE_NOT_FOUND   (-32002)
 MCP resource not found: unregistered URI (-32002).
 

Typedefs

typedef int(* mcp_resource_fn) (const char **returnMessage)
 Callback invoked when resources/read resolves a registered URI.
 
typedef int(* mcp_tool_fn) (int argc, const char **returnMessage, const char **args)
 Callback invoked for a validated tools/call request.
 
typedef void(* mcp_send_fn) (const char *json, int fd)
 Synchronous transport callback used by dispatch_with_sender().
 

Enumerations

enum  type { TYPE_STR , TYPE_INT , TYPE_FLOAT , TYPE_BOOL }
 JSON type used in a required argument's discovery schema. More...
 

Functions

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.
 
size_t mcp_resource_index_height (void)
 Read the height of the resource-URI lookup index for diagnostics.
 
size_t mcp_resource_lookup_steps (void)
 Read the comparison count of the latest resources/read lookup.
 
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.
 
size_t mcp_tool_lookup_steps (void)
 Read the comparison count of the latest tool-name lookup.
 
size_t mcp_tool_index_height (void)
 Read the height of the tool-name lookup index for diagnostics.
 
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.
 
size_t mcp_arena_used (void)
 Read current arena consumption, including alignment padding.
 
size_t mcp_arena_high_water (void)
 Read the arena's recorded high-water mark.
 
size_t mcp_heap_allocations (void)
 Count allocation attempts through the installed cJSON heap allocator.
 
void dispatch (const char *line, int fd)
 Dispatch one JSON-RPC message through the default transport hook.
 
void dispatch_with_sender (const char *line, int fd, mcp_send_fn send)
 Dispatch one JSON-RPC message through an application-provided sender.
 
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.
 
struct tool * add_tool (const char *name, const char *description)
 Register a tool name and its client-visible description during startup.
 
void free_tools (void)
 Release tool/resource registries and cached responses; reopen registration.
 

Detailed Description

Public API for the portable C MCP server.