@@ -12,6 +12,7 @@ import (
1212"cdr.dev/slog/sloggers/sloghuman"
1313"github.com/coder/coder/v2/buildinfo"
1414"github.com/coder/coder/v2/coderd/util/ptr"
15+ "github.com/coder/coder/v2/codersdk"
1516mcptools"github.com/coder/coder/v2/mcp/tools"
1617)
1718
@@ -20,6 +21,7 @@ type mcpOptions struct {
2021out io.Writer
2122instructions string
2223logger * slog.Logger
24+ client * codersdk.Client
2325}
2426
2527type Option func (* mcpOptions )
@@ -48,7 +50,13 @@ func WithStdout(out io.Writer) Option {
4850}
4951}
5052
51- func New (ctx context.Context ,opts ... Option ) io.Closer {
53+ func WithClient (client * codersdk.Client )Option {
54+ return func (o * mcpOptions ) {
55+ o .client = client
56+ }
57+ }
58+
59+ func New (ctx context.Context ,client * codersdk.Client ,opts ... Option ) io.Closer {
5260options := & mcpOptions {
5361in :os .Stdin ,
5462instructions :`` ,
@@ -58,6 +66,7 @@ func New(ctx context.Context, opts ...Option) io.Closer {
5866for _ ,opt := range opts {
5967opt (options )
6068}
69+
6170mcpSrv := server .NewMCPServer (
6271"Coder Agent" ,
6372buildinfo .Version (),
@@ -66,10 +75,10 @@ func New(ctx context.Context, opts ...Option) io.Closer {
6675
6776logger := slog .Make (sloghuman .Sink (os .Stdout ))
6877
69- mcptools .RegisterCoderReportTask (mcpSrv ,logger )
70- mcptools .RegisterCoderWhoami (mcpSrv )
71- mcptools .RegisterCoderListWorkspaces (mcpSrv )
72- mcptools .RegisterCoderWorkspaceExec (mcpSrv )
78+ mcptools .RegisterCoderReportTask (mcpSrv ,options . client , logger )
79+ mcptools .RegisterCoderWhoami (mcpSrv , options . client )
80+ mcptools .RegisterCoderListWorkspaces (mcpSrv , options . client )
81+ mcptools .RegisterCoderWorkspaceExec (mcpSrv , options . client )
7382
7483srv := server .NewStdioServer (mcpSrv )
7584srv .SetErrorLogger (log .New (options .out ,"" ,log .LstdFlags ))