CLI Entrypoint
Relevant source files
The following files were used as context for generating this wiki page:
The CLI Entrypoint is the primary interface for initializing and running the MBBank Model Context Protocol (MCP) server. It manages credential retrieval, authentication with the MBBank API, and the selection of server communication protocols (Stdio or SSE).
The entrypoint is defined in mbbank_mcp/__main__.py and exposed as a console script named mbbank-mcp via the project configuration. It acts as the bridge between the user's shell environment and the core logic found in mbbank_mcp/core.py.
Command Line Configuration
The CLI is built using the click library, providing a structured set of options for configuring the server at runtime. Users can provide credentials either through command-line flags or environment variables.
Configuration Options
| Option | Environment Variable | Default | Description |
|---|---|---|---|
--username | MBBANK_USERNAME | None | The account username for MBBank authentication. |
--password | MBBANK_PASSWORD | None | The account password for MBBank authentication. |
--host | N/A | localhost | The host address for the SSE server. |
--port | N/A | 3000 | The port for the SSE server. |
--sse | N/A | False | Flag to enable Server-Sent Events and HTTP mode instead of Stdio. |
Sources: mbbank_mcp/__main__.py:20-33, README.md:65-71, pyproject.toml:31
Execution Flow
When the CLI is invoked, it performs a sequence of initialization steps: credential validation, client instantiation, authentication verification, and finally, starting the server in the requested mode.
The application uses asyncio.run to trigger the initial authentication before determining which server transport to utilize.
Sources: mbbank_mcp/__main__.py:34-45, mbbank_mcp/__main__.py:73-77
Server Transport Modes
The entrypoint supports two distinct communication modes for the MCP server:
Stdio Mode
This is the default mode. The server communicates via standard input and output (stdin/stdout). This is typically used when the MCP server is managed as a subprocess by an MCP client, such as Claude Desktop.
Sources: mbbank_mcp/__main__.py:74-77, README.md:21-36
SSE (Server-Sent Events) Mode
Enabled with the --sse flag, this mode wraps the MCP server in a Starlette application and serves it via Uvicorn. It provides two endpoints:
/sse: The Server-Sent Events endpoint./mcp: The streamable HTTP endpoint.
Internal Components
The CLI entrypoint coordinates several key components:
MBBankAsync: The underlying client frommbbank-libthat handles API calls to the bank.crate_mcp_server: A factory function frommbbank_mcp/core.pythat configures theFastMCPinstance with available tools likeget_balancesandstart_transfer.eprint: A utility function to ensure error messages are written tosys.stderr, preventing interference with the MCP protocol messages onstdoutwhen in Stdio mode.
Sources: mbbank_mcp/__main__.py:13-18, mbbank_mcp/core.py:23-28, mbbank_mcp/modals.py:7-12
Summary
The CLI Entrypoint provides a flexible way to launch the MBBank MCP server. By handling both environment variables and direct CLI arguments, it accommodates various deployment scenarios ranging from local development (SSE mode) to integration with AI assistants (Stdio mode via Docker or uvx).