rokojori_action_library/Tools/mcp/JsonRpc.cs

45 lines
1.0 KiB
C#
Raw Normal View History

2026-10-03 12:15:58 +00:00
#if TOOLS
namespace Rokojori.Tools
{
using Rokojori;
public static class JsonRpc
{
public static JSONObject BuildResult( JSONData id, JSONData result )
{
var obj = new JSONObject();
obj.Set( "jsonrpc", "2.0" );
obj.Set( "id", id ?? new JSONValue() );
obj.Set( "result", result );
return obj;
}
public static JSONObject BuildError( JSONData id, int code, string message )
{
var error = new JSONObject();
error.Set( "code", (double) code );
error.Set( "message", message );
var obj = new JSONObject();
obj.Set( "jsonrpc", "2.0" );
obj.Set( "id", id ?? new JSONValue() );
obj.Set( "error", error );
return obj;
}
public static string GetMethod( JSONObject envelope )
{
var data = envelope.Get( "method" );
return data != null && data.isString ? data.stringValue : null;
}
public static bool IsNotification( JSONObject envelope )
{
return ! envelope.HasKey( "id" );
}
}
}
#endif