Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/mcp/instructions_warning.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The Functions MCP server is currently running in **read-only mode**.

**Disabled operations:**
- Configure Functions (envs, labels, volumes add/remove)
- Configure Git source settings and pipeline resources (config_git_set, config_git_remove)
- Deploy to cluster
- Delete from cluster
- Push a built image to a registry (`build` with `push` enabled)
Expand Down
8 changes: 8 additions & 0 deletions pkg/mcp/tools_config_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ type ConfigGitSetOutput struct {
}

func (s *Server) configGitSetHandler(ctx context.Context, r *mcp.CallToolRequest, input ConfigGitSetInput) (result *mcp.CallToolResult, output ConfigGitSetOutput, err error) {
if s.readonly.Load() {
err = fmt.Errorf("the server is currently in readonly mode. Please set %s and restart the MCP server", EnvMCPWrite)
return
}
if input.Path == "" {
err = fmt.Errorf("'path' is required")
return
Expand Down Expand Up @@ -153,6 +157,10 @@ type ConfigGitRemoveOutput struct {
}

func (s *Server) configGitRemoveHandler(ctx context.Context, r *mcp.CallToolRequest, input ConfigGitRemoveInput) (result *mcp.CallToolResult, output ConfigGitRemoveOutput, err error) {
if s.readonly.Load() {
err = fmt.Errorf("the server is currently in readonly mode. Please set %s and restart the MCP server", EnvMCPWrite)
return
}
if input.Path == "" {
err = fmt.Errorf("'path' is required")
return
Expand Down
61 changes: 61 additions & 0 deletions pkg/mcp/tools_config_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mcp
import (
"context"
"errors"
"strings"
"testing"

"github.com/modelcontextprotocol/go-sdk/mcp"
Expand Down Expand Up @@ -348,3 +349,63 @@ func TestTool_ConfigGitRemove_Error(t *testing.T) {
t.Fatal("expected error result, got success")
}
}

func TestTool_ConfigGitSet_Readonly(t *testing.T) {
executor := mock.NewExecutor()

client, server, err := newTestPair(t, WithExecutor(executor))
if err != nil {
t.Fatal(err)
}
server.readonly.Store(true)

result, err := client.CallTool(t.Context(), &mcp.CallToolParams{
Name: "config_git_set",
Arguments: map[string]any{
"path": ".",
"git_url": "https://github.com/user/repo",
"git_branch": "main",
},
})
if err != nil {
t.Fatal(err)
}
if !result.IsError {
t.Fatalf("expected error result in readonly mode, got success (executor invoked: %t)", executor.ExecuteInvoked)
}
got := resultToString(result)
if !strings.Contains(got, "readonly mode") {
t.Fatalf("expected readonly-mode error, got: %q", got)
}
if executor.ExecuteInvoked {
t.Fatal("executor should not be invoked in readonly mode")
}
}

func TestTool_ConfigGitRemove_Readonly(t *testing.T) {
executor := mock.NewExecutor()

client, server, err := newTestPair(t, WithExecutor(executor))
if err != nil {
t.Fatal(err)
}
server.readonly.Store(true)

result, err := client.CallTool(t.Context(), &mcp.CallToolParams{
Name: "config_git_remove",
Arguments: map[string]any{"path": ".", "delete_cluster": true},
})
if err != nil {
t.Fatal(err)
}
if !result.IsError {
t.Fatalf("expected error result in readonly mode, got success (executor invoked: %t)", executor.ExecuteInvoked)
}
got := resultToString(result)
if !strings.Contains(got, "readonly mode") {
t.Fatalf("expected readonly-mode error, got: %q", got)
}
if executor.ExecuteInvoked {
t.Fatal("executor should not be invoked in readonly mode")
}
}
Loading