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 — fix(mcp): remove writeEnabled from Start() to prevent readonly state … · knative/func@cfb26fb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • cmd
    • mcp.go
    • mcp_test.go
  • pkg
    • functions
      • client.go
      • client_test.go
    • mcp
      • mcp.go
      • mcp_test.go
    • mock
      • mcp_server.go
      • mcp_server_test.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cmd/mcp.go‎

Copy file name to clipboardExpand all lines: cmd/mcp.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ func runMCPStart(cmd *cobra.Command, args []string, newClient ClientFactory) err
118118
defer done()
119119

120120
// Start
121-
return client.StartMCPServer(cmd.Context(), writeEnabled)
121+
return client.StartMCPServer(cmd.Context())
122122

123123
}
Collapse file

‎cmd/mcp_test.go‎

Copy file name to clipboardExpand all lines: cmd/mcp_test.go
+11-17Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"context"
54
"testing"
65

76
fn "knative.dev/func/pkg/functions"
@@ -30,37 +29,32 @@ func TestMCP_Start(t *testing.T) {
3029
}
3130
}
3231

33-
// TestMCP_StartWriteable ensures that the server is started with write
34-
// enabled only when the environment variable FUNC_ENABLE_MCP_WRITE is set.
32+
// TestMCP_StartWriteable ensures that the FUNC_ENABLE_MCP_WRITE environment
33+
// variable is correctly parsed and the server starts in both default
34+
// (readonly) and write-enabled modes.
3535
func TestMCP_StartWriteable(t *testing.T) {
3636
_ = FromTempDirectory(t)
3737

38-
// Ensure it defaults to off.
38+
// Ensure it defaults to readonly (no env var set).
3939
server := mock.NewMCPServer()
40-
server.StartFn = func(_ context.Context, writeEnabled bool) error {
41-
if writeEnabled {
42-
t.Fatal("MCP server started write-enabled by default")
43-
}
44-
return nil
45-
}
4640
cmd := NewMCPCmd(NewTestClient(fn.WithMCPServer(server)))
4741
cmd.SetArgs([]string{"start"})
4842
if err := cmd.Execute(); err != nil {
4943
t.Fatal(err)
5044
}
45+
if !server.StartInvoked {
46+
t.Fatal("MCP server was not started in default mode")
47+
}
5148

52-
// Ensure it is set to true on proper truthy value
49+
// Ensure it starts successfully with write mode enabled.
5350
t.Setenv("FUNC_ENABLE_MCP_WRITE", "true")
5451
server = mock.NewMCPServer()
55-
server.StartFn = func(_ context.Context, writeEnabled bool) error {
56-
if !writeEnabled {
57-
t.Fatal("MCP server was not enabled")
58-
}
59-
return nil
60-
}
6152
cmd = NewMCPCmd(NewTestClient(fn.WithMCPServer(server)))
6253
cmd.SetArgs([]string{"start"})
6354
if err := cmd.Execute(); err != nil {
6455
t.Fatal(err)
6556
}
57+
if !server.StartInvoked {
58+
t.Fatal("MCP server was not started with write mode enabled")
59+
}
6660
}
Collapse file

‎pkg/functions/client.go‎

Copy file name to clipboardExpand all lines: pkg/functions/client.go
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ type PipelinesProvider interface {
221221
// MCPServer for a given client instance which performs bidirectional
222222
// communication with a client agent.
223223
type MCPServer interface {
224-
Start(context.Context, bool) error
224+
Start(context.Context) error
225225
}
226226

227227
// New client for function management.
@@ -1247,8 +1247,8 @@ func (c *Client) Push(ctx context.Context, f Function) (Function, bool, error) {
12471247

12481248
// StartMCPServer is currently a passthrough to the configured MCP Server
12491249
// instance.
1250-
func (c *Client) StartMCPServer(ctx context.Context, writeEnabled bool) error {
1251-
return c.mcpServer.Start(ctx, writeEnabled)
1250+
func (c *Client) StartMCPServer(ctx context.Context) error {
1251+
return c.mcpServer.Start(ctx)
12521252
}
12531253

12541254
// ensureRunDataDir creates a .func directory at the given path, and
@@ -1536,4 +1536,4 @@ func (n *noopDNSProvider) Provide(_ Function) error { return nil }
15361536
// MCPServer
15371537
type noopMCPServer struct{}
15381538

1539-
func (n *noopMCPServer) Start(_ context.Context, _ bool) error { return nil }
1539+
func (n *noopMCPServer) Start(_ context.Context) error { return nil }
Collapse file

‎pkg/functions/client_test.go‎

Copy file name to clipboardExpand all lines: pkg/functions/client_test.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ func TestClient_StartMCPServer(t *testing.T) {
12861286

12871287
client := fn.New(fn.WithMCPServer(server))
12881288

1289-
if err := client.StartMCPServer(t.Context(), true); err != nil {
1289+
if err := client.StartMCPServer(t.Context()); err != nil {
12901290
t.Fatal(err)
12911291
}
12921292

Collapse file

‎pkg/mcp/mcp.go‎

Copy file name to clipboardExpand all lines: pkg/mcp/mcp.go
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ func New(options ...Option) *Server {
144144
return s
145145
}
146146

147-
// Start the MCP server using the configured transport
148-
func (s *Server) Start(ctx context.Context, writeEnabled bool) error {
149-
s.readonly = !writeEnabled
147+
// Start the MCP server using the configured transport.
148+
// The server's readonly mode is determined at construction time via
149+
// WithReadonly; it cannot be changed after the server is created.
150+
func (s *Server) Start(ctx context.Context) error {
150151
return s.impl.Run(ctx, s.transport)
151152
}
152153

Collapse file

‎pkg/mcp/mcp_test.go‎

Copy file name to clipboardExpand all lines: pkg/mcp/mcp_test.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func newTestPairCore(t *testing.T, readonly bool, options ...Option) (session *m
8484

8585
// Start the Server
8686
go func() {
87-
errCh <- server.Start(t.Context(), !readonly)
87+
errCh <- server.Start(t.Context())
8888
}()
8989

9090
// Connect a client to trigger initialization
Collapse file

‎pkg/mock/mcp_server.go‎

Copy file name to clipboardExpand all lines: pkg/mock/mcp_server.go
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import (
66

77
type MCPServer struct {
88
StartInvoked bool
9-
StartFn func(context.Context, bool) error
9+
StartFn func(context.Context) error
1010
}
1111

1212
func NewMCPServer() *MCPServer {
1313
return &MCPServer{
14-
StartFn: func(context.Context, bool) error { return nil },
14+
StartFn: func(context.Context) error { return nil },
1515
}
1616
}
1717

18-
func (s *MCPServer) Start(ctx context.Context, writeEnabled bool) error {
18+
func (s *MCPServer) Start(ctx context.Context) error {
1919
s.StartInvoked = true
20-
return s.StartFn(ctx, writeEnabled)
20+
return s.StartFn(ctx)
2121
}
Collapse file

‎pkg/mock/mcp_server_test.go‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package mock
2+
3+
import (
4+
"context"
5+
"testing"
6+
)
7+
8+
func TestMCPServer_Start(t *testing.T) {
9+
s := NewMCPServer()
10+
if s.StartInvoked {
11+
t.Fatal("StartInvoked should be false before calling Start")
12+
}
13+
14+
err := s.Start(context.Background())
15+
if err != nil {
16+
t.Fatalf("unexpected error: %v", err)
17+
}
18+
if !s.StartInvoked {
19+
t.Fatal("StartInvoked should be true after calling Start")
20+
}
21+
}

0 commit comments

Comments
0 (0)
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.