-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.go
More file actions
87 lines (72 loc) · 2.65 KB
/
tools.go
File metadata and controls
87 lines (72 loc) · 2.65 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package mcp
import (
"context"
"fmt"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
// GetActionParametersArgs defines the parameters for the get_action_parameters tool.
type GetActionParametersArgs struct {
ActionRef string `json:"actionRef" jsonschema:"GitHub Action reference (e.g., 'actions/checkout@v5')"`
}
// handleGetActionParameters handles the get_action_parameters tool call.
func (m *MCPServer) handleGetActionParameters(ctx context.Context, req *mcp.CallToolRequest, args GetActionParametersArgs) (*mcp.CallToolResult, any, error) {
// Validate input
if args.ActionRef == "" {
return nil, nil, fmt.Errorf("actionRef is required")
}
// Fetch and parse action parameters
params, err := m.actionsService.GetActionParameters(args.ActionRef)
if err != nil {
return nil, nil, fmt.Errorf("failed to get action parameters: %w", err)
}
// Format as text output
textOutput := fmt.Sprintf("Action: %s\n\n", args.ActionRef)
// Add name and description if available
if name, ok := params["name"].(string); ok {
textOutput += fmt.Sprintf("Name: %s\n", name)
}
if desc, ok := params["description"].(string); ok {
textOutput += fmt.Sprintf("Description: %s\n", desc)
}
// Add inputs summary if available
if inputs, ok := params["inputs"].(map[string]interface{}); ok {
textOutput += fmt.Sprintf("\nInputs: %d defined\n", len(inputs))
}
// Add outputs summary if available
if outputs, ok := params["outputs"].(map[string]interface{}); ok {
textOutput += fmt.Sprintf("Outputs: %d defined\n", len(outputs))
}
textOutput += "\nFull action.yml structure returned in structured data."
// Return response with both text and structured data
return &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{
Text: textOutput,
},
},
}, params, nil
}
// GetReadmeArgs defines the parameters for the get_readme tool.
type GetReadmeArgs struct {
RepoRef string `json:"repoRef" jsonschema:"GitHub repository reference (e.g., 'owner/repo@main' or 'owner/repo'). If no ref is provided, defaults to 'main'."`
}
// handleGetReadme handles the get_readme tool call.
func (m *MCPServer) handleGetReadme(ctx context.Context, req *mcp.CallToolRequest, args GetReadmeArgs) (*mcp.CallToolResult, any, error) {
// Validate input
if args.RepoRef == "" {
return nil, nil, fmt.Errorf("repoRef is required")
}
// Fetch README content
content, err := m.actionsService.GetReadme(args.RepoRef)
if err != nil {
return nil, nil, fmt.Errorf("failed to get README: %w", err)
}
// Return response with README content
return &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{
Text: content,
},
},
}, map[string]string{"content": content}, nil
}