pyp6xer_export_xer
Export the current schedule as base64-encoded XER bytes for file download without requiring a writable server path.
Instructions
Export the current (possibly modified) schedule as base64-encoded XER bytes.
Returns serialised XER content encoded as base64 so callers can offer a file download without requiring a writable local path on the server.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cache_key | No | Cache key identifying the loaded XER file (set when calling pyp6xer_load_file) | default |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:1868-1898 (handler)The actual handler function for the pyp6xer_export_xer tool. It serialises the current (possibly modified) schedule from the cache into XER format, encodes it as base64, and returns it for client download.
@mcp.tool(annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False, idempotentHint=True, openWorldHint=False)) def pyp6xer_export_xer( cache_key: Annotated[str, Field(description="Cache key identifying the loaded XER file (set when calling pyp6xer_load_file)")] = "default", ctx: Context = None, ) -> str: """Export the current (possibly modified) schedule as base64-encoded XER bytes. Returns serialised XER content encoded as base64 so callers can offer a file download without requiring a writable local path on the server. Args: cache_key: Cache key of the loaded file. """ import base64 entry = _get_cache(ctx, cache_key) content = _serialize_xer(entry["header"], entry["table_order"], entry["raw_tables"]) xer_bytes = content.encode(Xer.CODEC) b64 = base64.b64encode(xer_bytes).decode("ascii") source = entry.get("source", "") filename = source.split("/")[-1].split("?")[0] if source else f"{cache_key}.xer" if not filename.endswith(".xer"): filename = f"{cache_key}.xer" return json.dumps({ "status": "exported", "cache_key": cache_key, "filename": filename, "base64_content": b64, "size_bytes": len(xer_bytes), }, indent=2) - server.py:1868-1898 (registration)The @mcp.tool decorator on pyp6xer_export_xer registers it as an MCP tool in the FastMCP server.
@mcp.tool(annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False, idempotentHint=True, openWorldHint=False)) def pyp6xer_export_xer( cache_key: Annotated[str, Field(description="Cache key identifying the loaded XER file (set when calling pyp6xer_load_file)")] = "default", ctx: Context = None, ) -> str: """Export the current (possibly modified) schedule as base64-encoded XER bytes. Returns serialised XER content encoded as base64 so callers can offer a file download without requiring a writable local path on the server. Args: cache_key: Cache key of the loaded file. """ import base64 entry = _get_cache(ctx, cache_key) content = _serialize_xer(entry["header"], entry["table_order"], entry["raw_tables"]) xer_bytes = content.encode(Xer.CODEC) b64 = base64.b64encode(xer_bytes).decode("ascii") source = entry.get("source", "") filename = source.split("/")[-1].split("?")[0] if source else f"{cache_key}.xer" if not filename.endswith(".xer"): filename = f"{cache_key}.xer" return json.dumps({ "status": "exported", "cache_key": cache_key, "filename": filename, "base64_content": b64, "size_bytes": len(xer_bytes), }, indent=2)