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): use atomic.Bool for Server.readonly to prevent data races · knative/func@09b5041

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkg/mcp
    • mcp.go
    • tools_delete.go
    • tools_delete_test.go
    • tools_deploy.go
    • tools_deploy_test.go
  • third_party/VENDOR-LICENSE/github.com
    • AlecAivazis/survey/v2/terminal
      • LICENSE.txt
    • hashicorp/hcl
      • .gitignore
      • Makefile
      • hcl
        • parser/test-fixtures
          • assign_deep.hcl
          • comment_crlf.hcl
          • complex_crlf.hcl
          • list.hcl
          • multiple.hcl
          • structure_basic.hcl
          • structure_empty.hcl
          • types.hcl
        • printer/testdata
          • comment_crlf.input
        • test-fixtures
          • comment.hcl
          • list.hcl
          • multiple.hcl
          • structure_basic.hcl
          • structure_empty.hcl
          • types.hcl
      • json
        • parser/test-fixtures
          • array.json
          • basic.json
          • object.json
          • types.json
        • test-fixtures
          • array.json
          • basic.json
          • object.json
          • types.json
      • test-fixtures
        • assign_deep.hcl
        • basic.hcl
        • basic.json
        • flat.hcl
        • structure.json
        • structure2.hcl
        • structure2.json
        • structure_flat.json
        • structure_flatmap.hcl
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkg/mcp/mcp.go‎

Copy file name to clipboardExpand all lines: pkg/mcp/mcp.go
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"os/exec"
66
"strings"
7+
"sync/atomic"
78

89
"github.com/modelcontextprotocol/go-sdk/mcp"
910
)
@@ -22,7 +23,7 @@ const (
2223
type Server struct {
2324
OnInit func(context.Context) // Invoked when the server is initialized
2425
prefix string // Command prefix ("func" or "kn func")
25-
readonly bool // disables deploy and delete when true
26+
readonly atomic.Bool // disables deploy and delete when true
2627
executor executor
2728
transport mcp.Transport // Transport to use (defaults to StdioTransport)
2829
impl *mcp.Server // implements the protocol
@@ -58,7 +59,7 @@ func WithTransport(transport mcp.Transport) Option {
5859
// WithReadonly sets the server to readonly mode.
5960
func WithReadonly(readonly bool) Option {
6061
return func(s *Server) {
61-
s.readonly = readonly
62+
s.readonly.Store(readonly)
6263
}
6364
}
6465

@@ -80,7 +81,7 @@ func New(options ...Option) *Server {
8081
Title: title,
8182
Version: version},
8283
&mcp.ServerOptions{
83-
Instructions: instructions(s.readonly),
84+
Instructions: instructions(s.readonly.Load()),
8485
HasPrompts: true,
8586
HasResources: true,
8687
HasTools: true,
@@ -146,7 +147,7 @@ func New(options ...Option) *Server {
146147

147148
// Start the MCP server using the configured transport
148149
func (s *Server) Start(ctx context.Context, writeEnabled bool) error {
149-
s.readonly = !writeEnabled
150+
s.readonly.Store(!writeEnabled)
150151
return s.impl.Run(ctx, s.transport)
151152
}
152153

Collapse file

‎pkg/mcp/tools_delete.go‎

Copy file name to clipboardExpand all lines: pkg/mcp/tools_delete.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var deleteTool = &mcp.Tool{
2020
}
2121

2222
func (s *Server) deleteHandler(ctx context.Context, r *mcp.CallToolRequest, input DeleteInput) (result *mcp.CallToolResult, output DeleteOutput, err error) {
23-
if s.readonly {
23+
if s.readonly.Load() {
2424
err = fmt.Errorf("the server is currently in readonly mode. Please set FUNC_ENABLE_MCP_WRITE and restart the client")
2525
return
2626
}
Collapse file

‎pkg/mcp/tools_delete_test.go‎

Copy file name to clipboardExpand all lines: pkg/mcp/tools_delete_test.go
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestTool_Delete_Args(t *testing.T) {
5555
t.Fatal(err)
5656
}
5757
// Delete requires write mode - enable it for this test
58-
server.readonly = false
58+
server.readonly.Store(false)
5959

6060
// Build input arguments from test data
6161
inputArgs := buildInputArgs(stringFlags, boolFlags)
@@ -76,3 +76,22 @@ func TestTool_Delete_Args(t *testing.T) {
7676
t.Fatal("executor was not invoked")
7777
}
7878
}
79+
80+
// TestTool_Delete_Readonly ensures the delete tool rejects requests in readonly mode.
81+
func TestTool_Delete_Readonly(t *testing.T) {
82+
client, _, err := newTestPairWithReadonly(t, true) // readonly = true
83+
if err != nil {
84+
t.Fatal(err)
85+
}
86+
87+
result, err := client.CallTool(t.Context(), &mcp.CallToolParams{
88+
Name: "delete",
89+
Arguments: map[string]any{"name": "my-function"},
90+
})
91+
if err != nil {
92+
t.Fatal(err)
93+
}
94+
if !result.IsError {
95+
t.Fatal("expected delete to be rejected in readonly mode")
96+
}
97+
}
Collapse file

‎pkg/mcp/tools_deploy.go‎

Copy file name to clipboardExpand all lines: pkg/mcp/tools_deploy.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var deployTool = &mcp.Tool{
2020
}
2121

2222
func (s *Server) deployHandler(ctx context.Context, r *mcp.CallToolRequest, input DeployInput) (result *mcp.CallToolResult, output DeployOutput, err error) {
23-
if s.readonly {
23+
if s.readonly.Load() {
2424
err = fmt.Errorf("the server is currently in readonly mode. Please set FUNC_ENABLE_MCP_WRITE and restart the client")
2525
return
2626
}
Collapse file

‎pkg/mcp/tools_deploy_test.go‎

Copy file name to clipboardExpand all lines: pkg/mcp/tools_deploy_test.go
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestTool_Deploy_Args(t *testing.T) {
5959
t.Fatal(err)
6060
}
6161
// Deploy requires write mode - enable it for this test
62-
server.readonly = false
62+
server.readonly.Store(false)
6363

6464
// Build input arguments from test data
6565
inputArgs := buildInputArgs(stringFlags, boolFlags)
@@ -79,3 +79,22 @@ func TestTool_Deploy_Args(t *testing.T) {
7979
t.Fatal("executor was not invoked")
8080
}
8181
}
82+
83+
// TestTool_Deploy_Readonly ensures the deploy tool rejects requests in readonly mode.
84+
func TestTool_Deploy_Readonly(t *testing.T) {
85+
client, _, err := newTestPairWithReadonly(t, true) // readonly = true
86+
if err != nil {
87+
t.Fatal(err)
88+
}
89+
90+
result, err := client.CallTool(t.Context(), &mcp.CallToolParams{
91+
Name: "deploy",
92+
Arguments: map[string]any{"path": "."},
93+
})
94+
if err != nil {
95+
t.Fatal(err)
96+
}
97+
if !result.IsError {
98+
t.Fatal("expected deploy to be rejected in readonly mode")
99+
}
100+
}
Collapse file

‎third_party/VENDOR-LICENSE/github.com/AlecAivazis/survey/v2/terminal/LICENSE.txt‎

Copy file name to clipboard
+22-22Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
Copyright (c) 2014 Takashi Kokubun
2-
3-
MIT License
4-
5-
Permission is hereby granted, free of charge, to any person obtaining
6-
a copy of this software and associated documentation files (the
7-
"Software"), to deal in the Software without restriction, including
8-
without limitation the rights to use, copy, modify, merge, publish,
9-
distribute, sublicense, and/or sell copies of the Software, and to
10-
permit persons to whom the Software is furnished to do so, subject to
11-
the following conditions:
12-
13-
The above copyright notice and this permission notice shall be
14-
included in all copies or substantial portions of the Software.
15-
16-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1+
Copyright (c) 2014 Takashi Kokubun
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Collapse file

‎third_party/VENDOR-LICENSE/github.com/hashicorp/hcl/.gitignore‎

Copy file name to clipboard
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
y.output
2-
3-
# ignore intellij files
4-
.idea
5-
*.iml
6-
*.ipr
7-
*.iws
8-
9-
*.test
1+
y.output
2+
3+
# ignore intellij files
4+
.idea
5+
*.iml
6+
*.ipr
7+
*.iws
8+
9+
*.test
Collapse file

‎third_party/VENDOR-LICENSE/github.com/hashicorp/hcl/Makefile‎

Copy file name to clipboard
+18-18Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
TEST?=./...
2-
3-
default: test
4-
5-
fmt: generate
6-
go fmt ./...
7-
8-
test: generate
9-
go get -t ./...
10-
go test $(TEST) $(TESTARGS)
11-
12-
generate:
13-
go generate ./...
14-
15-
updatedeps:
16-
go get -u golang.org/x/tools/cmd/stringer
17-
18-
.PHONY: default generate test updatedeps
1+
TEST?=./...
2+
3+
default: test
4+
5+
fmt: generate
6+
go fmt ./...
7+
8+
test: generate
9+
go get -t ./...
10+
go test $(TEST) $(TESTARGS)
11+
12+
generate:
13+
go generate ./...
14+
15+
updatedeps:
16+
go get -u golang.org/x/tools/cmd/stringer
17+
18+
.PHONY: default generate test updatedeps
Collapse file

‎third_party/VENDOR-LICENSE/github.com/hashicorp/hcl/hcl/parser/test-fixtures/assign_deep.hcl‎

Copy file name to clipboard
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
resource = [{
2-
foo = [{
3-
bar = {}
4-
}]
5-
}]
1+
resource = [{
2+
foo = [{
3+
bar = {}
4+
}]
5+
}]
Collapse file

‎third_party/VENDOR-LICENSE/github.com/hashicorp/hcl/hcl/parser/test-fixtures/comment_crlf.hcl‎

Copy file name to clipboard
+15-15Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
// Foo
2-
3-
/* Bar */
4-
5-
/*
6-
/*
7-
Baz
8-
*/
9-
10-
# Another
11-
12-
# Multiple
13-
# Lines
14-
15-
foo = "bar"
1+
// Foo
2+
3+
/* Bar */
4+
5+
/*
6+
/*
7+
Baz
8+
*/
9+
10+
# Another
11+
12+
# Multiple
13+
# Lines
14+
15+
foo = "bar"

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.