massgen 0.0.3__py3-none-any.whl → 0.1.0__py3-none-any.whl

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.

Potentially problematic release.


This version of massgen might be problematic. Click here for more details.

Files changed (268) hide show
  1. massgen/__init__.py +142 -8
  2. massgen/adapters/__init__.py +29 -0
  3. massgen/adapters/ag2_adapter.py +483 -0
  4. massgen/adapters/base.py +183 -0
  5. massgen/adapters/tests/__init__.py +0 -0
  6. massgen/adapters/tests/test_ag2_adapter.py +439 -0
  7. massgen/adapters/tests/test_agent_adapter.py +128 -0
  8. massgen/adapters/utils/__init__.py +2 -0
  9. massgen/adapters/utils/ag2_utils.py +236 -0
  10. massgen/adapters/utils/tests/__init__.py +0 -0
  11. massgen/adapters/utils/tests/test_ag2_utils.py +138 -0
  12. massgen/agent_config.py +329 -55
  13. massgen/api_params_handler/__init__.py +10 -0
  14. massgen/api_params_handler/_api_params_handler_base.py +99 -0
  15. massgen/api_params_handler/_chat_completions_api_params_handler.py +176 -0
  16. massgen/api_params_handler/_claude_api_params_handler.py +113 -0
  17. massgen/api_params_handler/_response_api_params_handler.py +130 -0
  18. massgen/backend/__init__.py +39 -4
  19. massgen/backend/azure_openai.py +385 -0
  20. massgen/backend/base.py +341 -69
  21. massgen/backend/base_with_mcp.py +1102 -0
  22. massgen/backend/capabilities.py +386 -0
  23. massgen/backend/chat_completions.py +577 -130
  24. massgen/backend/claude.py +1033 -537
  25. massgen/backend/claude_code.py +1203 -0
  26. massgen/backend/cli_base.py +209 -0
  27. massgen/backend/docs/BACKEND_ARCHITECTURE.md +126 -0
  28. massgen/backend/{CLAUDE_API_RESEARCH.md → docs/CLAUDE_API_RESEARCH.md} +18 -18
  29. massgen/backend/{GEMINI_API_DOCUMENTATION.md → docs/GEMINI_API_DOCUMENTATION.md} +9 -9
  30. massgen/backend/docs/Gemini MCP Integration Analysis.md +1050 -0
  31. massgen/backend/docs/MCP_IMPLEMENTATION_CLAUDE_BACKEND.md +177 -0
  32. massgen/backend/docs/MCP_INTEGRATION_RESPONSE_BACKEND.md +352 -0
  33. massgen/backend/docs/OPENAI_GPT5_MODELS.md +211 -0
  34. massgen/backend/{OPENAI_RESPONSES_API_FORMAT.md → docs/OPENAI_RESPONSE_API_TOOL_CALLS.md} +3 -3
  35. massgen/backend/docs/OPENAI_response_streaming.md +20654 -0
  36. massgen/backend/docs/inference_backend.md +257 -0
  37. massgen/backend/docs/permissions_and_context_files.md +1085 -0
  38. massgen/backend/external.py +126 -0
  39. massgen/backend/gemini.py +1850 -241
  40. massgen/backend/grok.py +40 -156
  41. massgen/backend/inference.py +156 -0
  42. massgen/backend/lmstudio.py +171 -0
  43. massgen/backend/response.py +1095 -322
  44. massgen/chat_agent.py +131 -113
  45. massgen/cli.py +1560 -275
  46. massgen/config_builder.py +2396 -0
  47. massgen/configs/BACKEND_CONFIGURATION.md +458 -0
  48. massgen/configs/README.md +559 -216
  49. massgen/configs/ag2/ag2_case_study.yaml +27 -0
  50. massgen/configs/ag2/ag2_coder.yaml +34 -0
  51. massgen/configs/ag2/ag2_coder_case_study.yaml +36 -0
  52. massgen/configs/ag2/ag2_gemini.yaml +27 -0
  53. massgen/configs/ag2/ag2_groupchat.yaml +108 -0
  54. massgen/configs/ag2/ag2_groupchat_gpt.yaml +118 -0
  55. massgen/configs/ag2/ag2_single_agent.yaml +21 -0
  56. massgen/configs/basic/multi/fast_timeout_example.yaml +37 -0
  57. massgen/configs/basic/multi/gemini_4o_claude.yaml +31 -0
  58. massgen/configs/basic/multi/gemini_gpt5nano_claude.yaml +36 -0
  59. massgen/configs/{gemini_4o_claude.yaml → basic/multi/geminicode_4o_claude.yaml} +3 -3
  60. massgen/configs/basic/multi/geminicode_gpt5nano_claude.yaml +36 -0
  61. massgen/configs/basic/multi/glm_gemini_claude.yaml +25 -0
  62. massgen/configs/basic/multi/gpt4o_audio_generation.yaml +30 -0
  63. massgen/configs/basic/multi/gpt4o_image_generation.yaml +31 -0
  64. massgen/configs/basic/multi/gpt5nano_glm_qwen.yaml +26 -0
  65. massgen/configs/basic/multi/gpt5nano_image_understanding.yaml +26 -0
  66. massgen/configs/{three_agents_default.yaml → basic/multi/three_agents_default.yaml} +8 -4
  67. massgen/configs/basic/multi/three_agents_opensource.yaml +27 -0
  68. massgen/configs/basic/multi/three_agents_vllm.yaml +20 -0
  69. massgen/configs/basic/multi/two_agents_gemini.yaml +19 -0
  70. massgen/configs/{two_agents.yaml → basic/multi/two_agents_gpt5.yaml} +14 -6
  71. massgen/configs/basic/multi/two_agents_opensource_lmstudio.yaml +31 -0
  72. massgen/configs/basic/multi/two_qwen_vllm_sglang.yaml +28 -0
  73. massgen/configs/{single_agent.yaml → basic/single/single_agent.yaml} +1 -1
  74. massgen/configs/{single_flash2.5.yaml → basic/single/single_flash2.5.yaml} +1 -2
  75. massgen/configs/basic/single/single_gemini2.5pro.yaml +16 -0
  76. massgen/configs/basic/single/single_gpt4o_audio_generation.yaml +22 -0
  77. massgen/configs/basic/single/single_gpt4o_image_generation.yaml +22 -0
  78. massgen/configs/basic/single/single_gpt4o_video_generation.yaml +24 -0
  79. massgen/configs/basic/single/single_gpt5nano.yaml +20 -0
  80. massgen/configs/basic/single/single_gpt5nano_file_search.yaml +18 -0
  81. massgen/configs/basic/single/single_gpt5nano_image_understanding.yaml +17 -0
  82. massgen/configs/basic/single/single_gptoss120b.yaml +15 -0
  83. massgen/configs/basic/single/single_openrouter_audio_understanding.yaml +15 -0
  84. massgen/configs/basic/single/single_qwen_video_understanding.yaml +15 -0
  85. massgen/configs/debug/code_execution/command_filtering_blacklist.yaml +29 -0
  86. massgen/configs/debug/code_execution/command_filtering_whitelist.yaml +28 -0
  87. massgen/configs/debug/code_execution/docker_verification.yaml +29 -0
  88. massgen/configs/debug/skip_coordination_test.yaml +27 -0
  89. massgen/configs/debug/test_sdk_migration.yaml +17 -0
  90. massgen/configs/docs/DISCORD_MCP_SETUP.md +208 -0
  91. massgen/configs/docs/TWITTER_MCP_ENESCINAR_SETUP.md +82 -0
  92. massgen/configs/providers/azure/azure_openai_multi.yaml +21 -0
  93. massgen/configs/providers/azure/azure_openai_single.yaml +19 -0
  94. massgen/configs/providers/claude/claude.yaml +14 -0
  95. massgen/configs/providers/gemini/gemini_gpt5nano.yaml +28 -0
  96. massgen/configs/providers/local/lmstudio.yaml +11 -0
  97. massgen/configs/providers/openai/gpt5.yaml +46 -0
  98. massgen/configs/providers/openai/gpt5_nano.yaml +46 -0
  99. massgen/configs/providers/others/grok_single_agent.yaml +19 -0
  100. massgen/configs/providers/others/zai_coding_team.yaml +108 -0
  101. massgen/configs/providers/others/zai_glm45.yaml +12 -0
  102. massgen/configs/{creative_team.yaml → teams/creative/creative_team.yaml} +16 -6
  103. massgen/configs/{travel_planning.yaml → teams/creative/travel_planning.yaml} +16 -6
  104. massgen/configs/{news_analysis.yaml → teams/research/news_analysis.yaml} +16 -6
  105. massgen/configs/{research_team.yaml → teams/research/research_team.yaml} +15 -7
  106. massgen/configs/{technical_analysis.yaml → teams/research/technical_analysis.yaml} +16 -6
  107. massgen/configs/tools/code-execution/basic_command_execution.yaml +25 -0
  108. massgen/configs/tools/code-execution/code_execution_use_case_simple.yaml +41 -0
  109. massgen/configs/tools/code-execution/docker_claude_code.yaml +32 -0
  110. massgen/configs/tools/code-execution/docker_multi_agent.yaml +32 -0
  111. massgen/configs/tools/code-execution/docker_simple.yaml +29 -0
  112. massgen/configs/tools/code-execution/docker_with_resource_limits.yaml +32 -0
  113. massgen/configs/tools/code-execution/multi_agent_playwright_automation.yaml +57 -0
  114. massgen/configs/tools/filesystem/cc_gpt5_gemini_filesystem.yaml +34 -0
  115. massgen/configs/tools/filesystem/claude_code_context_sharing.yaml +68 -0
  116. massgen/configs/tools/filesystem/claude_code_flash2.5.yaml +43 -0
  117. massgen/configs/tools/filesystem/claude_code_flash2.5_gptoss.yaml +49 -0
  118. massgen/configs/tools/filesystem/claude_code_gpt5nano.yaml +31 -0
  119. massgen/configs/tools/filesystem/claude_code_single.yaml +40 -0
  120. massgen/configs/tools/filesystem/fs_permissions_test.yaml +87 -0
  121. massgen/configs/tools/filesystem/gemini_gemini_workspace_cleanup.yaml +54 -0
  122. massgen/configs/tools/filesystem/gemini_gpt5_filesystem_casestudy.yaml +30 -0
  123. massgen/configs/tools/filesystem/gemini_gpt5nano_file_context_path.yaml +43 -0
  124. massgen/configs/tools/filesystem/gemini_gpt5nano_protected_paths.yaml +45 -0
  125. massgen/configs/tools/filesystem/gpt5mini_cc_fs_context_path.yaml +31 -0
  126. massgen/configs/tools/filesystem/grok4_gpt5_gemini_filesystem.yaml +32 -0
  127. massgen/configs/tools/filesystem/multiturn/grok4_gpt5_claude_code_filesystem_multiturn.yaml +58 -0
  128. massgen/configs/tools/filesystem/multiturn/grok4_gpt5_gemini_filesystem_multiturn.yaml +58 -0
  129. massgen/configs/tools/filesystem/multiturn/two_claude_code_filesystem_multiturn.yaml +47 -0
  130. massgen/configs/tools/filesystem/multiturn/two_gemini_flash_filesystem_multiturn.yaml +48 -0
  131. massgen/configs/tools/mcp/claude_code_discord_mcp_example.yaml +27 -0
  132. massgen/configs/tools/mcp/claude_code_simple_mcp.yaml +35 -0
  133. massgen/configs/tools/mcp/claude_code_twitter_mcp_example.yaml +32 -0
  134. massgen/configs/tools/mcp/claude_mcp_example.yaml +24 -0
  135. massgen/configs/tools/mcp/claude_mcp_test.yaml +27 -0
  136. massgen/configs/tools/mcp/five_agents_travel_mcp_test.yaml +157 -0
  137. massgen/configs/tools/mcp/five_agents_weather_mcp_test.yaml +103 -0
  138. massgen/configs/tools/mcp/gemini_mcp_example.yaml +24 -0
  139. massgen/configs/tools/mcp/gemini_mcp_filesystem_test.yaml +23 -0
  140. massgen/configs/tools/mcp/gemini_mcp_filesystem_test_sharing.yaml +23 -0
  141. massgen/configs/tools/mcp/gemini_mcp_filesystem_test_single_agent.yaml +17 -0
  142. massgen/configs/tools/mcp/gemini_mcp_filesystem_test_with_claude_code.yaml +24 -0
  143. massgen/configs/tools/mcp/gemini_mcp_test.yaml +27 -0
  144. massgen/configs/tools/mcp/gemini_notion_mcp.yaml +52 -0
  145. massgen/configs/tools/mcp/gpt5_nano_mcp_example.yaml +24 -0
  146. massgen/configs/tools/mcp/gpt5_nano_mcp_test.yaml +27 -0
  147. massgen/configs/tools/mcp/gpt5mini_claude_code_discord_mcp_example.yaml +38 -0
  148. massgen/configs/tools/mcp/gpt_oss_mcp_example.yaml +25 -0
  149. massgen/configs/tools/mcp/gpt_oss_mcp_test.yaml +28 -0
  150. massgen/configs/tools/mcp/grok3_mini_mcp_example.yaml +24 -0
  151. massgen/configs/tools/mcp/grok3_mini_mcp_test.yaml +27 -0
  152. massgen/configs/tools/mcp/multimcp_gemini.yaml +111 -0
  153. massgen/configs/tools/mcp/qwen_api_mcp_example.yaml +25 -0
  154. massgen/configs/tools/mcp/qwen_api_mcp_test.yaml +28 -0
  155. massgen/configs/tools/mcp/qwen_local_mcp_example.yaml +24 -0
  156. massgen/configs/tools/mcp/qwen_local_mcp_test.yaml +27 -0
  157. massgen/configs/tools/planning/five_agents_discord_mcp_planning_mode.yaml +140 -0
  158. massgen/configs/tools/planning/five_agents_filesystem_mcp_planning_mode.yaml +151 -0
  159. massgen/configs/tools/planning/five_agents_notion_mcp_planning_mode.yaml +151 -0
  160. massgen/configs/tools/planning/five_agents_twitter_mcp_planning_mode.yaml +155 -0
  161. massgen/configs/tools/planning/gpt5_mini_case_study_mcp_planning_mode.yaml +73 -0
  162. massgen/configs/tools/web-search/claude_streamable_http_test.yaml +43 -0
  163. massgen/configs/tools/web-search/gemini_streamable_http_test.yaml +43 -0
  164. massgen/configs/tools/web-search/gpt5_mini_streamable_http_test.yaml +43 -0
  165. massgen/configs/tools/web-search/gpt_oss_streamable_http_test.yaml +44 -0
  166. massgen/configs/tools/web-search/grok3_mini_streamable_http_test.yaml +43 -0
  167. massgen/configs/tools/web-search/qwen_api_streamable_http_test.yaml +44 -0
  168. massgen/configs/tools/web-search/qwen_local_streamable_http_test.yaml +43 -0
  169. massgen/coordination_tracker.py +708 -0
  170. massgen/docker/README.md +462 -0
  171. massgen/filesystem_manager/__init__.py +21 -0
  172. massgen/filesystem_manager/_base.py +9 -0
  173. massgen/filesystem_manager/_code_execution_server.py +545 -0
  174. massgen/filesystem_manager/_docker_manager.py +477 -0
  175. massgen/filesystem_manager/_file_operation_tracker.py +248 -0
  176. massgen/filesystem_manager/_filesystem_manager.py +813 -0
  177. massgen/filesystem_manager/_path_permission_manager.py +1261 -0
  178. massgen/filesystem_manager/_workspace_tools_server.py +1815 -0
  179. massgen/formatter/__init__.py +10 -0
  180. massgen/formatter/_chat_completions_formatter.py +284 -0
  181. massgen/formatter/_claude_formatter.py +235 -0
  182. massgen/formatter/_formatter_base.py +156 -0
  183. massgen/formatter/_response_formatter.py +263 -0
  184. massgen/frontend/__init__.py +1 -2
  185. massgen/frontend/coordination_ui.py +471 -286
  186. massgen/frontend/displays/base_display.py +56 -11
  187. massgen/frontend/displays/create_coordination_table.py +1956 -0
  188. massgen/frontend/displays/rich_terminal_display.py +1259 -619
  189. massgen/frontend/displays/simple_display.py +9 -4
  190. massgen/frontend/displays/terminal_display.py +27 -68
  191. massgen/logger_config.py +681 -0
  192. massgen/mcp_tools/README.md +232 -0
  193. massgen/mcp_tools/__init__.py +105 -0
  194. massgen/mcp_tools/backend_utils.py +1035 -0
  195. massgen/mcp_tools/circuit_breaker.py +195 -0
  196. massgen/mcp_tools/client.py +894 -0
  197. massgen/mcp_tools/config_validator.py +138 -0
  198. massgen/mcp_tools/docs/circuit_breaker.md +646 -0
  199. massgen/mcp_tools/docs/client.md +950 -0
  200. massgen/mcp_tools/docs/config_validator.md +478 -0
  201. massgen/mcp_tools/docs/exceptions.md +1165 -0
  202. massgen/mcp_tools/docs/security.md +854 -0
  203. massgen/mcp_tools/exceptions.py +338 -0
  204. massgen/mcp_tools/hooks.py +212 -0
  205. massgen/mcp_tools/security.py +780 -0
  206. massgen/message_templates.py +342 -64
  207. massgen/orchestrator.py +1515 -241
  208. massgen/stream_chunk/__init__.py +35 -0
  209. massgen/stream_chunk/base.py +92 -0
  210. massgen/stream_chunk/multimodal.py +237 -0
  211. massgen/stream_chunk/text.py +162 -0
  212. massgen/tests/mcp_test_server.py +150 -0
  213. massgen/tests/multi_turn_conversation_design.md +0 -8
  214. massgen/tests/test_azure_openai_backend.py +156 -0
  215. massgen/tests/test_backend_capabilities.py +262 -0
  216. massgen/tests/test_backend_event_loop_all.py +179 -0
  217. massgen/tests/test_chat_completions_refactor.py +142 -0
  218. massgen/tests/test_claude_backend.py +15 -28
  219. massgen/tests/test_claude_code.py +268 -0
  220. massgen/tests/test_claude_code_context_sharing.py +233 -0
  221. massgen/tests/test_claude_code_orchestrator.py +175 -0
  222. massgen/tests/test_cli_backends.py +180 -0
  223. massgen/tests/test_code_execution.py +679 -0
  224. massgen/tests/test_external_agent_backend.py +134 -0
  225. massgen/tests/test_final_presentation_fallback.py +237 -0
  226. massgen/tests/test_gemini_planning_mode.py +351 -0
  227. massgen/tests/test_grok_backend.py +7 -10
  228. massgen/tests/test_http_mcp_server.py +42 -0
  229. massgen/tests/test_integration_simple.py +198 -0
  230. massgen/tests/test_mcp_blocking.py +125 -0
  231. massgen/tests/test_message_context_building.py +29 -47
  232. massgen/tests/test_orchestrator_final_presentation.py +48 -0
  233. massgen/tests/test_path_permission_manager.py +2087 -0
  234. massgen/tests/test_rich_terminal_display.py +14 -13
  235. massgen/tests/test_timeout.py +133 -0
  236. massgen/tests/test_v3_3agents.py +11 -12
  237. massgen/tests/test_v3_simple.py +8 -13
  238. massgen/tests/test_v3_three_agents.py +11 -18
  239. massgen/tests/test_v3_two_agents.py +8 -13
  240. massgen/token_manager/__init__.py +7 -0
  241. massgen/token_manager/token_manager.py +400 -0
  242. massgen/utils.py +52 -16
  243. massgen/v1/agent.py +45 -91
  244. massgen/v1/agents.py +18 -53
  245. massgen/v1/backends/gemini.py +50 -153
  246. massgen/v1/backends/grok.py +21 -54
  247. massgen/v1/backends/oai.py +39 -111
  248. massgen/v1/cli.py +36 -93
  249. massgen/v1/config.py +8 -12
  250. massgen/v1/logging.py +43 -127
  251. massgen/v1/main.py +18 -32
  252. massgen/v1/orchestrator.py +68 -209
  253. massgen/v1/streaming_display.py +62 -163
  254. massgen/v1/tools.py +8 -12
  255. massgen/v1/types.py +9 -23
  256. massgen/v1/utils.py +5 -23
  257. massgen-0.1.0.dist-info/METADATA +1245 -0
  258. massgen-0.1.0.dist-info/RECORD +273 -0
  259. massgen-0.1.0.dist-info/entry_points.txt +2 -0
  260. massgen/frontend/logging/__init__.py +0 -9
  261. massgen/frontend/logging/realtime_logger.py +0 -197
  262. massgen-0.0.3.dist-info/METADATA +0 -568
  263. massgen-0.0.3.dist-info/RECORD +0 -76
  264. massgen-0.0.3.dist-info/entry_points.txt +0 -2
  265. /massgen/backend/{Function calling openai responses.md → docs/Function calling openai responses.md} +0 -0
  266. {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/WHEEL +0 -0
  267. {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/licenses/LICENSE +0 -0
  268. {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,478 @@
1
+ # MCP Configuration Validator
2
+
3
+ The MCP Configuration Validator provides comprehensive validation for MCP (Model Context Protocol) server configurations, ensuring security, correctness, and consistency across your MassGen setup. It integrates with the security module to enforce safe execution environments and validates configuration structure at multiple levels.
4
+
5
+ ## Overview
6
+
7
+ The `MCPConfigValidator` class serves as the central validation system for MCP configurations in MassGen. It performs three key functions:
8
+
9
+ 1. **Individual Server Validation** - Validates single MCP server configurations with security checks
10
+ 2. **Backend-Level Validation** - Validates MCP configurations within backend contexts
11
+ 3. **Orchestrator-Level Validation** - Validates complete orchestrator configurations with multiple agents
12
+
13
+ The validator integrates with the security module to ensure all server configurations meet safety requirements, preventing potential security vulnerabilities while maintaining flexibility for legitimate use cases.
14
+
15
+ ## Core Validation Methods
16
+
17
+ ### validate_server_config()
18
+
19
+ Validates a single MCP server configuration using integrated security validation.
20
+
21
+ ```python
22
+ @classmethod
23
+ def validate_server_config(cls, config: Dict[str, Any]) -> Dict[str, Any]:
24
+ ```
25
+
26
+ **Parameters:**
27
+
28
+ - `config` (Dict[str, Any]): Server configuration dictionary
29
+
30
+ **Returns:**
31
+
32
+ - Dict[str, Any]: Validated and normalized configuration
33
+
34
+ **Raises:**
35
+
36
+ - `MCPConfigurationError`: If configuration is invalid or fails security validation
37
+
38
+ **Example Usage:**
39
+
40
+ ```python
41
+ from massgen.mcp_tools.config_validator import MCPConfigValidator
42
+
43
+ server_config = {
44
+ "name": "weather",
45
+ "type": "stdio",
46
+ "command": "npx",
47
+ "args": ["-y", "@fak111/weather-mcp"]
48
+ }
49
+
50
+ validated_config = MCPConfigValidator.validate_server_config(server_config)
51
+ ```
52
+
53
+ ### validate_backend_mcp_config()
54
+
55
+ Validates MCP configuration for a backend, handling both dictionary and list formats for server definitions.
56
+
57
+ ```python
58
+ @classmethod
59
+ def validate_backend_mcp_config(cls, backend_config: Dict[str, Any]) -> Dict[str, Any]:
60
+ ```
61
+
62
+ **Parameters:**
63
+
64
+ - `backend_config` (Dict[str, Any]): Backend configuration dictionary
65
+
66
+ **Returns:**
67
+
68
+ - Dict[str, Any]: Validated configuration with normalized server list
69
+
70
+ **Raises:**
71
+
72
+ - `MCPConfigurationError`: If configuration is invalid
73
+
74
+ **Features:**
75
+
76
+ - Converts dictionary-format server definitions to list format
77
+ - Validates each server configuration individually
78
+ - Checks for duplicate server names
79
+ - Validates tool filtering parameters (`allowed_tools`, `exclude_tools`)
80
+
81
+ ### validate_orchestrator_config()
82
+
83
+ Validates orchestrator configuration for MCP integration, supporting both dictionary and list agent formats.
84
+
85
+ ```python
86
+ @classmethod
87
+ def validate_orchestrator_config(cls, orchestrator_config: Dict[str, Any]) -> Dict[str, Any]:
88
+ ```
89
+
90
+ **Parameters:**
91
+
92
+ - `orchestrator_config` (Dict[str, Any]): Orchestrator configuration dictionary
93
+
94
+ **Returns:**
95
+
96
+ - Dict[str, Any]: Validated configuration
97
+
98
+ **Raises:**
99
+
100
+ - `MCPConfigurationError`: If configuration is invalid
101
+
102
+ ## Configuration Examples
103
+
104
+ **Note on Command Configuration**: The examples below use the recommended `command` + `args` pattern for stdio transport configuration (e.g., `"command": "npx", "args": ["-y", "@fak111/weather-mcp"]`). The security validator also accepts a single `command` field as a string (which gets parsed and split) or as a list (which gets validated and converted), but the separate `command` and `args` fields provide better clarity and security validation.
105
+
106
+ ### Stdio Transport Configuration
107
+
108
+ Based on the Gemini MCP example, here's a complete stdio server configuration:
109
+
110
+ ```yaml
111
+ agents:
112
+ - id: "gemini2.5flash_mcp_weather"
113
+ backend:
114
+ type: "gemini"
115
+ model: "gemini-2.5-flash"
116
+ mcp_servers:
117
+ - name: "weather"
118
+ type: "stdio"
119
+ command: "npx"
120
+ args: ["-y", "@fak111/weather-mcp"]
121
+ # Optional security configuration
122
+ security:
123
+ level: "strict" # strict, moderate, or permissive
124
+ allowed_executables: ["npx", "node"]
125
+ env:
126
+ level: "strict"
127
+ mode: "denylist"
128
+ denied_vars: ["PATH", "HOME"]
129
+ # Optional environment variables
130
+ env:
131
+ NODE_ENV: "production"
132
+ # Optional working directory
133
+ cwd: "/path/to/working/directory"
134
+ ```
135
+
136
+ ### Dictionary Format Server Configuration
137
+
138
+ Based on the Claude Code Discord example:
139
+
140
+ ```yaml
141
+ agent:
142
+ id: "claude_code_discord_mcp"
143
+ backend:
144
+ type: "claude_code"
145
+ mcp_servers:
146
+ discord:
147
+ type: "stdio"
148
+ command: "npx"
149
+ args: ["-y", "mcp-discord", "--config", "YOUR_DISCORD_TOKEN"]
150
+ security:
151
+ level: "moderate"
152
+ weather:
153
+ type: "stdio"
154
+ command: "python"
155
+ args: ["-m", "weather_mcp_server"]
156
+ ```
157
+
158
+ ### Streamable-HTTP Transport Configuration
159
+
160
+ ```yaml
161
+ agents:
162
+ - id: "http_mcp_example"
163
+ backend:
164
+ type: "gemini"
165
+ mcp_servers:
166
+ - name: "web_api"
167
+ type: "streamable-http"
168
+ url: "https://api.example.com/mcp"
169
+ headers:
170
+ Authorization: "Bearer ${API_TOKEN}"
171
+ Content-Type: "application/json"
172
+ timeout: 30
173
+ http_read_timeout: 60
174
+ security:
175
+ level: "strict"
176
+ resolve_dns: true
177
+ allow_private_ips: false
178
+ allow_localhost: false
179
+ allowed_hostnames: ["api.example.com"]
180
+ ```
181
+
182
+ ## Tool Filtering
183
+
184
+ The validator supports tool filtering at the backend level to control which tools are available:
185
+
186
+ ### allowed_tools Configuration
187
+
188
+ ```yaml
189
+ backend:
190
+ type: "claude_code"
191
+ mcp_servers:
192
+ - name: "filesystem"
193
+ type: "stdio"
194
+ command: "python"
195
+ args: ["-m", "filesystem_mcp"]
196
+ # Only allow specific tools
197
+ allowed_tools:
198
+ - "mcp__filesystem__read_file"
199
+ - "mcp__filesystem__write_file"
200
+ - "Read" # Built-in Claude Code tool
201
+ - "Write" # Built-in Claude Code tool
202
+ ```
203
+
204
+ ### exclude_tools Configuration
205
+
206
+ ```yaml
207
+ backend:
208
+ type: "gemini"
209
+ mcp_servers:
210
+ - name: "system_tools"
211
+ type: "stdio"
212
+ command: "python"
213
+ args: ["-m", "system_mcp"]
214
+ # Exclude dangerous tools
215
+ exclude_tools:
216
+ - "mcp__system_tools__delete_file"
217
+ - "mcp__system_tools__format_disk"
218
+ ```
219
+
220
+ ### Tool Filtering Precedence
221
+
222
+ When both `allowed_tools` and `exclude_tools` are specified, `exclude_tools` takes precedence and overrides `allowed_tools`. This means that if a tool is listed in both configurations, it will be excluded.
223
+
224
+ **Precedence Order:**
225
+
226
+ 1. `exclude_tools` - Tools listed here are always blocked
227
+ 2. `allowed_tools` - Tools listed here are allowed (unless also in exclude_tools)
228
+ 3. Default behavior - All available tools are allowed if no filtering is specified
229
+
230
+ **Example demonstrating precedence:**
231
+
232
+ ```yaml
233
+ backend:
234
+ type: "claude_code"
235
+ mcp_servers:
236
+ - name: "filesystem"
237
+ type: "stdio"
238
+ command: "python"
239
+ args: ["-m", "filesystem_mcp"]
240
+ # Allow specific filesystem tools
241
+ allowed_tools:
242
+ - "mcp__filesystem__read_file"
243
+ - "mcp__filesystem__write_file"
244
+ - "mcp__filesystem__delete_file" # This will be blocked by exclude_tools
245
+ - "Read" # Built-in Claude Code tool
246
+ # Exclude dangerous operations
247
+ exclude_tools:
248
+ - "mcp__filesystem__delete_file" # This overrides the allowed_tools entry
249
+ - "mcp__filesystem__format_drive"
250
+ ```
251
+
252
+ In this example, even though `mcp__filesystem__delete_file` is listed in `allowed_tools`, it will be blocked because it's also listed in `exclude_tools`. The final available tools will be:
253
+
254
+ - `mcp__filesystem__read_file` ✅ (allowed and not excluded)
255
+ - `mcp__filesystem__write_file` ✅ (allowed and not excluded)
256
+ - `mcp__filesystem__delete_file` ❌ (excluded, overrides allowed)
257
+ - `Read` ✅ (allowed and not excluded)
258
+
259
+ ## Security Integration
260
+
261
+ The validator integrates with the security module to enforce comprehensive security checks:
262
+
263
+ ### Security Levels
264
+
265
+ - **strict**: Maximum security, limited executable allowlist, strict environment variable filtering
266
+ - **moderate**: Balanced security, expanded executable allowlist, moderate filtering
267
+ - **permissive**: Relaxed security for trusted environments, broader allowlist
268
+
269
+ ### Security Configuration Example
270
+
271
+ ```yaml
272
+ mcp_servers:
273
+ - name: "secure_server"
274
+ type: "stdio"
275
+ command: "python"
276
+ args: ["-m", "my_mcp_server"]
277
+ security:
278
+ level: "strict"
279
+ allowed_executables: ["python", "python3"]
280
+ env:
281
+ level: "strict"
282
+ mode: "allowlist"
283
+ allowed_vars: ["PYTHONPATH", "MY_APP_CONFIG"]
284
+ resolve_dns: true
285
+ allow_private_ips: false
286
+ allow_localhost: false
287
+ ```
288
+
289
+ ## Server Naming Conventions
290
+
291
+ ### Enforced Server Name Rules
292
+
293
+ Server names are validated and enforced by `validate_server_security()` in `security.py` with the following rules:
294
+
295
+ - **Character validation**: Only alphanumeric characters, underscores, and hyphens (regex: `^[a-zA-Z0-9_-]+$`)
296
+ - **Length limit**: Maximum 100 characters
297
+ - **Non-empty requirement**: Must be a non-empty string after trimming whitespace
298
+
299
+ These rules are enforced during configuration validation and will raise `ValueError` if violated.
300
+
301
+ ```yaml
302
+ # Valid names
303
+ mcp_servers:
304
+ - name: "weather-api" # Valid: hyphen allowed
305
+ - name: "file_system" # Valid: underscore allowed
306
+ - name: "server123" # Valid: alphanumeric
307
+ - name: "my_server_v2" # Valid: combination
308
+
309
+ # Invalid names (will raise ValueError)
310
+ mcp_servers:
311
+ - name: "server with spaces" # Invalid: spaces not allowed
312
+ - name: "server@domain" # Invalid: @ not allowed
313
+ - name: "" # Invalid: empty name
314
+ ```
315
+
316
+ ### Duplicate Detection
317
+
318
+ The validator automatically detects and prevents duplicate server names in `validate_backend_mcp_config()`:
319
+
320
+ ```python
321
+ # This will raise MCPConfigurationError
322
+ backend_config = {
323
+ "mcp_servers": [
324
+ {"name": "weather", "type": "stdio", "command": "python", "args": ["-m", "weather_server"]},
325
+ {"name": "weather", "type": "stdio", "command": "python", "args": ["-m", "other_weather"]} # Duplicate!
326
+ ]
327
+ }
328
+ ```
329
+
330
+ ## Error Handling and Troubleshooting
331
+
332
+ ### Common Validation Errors
333
+
334
+ #### Missing Required Fields
335
+
336
+ ```python
337
+ # Error: Missing 'name' field
338
+ server_config = {
339
+ "type": "stdio",
340
+ "command": "python",
341
+ "args": ["-m", "my_server"]
342
+ }
343
+ # Raises: MCPConfigurationError: Server configuration must include 'name'
344
+ ```
345
+
346
+ #### Invalid Transport Types
347
+
348
+ ```python
349
+ # Error: Unsupported transport type
350
+ server_config = {
351
+ "name": "test",
352
+ "type": "invalid_transport"
353
+ }
354
+ # Raises: MCPConfigurationError: Unsupported transport type: invalid_transport
355
+ ```
356
+
357
+ #### Security Validation Failures
358
+
359
+ ```python
360
+ # Error: Dangerous command
361
+ server_config = {
362
+ "name": "dangerous",
363
+ "type": "stdio",
364
+ "command": "rm -rf /" # Contains dangerous characters
365
+ }
366
+ # Raises: MCPConfigurationError: MCP command cannot contain shell metacharacters: ;
367
+ ```
368
+
369
+ #### Duplicate Server Names
370
+
371
+ ```python
372
+ # Error: Duplicate names
373
+ backend_config = {
374
+ "mcp_servers": [
375
+ {"name": "server1", "type": "stdio", "command": "python", "args": ["-m", "server1"]},
376
+ {"name": "server1", "type": "stdio", "command": "python", "args": ["-m", "server2"]}
377
+ ]
378
+ }
379
+ # Raises: MCPConfigurationError: Duplicate server names found: ['server1']
380
+ ```
381
+
382
+ ### Error Context Information
383
+
384
+ All validation errors include detailed context for debugging:
385
+
386
+ ```python
387
+ try:
388
+ MCPConfigValidator.validate_server_config(invalid_config)
389
+ except MCPConfigurationError as e:
390
+ print(f"Error: {e}")
391
+ print(f"Context: {e.context}")
392
+ # Context includes: config details, validation source, error location
393
+ ```
394
+
395
+ ### Debugging Tips
396
+
397
+ 1. **Check Error Context**: Always examine the `context` attribute of `MCPConfigurationError` for detailed information
398
+ 2. **Validate Incrementally**: Test individual server configurations before combining them
399
+ 3. **Use Security Levels**: Start with "permissive" security level for testing, then tighten to "strict"
400
+ 4. **Check Tool Names**: Ensure tool filtering lists use correct tool names (including MCP prefixes)
401
+
402
+ ## Best Practices
403
+
404
+ ### Configuration Structure
405
+
406
+ 1. **Use List Format**: Prefer list format for `mcp_servers` for better readability and validation
407
+ 2. **Explicit Security**: Always specify security configuration explicitly rather than relying on defaults
408
+ 3. **Descriptive Names**: Use clear, descriptive server names that indicate their purpose
409
+ 4. **Environment Isolation**: Use working directories (`cwd`) to isolate server execution environments
410
+
411
+ ### Security Settings
412
+
413
+ 1. **Start Strict**: Begin with "strict" security level and relax only when necessary
414
+ 2. **Minimal Permissions**: Use `allowed_tools` to grant only necessary tool access
415
+ 3. **Environment Control**: Carefully manage environment variables, especially in production
416
+ 4. **URL Validation**: For HTTP transports, use `allowed_hostnames` to restrict connections
417
+
418
+ ### Error Handling Patterns
419
+
420
+ ```python
421
+ import logging
422
+ import yaml
423
+ from massgen.mcp_tools.config_validator import validate_mcp_integration
424
+ from massgen.mcp_tools.exceptions import MCPConfigurationError
425
+
426
+ # Configure logging
427
+ logging.basicConfig(level=logging.INFO)
428
+ logger = logging.getLogger(__name__)
429
+
430
+ def load_and_validate_config(config_path: str) -> Dict[str, Any]:
431
+ """Load and validate MCP configuration with proper error handling."""
432
+ try:
433
+ with open(config_path) as f:
434
+ config = yaml.safe_load(f)
435
+
436
+ # Validate the configuration
437
+ validated_config = validate_mcp_integration(config)
438
+
439
+ return validated_config
440
+
441
+ except MCPConfigurationError as e:
442
+ logger.error(f"Configuration validation failed: {e}")
443
+ logger.error(f"Error context: {e.context}")
444
+ raise
445
+ except Exception as e:
446
+ logger.error(f"Unexpected error loading config: {e}")
447
+ raise MCPConfigurationError(
448
+ f"Failed to load configuration from {config_path}",
449
+ context={"config_file": config_path, "original_error": str(e)}
450
+ )
451
+ ```
452
+
453
+ ### Integration Patterns
454
+
455
+ ```python
456
+ # Validate before using in MCP client
457
+ def create_mcp_client(backend_config: Dict[str, Any]) -> MCPClient:
458
+ """Create MCP client with validated configuration."""
459
+ # Validate configuration first
460
+ validated_config = MCPConfigValidator.validate_backend_mcp_config(backend_config)
461
+
462
+ # Extract validated server configurations
463
+ mcp_servers = validated_config.get("mcp_servers", [])
464
+
465
+ # Create client with validated config
466
+ return MCPClient(servers=mcp_servers)
467
+ ```
468
+
469
+ ## API Reference Summary
470
+
471
+ | Method | Purpose | Input | Output | Exceptions |
472
+ | -------------------------------- | ----------------------------- | ------------------------ | ---------------- | ----------------------- |
473
+ | `validate_server_config()` | Validate single server | Server config dict | Validated config | `MCPConfigurationError` |
474
+ | `validate_backend_mcp_config()` | Validate backend MCP config | Backend config dict | Validated config | `MCPConfigurationError` |
475
+ | `validate_orchestrator_config()` | Validate orchestrator config | Orchestrator config dict | Validated config | `MCPConfigurationError` |
476
+ | `validate_mcp_integration()` | Validate complete integration | Full config dict | Validated config | `MCPConfigurationError` |
477
+
478
+ The configuration validator ensures that your MCP setup is secure, consistent, and properly structured, providing clear error messages and context when issues are detected. Use it as the first step in any MCP configuration workflow to catch problems early and maintain system security.