Newtosoftから、System.Text.Jsonに移行しました。コパイによれば、
- .NET Framework 4.x で `System.Text.Json` を使う場合 → **必ず NuGet パッケージが必要**
とのことです。
確かに、「参照」で追加した場合、DLLの相互依存が複雑らしくて、トラブルの元になりそうでした。NuGetで追加するのが確実なようです。
Jsonスキーマは、内部で、
JsonNode schema = options.GetJsonSchemaAsNode(typeof(singleA));
var json = JsonSerializer.Serialize(schema, new System.Text.Json.JsonSerializerOptions {
WriteIndented = true
});
で生成させることが出来ました。
singleAというC#クラスが、スケジュールナース制約全体を表します。下図は、2020年当時の構成図になります。(現在は少しだけUpdateしていますが大まかには、変わりません。)
普段は、これをJsonにシリアライズして、最適化ソルバに渡して、ソルバが解を生成している訳です。で、このスキーマを生成させる仕組みが、上の記述です。
Python MCPでやりたいことは、各構成要素をAPIで、設定できるようにすることです。普段は、GUIで設定しているのですが、MCPサーバでも個々にできるようにする、ということになります。それだけを公開して、あとは、AIに頑張ってもらう、という発想です。
人がGUIで制約を記述するのをAIに肩代わりしてもらう、あるいは、プログラミングで、自動設定する、という目的のためでもあります。以前、予定セルのプログラミング入力を構想していたことがありましたが、その目的も兼ねています。
以下は、生成したJsonスキーマになります。
一言で言えば、Jsonのフォーマットということになるでしょうか。
例えば、最初の”SO”は、シフトオブジェクトのクラスを表しています。その次の”DO”は、Dayオブジェクトと言った具合です。
このオブジェクト群を読み込み、設定、追加、編集できるようにすることが目指しているMCPサーバになります。
生成されるJsonは、大きいと数MBを超えます。となるとAIモデルのトークン数の上限を簡単に超えてしまうことが懸念されます。しかし、その多くは、予定や、コメント、Python記述で、エッセンス部分ではありません。なので、エッセンス部分を残してハンドリングするようにすれば、なんとかなるのでは?と思っています。
{
"type": [
"object",
"null"
],
"properties": {
"SO": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"use": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"auto_schedule": {
"type": "boolean"
},
"color": {
"type": [
"string",
"null"
]
},
"label": {
"type": [
"string",
"null"
]
},
"another_labels": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"another_colors": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"num_cnt": {
"type": "integer"
},
"work_start_time": {
"type": [
"string",
"null"
]
},
"work_hours": {
"type": "integer"
}
}
}
}
}
},
"DO": {
"type": [
"object",
"null"
],
"properties": {
"days": {
"type": "integer"
},
"target_year": {
"type": "integer"
},
"target_month": {
"type": "integer"
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"val": {
"type": "integer"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"dates": {
"type": [
"array",
"null"
]
},
"use": {
"type": "boolean"
},
"predefined": {
"type": "boolean"
}
}
}
}
}
},
"DA": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"Operator": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"dates": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"use": {
"type": "boolean"
}
}
}
}
}
},
"SA": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"use": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"color": {
"type": [
"string",
"null"
]
},
"Operator": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"label": {
"type": [
"string",
"null"
]
}
}
}
}
}
},
"PA": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"shift_name": {
"type": [
"string",
"null"
]
},
"list": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"type": {
"type": "integer"
},
"name": {
"type": [
"string",
"null"
]
},
"time_string": {
"type": [
"string",
"null"
]
},
"color": {
"type": [
"string",
"null"
]
},
"day": {
"type": "integer"
},
"phase_no": {
"type": "integer"
}
}
}
}
}
}
},
"primary_labels": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"alias_labels": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"dayphase_list": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/properties/PA/properties/members/items/properties/list/items"
}
}
}
},
"TAA": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"use": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"color": {
"type": [
"string",
"null"
]
},
"Operator": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"label": {
"type": [
"string",
"null"
]
}
}
}
}
}
},
"TO": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"use": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"auto_schedule": {
"type": "boolean"
},
"color": {
"type": [
"string",
"null"
]
},
"label": {
"type": [
"string",
"null"
]
},
"shift_ag_name": {
"type": [
"string",
"null"
]
},
"another_labels": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"another_colors": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"work_hours": {
"type": "integer"
}
}
}
}
}
},
"PO": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"use": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"auto_schedule": {
"type": "boolean"
},
"color": {
"type": [
"string",
"null"
]
},
"label": {
"type": [
"string",
"null"
]
},
"num_cnt": {
"type": "integer"
},
"work_hours": {
"type": "integer"
},
"tasks": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
}
}
}
}
}
},
"POA": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"use": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"color": {
"type": [
"string",
"null"
]
},
"label": {
"type": [
"string",
"null"
]
},
"phase_object_names": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
}
}
}
}
}
},
"GP": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"use": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
}
}
}
}
}
},
"GA": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"use": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"Operator": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
}
}
}
}
}
},
"SP": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"use": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"shifts": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"tasks": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"properties": {
"type": [
"object",
"null"
],
"additionalProperties": {
"type": [
"string",
"null"
]
}
}
}
}
}
}
},
"CC": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"phase_mode": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"use": {
"type": "boolean"
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"use": {
"type": "boolean"
},
"shift_type": {
"type": [
"string",
"null"
]
},
"shift_at_phase": {
"type": [
"string",
"null"
]
},
"task_type": {
"type": [
"string",
"null"
]
},
"primary_day_type": {
"type": [
"string",
"null"
]
},
"staff_property_type": {
"type": [
"string",
"null"
]
},
"constraint_type": {
"type": "integer"
},
"min_double": {
"type": "number"
},
"max_double": {
"type": "number"
},
"dayphase_vec_max": {
"type": [
"string",
"null"
]
},
"dayphase_vec_min": {
"type": [
"string",
"null"
]
},
"max_value": {
"type": "integer"
},
"min_value": {
"type": "integer"
},
"soft_constraint_level": {
"type": "integer"
},
"soft_constraint_level_max": {
"type": "integer"
}
}
}
}
}
}
}
}
},
"RC": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"phase_mode": {
"type": "boolean"
},
"equal_count_mode": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"use": {
"type": "boolean"
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"intercept": {
"type": "integer"
},
"phase_mode": {
"type": "boolean"
},
"equal_count_mode": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"use": {
"type": "boolean"
},
"primary_day_type": {
"type": [
"string",
"null"
]
},
"first_day_type": {
"type": [
"string",
"null"
]
},
"last_day_type": {
"type": [
"string",
"null"
]
},
"staff_property_type": {
"type": [
"string",
"null"
]
},
"pattern": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"shift": {
"type": [
"string",
"null"
]
},
"level": {
"type": "integer"
},
"a_ix": {
"type": "integer"
}
}
}
},
"shift_pattern": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/properties/RC/properties/members/items/properties/members/items/properties/pattern/items"
}
},
"inv_pattern": {
"type": [
"array",
"null"
],
"items": {
"type": "boolean"
}
},
"shift_inv_pattern": {
"type": [
"array",
"null"
],
"items": {
"type": "boolean"
}
},
"A_daytypes": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"B_daytypes": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"constraint_type": {
"type": "integer"
},
"max_value": {
"type": "integer"
},
"min_double": {
"type": "number"
},
"max_double": {
"type": "number"
},
"min_value": {
"type": "integer"
},
"min_staff_property": {
"type": [
"string",
"null"
]
},
"max_staff_property": {
"type": [
"string",
"null"
]
},
"soft_constraint_level": {
"type": "integer"
}
}
}
}
}
}
}
}
},
"SolP": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"solving_map": {
"type": [
"object",
"null"
],
"additionalProperties": {
"type": [
"object",
"null"
],
"additionalProperties": {
"type": "object",
"properties": {
"use": {
"type": "boolean"
},
"value": {
"type": "integer"
},
"total_max_errors": {
"type": "integer"
},
"weight": {
"type": "integer"
}
}
}
}
},
"external_constraint": {
"type": [
"string",
"null"
]
},
"external_constraint_python": {
"type": [
"string",
"null"
]
},
"python_property_file": {
"type": [
"string",
"null"
]
},
"python_property_file_post": {
"type": [
"string",
"null"
]
},
"comment": {
"type": [
"string",
"null"
]
},
"parameters": {
"type": [
"object",
"null"
],
"additionalProperties": {
"type": "integer"
}
},
"aws_parameters": {
"type": [
"object",
"null"
],
"additionalProperties": {
"type": [
"string",
"null"
]
}
}
}
},
"Sch": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/properties/RC/properties/members/items/properties/members/items/properties/pattern/items"
}
}
}
}
},
"TSch": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/properties/Sch/properties/members/items"
}
},
"days_property1": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"Dic": {
"type": [
"object",
"null"
],
"additionalProperties": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"first": {
"type": [
"string",
"null"
]
},
"second": {
"type": [
"string",
"null"
]
}
}
}
}
},
"task_name": {
"type": [
"string",
"null"
]
}
}
}
}
}
},
"PIC": {
"type": [
"object",
"null"
],
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"equal_count_mode": {
"type": "boolean"
},
"phase_mode": {
"type": "boolean"
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"use": {
"type": "boolean"
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"equal_count_mode": {
"type": "boolean"
},
"numerical_offset": {
"type": "integer"
},
"numerical_offset_string": {
"type": [
"string",
"null"
]
},
"phase_mode": {
"type": "boolean"
},
"phase_str": {
"type": [
"string",
"null"
]
},
"name": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"use": {
"type": "boolean"
},
"shift_typeA": {
"type": [
"string",
"null"
]
},
"shift_typeB": {
"type": [
"string",
"null"
]
},
"shift_typeA_at_phase": {
"type": [
"string",
"null"
]
},
"shift_typeB_at_phase": {
"type": [
"string",
"null"
]
},
"day_type": {
"type": [
"string",
"null"
]
},
"staff_property_typeA": {
"type": [
"string",
"null"
]
},
"staff_property_typeB": {
"type": [
"string",
"null"
]
},
"operatorA": {
"type": [
"string",
"null"
]
},
"operatorB": {
"type": [
"string",
"null"
]
},
"dayoffset": {
"type": "integer"
},
"constraint_type": {
"type": "integer"
},
"soft_constraint_level": {
"type": "integer"
}
}
}
}
}
}
}
}
},
"MA": {
"type": [
"object",
"null"
],
"properties": {
"fg": {
"type": [
"object",
"null"
],
"properties": {
"excel_file": {
"type": [
"string",
"null"
]
},
"sheet_name": {
"type": [
"string",
"null"
]
},
"enable_excel": {
"type": "boolean"
},
"excel_output_enable": {
"type": "boolean"
}
}
},
"guide_pdf_path": {
"type": [
"string",
"null"
]
},
"html_code": {
"type": [
"string",
"null"
]
},
"members": {
"type": [
"array",
"null"
],
"items": {
"type": [
"object",
"null"
],
"properties": {
"use": {
"type": "boolean"
},
"apply_ex": {
"type": "boolean"
},
"comment": {
"type": [
"string",
"null"
]
},
"expressions": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"daytype": {
"type": [
"string",
"null"
]
},
"grouptype": {
"type": [
"string",
"null"
]
},
"def_name": {
"type": [
"string",
"null"
]
},
"type": {
"type": "integer"
},
"value": {
"type": "integer"
},
"ex_value": {
"type": "integer"
},
"value_double": {
"type": "number"
},
"ex_value_double": {
"type": "number"
}
}
}
}
}
},
"major_version": {
"type": "integer"
},
"sub_version": {
"type": "integer"
},
"solver_version": {
"type": "integer"
},
"user_class": {
"type": [
"string",
"null"
]
},
"user_id": {
"type": [
"string",
"null"
]
},
"eval_id": {
"type": [
"string",
"null"
]
},
"ProjectName": {
"type": [
"string",
"null"
]
}
}
}