Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6bb2fe

Browse files
committed
chore: migrate mcp changes upstack for more focused review
1 parent6dfd388 commitb6bb2fe

File tree

10 files changed

+340
-388
lines changed

10 files changed

+340
-388
lines changed

‎Makefile‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ TAILNETTEST_MOCKS := \
636636
tailnet/tailnettest/subscriptionmock.go
637637

638638
AIBRIDGED_MOCKS :=\
639-
aibridged/aibridgedmock/clientmock.go\
640-
aibridged/aibridgedmock/poolmock.go
639+
x/aibridged/aibridgedmock/clientmock.go\
640+
x/aibridged/aibridgedmock/poolmock.go
641641

642642
GEN_FILES :=\
643643
tailnet/proto/tailnet.pb.go\
@@ -766,8 +766,8 @@ codersdk/workspacesdk/agentconnmock/agentconnmock.go: codersdk/workspacesdk/agen
766766
go generate ./codersdk/workspacesdk/agentconnmock/
767767
touch"$@"
768768

769-
$(AIBRIDGED_MOCKS): aibridged/client.go aibridged/pool.go
770-
go generate ./aibridged/aibridgedmock/
769+
$(AIBRIDGED_MOCKS):x/aibridged/client.gox/aibridged/pool.go
770+
go generate ./x/aibridged/aibridgedmock/
771771
touch"$@"
772772

773773
agent/agentcontainers/dcspec/dcspec_gen.go:\

‎go.mod‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ require (
478478
github.com/anthropics/anthropic-sdk-gov1.12.0
479479
github.com/brianvoe/gofakeit/v7v7.7.1
480480
github.com/coder/agentapi-sdk-gov0.0.0-20250505131810-560d1d88d225
481-
github.com/coder/aibridgev0.0.0
481+
github.com/coder/aibridgev0.0.0-20250924143139-6f2113f274a0// TODO: replace with published tag.
482482
github.com/coder/aisdk-gov0.0.9
483483
github.com/coder/previewv1.0.4
484484
github.com/dgraph-io/ristretto/v2v2.3.0
@@ -488,9 +488,6 @@ require (
488488
github.com/mark3labs/mcp-gov0.38.0
489489
)
490490

491-
// aibridge-related deps and directives. // TODO: replace with published tag.
492-
replacegithub.com/coder/aibridgev0.0.0 =>/home/coder/aibridge
493-
494491
require (
495492
cel.dev/exprv0.24.0// indirect
496493
cloud.google.com/gov0.121.4// indirect
@@ -535,7 +532,6 @@ require (
535532
github.com/moby/sys/userv0.4.0// indirect
536533
github.com/nfnt/resizev0.0.0-20180221191011-83c6a9932646// indirect
537534
github.com/openai/openai-gov1.12.0// indirect
538-
github.com/openai/openai-go/v2v2.7.0// indirect
539535
github.com/package-url/packageurl-gov0.1.3// indirect
540536
github.com/planetscale/vtprotobufv0.6.1-0.20240319094008-0393e58bdf10// indirect
541537
github.com/puzpuzpuz/xsync/v3v3.5.1// indirect

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,8 @@ github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 h1:aQ3y1lwWyqYPiWZThqv
911911
github.com/cncf/xds/gov0.0.0-20250501225837-2ac532fd4443/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
912912
github.com/coder/agentapi-sdk-gov0.0.0-20250505131810-560d1d88d225 h1:tRIViZ5JRmzdOEo5wUWngaGEFBG8OaE1o2GIHN5ujJ8=
913913
github.com/coder/agentapi-sdk-gov0.0.0-20250505131810-560d1d88d225/go.mod h1:rNLVpYgEVeu1Zk29K64z6Od8RBP9DwqCu9OfCzh8MR4=
914+
github.com/coder/aibridgev0.0.0-20250924143139-6f2113f274a0 h1:jUDPqPj8GcPnrVLpImdbsUKlMYOAGxw4C8Hxjv++7a8=
915+
github.com/coder/aibridgev0.0.0-20250924143139-6f2113f274a0/go.mod h1:JaQAEcVuLp/ufRif6yZfOQMvQ+qBODY0sT7ZjKI+8j0=
914916
github.com/coder/aisdk-gov0.0.9 h1:Vzo/k2qwVGLTR10ESDeP2Ecek1SdPfZlEjtTfMveiVo=
915917
github.com/coder/aisdk-gov0.0.9/go.mod h1:KF6/Vkono0FJJOtWtveh5j7yfNrSctVTpwgweYWSp5M=
916918
github.com/coder/bubbleteav1.2.2-0.20241212190825-007a1cdb2c41 h1:SBN/DA63+ZHwuWwPHPYoCZ/KLAjHv5g4h2MS4f2/MTI=
@@ -1643,8 +1645,6 @@ github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisti
16431645
github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessorv0.120.1/go.mod h1:Z/S1brD5gU2Ntht/bHxBVnGxXKTvZDr0dNv/riUzPmY=
16441646
github.com/openai/openai-gov1.12.0 h1:NBQCnXzqOTv5wsgNC36PrFEiskGfO5wccfCWDo9S1U0=
16451647
github.com/openai/openai-gov1.12.0/go.mod h1:g461MYGXEXBVdV5SaR/5tNzNbSfwTBBefwc+LlDCK0Y=
1646-
github.com/openai/openai-go/v2v2.7.0 h1:/8MSFCXcasin7AyuWQ2au6FraXL71gzAs+VfbMv+J3k=
1647-
github.com/openai/openai-go/v2v2.7.0/go.mod h1:jrJs23apqJKKbT+pqtFgNKpRju/KP9zpUTZhz3GElQE=
16481648
github.com/opencontainers/go-digestv1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
16491649
github.com/opencontainers/go-digestv1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
16501650
github.com/opencontainers/image-specv1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=

‎x/aibridged/aibridged.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (s *Server) GetRequestHandler(ctx context.Context, req Request) (http.Handl
139139
returnnil,xerrors.New("nil requestBridgePool")
140140
}
141141

142-
reqBridge,err:=s.requestBridgePool.Acquire(ctx,req,s.Client,NewMCPProxyFactory(s.logger,s.Client))
142+
reqBridge,err:=s.requestBridgePool.Acquire(ctx,req,s.Client)
143143
iferr!=nil {
144144
returnnil,xerrors.Errorf("acquire request bridge: %w",err)
145145
}

‎x/aibridged/aibridged_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestServeHTTP_FailureModes(t *testing.T) {
122122
// Should pass authorization.
123123
client.EXPECT().IsAuthorized(gomock.Any(),gomock.Any()).AnyTimes().Return(&proto.IsAuthorizedResponse{OwnerId:uuid.NewString()},nil)
124124
// But fail when acquiring a pool instance.
125-
pool.EXPECT().Acquire(gomock.Any(),gomock.Any(),gomock.Any(),gomock.Any()).AnyTimes().Return(nil,xerrors.New("oops"))
125+
pool.EXPECT().Acquire(gomock.Any(),gomock.Any(),gomock.Any()).AnyTimes().Return(nil,xerrors.New("oops"))
126126
},
127127
expectedErr:aibridged.ErrAcquireRequestHandler,
128128
expectedStatus:http.StatusInternalServerError,

‎x/aibridged/aibridgedmock/poolmock.go‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎x/aibridged/pool.go‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"cdr.dev/slog"
1515

1616
"github.com/coder/aibridge"
17-
"github.com/coder/aibridge/mcp"
1817
)
1918

2019
const (
@@ -24,7 +23,7 @@ const (
2423
// Pooler describes a pool of [*aibridge.RequestBridge] instances from which instances can be retrieved.
2524
// One [*aibridge.RequestBridge] instance is created per given key.
2625
typePoolerinterface {
27-
Acquire(ctx context.Context,reqRequest,clientFnClientFunc,mcpBootstrapperMCPProxyBuilder) (http.Handler,error)
26+
Acquire(ctx context.Context,reqRequest,clientFnClientFunc) (http.Handler,error)
2827
Shutdown(ctx context.Context)error
2928
}
3029

@@ -103,7 +102,7 @@ func NewCachedBridgePool(options PoolOptions, providers []aibridge.Provider, log
103102
//
104103
// Each returned [*aibridge.RequestBridge] is safe for concurrent use.
105104
// Each [*aibridge.RequestBridge] is stateful because it has MCP clients which maintain sessions to the configured MCP server.
106-
func (p*CachedBridgePool)Acquire(ctx context.Context,reqRequest,clientFnClientFunc,mcpProxyFactoryMCPProxyBuilder) (http.Handler,error) {
105+
func (p*CachedBridgePool)Acquire(ctx context.Context,reqRequest,clientFnClientFunc) (http.Handler,error) {
107106
iferr:=ctx.Err();err!=nil {
108107
returnnil,xerrors.Errorf("acquire: %w",err)
109108
}
@@ -142,25 +141,7 @@ func (p *CachedBridgePool) Acquire(ctx context.Context, req Request, clientFn Cl
142141
// Creating an *aibridge.RequestBridge may take some time, so gate all subsequent callers behind the initial request and return the resulting value.
143142
// TODO: track startup time since it adds latency to first request (histogram count will also help us see how often this occurs).
144143
instance,err,_:=p.singleflight.Do(req.InitiatorID.String(),func() (*aibridge.RequestBridge,error) {
145-
var (
146-
mcpServers mcp.ServerProxier
147-
errerror
148-
)
149-
150-
mcpServers,err=mcpProxyFactory.Build(ctx,req)
151-
iferr!=nil {
152-
p.logger.Warn(ctx,"failed to create MCP server proxiers",slog.Error(err))
153-
// Don't fail here; MCP server injection can gracefully degrade.
154-
}
155-
156-
ifmcpServers!=nil {
157-
// This will block while connections are established with upstream MCP server(s), and tools are listed.
158-
iferr:=mcpServers.Init(ctx);err!=nil {
159-
p.logger.Warn(ctx,"failed to initialize MCP server proxier(s)",slog.Error(err))
160-
}
161-
}
162-
163-
bridge,err:=aibridge.NewRequestBridge(ctx,p.providers,p.logger,recorder,mcpServers)
144+
bridge,err:=aibridge.NewRequestBridge(ctx,p.providers,p.logger,recorder,nil)
164145
iferr!=nil {
165146
returnnil,xerrors.Errorf("create new request bridge: %w",err)
166147
}

‎x/aibridged/pool_test.go‎

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"go.uber.org/mock/gomock"
1212

1313
"cdr.dev/slog/sloggers/slogtest"
14-
"github.com/coder/aibridge/mcp"
15-
"github.com/coder/aibridge/mcpmock"
1614
"github.com/coder/coder/v2/x/aibridged"
1715
mock"github.com/coder/coder/v2/x/aibridged/aibridgedmock"
1816
)
@@ -27,7 +25,6 @@ func TestPool(t *testing.T) {
2725

2826
ctrl:=gomock.NewController(t)
2927
client:=mock.NewMockDRPCClient(ctrl)
30-
mcpProxy:=mcpmock.NewMockServerProxier(ctrl)
3128

3229
opts:= aibridged.PoolOptions{MaxItems:1,TTL:time.Second}
3330
pool,err:=aibridged.NewCachedBridgePool(opts,nil,logger)
@@ -39,25 +36,19 @@ func TestPool(t *testing.T) {
3936
returnclient,nil
4037
}
4138

42-
// Once a pool instance is initialized, it will try setup its MCP proxier(s).
43-
// This is called exactly once since the instance below is only created once.
44-
mcpProxy.EXPECT().Init(gomock.Any()).Times(1).Return(nil)
45-
// This is part of the lifecycle.
46-
mcpProxy.EXPECT().Shutdown(gomock.Any()).AnyTimes().Return(nil)
47-
4839
// Acquiring a pool instance will create one the first time it sees an
4940
// initiator ID...
5041
inst,err:=pool.Acquire(t.Context(), aibridged.Request{
5142
SessionKey:"key",
5243
InitiatorID:id,
53-
},clientFn,newMockMCPFactory(mcpProxy))
44+
},clientFn)
5445
require.NoError(t,err,"acquire pool instance")
5546

5647
// ...and it will return it when acquired again.
5748
instB,err:=pool.Acquire(t.Context(), aibridged.Request{
5849
SessionKey:"key",
5950
InitiatorID:id,
60-
},clientFn,newMockMCPFactory(mcpProxy))
51+
},clientFn)
6152
require.NoError(t,err,"acquire pool instance")
6253
require.Same(t,inst,instB)
6354

@@ -67,14 +58,11 @@ func TestPool(t *testing.T) {
6758
require.EqualValues(t,1,metrics.Hits())
6859
require.EqualValues(t,1,metrics.Misses())
6960

70-
// This will get called again because a new instance will be created.
71-
mcpProxy.EXPECT().Init(gomock.Any()).Times(1).Return(nil)
72-
7361
// But that key will be evicted when a new initiator is seen (maxItems=1):
7462
inst2,err:=pool.Acquire(t.Context(), aibridged.Request{
7563
SessionKey:"key",
7664
InitiatorID:id2,
77-
},clientFn,newMockMCPFactory(mcpProxy))
65+
},clientFn)
7866
require.NoError(t,err,"acquire pool instance")
7967
require.NotSame(t,inst,inst2)
8068

@@ -88,17 +76,3 @@ func TestPool(t *testing.T) {
8876
// This requires Go 1.25's [synctest](https://pkg.go.dev/testing/synctest) since the
8977
// internal cache lib cannot be tested using coder/quartz.
9078
}
91-
92-
var_ aibridged.MCPProxyBuilder=&mockMCPFactory{}
93-
94-
typemockMCPFactorystruct {
95-
proxy*mcpmock.MockServerProxier
96-
}
97-
98-
funcnewMockMCPFactory(proxy*mcpmock.MockServerProxier)*mockMCPFactory {
99-
return&mockMCPFactory{proxy:proxy}
100-
}
101-
102-
func (m*mockMCPFactory)Build(ctx context.Context,req aibridged.Request) (mcp.ServerProxier,error) {
103-
returnm.proxy,nil
104-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp