Skip to content

Commit 6edde57

Browse files
authored
enhance: add the ability to close an individual MCP server (#967)
Signed-off-by: Donnie Adams <[email protected]>
1 parent 43aca8f commit 6edde57

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pkg/engine/engine.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ func (e *Engine) Start(ctx Context, input string) (ret *Return, err error) {
350350
}
351351
select {
352352
case <-ctx.userCancel:
353+
if ret == nil {
354+
ret = new(Return)
355+
}
353356
if ret.Result == nil {
354357
ret.Result = new(string)
355358
}

pkg/mcp/loader.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,32 @@ func (l *Local) LoadTools(ctx context.Context, server ServerConfig, toolName str
125125
return l.sessionToTools(ctx, session, toolName, allowedTools)
126126
}
127127

128+
func (l *Local) ShutdownServer(server ServerConfig) error {
129+
if l == nil {
130+
return nil
131+
}
132+
133+
id := hash.Digest(server)
134+
135+
l.lock.Lock()
136+
137+
if l.sessionCtx == nil {
138+
l.lock.Unlock()
139+
return nil
140+
}
141+
142+
session := l.sessions[id]
143+
delete(l.sessions, id)
144+
145+
l.lock.Unlock()
146+
147+
if session == nil {
148+
return nil
149+
}
150+
151+
return session.Client.Close()
152+
}
153+
128154
func (l *Local) Close() error {
129155
if l == nil {
130156
return nil

0 commit comments

Comments
 (0)