@@ -173,18 +173,30 @@ def __init__(
173173 except Exception :
174174 self .mcp ._mcp_server .version = "0.12.5"
175175
176- # Initialize authentication token
176+ # Initialize authentication token — check env, then ~/.hanzo/mcp_token
177177 self .auth_token = auth_token or os .environ .get ("HANZO_MCP_TOKEN" )
178178 if not self .auth_token :
179- # Generate a secure random token if none provided
179+ token_path = os .path .expanduser ("~/.hanzo/mcp_token" )
180+ try :
181+ if os .path .exists (token_path ):
182+ with open (token_path ) as f :
183+ self .auth_token = f .read ().strip ()
184+ except OSError :
185+ pass
186+
187+ if not self .auth_token :
188+ # Generate and persist to ~/.hanzo/mcp_token
180189 self .auth_token = secrets .token_urlsafe (32 )
190+ token_path = os .path .expanduser ("~/.hanzo/mcp_token" )
191+ try :
192+ os .makedirs (os .path .dirname (token_path ), exist_ok = True )
193+ with open (token_path , "w" ) as f :
194+ f .write (self .auth_token )
195+ os .chmod (token_path , 0o600 )
196+ except OSError :
197+ pass
181198 logger = logging .getLogger (__name__ )
182- logger .warning (
183- f"No auth token provided. Generated token: { self .auth_token } "
184- )
185- logger .warning (
186- "Set HANZO_MCP_TOKEN environment variable for persistent auth"
187- )
199+ logger .info (f"Auth token persisted to { token_path } " )
188200
189201 # Initialize permissions and command executor
190202 PermissionManager = _get_permission_manager ()
@@ -345,13 +357,16 @@ def _start_zap_server(self) -> None:
345357 # Collect tool manifest from registered MCP tools
346358 tool_list : list [dict ] = []
347359 try :
348- # FastMCP stores tools internally — extract names and schemas
349- for name , tool in getattr (self .mcp , "_tool_manager" , {}).items ():
350- tool_list .append ({
351- "name" : name ,
352- "description" : getattr (tool , "description" , "" ),
353- "inputSchema" : getattr (tool , "parameters" , {}),
354- })
360+ # FastMCP _tool_manager._tools is a dict[str, Tool]
361+ tm = getattr (self .mcp , "_tool_manager" , None )
362+ if tm is not None :
363+ tools_dict = getattr (tm , "_tools" , {})
364+ for name , tool in tools_dict .items ():
365+ tool_list .append ({
366+ "name" : name ,
367+ "description" : getattr (tool , "description" , "" ),
368+ "inputSchema" : getattr (tool , "parameters" , {}),
369+ })
355370 except Exception :
356371 pass
357372
@@ -363,7 +378,7 @@ def _start_zap_server(self) -> None:
363378 tool_list .append ({
364379 "name" : t .name ,
365380 "description" : t .description or "" ,
366- "inputSchema" : getattr (t , "inputSchema " , {}),
381+ "inputSchema" : getattr (t , "parameters " , {}),
367382 })
368383 except Exception :
369384 pass
0 commit comments