|
|
@@ -0,0 +1,116 @@
|
|
|
+"""Definition des outils MCP (operations ClientConfig)."""
|
|
|
+
|
|
|
+from __future__ import annotations
|
|
|
+
|
|
|
+from typing import Annotated, Any
|
|
|
+
|
|
|
+from pydantic import Field
|
|
|
+
|
|
|
+from mcp.types import ToolAnnotations
|
|
|
+
|
|
|
+from ..services.client_rest import ClientRest, HTTPMethod
|
|
|
+
|
|
|
+_WRITE_IDEMPOTENT = ToolAnnotations(
|
|
|
+ readOnlyHint=False, destructiveHint=True, idempotentHint=True
|
|
|
+)
|
|
|
+
|
|
|
+# --- createConfig ---
|
|
|
+ConfigKey = Annotated[str, Field(description="unique setting key")]
|
|
|
+ConfigLabel = Annotated[str, Field(description="display label")]
|
|
|
+ConfigValueOpt = Annotated[str | None, Field(default=None, description="initial setting value")]
|
|
|
+Xtype = Annotated[str | None, Field(default=None, description="field rendering type")]
|
|
|
+ConfigDescription = Annotated[str | None, Field(default=None, description="setting description")]
|
|
|
+IsRequired = Annotated[bool | None, Field(default=None, description="whether the setting is required")]
|
|
|
+SortOrder = Annotated[int | None, Field(default=None, description="display order")]
|
|
|
+ConfigDefault = Annotated[str | None, Field(default=None, description="default value")]
|
|
|
+ConfigGroup = Annotated[int | None, Field(default=None, description="ClientConfig group id")]
|
|
|
+Options = Annotated[str | None, Field(default=None, description="field options")]
|
|
|
+ProcessOptions = Annotated[bool | None, Field(default=None, description="whether options are processed")]
|
|
|
+Source = Annotated[int | None, Field(default=None, description="media source id")]
|
|
|
+
|
|
|
+# --- updateConfig ---
|
|
|
+ConfigId = Annotated[int | str, Field(description="configuration id")]
|
|
|
+ConfigValue = Annotated[str, Field(description="configuration value")]
|
|
|
+
|
|
|
+# --- createConfigGroup ---
|
|
|
+GroupLabel = Annotated[str, Field(description="group label")]
|
|
|
+GroupDescription = Annotated[str | None, Field(default=None, description="group description")]
|
|
|
+GroupSortOrder = Annotated[int | None, Field(default=None, description="display order")]
|
|
|
+
|
|
|
+
|
|
|
+def _omit_none(**kwargs: Any) -> dict[str, Any]:
|
|
|
+ return {key: value for key, value in kwargs.items() if value is not None}
|
|
|
+
|
|
|
+
|
|
|
+def register_config_tools(mcp_server: Any, client_rest: ClientRest) -> None:
|
|
|
+ """Enregistre les outils ClientConfig du serveur MCP."""
|
|
|
+
|
|
|
+ @mcp_server.tool(
|
|
|
+ description="Creer une configuration du site.",
|
|
|
+ annotations=_WRITE_IDEMPOTENT,
|
|
|
+ )
|
|
|
+ def createConfig(
|
|
|
+ key: ConfigKey,
|
|
|
+ label: ConfigLabel,
|
|
|
+ value: ConfigValueOpt = None,
|
|
|
+ xtype: Xtype = None,
|
|
|
+ description: ConfigDescription = None,
|
|
|
+ isRequired: IsRequired = None,
|
|
|
+ sortOrder: SortOrder = None,
|
|
|
+ default: ConfigDefault = None,
|
|
|
+ group: ConfigGroup = None,
|
|
|
+ options: Options = None,
|
|
|
+ processOptions: ProcessOptions = None,
|
|
|
+ source: Source = None,
|
|
|
+ ) -> dict[str, Any]:
|
|
|
+ return client_rest.execute(
|
|
|
+ method=HTTPMethod.POST,
|
|
|
+ endpoint="/rest/clientconfig/setting",
|
|
|
+ json=_omit_none(
|
|
|
+ key=key,
|
|
|
+ label=label,
|
|
|
+ value=value,
|
|
|
+ xtype=xtype,
|
|
|
+ description=description,
|
|
|
+ isRequired=isRequired,
|
|
|
+ sortOrder=sortOrder,
|
|
|
+ default=default,
|
|
|
+ group=group,
|
|
|
+ options=options,
|
|
|
+ processOptions=processOptions,
|
|
|
+ source=source,
|
|
|
+ ),
|
|
|
+ )
|
|
|
+
|
|
|
+ @mcp_server.tool(
|
|
|
+ description="Mettre a jour une configuration du site.",
|
|
|
+ annotations=_WRITE_IDEMPOTENT,
|
|
|
+ )
|
|
|
+ def updateConfig(
|
|
|
+ id: ConfigId,
|
|
|
+ value: ConfigValue,
|
|
|
+ ) -> dict[str, Any]:
|
|
|
+ return client_rest.execute(
|
|
|
+ method=HTTPMethod.PUT,
|
|
|
+ endpoint="/rest/clientconfig/setting",
|
|
|
+ json={"id": id, "value": value},
|
|
|
+ )
|
|
|
+
|
|
|
+ @mcp_server.tool(
|
|
|
+ description="Creer un groupe de configuration du site.",
|
|
|
+ annotations=_WRITE_IDEMPOTENT,
|
|
|
+ )
|
|
|
+ def createConfigGroup(
|
|
|
+ label: GroupLabel,
|
|
|
+ description: GroupDescription = None,
|
|
|
+ sortOrder: GroupSortOrder = None,
|
|
|
+ ) -> dict[str, Any]:
|
|
|
+ return client_rest.execute(
|
|
|
+ method=HTTPMethod.POST,
|
|
|
+ endpoint="/rest/clientconfig/group",
|
|
|
+ json=_omit_none(
|
|
|
+ label=label,
|
|
|
+ description=description,
|
|
|
+ sortOrder=sortOrder,
|
|
|
+ ),
|
|
|
+ )
|