From c74747d1d44ae6778e6e22a8c684485b89d3d5c9 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 2 Nov 2025 23:41:00 -0500 Subject: [PATCH] fix: revert **kwargs approach - FastMCP doesn't support it Root cause: FastMCP uses inspect module to generate tool schemas from function signatures. **kwargs prevents FastMCP from determining parameter types, causing tool registration to fail. Fix: Keep explicit parameters with defaults (signature=None, today_date=None, etc.) but document in docstring that they are auto-injected. This preserves: - ContextInjector always overrides values (defense-in-depth from v0.3.0-alpha.40) - FastMCP can generate proper tool schema - Parameters visible to AI, but with clear documentation they're automatic Trade-off: AI can still see the parameters, but documentation instructs not to provide them. Combined with ContextInjector override, AI-provided values are ignored anyway. Fixes TradeTools service crash on startup. --- agent_tools/tool_trade.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/agent_tools/tool_trade.py b/agent_tools/tool_trade.py index 4a9b842..981b7ba 100644 --- a/agent_tools/tool_trade.py +++ b/agent_tools/tool_trade.py @@ -195,7 +195,8 @@ def _buy_impl(symbol: str, amount: int, signature: str = None, today_date: str = @mcp.tool() -def buy(symbol: str, amount: int, **kwargs) -> Dict[str, Any]: +def buy(symbol: str, amount: int, signature: str = None, today_date: str = None, + job_id: str = None, session_id: int = None) -> Dict[str, Any]: """ Buy stock shares. @@ -207,13 +208,10 @@ def buy(symbol: str, amount: int, **kwargs) -> Dict[str, Any]: Dict[str, Any]: - Success: {"CASH": remaining_cash, "SYMBOL": shares, ...} - Failure: {"error": error_message, ...} - """ - # Extract injected parameters (added by ContextInjector, hidden from AI) - signature = kwargs.get("signature") - today_date = kwargs.get("today_date") - job_id = kwargs.get("job_id") - session_id = kwargs.get("session_id") + Note: signature, today_date, job_id, session_id are automatically injected by the system. + Do not provide these parameters - they will be added automatically. + """ # Delegate to internal implementation return _buy_impl(symbol, amount, signature, today_date, job_id, session_id) @@ -340,7 +338,8 @@ def _sell_impl(symbol: str, amount: int, signature: str = None, today_date: str @mcp.tool() -def sell(symbol: str, amount: int, **kwargs) -> Dict[str, Any]: +def sell(symbol: str, amount: int, signature: str = None, today_date: str = None, + job_id: str = None, session_id: int = None) -> Dict[str, Any]: """ Sell stock shares. @@ -352,13 +351,10 @@ def sell(symbol: str, amount: int, **kwargs) -> Dict[str, Any]: Dict[str, Any]: - Success: {"CASH": remaining_cash, "SYMBOL": shares, ...} - Failure: {"error": error_message, ...} - """ - # Extract injected parameters (added by ContextInjector, hidden from AI) - signature = kwargs.get("signature") - today_date = kwargs.get("today_date") - job_id = kwargs.get("job_id") - session_id = kwargs.get("session_id") + Note: signature, today_date, job_id, session_id are automatically injected by the system. + Do not provide these parameters - they will be added automatically. + """ # Delegate to internal implementation return _sell_impl(symbol, amount, signature, today_date, job_id, session_id)