#include <stdio.h>
static unsigned sensor_value;
static int read_sensor(const char **message)
{
const size_t capacity = 48;
int n = snprintf(text, capacity, "sensor value %u", sensor_value);
if (n < 0 || (size_t)n >= capacity) {
*message = "Sensor response formatting failed";
}
*message = text;
return 0;
}
static int register_sensor(void)
{
#if C_MCP_ENABLE_VFS
"Latest sensor measurement", "text/plain", read_sensor)) return -1;
#endif
}
void * mcp_arena_alloc(size_t size)
Allocate aligned storage from the current request arena.
int mcp_prepare(void)
Finish startup by caching discovery schemas and response templates.
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.
#define MCP_INTERNAL_ERROR
JSON-RPC internal error: allocation or callback failure (-32603).
Definition mcp.h:87
Public API for the portable C MCP server.
Read this resource with: {"jsonrpc":"2.0","id":2,"method":"resources/read","params":{"uri":"sensor://board/value"}}