Python API reference¶
The standalone server’s importable Python surface (used by the runnable examples and any agent that wraps the FastMCP instance directly).
pacs008-mcp: a Model Context Protocol server for the pacs008 library.
Tool / resource / prompt module¶
Model Context Protocol (MCP) server for Pacs008.
This server exposes the Pacs008 library’s ISO 20022 pacs.008 (FI-to-FI
Customer Credit Transfer) capabilities as MCP tools so that any MCP-compatible
client (Claude Desktop, IDEs, agents) can discover message types and scheme
profiles, validate records against the JSON Schema and against a rail’s usage
guidelines, generate validated XML, validate raw XML against the bundled XSD,
and parse inbound ISO 20022 messages.
Every tool is a thin, typed wrapper over the pacs008 library – the same
package used by the CLI and REST API – so all interfaces behave identically.
Tools return JSON-serializable data (dicts, lists, or strings); on a
ValueError they return an {"error": ...} payload rather than
raising.
- Launching the server:
As a console script:
pacs008-mcp
Programmatically:
from pacs008_mcp.server import main main()
In an MCP client config (e.g. Claude Desktop
claude_desktop_config.json):{ "mcpServers": { "pacs008": { "command": "pacs008-mcp" } } }
stdio by default; --transport streamable-http or --transport sse
listens on --host/--port instead. See pacs008_mcp._cli.
- pacs008_mcp.server.build_pacs008_message(goal='')[source]¶
Guided prompt teaching the recommended tool order for a pacs.008.
The MCP client sends this to the model to establish the correct build-and-validate sequence so it uses the server’s tools in order instead of guessing a message type or skipping a validation gate.
- pacs008_mcp.server.classify_address(address)[source]¶
Classify a postal address as structured, hybrid, or unstructured.
Use this to see where an address stands against the SWIFT structured-address rule:
structured(town + country + structured detail, no free-form lines),hybrid(town + country + 1-2 free-formadr_linelines, the minimum CBPR+ UG2026 bar), orunstructured(free-form only — rejected from the cliff date). To check acceptability under a policy usevalidate_address; to upgrade legacy lines userepair_address.Returns
{"classification": str, "is_structured": bool, "is_hybrid": bool, "is_unstructured": bool, "has_structured_fields": bool}or an{"error": ...}payload.
- pacs008_mcp.server.convert_mt103(mt103_text)[source]¶
Convert a legacy SWIFT MT103 into pacs.008-ready flat records.
This is the SWIFT MT-to-MX migration path (correspondent-banking MT103 coexistence with ISO 20022 ends November 2025): parse an MT103 text payload and get back the flat pacs.008 record(s) that can be fed straight into
validate_records/generate_message. An MT103 carries exactly one transfer, so therecordslist always holds a single record. No file is read or written.Returns
{"message_type": "pacs.008.001.08", "records": [{...}]}with the parsed flat record, or an{"error": ...}payload if the MT103 is missing a mandatory field (:20:,:32A:, beneficiary) or malformed.
- pacs008_mcp.server.generate_message(message_type, records)[source]¶
Generate a validated ISO 20022 pacs XML message from in-memory records.
This is the primary generation tool: pass payment records you already hold in memory and receive an XSD-validated XML document; no file is written. Run
validate_recordsfirst to surface record-level errors, andlist_message_typesto confirm themessage_typestring.Returns the validated XML document as a string, or an
{"error": ...}payload (serialized) if generation fails.
- pacs008_mcp.server.get_input_schema(message_type)[source]¶
Return the full JSON Schema for a message type’s flat input record.
Use this to learn every field, its type, and its constraints before assembling records, or to drive a form/UI. For just the required-field names use
get_required_fields; to check records against this schema usevalidate_records.
- pacs008_mcp.server.get_required_fields(message_type)[source]¶
List only the required input field names for a pacs message type.
Use this for a quick checklist of the mandatory columns before building payment records. For full type/format constraints (not just which fields are required), call
get_input_schemainstead.
- pacs008_mcp.server.get_scheme(scheme)[source]¶
Return the rule attributes of a scheme / usage-guideline profile.
Use this to inspect a rail’s constraints – whether the UETR is mandatory, the permitted charge bearers, remittance-info length cap, per-message transaction cardinality, pinned message versions, and which parties must carry an LEI – before assembling or validating a batch.
- pacs008_mcp.server.list_message_types()[source]¶
List every supported ISO 20022 pacs message type and its human name.
Use this first, before any generation or validation call, to discover the exact
message_typestrings this server accepts (e.g.pacs.008.001.08FI-to-FI Customer Credit Transfer). To learn a type’s required fields or full schema, callget_required_fieldsorget_input_schemainstead.Returns a list of
{"message_type": ..., "name": ...}dictionaries, one per supported message type.
- pacs008_mcp.server.list_schemes()[source]¶
List every registered scheme / usage-guideline profile.
Scheme profiles (CBPR+, HVPS+, Fedwire, CHAPS, T2 RTGS, SCT Inst, generic) layer rail-specific rules on top of base ISO 20022. Use this to discover the
schemenames accepted byget_schemeandvalidate_scheme.Registry aliases (e.g.
cbpr+,cbprplus) collapse to their canonical profile, so each profile appears exactly once. Returns a list of{"scheme": ..., "name": ...}dictionaries.
- pacs008_mcp.server.main(argv=None)[source]¶
Run the pacs008 MCP server (the
pacs008-mcpentry point).stdio by default;
--transport streamable-httpor--transport sselistens on--host/--portinstead. Seepacs008_mcp._cli.
- pacs008_mcp.server.message_types_resource()[source]¶
Expose the supported pacs message types as a JSON resource.
Returns the same catalogue as the
list_message_typestool – each supported ISO 20022 pacsmessage_typeand its human name – serialised as JSON, so an agent can load the accepted type set as reference context without a tool call. Mirrorslist_message_types, which takes no arguments and cannot fail, so no error envelope is needed.- Return type:
- pacs008_mcp.server.parse_message(xml)[source]¶
Parse and classify an inbound ISO 20022 XML message.
Use this on the receiving side to identify what a message is – its
msg_def_idr(e.g.pacs.002.001.10), family, version, and any Business Application Header – before processing it. Handles both bareDocumentmessages and BAH-wrapped envelopes.Returns a dict with
msg_def_idr,msg_family,version,root_local_name,namespace_uri,envelope_wrappedandbah.
- pacs008_mcp.server.repair_address(lines, country)[source]¶
Upgrade legacy unstructured address lines toward hybrid/structured form.
Experimental country-aware repair (
GB,US,DE,FR,JPhave dedicated heuristics; other countries get a best-effort pass promoting the last line to a town). Use this to lift pre-cliff data over the November 14, 2026 bar; audit the output before submitting, and keep both the original and derived address in your audit trail.Returns
{"address": {...}, "classification": str, "is_structured": bool, "is_hybrid": bool}(so you can see the unstructured -> hybrid / structured upgrade) or an{"error": ...}payload.
- pacs008_mcp.server.scheme_resource(scheme_id)[source]¶
Expose one scheme profile’s rule attributes as a templated JSON resource.
A templated MCP Resource returning the same payload as the
get_schemetool for a single scheme: the UETR requirement, permitted charge bearers, remittance-info length cap, per-message transaction cardinality, pinned message versions, and LEI-required parties. Lets an agent pinpacs008://scheme/cbpr_plusas stable reference context for the rail it is building against. An unknownscheme_idyields the same{"error": ...}payload asget_scheme(serialised), so no separate error handling is added here.
- pacs008_mcp.server.schemes_resource()[source]¶
Expose the registered scheme / usage-guideline profiles as JSON.
Returns the same catalogue as the
list_schemestool – each canonical rail profile (CBPR+, HVPS+, Fedwire, CHAPS, T2 RTGS, SCT Inst, generic) – serialised as JSON, so an agent can load the accepted scheme set as reference context without a tool call. Mirrorslist_schemes, which takes no arguments and cannot fail, so no error envelope is needed.- Return type:
- pacs008_mcp.server.validate_address(address, policy='hybrid_or_structured')[source]¶
Validate one postal address against an address policy.
Use this to decide whether an address will clear a rail. The default
hybrid_or_structuredpolicy is the November 14, 2026 cliff rule (SWIFT CBPR+, HVPS+, T2 RTGS, CHAPS, Fedwire, Lynx): it rejects fully unstructured addresses. Findings mirror the library’s pipeline severity (a policy rejection is a blocking finding).Returns
{"policy": str, "classification": str, "is_acceptable": bool, "findings": [{"severity": str, "message": str}, ...]}or an{"error": ...}payload.
- pacs008_mcp.server.validate_addresses(addresses, policy='hybrid_or_structured')[source]¶
Batch-validate every party address across a list of payment rows.
Use this before
generate_messageto catch addresses that will be rejected at the rail. The defaulthybrid_or_structuredpolicy enforces the November 14, 2026 cliff. Each finding is reported per offending(row, party)pair.Returns
{"policy": str, "is_valid": bool, "total": int, "errors": [{"row": int, "party": str, "severity": str, "message": str, "classification": str}, ...]}or an{"error": ...}payload.
- pacs008_mcp.server.validate_records(message_type, records)[source]¶
Validate flat payment records against a message type’s JSON Schema.
Use this before
generate_messageto catch structural/type errors per record and get a row-by-row error report. This checks JSON-Schema shape only; to check a batch against a rail’s usage guidelines usevalidate_scheme.Returns a report
{"is_valid": bool, "total": int, "valid": int, "errors": [...]}.
- pacs008_mcp.server.validate_scheme(scheme, records)[source]¶
Validate payment records against a scheme’s usage-guideline rules.
Use this to check a batch against a rail’s rulebook (CBPR+, HVPS+, Fedwire, CHAPS, T2 RTGS, SCT Inst) – charge-bearer restrictions, UETR presence, remittance-info length, and per-message transaction cardinality. This is complementary to
validate_records(JSON-Schema shape).Returns
{"scheme": str, "is_valid": bool, "total": int, "violations": [...]}.
- pacs008_mcp.server.validate_xml(message_type, xml)[source]¶
Validate a raw XML string against a message type’s bundled XSD.
Use this to check an externally produced XML document against the official ISO 20022 schema. To generate a document that is already XSD-validated, use
generate_messageinstead.Returns
{"message_type": str, "is_valid": bool}, or{"error": ...}for an unsupported type or DTD entities; a bad year is invalid.
- pacs008_mcp.server.verify_bic_online(bic, directory_url=None)[source]¶
Verify a BIC structurally, optionally enriched by a directory lookup.
Two-stage verification. First an OFFLINE ISO 9362 structural check (via the pacs008 library): confirms the 8- or 11-character shape and that the country code (chars 5-6) is a valid ISO 3166-1 alpha-2 code. A malformed BIC returns
{"bic": ..., "is_structurally_valid": False, "error": ...}and stops there.Then, only if a directory endpoint is configured (the
directory_urlargument or thePACS008_BIC_DIRECTORY_URLenvironment variable), the tool performs a read-only HTTP GET against that endpoint and folds whatever institutionname/city/country/statusit returns into adirectorysub-dict. There is no free authoritative SWIFT BIC directory, so with NO endpoint configured the tool returns the structural result plus anoteanddirectory: null– it never fabricates a bank name.Online lookups require the optional
onlineextra (pip install 'pacs008-mcp[online]', which pulls inhttpx); without it the tool still returns the structural result plus anerrorexplaining the missing extra. Endpoint 4xx/5xx responses and transport failures are likewise reported as a gracefulerroralongside the structural result.Returns a dict with
bic,is_structurally_valid,bank_code,country_code,location_code,branch_code,lengthand eitherdirectory(a dict of institution details, ornull) plus, when applicable,note/error.