Skip to content

API reference

The server's importable Python surface: the tools, the resource and the prompt are plain functions, so an agent framework or a test can call them in-process. Generated from the docstrings by mkdocstrings.

bankstatementparser_mcp.server

BankStatementParser MCP server.

Tools, the resource, and the prompt are thin adapters over the bankstatementparser parser core. The tools take inline content (the raw text of a statement) plus a filename hint, because an MCP client does not share the server's filesystem. Each call materialises the content in a private temporary file, runs the same create_parser pipeline the CLI uses, and returns plain JSON-serialisable data.

Run it with::

bankstatementparser-mcp                               # stdio (default)
bankstatementparser-mcp --transport streamable-http   # HTTP at /mcp
bankstatementparser-mcp --transport sse               # HTTP+SSE

list_supported_formats()

List every bank statement format identifier this server can parse.

Use this first to discover the valid format strings accepted by detect_format, parse_statement, validate_statement, and summarize_statement. For the file extensions and a human-readable description of each format, read the bankstatementparser://formats resource instead.

Returns:

Type Description
list[str]

The supported format identifiers.

Source code in bankstatementparser_mcp/server.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
@mcp.tool(title="List supported statement formats", annotations=_PURE_READ)
def list_supported_formats() -> list[str]:
    """List every bank statement format identifier this server can parse.

    Use this first to discover the valid ``format`` strings accepted by
    ``detect_format``, ``parse_statement``, ``validate_statement``, and
    ``summarize_statement``. For the file extensions and a human-readable
    description of each format, read the ``bankstatementparser://formats``
    resource instead.

    Returns:
        The supported format identifiers.
    """
    return list(_FORMAT_SUFFIX)

detect_format(content, filename='statement.xml')

Detect which bank statement format an inline payload is.

Use this when you hold statement text but do not yet know its format, to resolve the format identifier from the content plus filename hint. Once the format is known, use parse_statement to read the transactions.

Parameters:

Name Type Description Default
content Annotated[str, Field(description='The raw statement text to inspect, inline (not a file path). Supported formats include ISO 20022 CAMT.053 and pain.001 XML, SWIFT MT940, CSV exports, and OFX/QFX.')]

The raw statement text.

required
filename Annotated[str, Field(description="Original filename of the payload; its extension is the primary detection hint. Recognised extensions: .xml, .csv, .ofx, .qfx, .mt940, .sta. Defaults to 'statement.xml'.")]

Original filename; its extension is the primary hint.

'statement.xml'

Returns:

Type Description
str

The detected format identifier.

Raises:

Type Description
ToolError

If the format cannot be detected.

Source code in bankstatementparser_mcp/server.py
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
@mcp.tool(title="Detect statement format", annotations=_PURE_READ)
def detect_format(
    content: Annotated[
        str,
        Field(
            description=(
                "The raw statement text to inspect, inline (not a file "
                "path). Supported formats include ISO 20022 CAMT.053 and "
                "pain.001 XML, SWIFT MT940, CSV exports, and OFX/QFX."
            ),
        ),
    ],
    filename: Annotated[
        str,
        Field(
            description=(
                "Original filename of the payload; its extension is the "
                "primary detection hint. Recognised extensions: .xml, "
                ".csv, .ofx, .qfx, .mt940, .sta. Defaults to "
                "'statement.xml'."
            ),
        ),
    ] = "statement.xml",
) -> str:
    """Detect which bank statement format an inline payload is.

    Use this when you hold statement text but do not yet know its format,
    to resolve the ``format`` identifier from the content plus filename
    hint. Once the format is known, use ``parse_statement`` to read the
    transactions.

    Args:
        content: The raw statement text.
        filename: Original filename; its extension is the primary hint.

    Returns:
        The detected format identifier.

    Raises:
        ToolError: If the format cannot be detected.
    """
    suffix = _suffix_for(filename, None)
    with _materialise(content, suffix) as path:
        try:
            return detect_statement_format(path)
        except _PARSE_ERRORS as exc:
            raise _refused(exc, path, filename) from exc

parse_statement(content, filename='statement.xml', format=None, limit=None)

Parse an inline statement payload into transaction rows and a summary.

Returns the resolved format, the columns, the full transaction_count, the transactions as row dicts (at most limit) and the statement summary. For balances only, summarize_statement returns just the summary; to confirm a payload parses without any rows, validate_statement.

Raises:

Type Description
ToolError

If the format is unsupported, cannot be detected, or the payload does not parse.

Source code in bankstatementparser_mcp/server.py
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
@mcp.tool(
    title="Parse statement transactions and summary", annotations=_PURE_READ
)
def parse_statement(
    content: Annotated[
        str,
        Field(
            description=(
                "The raw statement text to parse, inline (not a file "
                "path). Accepts ISO 20022 CAMT.053 and pain.001 XML, "
                "SWIFT MT940, CSV exports, and OFX/QFX payloads."
            ),
        ),
    ],
    filename: Annotated[
        str,
        Field(
            description=(
                "Original filename; its extension (.xml, .csv, .ofx, "
                ".qfx, .mt940, .sta) selects the format when 'format' "
                "is omitted."
            ),
        ),
    ] = "statement.xml",
    format: _Format = None,
    limit: Annotated[
        int | None,
        Field(
            description=(
                "Maximum transaction rows to return; omitted returns "
                "all. 'transaction_count' is always the full count."
            ),
        ),
    ] = None,
) -> dict[str, Any]:
    """Parse an inline statement payload into transaction rows and a summary.

    Returns the resolved ``format``, the ``columns``, the full
    ``transaction_count``, the ``transactions`` as row dicts (at most
    ``limit``) and the statement ``summary``. For balances only,
    ``summarize_statement`` returns just the summary; to confirm a
    payload parses without any rows, ``validate_statement``.

    Raises:
        ToolError: If the format is unsupported, cannot be detected, or
            the payload does not parse.
    """
    if format is not None:
        _require_format(format)
    suffix = _suffix_for(filename, format)
    with _materialise(content, suffix) as path:
        try:
            parser = create_parser(path, format)
            frame = parser.parse()
            summary = _summary_to_jsonable(dict(parser.get_summary()))
        except _PARSE_ERRORS as exc:
            raise _refused(exc, path, filename) from exc
        records = frame.to_dict("records")
        total = len(records)
        if limit is not None:
            records = records[:limit]
        return {
            "format": format or detect_statement_format(path),
            "columns": list(frame.columns),
            "transaction_count": total,
            "transactions": [
                {k: (v if v is None else str(v)) for k, v in row.items()}
                for row in records
            ],
            "summary": summary,
        }

validate_statement(content, filename='statement.xml', format=None)

Dry-run parse an inline statement to check it parses cleanly.

Use this to confirm a payload is well-formed and parseable before committing to a full read; it returns a structured pass/fail with the transaction count but never the rows themselves, and never raises on a parse error. To actually read the transactions use parse_statement.

Parameters:

Name Type Description Default
content Annotated[str, Field(description='The raw statement text to validate, inline (not a file path). Accepts ISO 20022 CAMT.053 and pain.001 XML, SWIFT MT940, CSV exports, and OFX/QFX payloads.')]

The raw statement text.

required
filename Annotated[str, Field(description="Original filename of the payload; its extension (.xml, .csv, .ofx, .qfx, .mt940, .sta) selects the format when 'format' is omitted. Defaults to 'statement.xml'.")]

Original filename; its extension selects the format.

'statement.xml'
format _Format

Explicit format override.

None

Returns:

Type Description
dict[str, Any]

A dict with is_valid, the resolved format, the

dict[str, Any]

transaction_count on success, and an error on failure.

Source code in bankstatementparser_mcp/server.py
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
@mcp.tool(title="Validate statement (dry run)", annotations=_PURE_READ)
def validate_statement(
    content: Annotated[
        str,
        Field(
            description=(
                "The raw statement text to validate, inline (not a file "
                "path). Accepts ISO 20022 CAMT.053 and pain.001 XML, "
                "SWIFT MT940, CSV exports, and OFX/QFX payloads."
            ),
        ),
    ],
    filename: Annotated[
        str,
        Field(
            description=(
                "Original filename of the payload; its extension "
                "(.xml, .csv, .ofx, .qfx, .mt940, .sta) selects the "
                "format when 'format' is omitted. Defaults to "
                "'statement.xml'."
            ),
        ),
    ] = "statement.xml",
    format: _Format = None,
) -> dict[str, Any]:
    """Dry-run parse an inline statement to check it parses cleanly.

    Use this to confirm a payload is well-formed and parseable before
    committing to a full read; it returns a structured pass/fail with the
    transaction count but never the rows themselves, and never raises on a
    parse error. To actually read the transactions use ``parse_statement``.

    Args:
        content: The raw statement text.
        filename: Original filename; its extension selects the format.
        format: Explicit format override.

    Returns:
        A dict with ``is_valid``, the resolved ``format``, the
        ``transaction_count`` on success, and an ``error`` on failure.
    """
    if format is not None:
        _require_format(format)
    try:
        suffix = _suffix_for(filename, format)
        with _materialise(content, suffix) as path:
            resolved = format or detect_statement_format(path)
            parser = create_parser(path, format)
            frame = parser.parse()
        return {
            "is_valid": True,
            "format": resolved,
            "transaction_count": len(frame),
            "error": None,
        }
    except Exception as exc:
        return {
            "is_valid": False,
            "format": format,
            "transaction_count": 0,
            "error": str(exc),
        }

summarize_statement(content, filename='statement.xml', format=None)

Summarize an inline statement's balances and totals only.

Use this when you need just the opening/closing balances, currency, and other summary fields without the per-transaction rows. For the full transaction detail alongside the summary, use parse_statement instead.

Parameters:

Name Type Description Default
content Annotated[str, Field(description='The raw statement text to summarize, inline (not a file path). Accepts ISO 20022 CAMT.053 and pain.001 XML, SWIFT MT940, CSV exports, and OFX/QFX payloads.')]

The raw statement text.

required
filename Annotated[str, Field(description="Original filename of the payload; its extension (.xml, .csv, .ofx, .qfx, .mt940, .sta) selects the format when 'format' is omitted. Defaults to 'statement.xml'.")]

Original filename; its extension selects the format.

'statement.xml'
format _Format

Explicit format override.

None

Returns:

Type Description
dict[str, Any]

The summary record with Decimal values stringified.

Raises:

Type Description
ToolError

If the format is unsupported, cannot be detected, or the payload does not parse.

Source code in bankstatementparser_mcp/server.py
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
@mcp.tool(title="Summarize statement balances", annotations=_PURE_READ)
def summarize_statement(
    content: Annotated[
        str,
        Field(
            description=(
                "The raw statement text to summarize, inline (not a "
                "file path). Accepts ISO 20022 CAMT.053 and pain.001 "
                "XML, SWIFT MT940, CSV exports, and OFX/QFX payloads."
            ),
        ),
    ],
    filename: Annotated[
        str,
        Field(
            description=(
                "Original filename of the payload; its extension "
                "(.xml, .csv, .ofx, .qfx, .mt940, .sta) selects the "
                "format when 'format' is omitted. Defaults to "
                "'statement.xml'."
            ),
        ),
    ] = "statement.xml",
    format: _Format = None,
) -> dict[str, Any]:
    """Summarize an inline statement's balances and totals only.

    Use this when you need just the opening/closing balances, currency, and
    other summary fields without the per-transaction rows. For the full
    transaction detail alongside the summary, use ``parse_statement``
    instead.

    Args:
        content: The raw statement text.
        filename: Original filename; its extension selects the format.
        format: Explicit format override.

    Returns:
        The summary record with Decimal values stringified.

    Raises:
        ToolError: If the format is unsupported, cannot be detected, or
            the payload does not parse.
    """
    if format is not None:
        _require_format(format)
    suffix = _suffix_for(filename, format)
    with _materialise(content, suffix) as path:
        try:
            parser = create_parser(path, format)
            return _summary_to_jsonable(dict(parser.get_summary()))
        except _PARSE_ERRORS as exc:
            raise _refused(exc, path, filename) from exc

formats_resource()

Describe each supported statement format and its file extensions.

Returns:

Type Description
str

A human-readable catalogue of the supported formats.

Source code in bankstatementparser_mcp/server.py
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
@mcp.resource(
    "bankstatementparser://formats", title="Supported formats catalogue"
)
def formats_resource() -> str:
    """Describe each supported statement format and its file extensions.

    Returns:
        A human-readable catalogue of the supported formats.
    """
    lines = [
        "BankStatementParser supported input formats:",
        "",
        "- camt    : ISO 20022 CAMT.053 statements (.xml)",
        "- pain001 : ISO 20022 pain.001 credit-transfer (.xml)",
        "- csv     : delimited statement exports (.csv)",
        "- ofx     : Open Financial Exchange (.ofx)",
        "- qfx     : Quicken Financial Exchange (.qfx)",
        "- mt940   : SWIFT MT940 statement messages (.mt940, .sta)",
    ]
    return "\n".join(lines)

analyze_statement(filename='statement.xml')

Guided prompt for reading and reconciling a bank statement.

Parameters:

Name Type Description Default
filename Annotated[str, Field(description="The statement filename being analysed; its extension (.xml, .csv, .ofx, .qfx, .mt940, .sta) hints at the format. Defaults to 'statement.xml'.")]

The statement filename being analysed.

'statement.xml'

Returns:

Type Description
str

A prompt string instructing the model how to proceed.

Source code in bankstatementparser_mcp/server.py
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
@mcp.prompt(title="Analyse a bank statement")
def analyze_statement(
    filename: Annotated[
        str,
        Field(
            description=(
                "The statement filename being analysed; its extension "
                "(.xml, .csv, .ofx, .qfx, .mt940, .sta) hints at the "
                "format. Defaults to 'statement.xml'."
            ),
        ),
    ] = "statement.xml",
) -> str:
    """Guided prompt for reading and reconciling a bank statement.

    Args:
        filename: The statement filename being analysed.

    Returns:
        A prompt string instructing the model how to proceed.
    """
    return (
        f"Help me analyse the bank statement '{filename}'. First call "
        "detect_format with its content to confirm the format, then "
        "validate_statement to make sure it parses, then parse_statement "
        "to read the transactions and summarize_statement for the "
        "opening/closing balances. Reconcile the transaction total "
        "against the balances and flag anything that looks off."
    )

main(argv=None)

Run the BankStatementParser MCP server (the bankstatementparser-mcp entry point).

stdio by default; --transport streamable-http or --transport sse listens on --host/--port instead. See :mod:bankstatementparser_mcp._cli.

Parameters:

Name Type Description Default
argv list[str] | None

Command-line arguments; None reads sys.argv[1:].

None
Source code in bankstatementparser_mcp/server.py
540
541
542
543
544
545
546
547
548
549
550
def main(argv: list[str] | None = None) -> None:
    """Run the BankStatementParser MCP server (the ``bankstatementparser-mcp`` entry point).

    stdio by default; ``--transport streamable-http`` or ``--transport sse``
    listens on ``--host``/``--port`` instead. See
    :mod:`bankstatementparser_mcp._cli`.

    Args:
        argv: Command-line arguments; ``None`` reads ``sys.argv[1:]``.
    """
    _cli.serve(mcp, argv, "bankstatementparser-mcp", __version__)

bankstatementparser_mcp.adapters

Framework adapters: expose the BankStatementParser tools to agent frameworks.

The server registers its tools (list_supported_formats, detect_format, parse_statement, validate_statement, summarize_statement) with FastMCP. Agent frameworks such as LangChain, CrewAI and LlamaIndex each have their own tool object; this module introspects the FastMCP tool registry and wraps every registered tool into the requested framework's native tool type, one framework tool per server tool.

Each as_*_tools function pulls its framework in lazily, so importing this module -- and the base bankstatementparser-mcp install -- never depends on any agent framework. A framework is only needed when its adapter is actually called; if it is absent the adapter raises :class:ImportError naming the extra to install (e.g. pip install bankstatementparser-mcp[langchain]).

The tool metadata (name, description and the JSON inputSchema) and the underlying callable are read from the FastMCP tool registry via :func:_gateway_tools. The introspected JSON input schema is passed straight through to each framework's schema argument.

as_langchain_tools()

Wrap every server tool as a LangChain StructuredTool.

Returns one :class:langchain_core.tools.StructuredTool per registered server tool, carrying its name, description and JSON input schema; the callable is wrapped so raised errors surface as ToolException.

Raises:

Type Description
ImportError

if langchain-core is not installed (pip install bankstatementparser-mcp[langchain]).

Source code in bankstatementparser_mcp/adapters.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def as_langchain_tools() -> list[Any]:
    """Wrap every server tool as a LangChain ``StructuredTool``.

    Returns one :class:`langchain_core.tools.StructuredTool` per registered
    server tool, carrying its name, description and JSON input schema; the
    callable is wrapped so raised errors surface as ``ToolException``.

    Raises:
        ImportError: if ``langchain-core`` is not installed
            (``pip install bankstatementparser-mcp[langchain]``).
    """
    try:
        from langchain_core.tools import StructuredTool, ToolException
    except ImportError as exc:
        raise ImportError(
            "LangChain is not installed. Install it with "
            "`pip install bankstatementparser-mcp[langchain]`."
        ) from exc

    return [
        StructuredTool.from_function(
            func=_wrap_with_tool_exception(_tool_func(tool), ToolException),
            name=_tool_name(tool),
            description=_tool_desc(tool),
            args_schema=_tool_schema(tool),
        )
        for tool in _gateway_tools()
    ]

as_crewai_tools()

Wrap every server tool as a CrewAI CrewStructuredTool.

Returns one crewai.tools.CrewStructuredTool per registered server tool, carrying its name, description, JSON input schema and callable.

Raises:

Type Description
ImportError

if CrewAI is not installed (pip install bankstatementparser-mcp[crewai]).

Source code in bankstatementparser_mcp/adapters.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def as_crewai_tools() -> list[Any]:
    """Wrap every server tool as a CrewAI ``CrewStructuredTool``.

    Returns one ``crewai.tools.CrewStructuredTool`` per registered server
    tool, carrying its name, description, JSON input schema and callable.

    Raises:
        ImportError: if CrewAI is not installed
            (``pip install bankstatementparser-mcp[crewai]``).
    """
    try:
        from crewai.tools import CrewStructuredTool
    except ImportError as exc:
        raise ImportError(
            "CrewAI is not installed. Install it with "
            "`pip install bankstatementparser-mcp[crewai]`."
        ) from exc

    return [
        CrewStructuredTool.from_function(
            func=_tool_func(tool),
            name=_tool_name(tool),
            description=_tool_desc(tool),
            args_schema=_tool_schema(tool),
        )
        for tool in _gateway_tools()
    ]

as_llamaindex_tools()

Wrap every server tool as a LlamaIndex FunctionTool.

Returns one llama_index.core.tools.FunctionTool per registered server tool, carrying its name, description, JSON input schema and callable.

Raises:

Type Description
ImportError

if llama-index-core is not installed (pip install bankstatementparser-mcp[llamaindex]).

Source code in bankstatementparser_mcp/adapters.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def as_llamaindex_tools() -> list[Any]:
    """Wrap every server tool as a LlamaIndex ``FunctionTool``.

    Returns one ``llama_index.core.tools.FunctionTool`` per registered server
    tool, carrying its name, description, JSON input schema and callable.

    Raises:
        ImportError: if ``llama-index-core`` is not installed
            (``pip install bankstatementparser-mcp[llamaindex]``).
    """
    try:
        from llama_index.core.tools import FunctionTool
    except ImportError as exc:
        raise ImportError(
            "LlamaIndex is not installed. Install it with "
            "`pip install bankstatementparser-mcp[llamaindex]`."
        ) from exc

    return [
        FunctionTool.from_defaults(
            fn=_tool_func(tool),
            name=_tool_name(tool),
            description=_tool_desc(tool),
            fn_schema=_tool_schema(tool),
        )
        for tool in _gateway_tools()
    ]

bankstatementparser_mcp.completion

The bankstatementparser-mcp parser, for shell-completion generation.

make completions runs shtab bankstatementparser_mcp.completion.parser and writes completions/; CI regenerates them and fails on any difference. The parser is the one server.main parses with (:func:bankstatementparser_mcp._cli.build_parser), so the completions cannot drift from the flags the server takes. Importing this module does not import the MCP server.

parser()

Return the console script's argument parser.

Source code in bankstatementparser_mcp/completion.py
21
22
23
def parser() -> argparse.ArgumentParser:
    """Return the console script's argument parser."""
    return _cli.build_parser(PROG, __version__)