Skip to content

Commit f096936

Browse files
authored
mcp: refactors pkg for easy maintainability (knative#2928)
Signed-off-by: kapil <[email protected]>
1 parent 211df16 commit f096936

File tree

3 files changed

+433
-417
lines changed

3 files changed

+433
-417
lines changed

pkg/mcp/help.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package mcp
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os/exec"
7+
8+
"github.com/mark3labs/mcp-go/mcp"
9+
)
10+
11+
func handleRootHelpResource(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
12+
content, err := exec.Command("func", "--help").Output()
13+
if err != nil {
14+
return nil, err
15+
}
16+
17+
return []mcp.ResourceContents{
18+
mcp.TextResourceContents{
19+
URI: "func://docs",
20+
MIMEType: "text/plain",
21+
Text: string(content),
22+
},
23+
}, nil
24+
}
25+
26+
func runHelpCommand(args []string, uri string) ([]mcp.ResourceContents, error) {
27+
args = append(args, "--help")
28+
content, err := exec.Command("func", args...).Output()
29+
if err != nil {
30+
return nil, err
31+
}
32+
return []mcp.ResourceContents{
33+
mcp.TextResourceContents{
34+
URI: uri,
35+
MIMEType: "text/plain",
36+
Text: string(content),
37+
},
38+
}, nil
39+
}
40+
41+
func handleCmdHelpPrompt(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
42+
cmd := request.Params.Arguments["cmd"]
43+
if cmd == "" {
44+
return nil, fmt.Errorf("cmd is required")
45+
}
46+
47+
return mcp.NewGetPromptResult(
48+
"Cmd Help Prompt",
49+
[]mcp.PromptMessage{
50+
mcp.NewPromptMessage(
51+
mcp.RoleUser,
52+
mcp.NewTextContent("What can I do with this func command? Please provide help for the command: "+cmd),
53+
),
54+
mcp.NewPromptMessage(
55+
mcp.RoleAssistant,
56+
mcp.NewEmbeddedResource(mcp.TextResourceContents{
57+
URI: fmt.Sprintf("func://%s/docs", cmd),
58+
MIMEType: "text/plain",
59+
}),
60+
),
61+
},
62+
), nil
63+
}
64+
65+
func handleRootHelpPrompt(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
66+
return mcp.NewGetPromptResult(
67+
"Help Prompt",
68+
[]mcp.PromptMessage{
69+
mcp.NewPromptMessage(
70+
mcp.RoleUser,
71+
mcp.NewTextContent("What can I do with the func command?"),
72+
),
73+
mcp.NewPromptMessage(
74+
mcp.RoleAssistant,
75+
mcp.NewEmbeddedResource(mcp.TextResourceContents{
76+
URI: "func://docs",
77+
MIMEType: "text/plain",
78+
}),
79+
),
80+
},
81+
), nil
82+
}

0 commit comments

Comments
 (0)