feat: implement native MCP server support with safety guardrails - #145
feat: implement native MCP server support with safety guardrails#145Tech-no-mad wants to merge 3 commits into
Conversation
|
Hi @RafaelJohn9 , I've implemented the MCP server support as discussed in #140. |
|
Hi @Tech-no-mad , Could you kindly address the workflow errors. Also I'm deterred from merging this since we do not have |
RafaelJohn9
left a comment
There was a problem hiding this comment.
We need to add tests, fastmcp offers recommendation of implementing tests at: https://gofastmcp.com/development/tests, ,maybe we can draw insights from here 🤝
watersRand
left a comment
There was a problem hiding this comment.
Thanks for working on this! This is an excellent blueprint for the MCP server architecture—the use of enforce_security_guard and the explicit LLM agent instructions in the docstring are brilliant safety practices.Please note a few formatting noise issues and structural fixes:
Isolate the Linting: The automated formatting sweep is creating significant diff noise, completely obscuring your functional logic updates. Could we isolate the linting and styling fixes into a separate, independent commit or PR? This lets us track the core changes cleanly.
Expand Module Scope: Please remember to account for the wider integration footprint requested in the tracking issue. The implementation needs to provide tools for the full suite of M-Pesa operations—including C2B, B2C, B2B, Transaction Status, Account Balance, Reversals, Tax Remittance, and Dynamic QR—not just STK Push.
Fix Configuration Redundancy (stk_push): There is redundant environment variable lookup and parsing happening across both get_client() and individual tool actions (confusing API access credentials with merchant bank properties). Let’s centralize the configuration values (like keys, shortcodes, and passkeys) into a single configuration loader or class rather than re-querying os.environ inside every endpoint execution loop.
Remove Redundant Casts: FastMCP automatically uses your Python type hints (amount: int) to validate inputs via Pydantic before the tool runs. The manual amount=float(amount) typecasting inside the method is redundant. Trust the type hints and pass the variable directly.
a0dab86 to
4174011
Compare
RafaelJohn9
left a comment
There was a problem hiding this comment.
We still don't have ./mcp implementation .
RafaelJohn9
left a comment
There was a problem hiding this comment.
Hello @Tech-no-mad , thanks for updating PR few changes to consider.
- mcp should live at
./mcpnot./mpesakit/mcpto have two different packaages. - Address comments below.
- Remove the diff patch file
- I'd also recommend we split the
mcp/server.pyif possible. Currently it handles a lt and it maybe difficult to maintain and extend with new APIs.
| @@ -499,7 +499,7 @@ class StkPushQueryRequest(BaseModel): | |||
| json_schema_extra={ | |||
| "example": { | |||
| "BusinessShortCode": 654321, | |||
| "Password": "bXlwYXNzd29yZA==", | |||
| "Password": "bXlwYXNzd29yZA==", # nosec B105 | |||
| "Timestamp": "20240607123045", | |||
There was a problem hiding this comment.
no need for this fix, as is not part of the PR issue 🤝 .
Description
Type of Change
How Has This Been Tested?
Checklist
Screenshots (if applicable)
Additional Context