@@ -56,6 +56,7 @@ type ServerConfig struct {
56
56
BaseURL string `json:"baseURL,omitempty"`
57
57
Headers []string `json:"headers"`
58
58
Scope string `json:"scope"`
59
+ AllowedTools []string `json:"allowedTools"`
59
60
}
60
61
61
62
func (s * ServerConfig ) GetBaseURL () string {
@@ -99,7 +100,7 @@ func (l *Local) Load(ctx context.Context, tool types.Tool) (result []types.Tool,
99
100
}
100
101
101
102
for server := range maps .Keys (servers .MCPServers ) {
102
- tools , err := l .LoadSession (ctx , servers .MCPServers [server ], tool .Name )
103
+ tools , err := l .LoadTools (ctx , servers .MCPServers [server ], tool .Name )
103
104
if err != nil {
104
105
return nil , fmt .Errorf ("failed to load MCP session for server %s: %w" , server , err )
105
106
}
@@ -111,13 +112,17 @@ func (l *Local) Load(ctx context.Context, tool types.Tool) (result []types.Tool,
111
112
return nil , fmt .Errorf ("no MCP server configuration found in tool instructions: %s" , configData )
112
113
}
113
114
114
- func (l * Local ) LoadSession (ctx context.Context , server ServerConfig , toolName string ) ([]types.Tool , error ) {
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
+
115
120
session , err := l .loadSession (server )
116
121
if err != nil {
117
122
return nil , err
118
123
}
119
124
120
- return l .sessionToTools (ctx , session , toolName )
125
+ return l .sessionToTools (ctx , session , toolName , allowedTools )
121
126
}
122
127
123
128
func (l * Local ) Close () error {
@@ -148,7 +153,9 @@ func (l *Local) Close() error {
148
153
return errors .Join (errs ... )
149
154
}
150
155
151
- 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
+
152
159
tools , err := session .Client .ListTools (ctx , mcp.ListToolsRequest {})
153
160
if err != nil {
154
161
return nil , fmt .Errorf ("failed to list tools: %w" , err )
@@ -158,6 +165,10 @@ func (l *Local) sessionToTools(ctx context.Context, session *Session, toolName s
158
165
var toolNames []string
159
166
160
167
for _ , tool := range tools .Tools {
168
+ if ! allToolsAllowed && ! slices .Contains (allowedTools , tool .Name ) {
169
+ continue
170
+ }
171
+
161
172
var schema openapi3.Schema
162
173
163
174
schemaData , err := json .Marshal (tool .InputSchema )
0 commit comments