@@ -56,6 +56,7 @@ type ServerConfig struct {
5656 BaseURL string `json:"baseURL,omitempty"`
5757 Headers []string `json:"headers"`
5858 Scope string `json:"scope"`
59+ AllowedTools []string `json:"allowedTools"`
5960}
6061
6162func (s * ServerConfig ) GetBaseURL () string {
@@ -99,18 +100,31 @@ func (l *Local) Load(ctx context.Context, tool types.Tool) (result []types.Tool,
99100 }
100101
101102 for server := range maps .Keys (servers .MCPServers ) {
102- session , err := l .loadSession ( servers .MCPServers [server ])
103+ tools , err := l .LoadTools ( ctx , servers .MCPServers [server ], tool . Name )
103104 if err != nil {
104105 return nil , fmt .Errorf ("failed to load MCP session for server %s: %w" , server , err )
105106 }
106107
107- return l . sessionToTools ( ctx , session , tool . Name )
108+ return tools , nil
108109 }
109110
110111 // This should never happen, but just in case
111112 return nil , fmt .Errorf ("no MCP server configuration found in tool instructions: %s" , configData )
112113}
113114
115+ func (l * Local ) LoadTools (ctx context.Context , server ServerConfig , toolName string ) ([]types.Tool , error ) {
116+ allowedTools := server .AllowedTools
117+ // Reset so we don't start a new MCP server, no reason to if one is already running and the allowed tools change.
118+ server .AllowedTools = nil
119+
120+ session , err := l .loadSession (server )
121+ if err != nil {
122+ return nil , err
123+ }
124+
125+ return l .sessionToTools (ctx , session , toolName , allowedTools )
126+ }
127+
114128func (l * Local ) Close () error {
115129 if l == nil {
116130 return nil
@@ -139,7 +153,9 @@ func (l *Local) Close() error {
139153 return errors .Join (errs ... )
140154}
141155
142- func (l * Local ) sessionToTools (ctx context.Context , session * Session , toolName string ) ([]types.Tool , error ) {
156+ func (l * Local ) sessionToTools (ctx context.Context , session * Session , toolName string , allowedTools []string ) ([]types.Tool , error ) {
157+ allToolsAllowed := len (allowedTools ) == 0 || slices .Contains (allowedTools , "*" )
158+
143159 tools , err := session .Client .ListTools (ctx , mcp.ListToolsRequest {})
144160 if err != nil {
145161 return nil , fmt .Errorf ("failed to list tools: %w" , err )
@@ -149,6 +165,10 @@ func (l *Local) sessionToTools(ctx context.Context, session *Session, toolName s
149165 var toolNames []string
150166
151167 for _ , tool := range tools .Tools {
168+ if ! allToolsAllowed && ! slices .Contains (allowedTools , tool .Name ) {
169+ continue
170+ }
171+
152172 var schema openapi3.Schema
153173
154174 schemaData , err := json .Marshal (tool .InputSchema )
0 commit comments