-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp_servers.go
More file actions
71 lines (63 loc) · 2.48 KB
/
Copy pathmcp_servers.go
File metadata and controls
71 lines (63 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package flashduty
import (
"context"
"fmt"
"net/http"
)
// CreateMCPServerInput is the payload for POST /safari/mcp/server/create.
// Transport must be one of "stdio", "sse", or "streamable-http". Fields are
// conditionally required by the backend depending on Transport: stdio uses
// Command/Args/Env; sse and streamable-http use URL/Headers. ConnectTimeout
// and CallTimeout are in seconds.
//
// TeamID is always serialized (no omitempty) because 0 is a meaningful
// sentinel — it explicitly requests account scope, distinct from "field
// omitted". Callers must set it deliberately: 0 = account scope; >0 = team scope.
type CreateMCPServerInput struct {
ServerName string `json:"server_name"`
Description string `json:"description"`
Transport string `json:"transport"`
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
URL string `json:"url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
ConnectTimeout int `json:"connect_timeout,omitempty"`
CallTimeout int `json:"call_timeout,omitempty"`
Status string `json:"status,omitempty"`
TeamID int64 `json:"team_id"`
}
// CreateMCPServerOutput is the unwrapped data block returned by
// POST /safari/mcp/server/create.
type CreateMCPServerOutput struct {
ServerID string `json:"server_id"`
Status string `json:"status"`
}
// CreateMCPServer registers a new MCP server with Flashduty.
func (c *Client) CreateMCPServer(ctx context.Context, input *CreateMCPServerInput) (*CreateMCPServerOutput, error) {
if input == nil {
return nil, fmt.Errorf("create MCP server input is required")
}
resp, err := c.makeRequest(ctx, "POST", "/safari/mcp/server/create", input)
if err != nil {
return nil, fmt.Errorf("failed to create MCP server: %w", err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return nil, handleAPIError(c.logger, resp)
}
var result struct {
Error *DutyError `json:"error,omitempty"`
Data *CreateMCPServerOutput `json:"data,omitempty"`
}
if err := parseResponse(c.logger, resp, &result); err != nil {
return nil, err
}
if result.Error != nil {
return nil, result.Error
}
if result.Data == nil {
return nil, fmt.Errorf("create MCP server returned empty data")
}
return result.Data, nil
}