convert_edifact_to_bo4e
Convert EDIFACT messages to BO4E format for German energy market data transformation. This tool processes EDIFACT inputs and generates equivalent BO4E outputs using the TransformerBee.MCP server.
Instructions
Convert an EDIFACT message to its BO4E equivalent
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| edifact | Yes | ||
| edifact_format_version | No |
Implementation Reference
- src/transformerbeemcp/server.py:75-102 (handler)The handler function for the 'convert_edifact_to_bo4e' tool. It retrieves the TransformerBeeClient from context, performs the conversion, handles multiple results by raising errors, logs success, and returns the first transaction as JSON.@mcp.tool(description="Convert an EDIFACT message to its BO4E equivalent") async def convert_edifact_to_bo4e( ctx: Context, # type:ignore[type-arg] # no idea what the second type arg is edifact: str, edifact_format_version: EdifactFormatVersion | None = None, ) -> dict[str, Any]: """Tool that uses initialized resources""" _logger.debug("Context: %s", str(ctx.request_context.lifespan_context)) client: TransformerBeeClient = ctx.request_context.lifespan_context.transformerbeeclient if not edifact_format_version: edifact_format_version = get_current_edifact_format_version() try: marktnachrichten = await client.convert_to_bo4e(edifact=edifact, edifact_format_version=edifact_format_version) except ClientResponseError as cre: _logger.warning("transformer.bee rejected the request %s: %s", cre.request_info, cre.message) _logger.exception(cre) raise except Exception: _logger.exception("Error while converting EDIFACT to BO4E") raise if len(marktnachrichten) > 1: raise NotImplementedError(f"More than 1 Marktnachricht (got {len(marktnachrichten)}) not support yet") marktnachricht = marktnachrichten[0] await ctx.info(f"Successfully converted Marktnachricht with UNH {marktnachricht.unh} to BO4E") if len(marktnachricht.transaktionen) > 1: raise NotImplementedError(f"More than 1 transaction (got {len(marktnachricht.transaktionen)}) not support yet") transaktion = marktnachricht.transaktionen[0] return transaktion.model_dump(mode="json")