Skip to content

Commit a4900c4

Browse files
committed
enhance: add the ability to close an individual MCP server
Signed-off-by: Donnie Adams <[email protected]>
1 parent 43aca8f commit a4900c4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pkg/mcp/loader.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ 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+
defer l.lock.Unlock()
137+
138+
if l.sessionCtx == nil {
139+
return nil
140+
}
141+
142+
session := l.sessions[id]
143+
if session == nil {
144+
return nil
145+
}
146+
147+
delete(l.sessions, id)
148+
149+
return session.Client.Close()
150+
}
151+
128152
func (l *Local) Close() error {
129153
if l == nil {
130154
return nil

0 commit comments

Comments
 (0)