Skip to content

enhance: allow passing of MCP client options when creating clients #984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/mcp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
nmcp "github.com/nanobot-ai/nanobot/pkg/mcp"
)

func (l *Local) Client(server ServerConfig) (*Client, error) {
session, err := l.loadSession(server, "default")
func (l *Local) Client(server ServerConfig, clientOpts ...nmcp.ClientOption) (*Client, error) {
session, err := l.loadSession(server, "default", clientOpts...)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/mcp/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (l *Local) sessionToTools(ctx context.Context, session *Session, toolName s
return toolDefs, nil
}

func (l *Local) loadSession(server ServerConfig, serverName string) (*Session, error) {
func (l *Local) loadSession(server ServerConfig, serverName string, clientOpts ...nmcp.ClientOption) (*Session, error) {
id := hash.Digest(server)
l.lock.Lock()
existing, ok := l.sessions[id]
Expand All @@ -296,7 +296,7 @@ func (l *Local) loadSession(server ServerConfig, serverName string) (*Session, e
Args: server.Args,
BaseURL: server.GetBaseURL(),
Headers: splitIntoMap(server.Headers),
})
}, clientOpts...)
if err != nil {
return nil, fmt.Errorf("failed to create MCP stdio client: %w", err)
}
Expand Down
Loading