Skip to content

Commit 824911c

Browse files
authored
mcp: adds resource provider and prompt for root cmd docs (knative#2875)
Signed-off-by: kapil <[email protected]>
1 parent 1cccfd3 commit 824911c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

pkg/mcp/mcp.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ func NewServer() *MCPServer {
9191
handleBuildTool,
9292
)
9393

94+
mcpServer.AddResource(mcp.NewResource(
95+
"func://docs",
96+
"Root Help Command",
97+
mcp.WithResourceDescription("--help output of the func command"),
98+
mcp.WithMIMEType("text/plain"),
99+
), handleRootHelpResource)
100+
101+
mcpServer.AddPrompt(mcp.NewPrompt("help",
102+
mcp.WithPromptDescription("help prompt for the root command"),
103+
), handleHelpPrompt)
104+
94105
return &MCPServer{
95106
server: mcpServer,
96107
}
@@ -100,6 +111,40 @@ func (s *MCPServer) Start() error {
100111
return server.ServeStdio(s.server)
101112
}
102113

114+
func handleRootHelpResource(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
115+
content, err := exec.Command("func", "--help").Output()
116+
if err != nil {
117+
return nil, err
118+
}
119+
120+
return []mcp.ResourceContents{
121+
mcp.TextResourceContents{
122+
URI: "func://docs",
123+
MIMEType: "text/plain",
124+
Text: string(content),
125+
},
126+
}, nil
127+
}
128+
129+
func handleHelpPrompt(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
130+
return mcp.NewGetPromptResult(
131+
"Help Prompt",
132+
[]mcp.PromptMessage{
133+
mcp.NewPromptMessage(
134+
mcp.RoleUser,
135+
mcp.NewTextContent("What can I do with the func command?"),
136+
),
137+
mcp.NewPromptMessage(
138+
mcp.RoleAssistant,
139+
mcp.NewEmbeddedResource(mcp.TextResourceContents{
140+
URI: "func://docs",
141+
MIMEType: "text/plain",
142+
}),
143+
),
144+
},
145+
), nil
146+
}
147+
103148
func handleHealthCheckTool(
104149
ctx context.Context,
105150
request mcp.CallToolRequest,

0 commit comments

Comments
 (0)