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.
- massgen/__init__.py +142 -8
- massgen/adapters/__init__.py +29 -0
- massgen/adapters/ag2_adapter.py +483 -0
- massgen/adapters/base.py +183 -0
- massgen/adapters/tests/__init__.py +0 -0
- massgen/adapters/tests/test_ag2_adapter.py +439 -0
- massgen/adapters/tests/test_agent_adapter.py +128 -0
- massgen/adapters/utils/__init__.py +2 -0
- massgen/adapters/utils/ag2_utils.py +236 -0
- massgen/adapters/utils/tests/__init__.py +0 -0
- massgen/adapters/utils/tests/test_ag2_utils.py +138 -0
- massgen/agent_config.py +329 -55
- massgen/api_params_handler/__init__.py +10 -0
- massgen/api_params_handler/_api_params_handler_base.py +99 -0
- massgen/api_params_handler/_chat_completions_api_params_handler.py +176 -0
- massgen/api_params_handler/_claude_api_params_handler.py +113 -0
- massgen/api_params_handler/_response_api_params_handler.py +130 -0
- massgen/backend/__init__.py +39 -4
- massgen/backend/azure_openai.py +385 -0
- massgen/backend/base.py +341 -69
- massgen/backend/base_with_mcp.py +1102 -0
- massgen/backend/capabilities.py +386 -0
- massgen/backend/chat_completions.py +577 -130
- massgen/backend/claude.py +1033 -537
- massgen/backend/claude_code.py +1203 -0
- massgen/backend/cli_base.py +209 -0
- massgen/backend/docs/BACKEND_ARCHITECTURE.md +126 -0
- massgen/backend/{CLAUDE_API_RESEARCH.md → docs/CLAUDE_API_RESEARCH.md} +18 -18
- massgen/backend/{GEMINI_API_DOCUMENTATION.md → docs/GEMINI_API_DOCUMENTATION.md} +9 -9
- massgen/backend/docs/Gemini MCP Integration Analysis.md +1050 -0
- massgen/backend/docs/MCP_IMPLEMENTATION_CLAUDE_BACKEND.md +177 -0
- massgen/backend/docs/MCP_INTEGRATION_RESPONSE_BACKEND.md +352 -0
- massgen/backend/docs/OPENAI_GPT5_MODELS.md +211 -0
- massgen/backend/{OPENAI_RESPONSES_API_FORMAT.md → docs/OPENAI_RESPONSE_API_TOOL_CALLS.md} +3 -3
- massgen/backend/docs/OPENAI_response_streaming.md +20654 -0
- massgen/backend/docs/inference_backend.md +257 -0
- massgen/backend/docs/permissions_and_context_files.md +1085 -0
- massgen/backend/external.py +126 -0
- massgen/backend/gemini.py +1850 -241
- massgen/backend/grok.py +40 -156
- massgen/backend/inference.py +156 -0
- massgen/backend/lmstudio.py +171 -0
- massgen/backend/response.py +1095 -322
- massgen/chat_agent.py +131 -113
- massgen/cli.py +1560 -275
- massgen/config_builder.py +2396 -0
- massgen/configs/BACKEND_CONFIGURATION.md +458 -0
- massgen/configs/README.md +559 -216
- massgen/configs/ag2/ag2_case_study.yaml +27 -0
- massgen/configs/ag2/ag2_coder.yaml +34 -0
- massgen/configs/ag2/ag2_coder_case_study.yaml +36 -0
- massgen/configs/ag2/ag2_gemini.yaml +27 -0
- massgen/configs/ag2/ag2_groupchat.yaml +108 -0
- massgen/configs/ag2/ag2_groupchat_gpt.yaml +118 -0
- massgen/configs/ag2/ag2_single_agent.yaml +21 -0
- massgen/configs/basic/multi/fast_timeout_example.yaml +37 -0
- massgen/configs/basic/multi/gemini_4o_claude.yaml +31 -0
- massgen/configs/basic/multi/gemini_gpt5nano_claude.yaml +36 -0
- massgen/configs/{gemini_4o_claude.yaml → basic/multi/geminicode_4o_claude.yaml} +3 -3
- massgen/configs/basic/multi/geminicode_gpt5nano_claude.yaml +36 -0
- massgen/configs/basic/multi/glm_gemini_claude.yaml +25 -0
- massgen/configs/basic/multi/gpt4o_audio_generation.yaml +30 -0
- massgen/configs/basic/multi/gpt4o_image_generation.yaml +31 -0
- massgen/configs/basic/multi/gpt5nano_glm_qwen.yaml +26 -0
- massgen/configs/basic/multi/gpt5nano_image_understanding.yaml +26 -0
- massgen/configs/{three_agents_default.yaml → basic/multi/three_agents_default.yaml} +8 -4
- massgen/configs/basic/multi/three_agents_opensource.yaml +27 -0
- massgen/configs/basic/multi/three_agents_vllm.yaml +20 -0
- massgen/configs/basic/multi/two_agents_gemini.yaml +19 -0
- massgen/configs/{two_agents.yaml → basic/multi/two_agents_gpt5.yaml} +14 -6
- massgen/configs/basic/multi/two_agents_opensource_lmstudio.yaml +31 -0
- massgen/configs/basic/multi/two_qwen_vllm_sglang.yaml +28 -0
- massgen/configs/{single_agent.yaml → basic/single/single_agent.yaml} +1 -1
- massgen/configs/{single_flash2.5.yaml → basic/single/single_flash2.5.yaml} +1 -2
- massgen/configs/basic/single/single_gemini2.5pro.yaml +16 -0
- massgen/configs/basic/single/single_gpt4o_audio_generation.yaml +22 -0
- massgen/configs/basic/single/single_gpt4o_image_generation.yaml +22 -0
- massgen/configs/basic/single/single_gpt4o_video_generation.yaml +24 -0
- massgen/configs/basic/single/single_gpt5nano.yaml +20 -0
- massgen/configs/basic/single/single_gpt5nano_file_search.yaml +18 -0
- massgen/configs/basic/single/single_gpt5nano_image_understanding.yaml +17 -0
- massgen/configs/basic/single/single_gptoss120b.yaml +15 -0
- massgen/configs/basic/single/single_openrouter_audio_understanding.yaml +15 -0
- massgen/configs/basic/single/single_qwen_video_understanding.yaml +15 -0
- massgen/configs/debug/code_execution/command_filtering_blacklist.yaml +29 -0
- massgen/configs/debug/code_execution/command_filtering_whitelist.yaml +28 -0
- massgen/configs/debug/code_execution/docker_verification.yaml +29 -0
- massgen/configs/debug/skip_coordination_test.yaml +27 -0
- massgen/configs/debug/test_sdk_migration.yaml +17 -0
- massgen/configs/docs/DISCORD_MCP_SETUP.md +208 -0
- massgen/configs/docs/TWITTER_MCP_ENESCINAR_SETUP.md +82 -0
- massgen/configs/providers/azure/azure_openai_multi.yaml +21 -0
- massgen/configs/providers/azure/azure_openai_single.yaml +19 -0
- massgen/configs/providers/claude/claude.yaml +14 -0
- massgen/configs/providers/gemini/gemini_gpt5nano.yaml +28 -0
- massgen/configs/providers/local/lmstudio.yaml +11 -0
- massgen/configs/providers/openai/gpt5.yaml +46 -0
- massgen/configs/providers/openai/gpt5_nano.yaml +46 -0
- massgen/configs/providers/others/grok_single_agent.yaml +19 -0
- massgen/configs/providers/others/zai_coding_team.yaml +108 -0
- massgen/configs/providers/others/zai_glm45.yaml +12 -0
- massgen/configs/{creative_team.yaml → teams/creative/creative_team.yaml} +16 -6
- massgen/configs/{travel_planning.yaml → teams/creative/travel_planning.yaml} +16 -6
- massgen/configs/{news_analysis.yaml → teams/research/news_analysis.yaml} +16 -6
- massgen/configs/{research_team.yaml → teams/research/research_team.yaml} +15 -7
- massgen/configs/{technical_analysis.yaml → teams/research/technical_analysis.yaml} +16 -6
- massgen/configs/tools/code-execution/basic_command_execution.yaml +25 -0
- massgen/configs/tools/code-execution/code_execution_use_case_simple.yaml +41 -0
- massgen/configs/tools/code-execution/docker_claude_code.yaml +32 -0
- massgen/configs/tools/code-execution/docker_multi_agent.yaml +32 -0
- massgen/configs/tools/code-execution/docker_simple.yaml +29 -0
- massgen/configs/tools/code-execution/docker_with_resource_limits.yaml +32 -0
- massgen/configs/tools/code-execution/multi_agent_playwright_automation.yaml +57 -0
- massgen/configs/tools/filesystem/cc_gpt5_gemini_filesystem.yaml +34 -0
- massgen/configs/tools/filesystem/claude_code_context_sharing.yaml +68 -0
- massgen/configs/tools/filesystem/claude_code_flash2.5.yaml +43 -0
- massgen/configs/tools/filesystem/claude_code_flash2.5_gptoss.yaml +49 -0
- massgen/configs/tools/filesystem/claude_code_gpt5nano.yaml +31 -0
- massgen/configs/tools/filesystem/claude_code_single.yaml +40 -0
- massgen/configs/tools/filesystem/fs_permissions_test.yaml +87 -0
- massgen/configs/tools/filesystem/gemini_gemini_workspace_cleanup.yaml +54 -0
- massgen/configs/tools/filesystem/gemini_gpt5_filesystem_casestudy.yaml +30 -0
- massgen/configs/tools/filesystem/gemini_gpt5nano_file_context_path.yaml +43 -0
- massgen/configs/tools/filesystem/gemini_gpt5nano_protected_paths.yaml +45 -0
- massgen/configs/tools/filesystem/gpt5mini_cc_fs_context_path.yaml +31 -0
- massgen/configs/tools/filesystem/grok4_gpt5_gemini_filesystem.yaml +32 -0
- massgen/configs/tools/filesystem/multiturn/grok4_gpt5_claude_code_filesystem_multiturn.yaml +58 -0
- massgen/configs/tools/filesystem/multiturn/grok4_gpt5_gemini_filesystem_multiturn.yaml +58 -0
- massgen/configs/tools/filesystem/multiturn/two_claude_code_filesystem_multiturn.yaml +47 -0
- massgen/configs/tools/filesystem/multiturn/two_gemini_flash_filesystem_multiturn.yaml +48 -0
- massgen/configs/tools/mcp/claude_code_discord_mcp_example.yaml +27 -0
- massgen/configs/tools/mcp/claude_code_simple_mcp.yaml +35 -0
- massgen/configs/tools/mcp/claude_code_twitter_mcp_example.yaml +32 -0
- massgen/configs/tools/mcp/claude_mcp_example.yaml +24 -0
- massgen/configs/tools/mcp/claude_mcp_test.yaml +27 -0
- massgen/configs/tools/mcp/five_agents_travel_mcp_test.yaml +157 -0
- massgen/configs/tools/mcp/five_agents_weather_mcp_test.yaml +103 -0
- massgen/configs/tools/mcp/gemini_mcp_example.yaml +24 -0
- massgen/configs/tools/mcp/gemini_mcp_filesystem_test.yaml +23 -0
- massgen/configs/tools/mcp/gemini_mcp_filesystem_test_sharing.yaml +23 -0
- massgen/configs/tools/mcp/gemini_mcp_filesystem_test_single_agent.yaml +17 -0
- massgen/configs/tools/mcp/gemini_mcp_filesystem_test_with_claude_code.yaml +24 -0
- massgen/configs/tools/mcp/gemini_mcp_test.yaml +27 -0
- massgen/configs/tools/mcp/gemini_notion_mcp.yaml +52 -0
- massgen/configs/tools/mcp/gpt5_nano_mcp_example.yaml +24 -0
- massgen/configs/tools/mcp/gpt5_nano_mcp_test.yaml +27 -0
- massgen/configs/tools/mcp/gpt5mini_claude_code_discord_mcp_example.yaml +38 -0
- massgen/configs/tools/mcp/gpt_oss_mcp_example.yaml +25 -0
- massgen/configs/tools/mcp/gpt_oss_mcp_test.yaml +28 -0
- massgen/configs/tools/mcp/grok3_mini_mcp_example.yaml +24 -0
- massgen/configs/tools/mcp/grok3_mini_mcp_test.yaml +27 -0
- massgen/configs/tools/mcp/multimcp_gemini.yaml +111 -0
- massgen/configs/tools/mcp/qwen_api_mcp_example.yaml +25 -0
- massgen/configs/tools/mcp/qwen_api_mcp_test.yaml +28 -0
- massgen/configs/tools/mcp/qwen_local_mcp_example.yaml +24 -0
- massgen/configs/tools/mcp/qwen_local_mcp_test.yaml +27 -0
- massgen/configs/tools/planning/five_agents_discord_mcp_planning_mode.yaml +140 -0
- massgen/configs/tools/planning/five_agents_filesystem_mcp_planning_mode.yaml +151 -0
- massgen/configs/tools/planning/five_agents_notion_mcp_planning_mode.yaml +151 -0
- massgen/configs/tools/planning/five_agents_twitter_mcp_planning_mode.yaml +155 -0
- massgen/configs/tools/planning/gpt5_mini_case_study_mcp_planning_mode.yaml +73 -0
- massgen/configs/tools/web-search/claude_streamable_http_test.yaml +43 -0
- massgen/configs/tools/web-search/gemini_streamable_http_test.yaml +43 -0
- massgen/configs/tools/web-search/gpt5_mini_streamable_http_test.yaml +43 -0
- massgen/configs/tools/web-search/gpt_oss_streamable_http_test.yaml +44 -0
- massgen/configs/tools/web-search/grok3_mini_streamable_http_test.yaml +43 -0
- massgen/configs/tools/web-search/qwen_api_streamable_http_test.yaml +44 -0
- massgen/configs/tools/web-search/qwen_local_streamable_http_test.yaml +43 -0
- massgen/coordination_tracker.py +708 -0
- massgen/docker/README.md +462 -0
- massgen/filesystem_manager/__init__.py +21 -0
- massgen/filesystem_manager/_base.py +9 -0
- massgen/filesystem_manager/_code_execution_server.py +545 -0
- massgen/filesystem_manager/_docker_manager.py +477 -0
- massgen/filesystem_manager/_file_operation_tracker.py +248 -0
- massgen/filesystem_manager/_filesystem_manager.py +813 -0
- massgen/filesystem_manager/_path_permission_manager.py +1261 -0
- massgen/filesystem_manager/_workspace_tools_server.py +1815 -0
- massgen/formatter/__init__.py +10 -0
- massgen/formatter/_chat_completions_formatter.py +284 -0
- massgen/formatter/_claude_formatter.py +235 -0
- massgen/formatter/_formatter_base.py +156 -0
- massgen/formatter/_response_formatter.py +263 -0
- massgen/frontend/__init__.py +1 -2
- massgen/frontend/coordination_ui.py +471 -286
- massgen/frontend/displays/base_display.py +56 -11
- massgen/frontend/displays/create_coordination_table.py +1956 -0
- massgen/frontend/displays/rich_terminal_display.py +1259 -619
- massgen/frontend/displays/simple_display.py +9 -4
- massgen/frontend/displays/terminal_display.py +27 -68
- massgen/logger_config.py +681 -0
- massgen/mcp_tools/README.md +232 -0
- massgen/mcp_tools/__init__.py +105 -0
- massgen/mcp_tools/backend_utils.py +1035 -0
- massgen/mcp_tools/circuit_breaker.py +195 -0
- massgen/mcp_tools/client.py +894 -0
- massgen/mcp_tools/config_validator.py +138 -0
- massgen/mcp_tools/docs/circuit_breaker.md +646 -0
- massgen/mcp_tools/docs/client.md +950 -0
- massgen/mcp_tools/docs/config_validator.md +478 -0
- massgen/mcp_tools/docs/exceptions.md +1165 -0
- massgen/mcp_tools/docs/security.md +854 -0
- massgen/mcp_tools/exceptions.py +338 -0
- massgen/mcp_tools/hooks.py +212 -0
- massgen/mcp_tools/security.py +780 -0
- massgen/message_templates.py +342 -64
- massgen/orchestrator.py +1515 -241
- massgen/stream_chunk/__init__.py +35 -0
- massgen/stream_chunk/base.py +92 -0
- massgen/stream_chunk/multimodal.py +237 -0
- massgen/stream_chunk/text.py +162 -0
- massgen/tests/mcp_test_server.py +150 -0
- massgen/tests/multi_turn_conversation_design.md +0 -8
- massgen/tests/test_azure_openai_backend.py +156 -0
- massgen/tests/test_backend_capabilities.py +262 -0
- massgen/tests/test_backend_event_loop_all.py +179 -0
- massgen/tests/test_chat_completions_refactor.py +142 -0
- massgen/tests/test_claude_backend.py +15 -28
- massgen/tests/test_claude_code.py +268 -0
- massgen/tests/test_claude_code_context_sharing.py +233 -0
- massgen/tests/test_claude_code_orchestrator.py +175 -0
- massgen/tests/test_cli_backends.py +180 -0
- massgen/tests/test_code_execution.py +679 -0
- massgen/tests/test_external_agent_backend.py +134 -0
- massgen/tests/test_final_presentation_fallback.py +237 -0
- massgen/tests/test_gemini_planning_mode.py +351 -0
- massgen/tests/test_grok_backend.py +7 -10
- massgen/tests/test_http_mcp_server.py +42 -0
- massgen/tests/test_integration_simple.py +198 -0
- massgen/tests/test_mcp_blocking.py +125 -0
- massgen/tests/test_message_context_building.py +29 -47
- massgen/tests/test_orchestrator_final_presentation.py +48 -0
- massgen/tests/test_path_permission_manager.py +2087 -0
- massgen/tests/test_rich_terminal_display.py +14 -13
- massgen/tests/test_timeout.py +133 -0
- massgen/tests/test_v3_3agents.py +11 -12
- massgen/tests/test_v3_simple.py +8 -13
- massgen/tests/test_v3_three_agents.py +11 -18
- massgen/tests/test_v3_two_agents.py +8 -13
- massgen/token_manager/__init__.py +7 -0
- massgen/token_manager/token_manager.py +400 -0
- massgen/utils.py +52 -16
- massgen/v1/agent.py +45 -91
- massgen/v1/agents.py +18 -53
- massgen/v1/backends/gemini.py +50 -153
- massgen/v1/backends/grok.py +21 -54
- massgen/v1/backends/oai.py +39 -111
- massgen/v1/cli.py +36 -93
- massgen/v1/config.py +8 -12
- massgen/v1/logging.py +43 -127
- massgen/v1/main.py +18 -32
- massgen/v1/orchestrator.py +68 -209
- massgen/v1/streaming_display.py +62 -163
- massgen/v1/tools.py +8 -12
- massgen/v1/types.py +9 -23
- massgen/v1/utils.py +5 -23
- massgen-0.1.0.dist-info/METADATA +1245 -0
- massgen-0.1.0.dist-info/RECORD +273 -0
- massgen-0.1.0.dist-info/entry_points.txt +2 -0
- massgen/frontend/logging/__init__.py +0 -9
- massgen/frontend/logging/realtime_logger.py +0 -197
- massgen-0.0.3.dist-info/METADATA +0 -568
- massgen-0.0.3.dist-info/RECORD +0 -76
- massgen-0.0.3.dist-info/entry_points.txt +0 -2
- /massgen/backend/{Function calling openai responses.md → docs/Function calling openai responses.md} +0 -0
- {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/WHEEL +0 -0
- {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/licenses/LICENSE +0 -0
- {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# MCP Tools Module
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
**What is MCP?**
|
|
6
|
+
MCP (Model Context Protocol) is like a universal translator that lets AI systems safely use external tools and services. Think of it as a secure way for MassGen to connect to other programs and use their capabilities.
|
|
7
|
+
|
|
8
|
+
**What does this module do?**
|
|
9
|
+
The MCP Tools module is the bridge that connects MassGen to external MCP servers. It handles all the technical details of:
|
|
10
|
+
|
|
11
|
+
- Finding and connecting to MCP servers
|
|
12
|
+
- Discovering what tools are available
|
|
13
|
+
- Running tools safely with security checks
|
|
14
|
+
- Managing connections and handling errors
|
|
15
|
+
|
|
16
|
+
**Why do you need it?**
|
|
17
|
+
Instead of MassGen being limited to its built-in capabilities, MCP lets it use external tools like:
|
|
18
|
+
|
|
19
|
+
- File management systems
|
|
20
|
+
- Web scrapers
|
|
21
|
+
- Database connectors
|
|
22
|
+
- Code analysis tools
|
|
23
|
+
- API integrations
|
|
24
|
+
- And much more!
|
|
25
|
+
|
|
26
|
+
This module makes sure all these external connections are secure and reliable.
|
|
27
|
+
|
|
28
|
+
## Architecture
|
|
29
|
+
|
|
30
|
+
```mermaid
|
|
31
|
+
sequenceDiagram
|
|
32
|
+
participant User
|
|
33
|
+
participant MassGen
|
|
34
|
+
participant MCPClient
|
|
35
|
+
participant MCPServer
|
|
36
|
+
participant ExternalTool
|
|
37
|
+
|
|
38
|
+
User->>MassGen: Request with task
|
|
39
|
+
MassGen->>MCPClient: Initialize with config
|
|
40
|
+
MCPClient->>MCPClient: Validate security settings
|
|
41
|
+
MCPClient->>MCPServer: Connect (stdio/http)
|
|
42
|
+
MCPServer-->>MCPClient: Connection established
|
|
43
|
+
MCPClient->>MCPServer: Discover tools/resources
|
|
44
|
+
MCPServer-->>MCPClient: Available capabilities
|
|
45
|
+
MassGen->>MCPClient: Call tool with arguments
|
|
46
|
+
MCPClient->>MCPClient: Validate tool arguments
|
|
47
|
+
MCPClient->>MCPServer: Execute tool call
|
|
48
|
+
MCPServer->>ExternalTool: Perform operation
|
|
49
|
+
ExternalTool-->>MCPServer: Operation result
|
|
50
|
+
MCPServer-->>MCPClient: Tool response
|
|
51
|
+
MCPClient-->>MassGen: Processed result
|
|
52
|
+
MassGen-->>User: Final response
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
### What You Can Do
|
|
58
|
+
|
|
59
|
+
- **Connect to Multiple Servers**: Use tools from many different MCP servers at the same time
|
|
60
|
+
- **Automatic Tool Discovery**: The system finds and lists all available tools for you
|
|
61
|
+
- **Secure Operations**: Built-in security checks prevent malicious code from running
|
|
62
|
+
- **Reliable Connections**: Automatic reconnection if servers go down
|
|
63
|
+
- **Easy Configuration**: Simple YAML files to set up your servers
|
|
64
|
+
- **Error Handling**: Clear error messages help you fix problems quickly
|
|
65
|
+
|
|
66
|
+
### How It Connects
|
|
67
|
+
|
|
68
|
+
- **stdio**: Runs MCP servers as separate programs on your computer
|
|
69
|
+
- **HTTP**: Connects to MCP servers running on the web or network
|
|
70
|
+
|
|
71
|
+
### Security Protection
|
|
72
|
+
|
|
73
|
+
- **Command Safety**: Blocks dangerous commands that could harm your system
|
|
74
|
+
- **Network Security**: Prevents connections to unsafe websites or internal systems
|
|
75
|
+
- **Data Protection**: Filters out passwords and sensitive information
|
|
76
|
+
- **Input Validation**: Checks all data before sending it to servers
|
|
77
|
+
- **Configurable Levels**: Choose how strict security should be (strict/moderate/permissive)
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
### Basic Usage
|
|
82
|
+
|
|
83
|
+
#### 1. Start a Test Server
|
|
84
|
+
|
|
85
|
+
Use the included test server for development. It provides sample tools like `mcp_echo` and `add_numbers`:
|
|
86
|
+
|
|
87
|
+
Note: If you're using an agent config with `type: "stdio"` (for example `massgen/configs/gemini_mcp_test.yaml`), you do not need to run this manually , MassGen will automatically launch the server from the config.
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
# Run the test server (from massgen/tests/mcp_test_server.py)
|
|
91
|
+
uv run python -m massgen.tests.mcp_test_server
|
|
92
|
+
```
|
|
93
|
+
For streamable-http connections, start the HTTP test server instead:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
uv run python massgen/tests/test_http_mcp_server.py
|
|
97
|
+
```
|
|
98
|
+
This serves at `http://localhost:8000/mcp` and pairs with `massgen/configs/gemini_streamable_http_test.yaml`.
|
|
99
|
+
|
|
100
|
+
#### 2. Configure MCP Connection
|
|
101
|
+
|
|
102
|
+
Create a configuration file or use the provided examples:
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
# Based on massgen/configs/gemini_mcp_test.yaml
|
|
106
|
+
# The `mcp_servers` list should be added to your agent's backend configuration.
|
|
107
|
+
# The following example shows how to configure a connection to the test server.
|
|
108
|
+
mcp_servers:
|
|
109
|
+
- name: "test_server"
|
|
110
|
+
type: "stdio"
|
|
111
|
+
command: "python"
|
|
112
|
+
args: ["-u", "-m", "massgen.tests.mcp_test_server"]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
For a complete, runnable example, see `massgen/configs/gemini_mcp_test.yaml`. To test the full configuration, run:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
uv run python -m massgen.cli --config massgen/configs/gemini_mcp_test.yaml "Test the MCP tools by calling mcp_echo with text 'Hello massgen' and add_numbers with 46 and 52"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Supported Transports
|
|
122
|
+
|
|
123
|
+
# Note: type accepts "stdio" and "streamable-http"
|
|
124
|
+
|
|
125
|
+
### stdio Transport
|
|
126
|
+
|
|
127
|
+
Direct process communication through stdin/stdout:
|
|
128
|
+
|
|
129
|
+
```yaml
|
|
130
|
+
type: "stdio"
|
|
131
|
+
command: "python"
|
|
132
|
+
args: ["-m", "your.mcp.server"]
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### streamable-http Transport
|
|
136
|
+
|
|
137
|
+
HTTP-based communication:
|
|
138
|
+
|
|
139
|
+
```yaml
|
|
140
|
+
type: "streamable-http"
|
|
141
|
+
url: "http://localhost:8000/mcp"
|
|
142
|
+
headers:
|
|
143
|
+
Authorization: "Bearer your-token"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Tool Discovery and Naming
|
|
147
|
+
|
|
148
|
+
- Tools are automatically discovered upon connection
|
|
149
|
+
- Multi-server setups use prefixed naming: `mcp__server_name__tool_name`
|
|
150
|
+
- Tool names are sanitized for security using `sanitize_tool_name`
|
|
151
|
+
- Resources and prompts follow similar naming conventions
|
|
152
|
+
|
|
153
|
+
## Error Handling
|
|
154
|
+
|
|
155
|
+
The module provides comprehensive error handling through custom exceptions:
|
|
156
|
+
|
|
157
|
+
- `MCPConnectionError`: Connection-related issues
|
|
158
|
+
- `MCPServerError`: Server execution failures
|
|
159
|
+
- `MCPConfigurationError`: Configuration validation failures
|
|
160
|
+
- `MCPTimeoutError`: Operation timeouts
|
|
161
|
+
- `MCPValidationError`: Input validation errors
|
|
162
|
+
- `MCPResourceError`: Resource access failures
|
|
163
|
+
|
|
164
|
+
## Documentation
|
|
165
|
+
|
|
166
|
+
- **[Client Documentation](client.md)**: Detailed API reference and usage examples
|
|
167
|
+
- **[Security Documentation](security.md)**: Security features and best practices
|
|
168
|
+
- **[Circuit Breaker Documentation](circuit_breaker.md)**: Details on the circuit breaker implementation
|
|
169
|
+
- **[Config Validator Documentation](config_validator.md)**: Information about configuration validation
|
|
170
|
+
- **[Exceptions Documentation](exceptions.md)**: Custom exception classes and handling
|
|
171
|
+
|
|
172
|
+
## Troubleshooting
|
|
173
|
+
|
|
174
|
+
### Common Issues
|
|
175
|
+
|
|
176
|
+
**Connection Failures**
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
MCPConnectionError: Failed to connect to server
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
- Verify server command and arguments
|
|
183
|
+
- Check if the server process starts correctly
|
|
184
|
+
- Ensure proper permissions for stdio transport
|
|
185
|
+
|
|
186
|
+
**Tool Not Found**
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
MCPServerError: Tool 'example_tool' not found
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
- Verify tool name spelling and case
|
|
193
|
+
- Check if server properly advertises the tool
|
|
194
|
+
- For multi-server setups, use prefixed names
|
|
195
|
+
|
|
196
|
+
**Security Validation Errors**
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
MCPSecurityError: Command contains dangerous characters
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
- Review security level configuration
|
|
203
|
+
- Check command arguments for shell metacharacters
|
|
204
|
+
- Consult security documentation for allowed patterns
|
|
205
|
+
|
|
206
|
+
**Timeout Issues**
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
MCPTimeoutError: Operation timed out after 30 seconds
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
- Increase timeout values in configuration
|
|
213
|
+
- Check server responsiveness
|
|
214
|
+
- Consider using circuit breaker settings
|
|
215
|
+
|
|
216
|
+
### Debug Mode
|
|
217
|
+
|
|
218
|
+
Enable debug logging for detailed troubleshooting:
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
import logging
|
|
222
|
+
logging.getLogger('massgen.mcp_tools').setLevel(logging.DEBUG)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Examples
|
|
226
|
+
|
|
227
|
+
See the `massgen/configs/` directory for complete configuration examples:
|
|
228
|
+
|
|
229
|
+
- `gemini_mcp_test.yaml`: Basic single-server setup for testing
|
|
230
|
+
- `gemini_mcp_example.yaml`: Example with an external weather tool
|
|
231
|
+
- `gemini_streamable_http_test.yaml`: MCP server connection with streamable-http transport type
|
|
232
|
+
- `multimcp_gemini.yaml`: Multiple MCP servers (Airbnb + Brave Search) with Gemini backend for travel research
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
MCP (Model Context Protocol) integration for MassGen.
|
|
4
|
+
|
|
5
|
+
This module provides enhanced MCP client functionality to connect with MCP servers
|
|
6
|
+
and integrate external tools and resources into the MassGen workflow.
|
|
7
|
+
|
|
8
|
+
Features:
|
|
9
|
+
- Official MCP library integration
|
|
10
|
+
- Multi-server support via MCPClient
|
|
11
|
+
- Enhanced security with command sanitization
|
|
12
|
+
- Modern transport methods (stdio, streamable-http)
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from mcp import types as mcp_types
|
|
16
|
+
|
|
17
|
+
# shared utilities for backend integration
|
|
18
|
+
from .backend_utils import (
|
|
19
|
+
Function,
|
|
20
|
+
MCPCircuitBreakerManager,
|
|
21
|
+
MCPConfigHelper,
|
|
22
|
+
MCPErrorHandler,
|
|
23
|
+
MCPExecutionManager,
|
|
24
|
+
MCPMessageManager,
|
|
25
|
+
MCPResourceManager,
|
|
26
|
+
MCPRetryHandler,
|
|
27
|
+
MCPSetupManager,
|
|
28
|
+
)
|
|
29
|
+
from .circuit_breaker import CircuitBreakerConfig, MCPCircuitBreaker
|
|
30
|
+
from .client import MCPClient
|
|
31
|
+
from .config_validator import MCPConfigValidator
|
|
32
|
+
from .exceptions import (
|
|
33
|
+
MCPAuthenticationError,
|
|
34
|
+
MCPConfigurationError,
|
|
35
|
+
MCPConnectionError,
|
|
36
|
+
MCPError,
|
|
37
|
+
MCPResourceError,
|
|
38
|
+
MCPServerError,
|
|
39
|
+
MCPTimeoutError,
|
|
40
|
+
MCPValidationError,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Hook system for function call interception
|
|
44
|
+
from .hooks import (
|
|
45
|
+
FunctionHook,
|
|
46
|
+
FunctionHookManager,
|
|
47
|
+
HookResult,
|
|
48
|
+
HookType,
|
|
49
|
+
PermissionClientSession,
|
|
50
|
+
convert_sessions_to_permission_sessions,
|
|
51
|
+
)
|
|
52
|
+
from .security import (
|
|
53
|
+
prepare_command,
|
|
54
|
+
sanitize_tool_name,
|
|
55
|
+
substitute_env_variables,
|
|
56
|
+
validate_server_security,
|
|
57
|
+
validate_tool_arguments,
|
|
58
|
+
validate_url,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
__all__ = [
|
|
62
|
+
# Core client classes
|
|
63
|
+
"MCPClient",
|
|
64
|
+
# Circuit breaker
|
|
65
|
+
"MCPCircuitBreaker",
|
|
66
|
+
"CircuitBreakerConfig",
|
|
67
|
+
# Official MCP types
|
|
68
|
+
"mcp_types",
|
|
69
|
+
# Exception classes
|
|
70
|
+
"MCPError",
|
|
71
|
+
"MCPConnectionError",
|
|
72
|
+
"MCPServerError",
|
|
73
|
+
"MCPValidationError",
|
|
74
|
+
"MCPTimeoutError",
|
|
75
|
+
"MCPAuthenticationError",
|
|
76
|
+
"MCPConfigurationError",
|
|
77
|
+
"MCPResourceError",
|
|
78
|
+
# Utility functions
|
|
79
|
+
# Security utilities
|
|
80
|
+
"prepare_command",
|
|
81
|
+
"sanitize_tool_name",
|
|
82
|
+
"substitute_env_variables",
|
|
83
|
+
"validate_url",
|
|
84
|
+
"validate_tool_arguments",
|
|
85
|
+
"validate_server_security",
|
|
86
|
+
# Configuration validation
|
|
87
|
+
"MCPConfigValidator",
|
|
88
|
+
# shared utilities for backend integration
|
|
89
|
+
"Function",
|
|
90
|
+
"MCPErrorHandler",
|
|
91
|
+
"MCPRetryHandler",
|
|
92
|
+
"MCPMessageManager",
|
|
93
|
+
"MCPConfigHelper",
|
|
94
|
+
"MCPCircuitBreakerManager",
|
|
95
|
+
"MCPResourceManager",
|
|
96
|
+
"MCPSetupManager",
|
|
97
|
+
"MCPExecutionManager",
|
|
98
|
+
# Hook system
|
|
99
|
+
"HookType",
|
|
100
|
+
"FunctionHook",
|
|
101
|
+
"HookResult",
|
|
102
|
+
"FunctionHookManager",
|
|
103
|
+
"PermissionClientSession",
|
|
104
|
+
"convert_sessions_to_permission_sessions",
|
|
105
|
+
]
|