Skip to content

Commit 4565a3e

Browse files
committed
change mcp package and add logic
1 parent 0cde18a commit 4565a3e

File tree

13 files changed

+1132
-157
lines changed

13 files changed

+1132
-157
lines changed

cmd/internal/mcp.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import (
44
"github.com/spf13/cobra"
55

66
"github.com/flowexec/flow/internal/context"
7-
"github.com/flowexec/flow/internal/services/mcp"
7+
"github.com/flowexec/flow/internal/logger"
8+
"github.com/flowexec/flow/internal/mcp"
89
)
910

1011
func RegisterMCPCmd(ctx *context.Context, rootCmd *cobra.Command) {
@@ -19,9 +20,9 @@ func RegisterMCPCmd(ctx *context.Context, rootCmd *cobra.Command) {
1920
rootCmd.AddCommand(subCmd)
2021
}
2122

22-
func mcpFunc(_ *context.Context, _ *cobra.Command, _ []string) {
23-
server := mcp.NewMCPServer()
23+
func mcpFunc(ctx *context.Context, _ *cobra.Command, _ []string) {
24+
server := mcp.NewMCPServer(ctx)
2425
if err := server.Run(); err != nil {
25-
panic(err)
26+
logger.Log().FatalErr(err)
2627
}
2728
}

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ require (
1414
github.com/flowexec/vault v0.1.2
1515
github.com/gen2brain/beeep v0.11.1
1616
github.com/jahvon/glamour v0.8.1-patch3
17+
github.com/mark3labs/mcp-go v0.36.0
1718
github.com/mattn/go-runewidth v0.0.16
18-
github.com/modelcontextprotocol/go-sdk v0.2.0
1919
github.com/muesli/termenv v0.16.0
2020
github.com/onsi/ginkgo/v2 v2.23.4
2121
github.com/onsi/gomega v1.37.0
@@ -42,6 +42,8 @@ require (
4242
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
4343
github.com/aymanbagabas/go-udiff v0.2.0 // indirect
4444
github.com/aymerick/douceur v0.2.0 // indirect
45+
github.com/bahlo/generic-list-go v0.2.0 // indirect
46+
github.com/buger/jsonparser v1.1.1 // indirect
4547
github.com/catppuccin/go v0.3.0 // indirect
4648
github.com/charmbracelet/colorprofile v0.3.1 // indirect
4749
github.com/charmbracelet/huh v0.7.0 // indirect
@@ -67,8 +69,10 @@ require (
6769
github.com/gorilla/css v1.0.1 // indirect
6870
github.com/huandu/xstrings v1.5.0 // indirect
6971
github.com/inconshreveable/mousetrap v1.1.0 // indirect
72+
github.com/invopop/jsonschema v0.13.0 // indirect
7073
github.com/jackmordaunt/icns/v3 v3.0.1 // indirect
7174
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
75+
github.com/mailru/easyjson v0.7.7 // indirect
7276
github.com/mattn/go-isatty v0.0.20 // indirect
7377
github.com/mattn/go-localereader v0.0.1 // indirect
7478
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
@@ -86,8 +90,9 @@ require (
8690
github.com/sergeymakinen/go-bmp v1.0.0 // indirect
8791
github.com/sergeymakinen/go-ico v1.0.0-beta.0 // indirect
8892
github.com/shopspring/decimal v1.4.0 // indirect
89-
github.com/spf13/cast v1.7.0 // indirect
93+
github.com/spf13/cast v1.7.1 // indirect
9094
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
95+
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
9196
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
9297
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
9398
github.com/yuin/goldmark v1.7.4 // indirect

go.sum

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp
2828
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
2929
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
3030
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
31+
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
32+
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
33+
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
34+
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
3135
github.com/catppuccin/go v0.3.0 h1:d+0/YicIq+hSTo5oPuRi5kOpqkVA5tAsU6dNhvRu+aY=
3236
github.com/catppuccin/go v0.3.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
3337
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
@@ -113,10 +117,13 @@ github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI
113117
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
114118
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
115119
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
120+
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
121+
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
116122
github.com/jackmordaunt/icns/v3 v3.0.1 h1:xxot6aNuGrU+lNgxz5I5H0qSeCjNKp8uTXB1j8D4S3o=
117123
github.com/jackmordaunt/icns/v3 v3.0.1/go.mod h1:5sHL59nqTd2ynTnowxB/MDQFhKNqkK8X687uKNygaSQ=
118124
github.com/jahvon/glamour v0.8.1-patch3 h1:LfyMACZavV8yxK4UsPENNQQOqafWuq4ZdLuEAP2ZLE8=
119125
github.com/jahvon/glamour v0.8.1-patch3/go.mod h1:30MVJwG3rcEHrN277NrA4DKzndSL9lBtEmpcfOygwCQ=
126+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
120127
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
121128
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
122129
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -125,6 +132,10 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
125132
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
126133
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
127134
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
135+
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
136+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
137+
github.com/mark3labs/mcp-go v0.36.0 h1:rIZaijrRYPeSbJG8/qNDe0hWlGrCJ7FWHNMz2SQpTis=
138+
github.com/mark3labs/mcp-go v0.36.0/go.mod h1:T7tUa2jO6MavG+3P25Oy/jR7iCeJPHImCZHRymCn39g=
128139
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
129140
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
130141
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
@@ -140,8 +151,6 @@ github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4
140151
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
141152
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
142153
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
143-
github.com/modelcontextprotocol/go-sdk v0.2.0 h1:PESNYOmyM1c369tRkzXLY5hHrazj8x9CY1Xu0fLCryM=
144-
github.com/modelcontextprotocol/go-sdk v0.2.0/go.mod h1:0sL9zUKKs2FTTkeCCVnKqbLJTw5TScefPAzojjU459E=
145154
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
146155
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
147156
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
@@ -182,8 +191,8 @@ github.com/sergeymakinen/go-ico v1.0.0-beta.0 h1:m5qKH7uPKLdrygMWxbamVn+tl2HfiA3
182191
github.com/sergeymakinen/go-ico v1.0.0-beta.0/go.mod h1:wQ47mTczswBO5F0NoDt7O0IXgnV4Xy3ojrroMQzyhUk=
183192
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
184193
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
185-
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
186-
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
194+
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
195+
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
187196
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
188197
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
189198
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
@@ -198,6 +207,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
198207
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
199208
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
200209
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
210+
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
211+
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
201212
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
202213
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
203214
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=

internal/context/context.go

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8-
"runtime"
9-
"strings"
108

119
"github.com/flowexec/tuikit"
1210
"github.com/flowexec/tuikit/themes"
@@ -188,43 +186,11 @@ func ExpandRef(ctx *Context, ref executable.Ref) executable.Ref {
188186
}
189187

190188
func currentWorkspace(cfg *config.Config) (*workspace.Workspace, error) {
191-
var ws, wsPath string
192-
mode := cfg.WorkspaceMode
193-
194-
switch mode {
195-
case config.ConfigWorkspaceModeDynamic:
196-
wd, err := os.Getwd()
197-
if err != nil {
198-
return nil, err
199-
}
200-
if runtime.GOOS == "darwin" {
201-
// On macOS, paths that start with /tmp (and some other system directories)
202-
// are actually symbolic links to paths under /private. The OS may return
203-
// either form of the path - e.g., both "/tmp/file" and "/private/tmp/file"
204-
// refer to the same location. We strip the "/private" prefix for consistent
205-
// path comparison, while preserving the original paths for filesystem operations.
206-
wd = strings.TrimPrefix(wd, "/private")
207-
}
208-
209-
for wsName, path := range cfg.Workspaces {
210-
rel, err := filepath.Rel(filepath.Clean(path), filepath.Clean(wd))
211-
if err != nil {
212-
return nil, err
213-
}
214-
if !strings.HasPrefix(rel, "..") {
215-
ws = wsName
216-
wsPath = path
217-
break
218-
}
219-
}
220-
fallthrough
221-
case config.ConfigWorkspaceModeFixed:
222-
if ws != "" && wsPath != "" {
223-
break
224-
}
225-
ws = cfg.CurrentWorkspace
226-
wsPath = cfg.Workspaces[ws]
189+
ws, err := cfg.CurrentWorkspaceName()
190+
if err != nil {
191+
return nil, err
227192
}
193+
wsPath := cfg.Workspaces[ws]
228194
if ws == "" || wsPath == "" {
229195
return nil, fmt.Errorf("current workspace not found")
230196
}

0 commit comments

Comments
 (0)