GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — func/cmd/mcp.go at main · stackbuilders/func

Expand file tree

/

mcp.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
123 lines (98 loc) · 3.49 KB
/

mcp.go

Copy path

File metadata and controls

123 lines (98 loc) · 3.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package cmd
import (
"fmt"
"os"
"strconv"
"github.com/spf13/cobra"
"knative.dev/func/pkg/mcp"
fn "knative.dev/func/pkg/functions"
)
func NewMCPCmd(newClient ClientFactory) *cobra.Command {
cmd := &cobra.Command{
Use: "mcp",
Short: "Model Context Protocol (MCP) server",
Long: `
NAME
{{rootCmdUse}} mcp - Model Context Protocol (MCP) server
SYNOPSIS
{{rootCmdUse}} mcp [command] [flags]
DESCRIPTION
The Functions Model Context Protocol (MCP) server can be used to give
agents the power of Functions.
Configure your agentic client to use the MCP server with command
"{{rootCmdUse}} mcp start". Then get the conversation started with
"Let's create a Function!".
By default the MCP server operates in read-only mode, allowing Function
creation, building, and inspection, but preventing deployment and deletion.
To enable full write access (deploy and delete operations), set the
environment variable FUNC_ENABLE_MCP_WRITE=true.
This is an experimental feature, and using an LLM to create and deploy
code running on your cluster requires careful supervision. Functions is
an inherently "mutative" tool, so enabling write mode for your LLM is
essentially giving (sometimes unpredictable) AI the ability to create,
modify, deploy, and delete Function instances on your currently connected
cluster.
The command "{{rootCmdUse}} mcp start" is meant to be invoked by your MCP
client (such as Claude Code, Cursor, VS Code, Windsurf, etc.); not run
directly. Configure your client of choice with a new MCP server which runs
this command. For example, in Claude Code this can be accomplished with:
claude mcp add func func mcp start
Instructions for other clients can be found at:
https://github.com/knative/func/blob/main/docs/mcp-integration/integration.md
AVAILABLE COMMANDS
start Start the MCP server (for use by your agent)
EXAMPLES
o View this help:
{{rootCmdUse}} mcp --help
`,
}
cmd.AddCommand(NewMCPStartCmd(newClient))
return cmd
}
func NewMCPStartCmd(newClient ClientFactory) *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Start the MCP server",
Long: `
NAME
{{rootCmdUse}} mcp start - start the Model Context Protocol (MCP) server
SYNOPSIS
{{rootCmdUse}} mcp start [flags]
DESCRIPTION
Starts the Model Context Protocol (MCP) server.
This command is designed to be invoked by MCP clients directly
(such as Claude Code, Claude Desktop, Cursor, VS Code, Windsurf, etc.);
not run directly.
Please see '{{rootCmdUse}} mcp --help' for more information.
`,
RunE: func(cmd *cobra.Command, args []string) error {
return runMCPStart(cmd, args, newClient)
},
}
// no flags at this time; future enhancements may be to allow configuring
// HTTP Stream vs stdio, single vs multiuser modes, etc. For now
// we just use a simple gathering of options in runMCPStart.
return cmd
}
func runMCPStart(cmd *cobra.Command, args []string, newClient ClientFactory) error {
// Configure write mode
writeEnabled := false
if val := os.Getenv(mcp.EnvMCPWrite); val != "" {
parsed, err := strconv.ParseBool(val)
if err != nil {
return fmt.Errorf("%s should be a boolean (true/false, 1/0, etc). Received %q", mcp.EnvMCPWrite, val)
}
writeEnabled = parsed
}
// Configure 'func' or 'kn func'?
rootCmd := cmd.Root()
cmdPrefix := rootCmd.Use
// Instantiate
client, done := newClient(ClientConfig{},
fn.WithMCPServer(mcp.New(
mcp.WithPrefix(cmdPrefix),
mcp.WithReadonly(!writeEnabled))))
defer done()
// Start
return client.StartMCPServer(cmd.Context())
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.