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 | |
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 | |
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 | |
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 |
dict[str, Any]
|
|
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 | |
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 | |
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 | |
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 | |
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
|
Source code in bankstatementparser_mcp/server.py
540 541 542 543 544 545 546 547 548 549 550 | |
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 |
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 | |
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
( |
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 | |
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 |
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 | |
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 | |