CreateEnvironment creates a new environment via MCP
(title, explanation string)
| 87 | |
| 88 | // CreateEnvironment creates a new environment via MCP |
| 89 | func (s *MCPServerProcess) CreateEnvironment(title, explanation string) (string, error) { |
| 90 | ctx := context.Background() |
| 91 | |
| 92 | request := mcp.CallToolRequest{} |
| 93 | request.Params.Name = "environment_create" |
| 94 | request.Params.Arguments = map[string]any{ |
| 95 | "environment_source": s.repoDir, |
| 96 | "title": title, |
| 97 | "explanation": explanation, |
| 98 | } |
| 99 | |
| 100 | result, err := s.client.CallTool(ctx, request) |
| 101 | if err != nil { |
| 102 | return "", err |
| 103 | } |
| 104 | |
| 105 | // Check if the tool call resulted in an error |
| 106 | if result.IsError && len(result.Content) > 0 { |
| 107 | if textContent, ok := result.Content[0].(mcp.TextContent); ok { |
| 108 | return "", fmt.Errorf("environment creation failed: %s", textContent.Text) |
| 109 | } |
| 110 | return "", fmt.Errorf("environment creation failed with unknown error format") |
| 111 | } |
| 112 | |
| 113 | if len(result.Content) > 0 { |
| 114 | if textContent, ok := result.Content[0].(mcp.TextContent); ok { |
| 115 | var envResponse struct { |
| 116 | ID string `json:"id"` |
| 117 | } |
| 118 | if err := json.Unmarshal([]byte(textContent.Text), &envResponse); err != nil { |
| 119 | return "", fmt.Errorf("failed to parse environment response (content: %q): %w", textContent.Text, err) |
| 120 | } |
| 121 | return envResponse.ID, nil |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return "", fmt.Errorf("no valid response content found") |
| 126 | } |
| 127 | |
| 128 | // FileRead reads a file from an environment via MCP |
| 129 | func (s *MCPServerProcess) FileRead(envID, targetFile string) (string, error) { |
no test coverage detected