Skip to main content
Glama
fundsxml-mcp

fundsxml-mcp

Official
by fundsxml
README.md
# FundsXML Knowledge Pack

Generates the **FundsXML knowledge pack**: one JSON file per schema version that describes every element of
[FundsXML](https://github.com/fundsxml/schema) in a form tools and AI agents can look up without reading a 2.5 MB XSD.
It answers questions like *where does a value go*, *what does this element allow*, *which element carries
TPT datapoint 12 or EMT field 00096* and *what changed between two versions*.

The pack is the knowledge layer for a FundsXML MCP server: the FundsXML plugin of
[FreeXmlToolkit](https://github.com/karlkauc/FreeXmlToolkit) (`fxt-cli mcp`) and a planned read-only server
serve their lookup tools from it. It is derived from the schema only, so it is versioned and released with it.

## Usage

Needs Python 3.12 or later and a checkout of the schema repository; the generator uses no other packages.

```bash
git clone https://github.com/fundsxml/schema.git ../schema
git clone https://github.com/fundsxml/knowledge.git && cd knowledge

python3 -m fundsxml_knowledge                      # schema working tree -> dist/fundsxml-knowledge-<version>.json(.gz)
python3 -m fundsxml_knowledge --git-ref 4.2.11     # a released version
python3 -m fundsxml_knowledge.diff dist/fundsxml-knowledge-4.2.11.json dist/fundsxml-knowledge-4.2.12.json
python3 -m unittest -v
```

The schema checkout is found through `--schema PATH`, then `$FUNDSXML_SCHEMA`, then a folder `schema` or
`fundsxml_schema` next to this repository. The version label is the tag name with `--git-ref`; for the working
tree it is the unreleased version of `CHANGELOG.md` when that is newer than the schema's `version` attribute.
The same input gives the same bytes, also in the `.gz`.

## What the pack contains

| Key | Content |
|---|---|
| `schema_version`, `source` | version label, the schema's `version` attribute, commit of fundsxml/schema |
| `templates` | regulatory templates below `RegulatoryReportings` (EMT, EET, TPT, EPT, EFT, …) with version and container path |
| `types` | every named and anonymous type: base, enumeration, facets, documentation, effective attributes and child elements (inherited first) |
| `elements` | every element declaration, keyed `<owner type>/<name>` (anonymous types as `{…}`): type, `min`, `max`, `required`, `choice` alternatives, documentation (en, de, fr), `since`, `deprecated`, examples, `key`/`keyref` |
| `paths` | every element path of an instance document with its declaration, about 24,000 for 4.2.12; recursion (`ParentCompany`) is cut and listed in `recursive_paths` |
| `fields` | datapoints named in the documentation: `kind: field` with template, version, code, label and path, or `kind: range` for a group element that covers a code range (EET indicators such as 31050–31080) |
| `changes` | `@since` / `@deprecated` index per version, and the `CHANGELOG.md` sections |

An element, as in the pack:

```json
"{PositionType/Future}/InitialMargin": {
  "name": "InitialMargin", "module": "FundsXML4_PortfolioData.xsd", "type": "FundAmountType",
  "min": 0, "max": 1, "required": false,
  "doc": {"en": "Initial margin deposited for this futures position as of the valuation date", "de": "…", "fr": "…"},
  "since": "4.2.12"
}
```

and a datapoint:

```json
{"template": "TPT", "version": "8.0", "kind": "field", "code": "12",
 "label": "CIC_code_of_the_instrument CIC code - Alphanumeric (4)",
 "path": "/FundsXML4/RegulatoryReportings/IndirectReporting/TripartiteTemplateSolvencyII_V8/Portfolio/Positions/Position/CICCodeOfTheInstrument"}
```

### Limits

- Datapoints come from the schema documentation as written. Where a code is missing, wrong or used twice, the
  pack shows it the same way; EET indicators are only known as ranges, because the schema does not name their
  single datapoints. A curated mapping table is a later step.
- Mapping from regulation-neutral core elements (positions, assets) to TPT datapoints is not derived yet.
- `xs:assert`, `xs:key`/`xs:keyref` and `xs:unique` are recorded as written, not evaluated.

## MCP server

`fundsxml_knowledge.server` serves a pack to AI agents over the
[Model Context Protocol](https://modelcontextprotocol.io): read-only, locally over stdio or as a remote server over
Streamable HTTP. It needs the
`mcp` package; the lookups themselves (`lookup.py`) use the standard library only.

```bash
python3 -m venv .venv && .venv/bin/pip install -e '.[server]'
python3 -m fundsxml_knowledge                       # build a pack into dist/ first

# Claude Code, in the folder you work in (e.g. the schema checkout):
claude mcp add fundsxml -- /path/to/knowledge/.venv/bin/fundsxml-mcp
```

Other clients take `{"command": "/path/to/knowledge/.venv/bin/fundsxml-mcp", "args": ["--pack", "…"]}`. Without
`--pack` it serves `$FUNDSXML_KNOWLEDGE_PACK` or the newest pack in `dist/`. `--pack` may name a folder: then it
serves every pack in it, by default the newest released version, and each tool takes `schema_version`.

| Tool | Question it answers |
|---|---|
| `schema_overview` | Which version, which top-level blocks, which templates in which versions? |
| `find_element` | Where does a value go? Words in English or German against names and documentation; copies of the same field are grouped, the core model ranks before template copies. |
| `describe` | What is allowed at this path? Type, cardinality, choice, codes, facets, documentation, `@since`/`@deprecated`, attributes, children, `key`/`keyref`, datapoints. A unique tail (`Position/Future/InitialMargin`) is enough; a wrong path returns the nearest existing one. |
| `map_field` | Datapoint ↔ element: `TPT 12`, `EMT 00096`, `EET 31060` (as a range), or all datapoints of a path. |
| `modelling_guide` | How FundsXML models references, currencies, umbrellas, look-through, core vs templates, versions: curated rules from `rules/`. |
| `changes` | What a schema version added (or everything since a version), with CHANGELOG sections, and what is deprecated. |
| `skeleton` | A minimal document with the required elements and the way to the paths you name, placeholder values of the right types. |

The server does not read or validate documents; use an XSD 1.1 validator, or `fxt-cli mcp`
([FreeXmlToolkit](https://github.com/karlkauc/FreeXmlToolkit)) next to it, whose `fundsxml_skeleton` also validates.

The modelling rules are MCP resources too (`fundsxml://rules/<id>`), and two prompts start common work:
`map_to_fundsxml` (a spreadsheet or template column by column to FundsXML paths) and `schema_change` (where a new
datapoint belongs, following the rules).

### Remote server (Streamable HTTP)

```bash
fundsxml-mcp --http --pack dist/                    # http://127.0.0.1:8000/mcp, /healthz
docker build -t fundsxml-mcp .                      # the packs of the latest release, fetched and checked
docker run --rm -p 8000:8000 fundsxml-mcp           # add server options after the image name
claude mcp add --transport http fundsxml http://127.0.0.1:8000/mcp
```

It is stateless (JSON responses, no sessions), accepts request bodies up to 64 KiB, and limits each client address
to `--rate` requests per minute with a `--burst` (default 60 and 20; answer 429 with `Retry-After`). On
127.0.0.1 it accepts only local `Host` headers; behind a reverse proxy on a public name, give
`--allowed-host <name>` (checks `Host` and `Origin`) and `--trust-proxy` (client address from `X-Forwarded-For`, so the
limit counts per client and not per proxy). Request logs with client addresses are off unless `--access-log`. It
reads no documents, keeps nothing between calls and needs no network at run time; a container with two packs in
use takes about 160 MB of memory. TLS and authentication belong to the proxy in front of it.

## Modelling rules

`rules/*.md` hold short, curated rules for what the element documentation alone does not explain (look-through,
references, currencies, …). Each file has a front matter with `title` and `keywords`; the generator puts them into the
pack with the `/FundsXML4/…` paths they name, and marks paths that a schema version does not have. A test fails when
a rule names a path the current schema lacks, so the rules stay in step with the schema.

## Core sources

`sources/<template>.json` names, per template datapoint, the core elements it can be generated from and how to
convert (`TPT.json`, `EMT.json`, `EET.json`). Paths start with an alias (`Asset`, `Position`, `Portfolio`, `Fund`, `ShareClass`,
`ControlData`) and may use `*` for one element. The generator makes them full paths per schema version;
`map_field` returns them as `core_sources` of a datapoint, and for a core path the datapoints it feeds as
`feeds_datapoints`. TPT up to V7 numbers its fields `A46` where V8 writes `46`; both find the same sources.

## Releases

Every release of this repository carries the packs of all released schema versions from 4.2.0 on, the pack of the
unreleased state of the schema (`<version>-unreleased`, when there is one) and `index.json` (version, file,
size, sha256, schema commit). Clients use the stable URLs

```
https://github.com/fundsxml/knowledge/releases/latest/download/index.json
https://github.com/fundsxml/knowledge/releases/latest/download/fundsxml-knowledge-4.2.11.json.gz
```

A tag `v*` publishes a release; *Run workflow* on the release workflow publishes one without a tag (named
`packs-<date>`), for example after a schema change.

## Release checks: `diff`

`python3 -m fundsxml_knowledge.diff OLD NEW` compares two packs and lists added and removed elements (one line per
declaration), additions without `@since <new version>`, changes the `CHANGELOG.md` of the new version does not
mention, and datapoints added or removed per template. It exits with 1 when something is unmarked, unlisted or
removed, so it can gate a schema release. CI runs it against the latest release tag and puts the result in the
job summary.

## Licence

MIT, like the schema.