momo-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- momo_mcp-0.1.0/.gitignore +11 -0
- momo_mcp-0.1.0/LICENSE +21 -0
- momo_mcp-0.1.0/PKG-INFO +185 -0
- momo_mcp-0.1.0/README.md +156 -0
- momo_mcp-0.1.0/SKILL.md +65 -0
- momo_mcp-0.1.0/examples/claude_desktop_config.json +11 -0
- momo_mcp-0.1.0/examples/live_sandbox_config.json +17 -0
- momo_mcp-0.1.0/pyproject.toml +65 -0
- momo_mcp-0.1.0/server.json +21 -0
- momo_mcp-0.1.0/src/momo_mcp/__init__.py +3 -0
- momo_mcp-0.1.0/src/momo_mcp/__main__.py +4 -0
- momo_mcp-0.1.0/src/momo_mcp/demo.py +75 -0
- momo_mcp-0.1.0/src/momo_mcp/server.py +350 -0
- momo_mcp-0.1.0/tests/test_server.py +180 -0
momo_mcp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gedeon ONDELE
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
momo_mcp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: momo-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MTN Mobile Money sandbox tools for AI agents, exposed over MCP.
|
|
5
|
+
Project-URL: Homepage, https://github.com/G2on61/momo-mcp
|
|
6
|
+
Project-URL: Repository, https://github.com/G2on61/momo-mcp
|
|
7
|
+
Project-URL: Issues, https://github.com/G2on61/momo-mcp/issues
|
|
8
|
+
Author-email: Gedeon ONDELE <gedeon@ondele.fr>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai-agents,claude,cursor,mcp,mobile-money,momo,mtn
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: mcp<3,>=2.3
|
|
23
|
+
Requires-Dist: mtn-momo-collection<0.2,>=0.1
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: mypy>=1.14; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.11; extra == 'dev'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# momo-mcp
|
|
31
|
+
|
|
32
|
+
[](https://github.com/G2on61/momo-mcp/actions/workflows/ci.yml)
|
|
33
|
+
[](LICENSE)
|
|
34
|
+
|
|
35
|
+
**MTN Mobile Money sandbox tools for AI agents, over MCP.**
|
|
36
|
+
|
|
37
|
+
<!-- mcp-name: io.github.G2on61/momo-mcp -->
|
|
38
|
+
|
|
39
|
+
`momo-mcp` lets Claude Code, Cursor, Codex and other MCP clients test MTN MoMo
|
|
40
|
+
flows without reading a 200-page API spec first. It runs in **demo mode by
|
|
41
|
+
default**: no credentials, no network calls, no real money.
|
|
42
|
+
|
|
43
|
+
Ask your agent:
|
|
44
|
+
|
|
45
|
+
> Create a sandbox collection of 100 EUR for +237650000000, then check its status.
|
|
46
|
+
|
|
47
|
+
The agent gets a reference id, a PENDING status, and a clear next step. The
|
|
48
|
+
first status check moves the demo transaction to SUCCESSFUL so the full flow is
|
|
49
|
+
visible without any network call.
|
|
50
|
+
|
|
51
|
+
## Why
|
|
52
|
+
|
|
53
|
+
AI agents are good at calling tools, but payment APIs are still awkward:
|
|
54
|
+
authentication, product-specific endpoints, reference ids, status polling and
|
|
55
|
+
sandbox setup. `momo-mcp` exposes a small, safe tool surface so an agent can:
|
|
56
|
+
|
|
57
|
+
- inspect the active product and configuration;
|
|
58
|
+
- list MoMo products and capabilities;
|
|
59
|
+
- read a balance;
|
|
60
|
+
- check whether a number is active;
|
|
61
|
+
- create a sandbox collection request;
|
|
62
|
+
- read a transaction status.
|
|
63
|
+
|
|
64
|
+
It is built on top of the published
|
|
65
|
+
[`mtn-momo-collection`](https://pypi.org/project/mtn-momo-collection/) SDK.
|
|
66
|
+
|
|
67
|
+
## Quick start
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
git clone https://github.com/G2on61/momo-mcp.git
|
|
71
|
+
cd momo-mcp
|
|
72
|
+
uv run momo-mcp
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The server speaks MCP over stdio. It starts in demo mode.
|
|
76
|
+
|
|
77
|
+
### Claude Desktop / Cursor
|
|
78
|
+
|
|
79
|
+
Add this to your MCP client configuration:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"mcpServers": {
|
|
84
|
+
"momo": {
|
|
85
|
+
"command": "uv",
|
|
86
|
+
"args": ["run", "--directory", "/absolute/path/to/momo-mcp", "momo-mcp"],
|
|
87
|
+
"env": {
|
|
88
|
+
"MOMO_MCP_MODE": "demo"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
After the package is published to PyPI, the command can be shortened to:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"mcpServers": {
|
|
100
|
+
"momo": {
|
|
101
|
+
"command": "uvx",
|
|
102
|
+
"args": ["momo-mcp"],
|
|
103
|
+
"env": {
|
|
104
|
+
"MOMO_MCP_MODE": "demo"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Tools
|
|
112
|
+
|
|
113
|
+
| Tool | What it does |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `momo_get_config` | Shows mode, product and whether live credentials are present. |
|
|
116
|
+
| `momo_list_products` | Lists collections, disbursements and remittances capabilities. |
|
|
117
|
+
| `momo_get_balance` | Reads the active product balance. |
|
|
118
|
+
| `momo_check_msisdn` | Checks whether a number is active. |
|
|
119
|
+
| `momo_request_collection` | Creates a collection request and returns a reference id. |
|
|
120
|
+
| `momo_get_transaction_status` | Reads a collection, disbursement or remittance status. |
|
|
121
|
+
| `momo_list_demo_transactions` | Lists transactions created in the current demo process. |
|
|
122
|
+
|
|
123
|
+
## Demo mode vs live sandbox
|
|
124
|
+
|
|
125
|
+
Demo mode is the default and is intentionally fake:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
MOMO_MCP_MODE=demo uv run momo-mcp
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Live sandbox mode calls the MTN sandbox API. You need a subscription key and
|
|
132
|
+
sandbox API user/key:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
export MOMO_MCP_MODE=live
|
|
136
|
+
export MOMO_PRODUCT=collections
|
|
137
|
+
export MOMO_SUBSCRIPTION_KEY="..."
|
|
138
|
+
export MOMO_API_USER="..."
|
|
139
|
+
export MOMO_API_KEY="..."
|
|
140
|
+
export MOMO_TARGET_ENVIRONMENT="sandbox"
|
|
141
|
+
uv run momo-mcp
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Live mode only accepts `MOMO_TARGET_ENVIRONMENT=sandbox`. Any other target is
|
|
145
|
+
refused unless `MOMO_MCP_ALLOW_PRODUCTION=1` is set explicitly. Collection
|
|
146
|
+
amounts are capped by `MOMO_MCP_MAX_AMOUNT`, which defaults to `1000.00`.
|
|
147
|
+
|
|
148
|
+
Optional variables:
|
|
149
|
+
|
|
150
|
+
| Variable | Default | Description |
|
|
151
|
+
|---|---|---|
|
|
152
|
+
| `MOMO_PRODUCT` | `collections` | `collections`, `disbursements` or `remittances`. |
|
|
153
|
+
| `MOMO_TARGET_ENVIRONMENT` | `sandbox` | MTN target environment. |
|
|
154
|
+
| `MOMO_BASE_URL` | MTN sandbox URL | Override the API base URL. |
|
|
155
|
+
| `MOMO_TIMEOUT` | `30` | Request timeout in seconds. |
|
|
156
|
+
| `MOMO_MAX_RETRIES` | `2` | Retry count for transient failures. |
|
|
157
|
+
| `MOMO_MCP_MAX_AMOUNT` | `1000.00` | Maximum collection amount accepted by this server. |
|
|
158
|
+
| `MOMO_MCP_ALLOW_PRODUCTION` | unset | Must be `1` to allow a non-sandbox target environment. |
|
|
159
|
+
|
|
160
|
+
## Security
|
|
161
|
+
|
|
162
|
+
- Demo mode is the default. It never contacts MTN and never moves money.
|
|
163
|
+
- Live mode refuses non-sandbox targets unless `MOMO_MCP_ALLOW_PRODUCTION=1`.
|
|
164
|
+
- Collection amounts are capped by `MOMO_MCP_MAX_AMOUNT` (default `1000.00`).
|
|
165
|
+
- Secrets are read from environment variables and are never returned by tools.
|
|
166
|
+
- `momo_get_config` reports whether credentials exist, not their values.
|
|
167
|
+
- If a live collection request loses its response, the tool returns the original
|
|
168
|
+
`reference_id` with `status: UNKNOWN` and tells the agent to verify that
|
|
169
|
+
reference id instead of creating a second request.
|
|
170
|
+
- A rejected request returns `status: FAILED` and must not be polled.
|
|
171
|
+
- Do not point this server at production without an explicit review of limits,
|
|
172
|
+
approvals, idempotency and audit logging.
|
|
173
|
+
|
|
174
|
+
## Development
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
uv sync --extra dev
|
|
178
|
+
uv run ruff check .
|
|
179
|
+
uv run mypy
|
|
180
|
+
uv run pytest
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT
|
momo_mcp-0.1.0/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# momo-mcp
|
|
2
|
+
|
|
3
|
+
[](https://github.com/G2on61/momo-mcp/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
**MTN Mobile Money sandbox tools for AI agents, over MCP.**
|
|
7
|
+
|
|
8
|
+
<!-- mcp-name: io.github.G2on61/momo-mcp -->
|
|
9
|
+
|
|
10
|
+
`momo-mcp` lets Claude Code, Cursor, Codex and other MCP clients test MTN MoMo
|
|
11
|
+
flows without reading a 200-page API spec first. It runs in **demo mode by
|
|
12
|
+
default**: no credentials, no network calls, no real money.
|
|
13
|
+
|
|
14
|
+
Ask your agent:
|
|
15
|
+
|
|
16
|
+
> Create a sandbox collection of 100 EUR for +237650000000, then check its status.
|
|
17
|
+
|
|
18
|
+
The agent gets a reference id, a PENDING status, and a clear next step. The
|
|
19
|
+
first status check moves the demo transaction to SUCCESSFUL so the full flow is
|
|
20
|
+
visible without any network call.
|
|
21
|
+
|
|
22
|
+
## Why
|
|
23
|
+
|
|
24
|
+
AI agents are good at calling tools, but payment APIs are still awkward:
|
|
25
|
+
authentication, product-specific endpoints, reference ids, status polling and
|
|
26
|
+
sandbox setup. `momo-mcp` exposes a small, safe tool surface so an agent can:
|
|
27
|
+
|
|
28
|
+
- inspect the active product and configuration;
|
|
29
|
+
- list MoMo products and capabilities;
|
|
30
|
+
- read a balance;
|
|
31
|
+
- check whether a number is active;
|
|
32
|
+
- create a sandbox collection request;
|
|
33
|
+
- read a transaction status.
|
|
34
|
+
|
|
35
|
+
It is built on top of the published
|
|
36
|
+
[`mtn-momo-collection`](https://pypi.org/project/mtn-momo-collection/) SDK.
|
|
37
|
+
|
|
38
|
+
## Quick start
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
git clone https://github.com/G2on61/momo-mcp.git
|
|
42
|
+
cd momo-mcp
|
|
43
|
+
uv run momo-mcp
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The server speaks MCP over stdio. It starts in demo mode.
|
|
47
|
+
|
|
48
|
+
### Claude Desktop / Cursor
|
|
49
|
+
|
|
50
|
+
Add this to your MCP client configuration:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"mcpServers": {
|
|
55
|
+
"momo": {
|
|
56
|
+
"command": "uv",
|
|
57
|
+
"args": ["run", "--directory", "/absolute/path/to/momo-mcp", "momo-mcp"],
|
|
58
|
+
"env": {
|
|
59
|
+
"MOMO_MCP_MODE": "demo"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
After the package is published to PyPI, the command can be shortened to:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"mcpServers": {
|
|
71
|
+
"momo": {
|
|
72
|
+
"command": "uvx",
|
|
73
|
+
"args": ["momo-mcp"],
|
|
74
|
+
"env": {
|
|
75
|
+
"MOMO_MCP_MODE": "demo"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Tools
|
|
83
|
+
|
|
84
|
+
| Tool | What it does |
|
|
85
|
+
|---|---|
|
|
86
|
+
| `momo_get_config` | Shows mode, product and whether live credentials are present. |
|
|
87
|
+
| `momo_list_products` | Lists collections, disbursements and remittances capabilities. |
|
|
88
|
+
| `momo_get_balance` | Reads the active product balance. |
|
|
89
|
+
| `momo_check_msisdn` | Checks whether a number is active. |
|
|
90
|
+
| `momo_request_collection` | Creates a collection request and returns a reference id. |
|
|
91
|
+
| `momo_get_transaction_status` | Reads a collection, disbursement or remittance status. |
|
|
92
|
+
| `momo_list_demo_transactions` | Lists transactions created in the current demo process. |
|
|
93
|
+
|
|
94
|
+
## Demo mode vs live sandbox
|
|
95
|
+
|
|
96
|
+
Demo mode is the default and is intentionally fake:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
MOMO_MCP_MODE=demo uv run momo-mcp
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Live sandbox mode calls the MTN sandbox API. You need a subscription key and
|
|
103
|
+
sandbox API user/key:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
export MOMO_MCP_MODE=live
|
|
107
|
+
export MOMO_PRODUCT=collections
|
|
108
|
+
export MOMO_SUBSCRIPTION_KEY="..."
|
|
109
|
+
export MOMO_API_USER="..."
|
|
110
|
+
export MOMO_API_KEY="..."
|
|
111
|
+
export MOMO_TARGET_ENVIRONMENT="sandbox"
|
|
112
|
+
uv run momo-mcp
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Live mode only accepts `MOMO_TARGET_ENVIRONMENT=sandbox`. Any other target is
|
|
116
|
+
refused unless `MOMO_MCP_ALLOW_PRODUCTION=1` is set explicitly. Collection
|
|
117
|
+
amounts are capped by `MOMO_MCP_MAX_AMOUNT`, which defaults to `1000.00`.
|
|
118
|
+
|
|
119
|
+
Optional variables:
|
|
120
|
+
|
|
121
|
+
| Variable | Default | Description |
|
|
122
|
+
|---|---|---|
|
|
123
|
+
| `MOMO_PRODUCT` | `collections` | `collections`, `disbursements` or `remittances`. |
|
|
124
|
+
| `MOMO_TARGET_ENVIRONMENT` | `sandbox` | MTN target environment. |
|
|
125
|
+
| `MOMO_BASE_URL` | MTN sandbox URL | Override the API base URL. |
|
|
126
|
+
| `MOMO_TIMEOUT` | `30` | Request timeout in seconds. |
|
|
127
|
+
| `MOMO_MAX_RETRIES` | `2` | Retry count for transient failures. |
|
|
128
|
+
| `MOMO_MCP_MAX_AMOUNT` | `1000.00` | Maximum collection amount accepted by this server. |
|
|
129
|
+
| `MOMO_MCP_ALLOW_PRODUCTION` | unset | Must be `1` to allow a non-sandbox target environment. |
|
|
130
|
+
|
|
131
|
+
## Security
|
|
132
|
+
|
|
133
|
+
- Demo mode is the default. It never contacts MTN and never moves money.
|
|
134
|
+
- Live mode refuses non-sandbox targets unless `MOMO_MCP_ALLOW_PRODUCTION=1`.
|
|
135
|
+
- Collection amounts are capped by `MOMO_MCP_MAX_AMOUNT` (default `1000.00`).
|
|
136
|
+
- Secrets are read from environment variables and are never returned by tools.
|
|
137
|
+
- `momo_get_config` reports whether credentials exist, not their values.
|
|
138
|
+
- If a live collection request loses its response, the tool returns the original
|
|
139
|
+
`reference_id` with `status: UNKNOWN` and tells the agent to verify that
|
|
140
|
+
reference id instead of creating a second request.
|
|
141
|
+
- A rejected request returns `status: FAILED` and must not be polled.
|
|
142
|
+
- Do not point this server at production without an explicit review of limits,
|
|
143
|
+
approvals, idempotency and audit logging.
|
|
144
|
+
|
|
145
|
+
## Development
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
uv sync --extra dev
|
|
149
|
+
uv run ruff check .
|
|
150
|
+
uv run mypy
|
|
151
|
+
uv run pytest
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
MIT
|
momo_mcp-0.1.0/SKILL.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: momo-mcp
|
|
3
|
+
description: Use when the user asks to test MTN Mobile Money, create a MoMo sandbox collection, check a MoMo transaction status, inspect a MoMo balance, or verify whether a mobile money number is active. Defaults to a safe demo mode with no real money.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# MTN Mobile Money sandbox with `momo-mcp`
|
|
7
|
+
|
|
8
|
+
Use the `momo-mcp` tools when the user wants to exercise MTN MoMo flows.
|
|
9
|
+
|
|
10
|
+
## Safety rules
|
|
11
|
+
|
|
12
|
+
1. Assume demo mode unless the user explicitly configured live credentials.
|
|
13
|
+
2. Never claim a payment succeeded. Report the exact `status` returned by a tool.
|
|
14
|
+
3. Always keep and show the `reference_id`.
|
|
15
|
+
4. Do not retry a collection request with a new reference id to "make it work".
|
|
16
|
+
First read the status of the existing reference id.
|
|
17
|
+
5. If a live request returns `status: UNKNOWN`, verify the same `reference_id`.
|
|
18
|
+
Never create a second collection just because the response was lost.
|
|
19
|
+
6. If a request returns `status: FAILED`, do not poll it. Show the error and fix
|
|
20
|
+
the request first.
|
|
21
|
+
7. Respect `MOMO_MCP_MAX_AMOUNT`; do not split a large payment into multiple
|
|
22
|
+
requests to bypass the cap.
|
|
23
|
+
8. Live mode is sandbox-only unless the user explicitly enabled
|
|
24
|
+
`MOMO_MCP_ALLOW_PRODUCTION=1`.
|
|
25
|
+
9. Never ask for or print `MOMO_SUBSCRIPTION_KEY`, `MOMO_API_USER` or
|
|
26
|
+
`MOMO_API_KEY`.
|
|
27
|
+
|
|
28
|
+
## Typical flow
|
|
29
|
+
|
|
30
|
+
1. Call `momo_get_config` to see whether the server is in demo or live mode.
|
|
31
|
+
2. Call `momo_list_products` if the user is unsure which product they need.
|
|
32
|
+
3. For a collection:
|
|
33
|
+
- call `momo_request_collection` with amount, currency, external_id and
|
|
34
|
+
payer MSISDN;
|
|
35
|
+
- keep the returned `reference_id`;
|
|
36
|
+
- call `momo_get_transaction_status` with that reference id.
|
|
37
|
+
4. For balances, call `momo_get_balance`.
|
|
38
|
+
5. For number validation, call `momo_check_msisdn`.
|
|
39
|
+
|
|
40
|
+
## Example
|
|
41
|
+
|
|
42
|
+
User: "Create a 100 EUR sandbox collection for +237650000000 and check it."
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"amount": "100.00",
|
|
47
|
+
"currency": "EUR",
|
|
48
|
+
"external_id": "invoice-2026-001",
|
|
49
|
+
"payer_msisdn": "+237650000000",
|
|
50
|
+
"payer_message": "Test payment",
|
|
51
|
+
"payee_note": "Sandbox collection"
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then read the returned `reference_id` with `momo_get_transaction_status`.
|
|
56
|
+
|
|
57
|
+
## Failure handling
|
|
58
|
+
|
|
59
|
+
- If a tool says the reference id is unknown, do not invent a status. Create a
|
|
60
|
+
new request only if the user asks.
|
|
61
|
+
- If a live request returns `UNKNOWN`, check the status of the returned
|
|
62
|
+
`reference_id`; do not create another request.
|
|
63
|
+
- If live mode reports missing credentials, explain which environment variables
|
|
64
|
+
are missing without printing any values.
|
|
65
|
+
- If the API returns `FAILED`, show the error and the reference id, and stop.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mcpServers": {
|
|
3
|
+
"momo": {
|
|
4
|
+
"command": "uv",
|
|
5
|
+
"args": ["run", "--directory", "/absolute/path/to/momo-mcp", "momo-mcp"],
|
|
6
|
+
"env": {
|
|
7
|
+
"MOMO_MCP_MODE": "live",
|
|
8
|
+
"MOMO_PRODUCT": "collections",
|
|
9
|
+
"MOMO_TARGET_ENVIRONMENT": "sandbox",
|
|
10
|
+
"MOMO_SUBSCRIPTION_KEY": "replace-me",
|
|
11
|
+
"MOMO_API_USER": "replace-me",
|
|
12
|
+
"MOMO_API_KEY": "replace-me",
|
|
13
|
+
"MOMO_MCP_MAX_AMOUNT": "1000.00"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "momo-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "MTN Mobile Money sandbox tools for AI agents, exposed over MCP."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Gedeon ONDELE", email = "gedeon@ondele.fr" }]
|
|
13
|
+
keywords = ["mcp", "mtn", "momo", "mobile-money", "ai-agents", "claude", "cursor"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Software Development :: Libraries",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"mcp>=2.3,<3",
|
|
27
|
+
"mtn-momo-collection>=0.1,<0.2",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
dev = [
|
|
32
|
+
"mypy>=1.14",
|
|
33
|
+
"pytest>=8.3",
|
|
34
|
+
"ruff>=0.11",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.scripts]
|
|
38
|
+
momo-mcp = "momo_mcp.server:main"
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/G2on61/momo-mcp"
|
|
42
|
+
Repository = "https://github.com/G2on61/momo-mcp"
|
|
43
|
+
Issues = "https://github.com/G2on61/momo-mcp/issues"
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.wheel]
|
|
46
|
+
packages = ["src/momo_mcp"]
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.sdist]
|
|
49
|
+
include = ["src/momo_mcp", "tests", "examples", "server.json", "README.md", "SKILL.md", "LICENSE"]
|
|
50
|
+
|
|
51
|
+
[tool.pytest.ini_options]
|
|
52
|
+
testpaths = ["tests"]
|
|
53
|
+
pythonpath = ["src"]
|
|
54
|
+
|
|
55
|
+
[tool.ruff]
|
|
56
|
+
line-length = 100
|
|
57
|
+
target-version = "py310"
|
|
58
|
+
|
|
59
|
+
[tool.ruff.lint]
|
|
60
|
+
select = ["E", "F", "I", "UP", "B", "SIM"]
|
|
61
|
+
|
|
62
|
+
[tool.mypy]
|
|
63
|
+
python_version = "3.10"
|
|
64
|
+
strict = true
|
|
65
|
+
files = ["src", "tests"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.G2on61/momo-mcp",
|
|
4
|
+
"title": "MTN Mobile Money",
|
|
5
|
+
"description": "Sandbox-first MTN Mobile Money tools for AI agents, over MCP.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "https://github.com/G2on61/momo-mcp",
|
|
8
|
+
"source": "github"
|
|
9
|
+
},
|
|
10
|
+
"version": "0.1.0",
|
|
11
|
+
"packages": [
|
|
12
|
+
{
|
|
13
|
+
"registryType": "pypi",
|
|
14
|
+
"identifier": "momo-mcp",
|
|
15
|
+
"version": "0.1.0",
|
|
16
|
+
"transport": {
|
|
17
|
+
"type": "stdio"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Credential-free demo backend for local exploration and tests."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import threading
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
_LOCK = threading.Lock()
|
|
10
|
+
_TRANSACTIONS: dict[str, dict[str, Any]] = {}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _now() -> str:
|
|
14
|
+
return datetime.now(timezone.utc).isoformat()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def balance(currency: str = "EUR") -> dict[str, Any]:
|
|
18
|
+
return {
|
|
19
|
+
"availableBalance": "100000.00",
|
|
20
|
+
"currency": currency.upper(),
|
|
21
|
+
"mode": "demo",
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def request_collection(
|
|
26
|
+
*,
|
|
27
|
+
reference_id: str,
|
|
28
|
+
amount: str,
|
|
29
|
+
currency: str,
|
|
30
|
+
external_id: str,
|
|
31
|
+
payer_msisdn: str,
|
|
32
|
+
payer_message: str = "",
|
|
33
|
+
payee_note: str = "",
|
|
34
|
+
) -> dict[str, Any]:
|
|
35
|
+
record: dict[str, Any] = {
|
|
36
|
+
"reference_id": reference_id,
|
|
37
|
+
"status": "PENDING",
|
|
38
|
+
"amount": amount,
|
|
39
|
+
"currency": currency.upper(),
|
|
40
|
+
"external_id": external_id,
|
|
41
|
+
"payer_msisdn": payer_msisdn,
|
|
42
|
+
"payer_message": payer_message,
|
|
43
|
+
"payee_note": payee_note,
|
|
44
|
+
"mode": "demo",
|
|
45
|
+
"created_at": _now(),
|
|
46
|
+
}
|
|
47
|
+
with _LOCK:
|
|
48
|
+
_TRANSACTIONS[reference_id] = record
|
|
49
|
+
return dict(record)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def get_transaction(reference_id: str) -> dict[str, Any]:
|
|
53
|
+
with _LOCK:
|
|
54
|
+
record = _TRANSACTIONS.get(reference_id)
|
|
55
|
+
if record is None:
|
|
56
|
+
return {
|
|
57
|
+
"reference_id": reference_id,
|
|
58
|
+
"status": "UNKNOWN",
|
|
59
|
+
"mode": "demo",
|
|
60
|
+
"detail": "No demo transaction with this reference id. Create one first.",
|
|
61
|
+
}
|
|
62
|
+
if record["status"] == "PENDING":
|
|
63
|
+
record = {**record, "status": "SUCCESSFUL", "updated_at": _now()}
|
|
64
|
+
_TRANSACTIONS[reference_id] = record
|
|
65
|
+
return dict(record)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def list_transactions() -> list[dict[str, Any]]:
|
|
69
|
+
with _LOCK:
|
|
70
|
+
return [dict(record) for record in _TRANSACTIONS.values()]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def reset() -> None:
|
|
74
|
+
with _LOCK:
|
|
75
|
+
_TRANSACTIONS.clear()
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"""MCP server exposing MTN Mobile Money sandbox tools to AI agents."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
from decimal import Decimal, InvalidOperation
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from mcp.server.mcpserver import MCPServer
|
|
11
|
+
from mtn_momo import (
|
|
12
|
+
APIError,
|
|
13
|
+
Collections,
|
|
14
|
+
Config,
|
|
15
|
+
Disbursements,
|
|
16
|
+
MoMoError,
|
|
17
|
+
NetworkError,
|
|
18
|
+
Remittances,
|
|
19
|
+
Transaction,
|
|
20
|
+
new_reference_id,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
from momo_mcp import __version__, demo
|
|
24
|
+
|
|
25
|
+
SERVER_NAME = "momo-mcp"
|
|
26
|
+
PRODUCTS = ("collections", "disbursements", "remittances")
|
|
27
|
+
SANDBOX_TARGET_ENVIRONMENT = "sandbox"
|
|
28
|
+
DEFAULT_MAX_AMOUNT = "1000.00"
|
|
29
|
+
_CURRENCY_RE = re.compile(r"^[A-Za-z]{3}$")
|
|
30
|
+
_MSISDN_RE = re.compile(r"^\+?\d{6,15}$")
|
|
31
|
+
|
|
32
|
+
server = MCPServer(
|
|
33
|
+
name=SERVER_NAME,
|
|
34
|
+
title="MTN Mobile Money",
|
|
35
|
+
description=(
|
|
36
|
+
"Sandbox-first MTN MoMo tools for AI agents: collections, disbursements, "
|
|
37
|
+
"remittances, balances and transaction status."
|
|
38
|
+
),
|
|
39
|
+
version=__version__,
|
|
40
|
+
instructions=(
|
|
41
|
+
"Demo mode is enabled by default and never moves real money. "
|
|
42
|
+
"Set MOMO_MCP_MODE=live plus MOMO_SUBSCRIPTION_KEY, MOMO_API_USER and "
|
|
43
|
+
"MOMO_API_KEY to call the MTN sandbox. Live mode refuses non-sandbox "
|
|
44
|
+
"targets unless MOMO_MCP_ALLOW_PRODUCTION=1 is set explicitly. Collection "
|
|
45
|
+
"amounts are capped by MOMO_MCP_MAX_AMOUNT. Always show the reference id "
|
|
46
|
+
"and status returned by a tool. If a request returns UNKNOWN, verify that "
|
|
47
|
+
"reference id instead of creating a second collection. Never invent a "
|
|
48
|
+
"successful payment status."
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _mode() -> str:
|
|
54
|
+
mode = os.getenv("MOMO_MCP_MODE", "demo").strip().lower()
|
|
55
|
+
if mode not in {"demo", "live"}:
|
|
56
|
+
raise ValueError("MOMO_MCP_MODE must be 'demo' or 'live'")
|
|
57
|
+
return mode
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _product_name() -> str:
|
|
61
|
+
product = os.getenv("MOMO_PRODUCT", "collections").strip().lower()
|
|
62
|
+
if product not in PRODUCTS:
|
|
63
|
+
raise ValueError(f"MOMO_PRODUCT must be one of: {', '.join(PRODUCTS)}")
|
|
64
|
+
return product
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _env_flag(name: str) -> bool:
|
|
68
|
+
return os.getenv(name, "").strip().lower() in {"1", "true", "yes", "on"}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _allow_production() -> bool:
|
|
72
|
+
return _env_flag("MOMO_MCP_ALLOW_PRODUCTION")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _max_amount() -> Decimal:
|
|
76
|
+
raw = os.getenv("MOMO_MCP_MAX_AMOUNT", DEFAULT_MAX_AMOUNT).strip()
|
|
77
|
+
try:
|
|
78
|
+
value = Decimal(raw)
|
|
79
|
+
except (InvalidOperation, ValueError) as exc:
|
|
80
|
+
raise ValueError("MOMO_MCP_MAX_AMOUNT must be a decimal number") from exc
|
|
81
|
+
if not value.is_finite() or value <= 0:
|
|
82
|
+
raise ValueError("MOMO_MCP_MAX_AMOUNT must be a finite number greater than zero")
|
|
83
|
+
return value
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _live_config() -> Config:
|
|
87
|
+
env_names = ("MOMO_SUBSCRIPTION_KEY", "MOMO_API_USER", "MOMO_API_KEY")
|
|
88
|
+
missing = [name for name in env_names if not os.getenv(name)]
|
|
89
|
+
if missing:
|
|
90
|
+
raise RuntimeError(f"Live mode needs these environment variables: {', '.join(missing)}")
|
|
91
|
+
config = Config.from_env()
|
|
92
|
+
if config.target_environment != SANDBOX_TARGET_ENVIRONMENT and not _allow_production():
|
|
93
|
+
raise RuntimeError(
|
|
94
|
+
"Live mode refuses non-sandbox targets. Set MOMO_MCP_ALLOW_PRODUCTION=1 "
|
|
95
|
+
"only after reviewing transaction limits and approval controls."
|
|
96
|
+
)
|
|
97
|
+
return config
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _live_product(config: Config) -> Any:
|
|
101
|
+
product = _product_name()
|
|
102
|
+
if product == "collections":
|
|
103
|
+
return Collections(config)
|
|
104
|
+
if product == "disbursements":
|
|
105
|
+
return Disbursements(config)
|
|
106
|
+
return Remittances(config)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _validate_amount(amount: str) -> str:
|
|
110
|
+
try:
|
|
111
|
+
value = Decimal(str(amount))
|
|
112
|
+
except (InvalidOperation, ValueError) as exc:
|
|
113
|
+
raise ValueError("amount must be a decimal number, for example '100.00'") from exc
|
|
114
|
+
if not value.is_finite() or value <= 0:
|
|
115
|
+
raise ValueError("amount must be a finite number greater than zero")
|
|
116
|
+
maximum = _max_amount()
|
|
117
|
+
if value > maximum:
|
|
118
|
+
raise ValueError(f"amount exceeds MOMO_MCP_MAX_AMOUNT ({maximum})")
|
|
119
|
+
return str(amount)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _validate_currency(currency: str) -> str:
|
|
123
|
+
if not _CURRENCY_RE.fullmatch(currency):
|
|
124
|
+
raise ValueError("currency must be a 3-letter ISO code, for example 'EUR'")
|
|
125
|
+
return currency.upper()
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _validate_msisdn(msisdn: str) -> str:
|
|
129
|
+
if not _MSISDN_RE.fullmatch(msisdn):
|
|
130
|
+
raise ValueError("payer_msisdn must be digits with an optional leading +")
|
|
131
|
+
return msisdn
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _transaction_dict(transaction: Transaction) -> dict[str, Any]:
|
|
135
|
+
return {
|
|
136
|
+
"reference_id": transaction.reference_id,
|
|
137
|
+
"status": transaction.status.value,
|
|
138
|
+
"amount": transaction.amount,
|
|
139
|
+
"currency": transaction.currency,
|
|
140
|
+
"external_id": transaction.external_id,
|
|
141
|
+
"financial_transaction_id": transaction.financial_transaction_id,
|
|
142
|
+
"reason": transaction.reason,
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@server.tool(description="Show the active mode, product and safe configuration summary.")
|
|
147
|
+
def momo_get_config() -> dict[str, Any]:
|
|
148
|
+
mode = _mode()
|
|
149
|
+
product = _product_name()
|
|
150
|
+
live_ready = all(
|
|
151
|
+
os.getenv(name)
|
|
152
|
+
for name in ("MOMO_SUBSCRIPTION_KEY", "MOMO_API_USER", "MOMO_API_KEY")
|
|
153
|
+
)
|
|
154
|
+
return {
|
|
155
|
+
"mode": mode,
|
|
156
|
+
"product": product,
|
|
157
|
+
"target_environment": os.getenv("MOMO_TARGET_ENVIRONMENT", "sandbox"),
|
|
158
|
+
"live_ready": live_ready,
|
|
159
|
+
"production_allowed": _allow_production(),
|
|
160
|
+
"max_amount": str(_max_amount()),
|
|
161
|
+
"demo_by_default": True,
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@server.tool(
|
|
166
|
+
description="List the MTN MoMo products and the actions available through this server."
|
|
167
|
+
)
|
|
168
|
+
def momo_list_products() -> list[dict[str, Any]]:
|
|
169
|
+
return [
|
|
170
|
+
{
|
|
171
|
+
"name": "collections",
|
|
172
|
+
"description": "Request payments from a payer and read collection status.",
|
|
173
|
+
"actions": ["request_collection", "get_transaction_status", "get_balance"],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"name": "disbursements",
|
|
177
|
+
"description": "Read disbursement balance and transfer status.",
|
|
178
|
+
"actions": ["get_transaction_status", "get_balance"],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"name": "remittances",
|
|
182
|
+
"description": "Read remittance balance and transfer status.",
|
|
183
|
+
"actions": ["get_transaction_status", "get_balance"],
|
|
184
|
+
},
|
|
185
|
+
]
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
@server.tool(description="Read the MTN MoMo account balance for the active product.")
|
|
189
|
+
def momo_get_balance(currency: str = "EUR") -> dict[str, Any]:
|
|
190
|
+
currency = _validate_currency(currency)
|
|
191
|
+
if _mode() == "demo":
|
|
192
|
+
return demo.balance(currency)
|
|
193
|
+
result = dict(_live_product(_live_config()).balance())
|
|
194
|
+
result["requested_currency"] = currency
|
|
195
|
+
actual_currency = str(result.get("currency", "")).upper()
|
|
196
|
+
if actual_currency and actual_currency != currency:
|
|
197
|
+
result["currency_mismatch"] = True
|
|
198
|
+
return result
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
@server.tool(description="Check whether a mobile money number is active for the active product.")
|
|
202
|
+
def momo_check_msisdn(msisdn: str) -> dict[str, Any]:
|
|
203
|
+
msisdn = _validate_msisdn(msisdn)
|
|
204
|
+
if _mode() == "demo":
|
|
205
|
+
return {"msisdn": msisdn, "active": True, "mode": "demo"}
|
|
206
|
+
active = bool(_live_product(_live_config()).is_active(msisdn))
|
|
207
|
+
return {"msisdn": msisdn, "active": active, "mode": "live"}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
@server.tool(
|
|
211
|
+
description=(
|
|
212
|
+
"Create a sandbox collection request (request-to-pay) and return its reference id. "
|
|
213
|
+
"In demo mode this never contacts MTN and never moves money."
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
def momo_request_collection(
|
|
217
|
+
amount: str,
|
|
218
|
+
currency: str,
|
|
219
|
+
external_id: str,
|
|
220
|
+
payer_msisdn: str,
|
|
221
|
+
payer_message: str = "",
|
|
222
|
+
payee_note: str = "",
|
|
223
|
+
) -> dict[str, Any]:
|
|
224
|
+
if _product_name() != "collections":
|
|
225
|
+
raise ValueError("momo_request_collection requires MOMO_PRODUCT=collections")
|
|
226
|
+
amount = _validate_amount(amount)
|
|
227
|
+
currency = _validate_currency(currency)
|
|
228
|
+
payer_msisdn = _validate_msisdn(payer_msisdn)
|
|
229
|
+
if not external_id.strip():
|
|
230
|
+
raise ValueError("external_id must not be empty")
|
|
231
|
+
reference_id = new_reference_id()
|
|
232
|
+
|
|
233
|
+
if _mode() == "demo":
|
|
234
|
+
record = demo.request_collection(
|
|
235
|
+
reference_id=reference_id,
|
|
236
|
+
amount=amount,
|
|
237
|
+
currency=currency,
|
|
238
|
+
external_id=external_id,
|
|
239
|
+
payer_msisdn=payer_msisdn,
|
|
240
|
+
payer_message=payer_message,
|
|
241
|
+
payee_note=payee_note,
|
|
242
|
+
)
|
|
243
|
+
return {
|
|
244
|
+
**record,
|
|
245
|
+
"next_step": "Call momo_get_transaction_status with this reference_id.",
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
result: dict[str, Any] = {
|
|
249
|
+
"reference_id": reference_id,
|
|
250
|
+
"amount": amount,
|
|
251
|
+
"currency": currency,
|
|
252
|
+
"external_id": external_id,
|
|
253
|
+
"mode": "live",
|
|
254
|
+
}
|
|
255
|
+
try:
|
|
256
|
+
product = _live_product(_live_config())
|
|
257
|
+
product.request_to_pay(
|
|
258
|
+
reference_id=reference_id,
|
|
259
|
+
amount=amount,
|
|
260
|
+
currency=currency,
|
|
261
|
+
external_id=external_id,
|
|
262
|
+
msisdn=payer_msisdn,
|
|
263
|
+
payer_message=payer_message,
|
|
264
|
+
payee_note=payee_note,
|
|
265
|
+
)
|
|
266
|
+
except APIError as exc:
|
|
267
|
+
if exc.status_code < 500 and exc.status_code not in {408, 409, 429}:
|
|
268
|
+
return {
|
|
269
|
+
**result,
|
|
270
|
+
"status": "FAILED",
|
|
271
|
+
"error": str(exc),
|
|
272
|
+
"next_step": (
|
|
273
|
+
"The request was rejected before acceptance. "
|
|
274
|
+
"Fix the error before retrying."
|
|
275
|
+
),
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
**result,
|
|
279
|
+
"status": "UNKNOWN",
|
|
280
|
+
"error": str(exc),
|
|
281
|
+
"next_step": (
|
|
282
|
+
"Do not create another collection. Call momo_get_transaction_status "
|
|
283
|
+
"with this reference_id first."
|
|
284
|
+
),
|
|
285
|
+
}
|
|
286
|
+
except NetworkError as exc:
|
|
287
|
+
return {
|
|
288
|
+
**result,
|
|
289
|
+
"status": "UNKNOWN",
|
|
290
|
+
"error": type(exc).__name__,
|
|
291
|
+
"next_step": (
|
|
292
|
+
"Do not create another collection. Call momo_get_transaction_status "
|
|
293
|
+
"with this reference_id first."
|
|
294
|
+
),
|
|
295
|
+
}
|
|
296
|
+
except MoMoError as exc:
|
|
297
|
+
return {
|
|
298
|
+
**result,
|
|
299
|
+
"status": "UNKNOWN",
|
|
300
|
+
"error": type(exc).__name__,
|
|
301
|
+
"next_step": (
|
|
302
|
+
"Do not create another collection. Call momo_get_transaction_status "
|
|
303
|
+
"with this reference_id first."
|
|
304
|
+
),
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
**result,
|
|
308
|
+
"status": "PENDING",
|
|
309
|
+
"next_step": "Call momo_get_transaction_status with this reference_id.",
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
@server.tool(
|
|
314
|
+
description=(
|
|
315
|
+
"Read the status of a collection, disbursement or remittance by reference id. "
|
|
316
|
+
"Use the reference id returned by momo_request_collection."
|
|
317
|
+
)
|
|
318
|
+
)
|
|
319
|
+
def momo_get_transaction_status(reference_id: str) -> dict[str, Any]:
|
|
320
|
+
if not reference_id.strip():
|
|
321
|
+
raise ValueError("reference_id must not be empty")
|
|
322
|
+
if _mode() == "demo":
|
|
323
|
+
return demo.get_transaction(reference_id)
|
|
324
|
+
|
|
325
|
+
product_name = _product_name()
|
|
326
|
+
config = _live_config()
|
|
327
|
+
if product_name == "collections":
|
|
328
|
+
transaction = Collections(config).get_payment(reference_id)
|
|
329
|
+
elif product_name == "disbursements":
|
|
330
|
+
transaction = Disbursements(config).get_transfer(reference_id)
|
|
331
|
+
else:
|
|
332
|
+
transaction = Remittances(config).get_transfer(reference_id)
|
|
333
|
+
return _transaction_dict(transaction)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
@server.tool(
|
|
337
|
+
description="List transactions created in this demo process. Unavailable in live mode."
|
|
338
|
+
)
|
|
339
|
+
def momo_list_demo_transactions() -> list[dict[str, Any]]:
|
|
340
|
+
if _mode() != "demo":
|
|
341
|
+
raise RuntimeError("momo_list_demo_transactions is only available in demo mode")
|
|
342
|
+
return demo.list_transactions()
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def main() -> None:
|
|
346
|
+
server.run()
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
if __name__ == "__main__":
|
|
350
|
+
main()
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
from mtn_momo import NetworkError
|
|
8
|
+
|
|
9
|
+
from momo_mcp import demo
|
|
10
|
+
from momo_mcp.server import (
|
|
11
|
+
_live_config,
|
|
12
|
+
momo_get_balance,
|
|
13
|
+
momo_request_collection,
|
|
14
|
+
server,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def call(name: str, arguments: dict[str, Any]) -> Any:
|
|
19
|
+
result: Any = asyncio.run(server.call_tool(name, arguments))
|
|
20
|
+
assert not result.is_error, result
|
|
21
|
+
data = result.structured_content
|
|
22
|
+
if isinstance(data, dict) and set(data) == {"result"}:
|
|
23
|
+
return data["result"]
|
|
24
|
+
return data
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.fixture(autouse=True)
|
|
28
|
+
def demo_environment(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
29
|
+
demo.reset()
|
|
30
|
+
monkeypatch.setenv("MOMO_MCP_MODE", "demo")
|
|
31
|
+
for name in (
|
|
32
|
+
"MOMO_PRODUCT",
|
|
33
|
+
"MOMO_SUBSCRIPTION_KEY",
|
|
34
|
+
"MOMO_API_USER",
|
|
35
|
+
"MOMO_API_KEY",
|
|
36
|
+
"MOMO_TARGET_ENVIRONMENT",
|
|
37
|
+
"MOMO_BASE_URL",
|
|
38
|
+
"MOMO_MCP_ALLOW_PRODUCTION",
|
|
39
|
+
"MOMO_MCP_MAX_AMOUNT",
|
|
40
|
+
):
|
|
41
|
+
monkeypatch.delenv(name, raising=False)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_config_is_demo_by_default() -> None:
|
|
45
|
+
config = call("momo_get_config", {})
|
|
46
|
+
assert config["mode"] == "demo"
|
|
47
|
+
assert config["product"] == "collections"
|
|
48
|
+
assert config["demo_by_default"] is True
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_list_products() -> None:
|
|
52
|
+
products = call("momo_list_products", {})
|
|
53
|
+
assert [product["name"] for product in products] == [
|
|
54
|
+
"collections",
|
|
55
|
+
"disbursements",
|
|
56
|
+
"remittances",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_demo_collection_and_status_round_trip() -> None:
|
|
61
|
+
created = call(
|
|
62
|
+
"momo_request_collection",
|
|
63
|
+
{
|
|
64
|
+
"amount": "100.00",
|
|
65
|
+
"currency": "eur",
|
|
66
|
+
"external_id": "invoice-001",
|
|
67
|
+
"payer_msisdn": "+237650000000",
|
|
68
|
+
},
|
|
69
|
+
)
|
|
70
|
+
reference_id = created["reference_id"]
|
|
71
|
+
assert created["status"] == "PENDING"
|
|
72
|
+
assert created["currency"] == "EUR"
|
|
73
|
+
|
|
74
|
+
status = call("momo_get_transaction_status", {"reference_id": reference_id})
|
|
75
|
+
assert status["reference_id"] == reference_id
|
|
76
|
+
assert status["status"] == "SUCCESSFUL"
|
|
77
|
+
assert status["amount"] == "100.00"
|
|
78
|
+
assert "updated_at" in status
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_demo_balance_and_msisdn() -> None:
|
|
82
|
+
assert call("momo_get_balance", {"currency": "XAF"})["currency"] == "XAF"
|
|
83
|
+
assert call("momo_check_msisdn", {"msisdn": "+237650000000"})["active"] is True
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def test_unknown_demo_reference_is_not_invented() -> None:
|
|
87
|
+
status = call("momo_get_transaction_status", {"reference_id": "missing"})
|
|
88
|
+
assert status["status"] == "UNKNOWN"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_invalid_amount_is_rejected() -> None:
|
|
92
|
+
with pytest.raises(ValueError, match="greater than zero"):
|
|
93
|
+
momo_request_collection(
|
|
94
|
+
amount="-1",
|
|
95
|
+
currency="EUR",
|
|
96
|
+
external_id="invoice-001",
|
|
97
|
+
payer_msisdn="+237650000000",
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_live_mode_without_credentials_reports_missing_variables(
|
|
102
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
103
|
+
) -> None:
|
|
104
|
+
monkeypatch.setenv("MOMO_MCP_MODE", "live")
|
|
105
|
+
with pytest.raises(RuntimeError, match="MOMO_SUBSCRIPTION_KEY"):
|
|
106
|
+
momo_get_balance()
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_collection_requires_collections_product(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
110
|
+
monkeypatch.setenv("MOMO_PRODUCT", "disbursements")
|
|
111
|
+
with pytest.raises(ValueError, match="MOMO_PRODUCT=collections"):
|
|
112
|
+
momo_request_collection(
|
|
113
|
+
amount="100.00",
|
|
114
|
+
currency="EUR",
|
|
115
|
+
external_id="invoice-001",
|
|
116
|
+
payer_msisdn="+237650000000",
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_live_refuses_non_sandbox_target(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
121
|
+
monkeypatch.setenv("MOMO_MCP_MODE", "live")
|
|
122
|
+
monkeypatch.setenv("MOMO_SUBSCRIPTION_KEY", "key")
|
|
123
|
+
monkeypatch.setenv("MOMO_API_USER", "user")
|
|
124
|
+
monkeypatch.setenv("MOMO_API_KEY", "secret")
|
|
125
|
+
monkeypatch.setenv("MOMO_TARGET_ENVIRONMENT", "mtncongo")
|
|
126
|
+
monkeypatch.setenv("MOMO_BASE_URL", "https://api.momo.example")
|
|
127
|
+
with pytest.raises(RuntimeError, match="MOMO_MCP_ALLOW_PRODUCTION"):
|
|
128
|
+
_live_config()
|
|
129
|
+
|
|
130
|
+
monkeypatch.setenv("MOMO_MCP_ALLOW_PRODUCTION", "1")
|
|
131
|
+
assert _live_config().target_environment == "mtncongo"
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_amount_cap_is_enforced(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
135
|
+
monkeypatch.setenv("MOMO_MCP_MAX_AMOUNT", "50.00")
|
|
136
|
+
with pytest.raises(ValueError, match="MOMO_MCP_MAX_AMOUNT"):
|
|
137
|
+
momo_request_collection(
|
|
138
|
+
amount="100.00",
|
|
139
|
+
currency="EUR",
|
|
140
|
+
external_id="invoice-001",
|
|
141
|
+
payer_msisdn="+237650000000",
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_live_network_error_preserves_reference(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
146
|
+
monkeypatch.setenv("MOMO_MCP_MODE", "live")
|
|
147
|
+
monkeypatch.setenv("MOMO_SUBSCRIPTION_KEY", "key")
|
|
148
|
+
monkeypatch.setenv("MOMO_API_USER", "user")
|
|
149
|
+
monkeypatch.setenv("MOMO_API_KEY", "secret")
|
|
150
|
+
|
|
151
|
+
class FailingProduct:
|
|
152
|
+
def request_to_pay(self, **kwargs: Any) -> None:
|
|
153
|
+
raise NetworkError("response lost")
|
|
154
|
+
|
|
155
|
+
monkeypatch.setattr("momo_mcp.server._live_product", lambda config: FailingProduct())
|
|
156
|
+
result = momo_request_collection(
|
|
157
|
+
amount="100.00",
|
|
158
|
+
currency="EUR",
|
|
159
|
+
external_id="invoice-001",
|
|
160
|
+
payer_msisdn="+237650000000",
|
|
161
|
+
)
|
|
162
|
+
assert result["status"] == "UNKNOWN"
|
|
163
|
+
assert result["reference_id"]
|
|
164
|
+
assert "Do not create another collection" in result["next_step"]
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_live_balance_reports_currency_mismatch(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
168
|
+
monkeypatch.setenv("MOMO_MCP_MODE", "live")
|
|
169
|
+
monkeypatch.setenv("MOMO_SUBSCRIPTION_KEY", "key")
|
|
170
|
+
monkeypatch.setenv("MOMO_API_USER", "user")
|
|
171
|
+
monkeypatch.setenv("MOMO_API_KEY", "secret")
|
|
172
|
+
|
|
173
|
+
class BalanceProduct:
|
|
174
|
+
def balance(self) -> dict[str, str]:
|
|
175
|
+
return {"availableBalance": "1000.00", "currency": "XAF"}
|
|
176
|
+
|
|
177
|
+
monkeypatch.setattr("momo_mcp.server._live_product", lambda config: BalanceProduct())
|
|
178
|
+
result = momo_get_balance(currency="EUR")
|
|
179
|
+
assert result["requested_currency"] == "EUR"
|
|
180
|
+
assert result["currency_mismatch"] is True
|