For the example server, the following code is used:
Resource metrics_resource;
metrics_resource.uri = "metrics://server/stats";
metrics_resource.name = "Server Metrics";
metrics_resource.description = mcp::make_optional(std::string("Server performance metrics and statistics"));
metrics_resource.mimeType = mcp::make_optional(std::string("application/json"));
server.registerResource(metrics_resource);
Calling
{
"method": "resources/read",
"params": {
"uri": "metrics://server/stats",
"_meta": {
"progressToken": 4
}
},
"jsonrpc": "2.0",
"id": 4
}
Results in:
{
"id": 4,
"jsonrpc": "2.0",
"result": {
"contentCount": 1,
"uri": "metrics://server/stats"
}
}
Which has 2 problems:
- the result of a resource read is an array and the contents of the object different according to the schema
- There is nowhere to plug in how to perform responses to resource read requests, so it would only work for http (which is handled by the client).
For the example server, the following code is used:
Calling
{ "method": "resources/read", "params": { "uri": "metrics://server/stats", "_meta": { "progressToken": 4 } }, "jsonrpc": "2.0", "id": 4 }Results in:
{ "id": 4, "jsonrpc": "2.0", "result": { "contentCount": 1, "uri": "metrics://server/stats" } }Which has 2 problems: