UNPKG

endfield-mcp

Version:

MCP Server for Arknights: Endfield (TypeScript / stdio + Streamable HTTP)

31 lines (30 loc) • 1.48 kB
/** * Parsetree XML parser — extracts structured template data from MediaWiki * `action=parse&prop=parsetree` output. * * Split out of `endfieldWiki.ts` so the wiki client stays under the file-size * guard (see `docs/dev/STYLE.md`). This module is a self-contained, * network-free, side-effect-free pure function over a string — exactly the * kind of unit that earns its own file: deep nesting in the original, * independently testable, and consumed by exactly one caller * (`getTemplateData`) via a single narrow entry point. * * Ported verbatim from PRTS-MCP's `ts/src/api/prtsWiki.ts` parsetree block; * the MediaWiki parsetree XML shape is game-agnostic. */ /** * Parse a MediaWiki parsetree XML document into a map of template name → * fields. Each template becomes: * * - Named parameters (`{{T|key=value}}`) → top-level keys. * - Positional parameters (`{{T|value1|value2}}`) → `_positional` array. * - The template's own `<!-- comment -->` → `_comment` string. * * Templates with no extractable fields are omitted. When multiple templates * share the same name, the last one wins (matches MediaWiki semantics where * later invocations override earlier display output). * * @param xml The raw `parsetree["*"]` string from `action=parse&prop=parsetree`. * @returns Map keyed by template title (whitespace-trimmed, newlines removed). */ export declare function parseParsetreeXml(xml: string): Record<string, Record<string, unknown>>;