@@ -315,21 +315,6 @@ async def wrapper(*args, **kwargs):
315315 return decorator
316316
317317
318- # Define input and output structures for the tool
319- # These can be Pydantic models for more robust validation if the SDK supports it,
320- # or TypedDicts as used here.
321- class GenerateMockApiInput (TypedDict ):
322- spec_url_or_path : str
323- output_dir_name : str | None
324- # Example: Add more parameters like target_port: Optional[int]
325-
326-
327- class GenerateMockApiOutput (TypedDict ):
328- generated_mock_path : str
329- message : str
330- status : str # "success" or "error"
331-
332-
333318# New TypedDict definitions for enhanced tools
334319class QueryMockLogsInput (TypedDict ):
335320 server_url : str
@@ -399,8 +384,6 @@ class ManageMockDataOutput(TypedDict):
399384 name = "generate_mock_api" ,
400385 description = "Generates a FastAPI mock server from an API specification (e.g., OpenAPI). "
401386 "The mock server includes request/response logging and Docker support." ,
402- # input_schema=GenerateMockApiInput, # FastMCP infers from type hints
403- # output_schema=GenerateMockApiOutput, # FastMCP infers from return type hint
404387)
405388@mcp_audit_tool ("generate_mock_api" )
406389async def generate_mock_api_tool (
@@ -413,15 +396,14 @@ async def generate_mock_api_tool(
413396 business_port : int = 8000 ,
414397 admin_port : int | None = None ,
415398 # ctx: Context # MCP Context, can be added if tool needs to report progress, etc.
416- ) -> GenerateMockApiOutput :
399+ ) -> str :
417400 """
418401 MCP Tool to generate a mock API server.
419402
420403 Args:
421404 spec_url_or_path: URL or local file path to the API specification.
422405 output_dir_name: Optional name for the generated mock server directory.
423406 If None, a name is derived from the API title and version.
424- # ctx: The MCP Context object, automatically injected if type-hinted.
425407 """
426408 try :
427409 # Helper to robustly convert to boolean
@@ -434,76 +416,35 @@ def _tool_to_bool(value: Any) -> bool:
434416 return value != 0
435417 return bool (value )
436418
437- # Explicitly convert boolean flags at the tool entry point
438- # auth_enabled_bool = _tool_to_bool(auth_enabled)
439- # webhooks_enabled_bool = _tool_to_bool(webhooks_enabled)
440- # admin_ui_enabled_bool = _tool_to_bool(admin_ui_enabled)
441- # storage_enabled_bool = _tool_to_bool(storage_enabled)
442-
443- # DEBUG: Hardcode to True to test propagation to generator.py
444- auth_enabled_debug = True
445- webhooks_enabled_debug = True
446- admin_ui_enabled_debug = True
447- storage_enabled_debug = True
448-
449- # If using ctx for logging to MCP client:
450- # await ctx.info(f"Loading API specification from: {spec_url_or_path}")
451-
452- # Print received boolean flags for debugging
419+ # Convert boolean flags
420+ auth_enabled_bool = _tool_to_bool (auth_enabled )
421+ webhooks_enabled_bool = _tool_to_bool (webhooks_enabled )
422+ admin_ui_enabled_bool = _tool_to_bool (admin_ui_enabled )
423+ storage_enabled_bool = _tool_to_bool (storage_enabled )
453424
454425 parsed_spec = load_api_specification (spec_url_or_path )
455426
456- # await ctx.info(f"Generating mock API server...")
457- if output_dir_name :
458- # await ctx.info(f"Using custom output directory name: {output_dir_name}")
459- pass
460-
461427 generated_path = generate_mock_api (
462428 spec_data = parsed_spec ,
463429 mock_server_name = output_dir_name ,
464- auth_enabled = auth_enabled_debug , # Pass debug hardcoded True
465- webhooks_enabled = webhooks_enabled_debug , # Pass debug hardcoded True
466- admin_ui_enabled = admin_ui_enabled_debug , # Pass debug hardcoded True
467- storage_enabled = storage_enabled_debug , # Pass debug hardcoded True
430+ auth_enabled = auth_enabled_bool ,
431+ webhooks_enabled = webhooks_enabled_bool ,
432+ admin_ui_enabled = admin_ui_enabled_bool ,
433+ storage_enabled = storage_enabled_bool ,
468434 business_port = business_port ,
469435 admin_port = admin_port ,
470- # output_base_dir can be configured if needed, defaults to "generated_mocks"
471436 )
472437
473438 resolved_path = str (generated_path .resolve ())
474- # await ctx.info(f"Mock API server generated successfully at: {resolved_path}")
475439
476- return {
477- "generated_mock_path" : resolved_path ,
478- "message" : f"Mock API server generated successfully at { resolved_path } . "
479- f"Navigate to this directory and use 'docker-compose up --build' to run it." ,
480- "status" : "success" ,
481- }
440+ return f"Mock API server generated successfully at { resolved_path } . Navigate to this directory and use 'docker-compose up --build' to run it."
482441
483442 except APIParsingError as e :
484- # await ctx.error(f"Error parsing API specification: {e}")
485- return {
486- "generated_mock_path" : "" ,
487- "message" : f"Error parsing API specification: { e } " ,
488- "status" : "error" ,
489- }
443+ return f"Error parsing API specification: { e } "
490444 except APIGenerationError as e :
491- # await ctx.error(f"Error generating mock API: {e}")
492- return {
493- "generated_mock_path" : "" ,
494- "message" : f"Error generating mock API: { e } " ,
495- "status" : "error" ,
496- }
445+ return f"Error generating mock API: { e } "
497446 except Exception as e :
498- import traceback
499-
500- traceback .format_exc ()
501- # await ctx.error(f"An unexpected error occurred: {e}\n{error_details}")
502- return {
503- "generated_mock_path" : "" ,
504- "message" : f"An unexpected error occurred: { e } " ,
505- "status" : "error" ,
506- }
447+ return f"An unexpected error occurred: { e } "
507448
508449
509450@server .tool (
@@ -1794,21 +1735,13 @@ async def run_tool_from_cli(args):
17941735 # This simulates how the MCP server would call the tool.
17951736 # The actual MCP server handles the async nature and context injection.
17961737
1797- # Create a dummy context if your tool expects one and you want to test that part.
1798- # class DummyContext:
1799- # async def info(self, msg): print(f"CTX.INFO: {msg}")
1800- # async def error(self, msg): print(f"CTX.ERROR: {msg}")
1801- # dummy_ctx = DummyContext()
1802-
18031738 result = await generate_mock_api_tool (
18041739 spec_url_or_path = args .spec_source ,
18051740 output_dir_name = args .output_name ,
1806- # ctx=dummy_ctx # if tool expects context
18071741 )
1808- if result ["generated_mock_path" ]:
1809- pass
1742+ print (result )
18101743
1811- if result [ "status" ] == "error" :
1744+ if "Error" in result :
18121745 sys .exit (1 )
18131746
18141747
0 commit comments