Skip to content

Commit 664d93c

Browse files
committed
chore: separate the LoadSession function in the MCP loader
This keeps us from having to duplicate this code in other places. Signed-off-by: Donnie Adams <[email protected]>
1 parent ed2fc20 commit 664d93c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/mcp/loader.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,27 @@ func (l *Local) Load(ctx context.Context, tool types.Tool) (result []types.Tool,
9999
}
100100

101101
for server := range maps.Keys(servers.MCPServers) {
102-
session, err := l.loadSession(servers.MCPServers[server])
102+
tools, err := l.LoadSession(ctx, servers.MCPServers[server], tool.Name)
103103
if err != nil {
104104
return nil, fmt.Errorf("failed to load MCP session for server %s: %w", server, err)
105105
}
106106

107-
return l.sessionToTools(ctx, session, tool.Name)
107+
return tools, nil
108108
}
109109

110110
// This should never happen, but just in case
111111
return nil, fmt.Errorf("no MCP server configuration found in tool instructions: %s", configData)
112112
}
113113

114+
func (l *Local) LoadSession(ctx context.Context, server ServerConfig, toolName string) ([]types.Tool, error) {
115+
session, err := l.loadSession(server)
116+
if err != nil {
117+
return nil, err
118+
}
119+
120+
return l.sessionToTools(ctx, session, toolName)
121+
}
122+
114123
func (l *Local) Close() error {
115124
if l == nil {
116125
return nil

0 commit comments

Comments
 (0)