11package cmd
22
33import (
4- "fmt"
54 "log"
6- "os"
7- "runtime"
85
96 "github.com/spf13/cobra"
107 "knative.dev/func/pkg/mcp"
@@ -13,39 +10,39 @@ import (
1310func NewMCPServerCmd () * cobra.Command {
1411 cmd := & cobra.Command {
1512 Use : "mcp" ,
16- Short : "Manage Model Context Protocol (MCP) server" ,
13+ Short : "The Functions Model Context Protocol (MCP) server" ,
1714 Long : `
1815NAME
19- {{rootCmdUse}} mcp - manage a Model Context Protocol (MCP) server
16+ {{rootCmdUse}} mcp - The Functions Model Context Protocol (MCP) server
2017
2118SYNOPSIS
2219 {{rootCmdUse}} mcp [command] [flags]
2320
2421DESCRIPTION
25- Manages a Model Context Protocol (MCP) server over standard input/output (stdio) transport.
26- This server enables AI language models to interact with Knative Functions through the
27- Model Context Protocol.
22+ The Functions Model Context Protocol (MCP) server can be used to give agents
23+ the power of Functions.
24+
25+ Configure your agentic client to use the MCP server with command
26+ "{{rootCmdUse}} mcp start". Then get the conversation started with
2827
29- IMPORTANT: This command is designed to be invoked by MCP clients (such as Claude Desktop,
30- Cursor, VS Code, Windsurf, etc.), not run directly by users. The MCP client automatically
31- launches and manages the server based on its configuration.
28+ "Let's create a Function!".
3229
33- For setup instructions and client configuration examples, see:
34- https://github.com/knative/func/blob/main/docs/mcp-integration/integration.md
30+ IMPORTANT: This is an EXPERIMENTAL feature. The FUNC_ENABLE_MCP environment
31+ variable must be set before the server will take any meaninigful action.
3532
36- Note: This is an EXPERIMENTAL feature. The FUNC_ENABLE_MCP environment variable must be
37- set to "true" for the server to start. See documentation for details.
33+ IMPORTANT: "{{rootCmdUse}} mcp start" is designed to be invoked by MCP
34+ clients (such as Claude Code, Cursor, VS Code, Windsurf, etc.). Do not run
35+ this directly. Instead, configure your client to invoke. For setup
36+ instructions and client configuration examples, see:
37+ https://github.com/knative/func/blob/main/docs/mcp-integration/integration.md
3838
3939AVAILABLE COMMANDS
40- start Start the MCP server
40+ start Start the MCP server (for use by your agent)
4141
4242EXAMPLES
4343
4444 o View this help:
4545 {{rootCmdUse}} mcp --help
46-
47- Note: End users should configure their MCP client, not run these commands directly.
48- See the documentation link above for configuration instructions.
4946` ,
5047 }
5148
@@ -67,35 +64,16 @@ SYNOPSIS
6764 {{rootCmdUse}} mcp start [flags]
6865
6966DESCRIPTION
70- Starts a Model Context Protocol (MCP) server over standard input/output (stdio) transport.
71- This server provides tools for AI language models to deploy and create Knative serverless
72- functions through the Model Context Protocol.
67+ Starts the Model Context Protocol (MCP) server.
7368
74- IMPORTANT: This command is designed to be invoked by MCP clients (such as Claude Desktop,
75- Cursor, VS Code, Windsurf, etc.), not run directly by users. The MCP client automatically
76- launches this command based on its configuration and manages the server lifecycle.
69+ IMPORTANT: This command is designed to be invoked by MCP clients (such as
70+ Claude Desktop, Cursor, VS Code, Windsurf, etc.), not run directly.
7771
78- PREREQUISITES :
72+ IMPORTANT :
7973 - The FUNC_ENABLE_MCP environment variable must be set to "true"
80- - The MCP client must be properly configured
8174
8275 For detailed setup instructions and client configuration examples, see:
8376 https://github.com/knative/func/blob/main/docs/mcp-integration/integration.md
84-
85- EXAMPLES
86-
87- This command is typically not run directly. Instead, configure your MCP client with:
88-
89- {
90- "mcpServers": {
91- "func-mcp": {
92- "command": "{{rootCmdUse}}",
93- "args": ["mcp", "start"]
94- }
95- }
96- }
97-
98- For complete configuration instructions, see the documentation link above.
9977` ,
10078 RunE : func (cmd * cobra.Command , args []string ) error {
10179 return runMCPServer (cmd , args )
@@ -104,74 +82,7 @@ EXAMPLES
10482 return cmd
10583}
10684
107- func getEnvVarInstructions () string {
108- switch runtime .GOOS {
109- case "windows" :
110- return ` Windows (PowerShell):
111- Set permanently via System Environment Variables:
112- [System.Environment]::SetEnvironmentVariable('FUNC_ENABLE_MCP', 'true', 'User')
113-
114- Then restart your terminal/IDE.
115-
116- Alternatively, add to your PowerShell profile ($PROFILE):
117- $env:FUNC_ENABLE_MCP = "true"
118-
119- Windows (CMD):
120- Set permanently via System Environment Variables GUI:
121- 1. Open System Properties → Advanced → Environment Variables
122- 2. Add User variable: FUNC_ENABLE_MCP=true
123- 3. Restart terminal/IDE`
124-
125- case "darwin" :
126- return ` macOS:
127- Add to your shell config (~/.zshrc, ~/.bash_profile, etc.):
128- export FUNC_ENABLE_MCP=true
129-
130- Then reload: source ~/.zshrc (or restart terminal)`
131-
132- case "linux" :
133- return ` Linux:
134- Add to your shell config (~/.bashrc, ~/.zshrc, etc.):
135- export FUNC_ENABLE_MCP=true
136-
137- Then reload: source ~/.bashrc (or restart terminal)`
138-
139- default :
140- // Fallback for unknown OS - show Unix-style instructions
141- return ` Unix/Linux/macOS:
142- Add to your shell config (~/.bashrc, ~/.zshrc, etc.):
143- export FUNC_ENABLE_MCP=true
144-
145- Then reload your shell configuration or restart terminal`
146- }
147- }
148-
14985func runMCPServer (cmd * cobra.Command , args []string ) error {
150- // Check if experimental MCP feature is explicitly enabled
151- if os .Getenv ("FUNC_ENABLE_MCP" ) != "true" {
152- errorMsg := `Error: MCP server is currently an EXPERIMENTAL feature
153-
154- WARNING: The MCP (Model Context Protocol) server enables AI language models to
155- execute commands on your system, including:
156- - Creating and modifying code
157- - Building container images
158- - Deploying to Kubernetes clusters
159- - Modifying function configurations
160-
161- AI models can generate incorrect code and make unintended changes.
162- USER DISCRETION IS ADVISED.
163-
164- To enable this experimental feature, set the following environment variable:
165-
166- %s
167-
168- For detailed instructions, see: docs/mcp-integration/integration.md`
169-
170- fmt .Fprintf (os .Stderr , errorMsg , getEnvVarInstructions ())
171- fmt .Fprintln (os .Stderr ) // Add final newline
172- os .Exit (1 )
173- }
174-
17586 // Get the root command's path to determine if we're "func" or "kn func"
17687 rootCmd := cmd .Root ()
17788 cmdPrefix := rootCmd .Use
0 commit comments