Skip to content

Commit 72a426d

Browse files
committed
Add scope MCP server config and close method to loader
Signed-off-by: Donnie Adams <[email protected]>
1 parent a85e68d commit 72a426d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

pkg/loader/loader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ type Options struct {
417417

418418
type MCPLoader interface {
419419
Load(ctx context.Context, tool types.Tool) ([]types.Tool, error)
420+
Close() error
420421
}
421422

422423
func complete(opts ...Options) (result Options) {

pkg/loader/openapi_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,7 @@ type fakeMCPLoader struct{}
131131
func (fakeMCPLoader) Load(context.Context, types.Tool) ([]types.Tool, error) {
132132
return nil, nil
133133
}
134+
135+
func (fakeMCPLoader) Close() error {
136+
return nil
137+
}

pkg/mcp/loader.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package mcp
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"maps"
89
"slices"
@@ -49,6 +50,7 @@ type ServerConfig struct {
4950
URL string `json:"url"`
5051
BaseURL string `json:"baseURL,omitempty"`
5152
Headers []string `json:"headers"`
53+
Scope string `json:"scope"`
5254
}
5355

5456
func (s *ServerConfig) GetBaseURL() string {
@@ -104,6 +106,24 @@ func (l *Local) Load(ctx context.Context, tool types.Tool) (result []types.Tool,
104106
return nil, fmt.Errorf("no MCP server configuration found in tool instructions: %s", configData)
105107
}
106108

109+
func (l *Local) Close() error {
110+
if l == nil {
111+
return nil
112+
}
113+
114+
l.lock.Lock()
115+
defer l.lock.Unlock()
116+
117+
var errs []error
118+
for id, session := range l.sessions {
119+
if err := session.Client.Close(); err != nil {
120+
errs = append(errs, fmt.Errorf("failed to close MCP client %s: %w", id, err))
121+
}
122+
}
123+
124+
return errors.Join(errs...)
125+
}
126+
107127
func (l *Local) sessionToTools(ctx context.Context, session *Session, toolName string) ([]types.Tool, error) {
108128
tools, err := session.Client.ListTools(ctx, mcp.ListToolsRequest{})
109129
if err != nil {

0 commit comments

Comments
 (0)