@@ -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,18 +100,31 @@ 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
- session , err := l .loadSession ( servers .MCPServers [server ])
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
}
106
107
107
- return l . sessionToTools ( ctx , session , tool . Name )
108
+ return tools , nil
108
109
}
109
110
110
111
// This should never happen, but just in case
111
112
return nil , fmt .Errorf ("no MCP server configuration found in tool instructions: %s" , configData )
112
113
}
113
114
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
+
114
128
func (l * Local ) Close () error {
115
129
if l == nil {
116
130
return nil
@@ -139,7 +153,9 @@ func (l *Local) Close() error {
139
153
return errors .Join (errs ... )
140
154
}
141
155
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
+
143
159
tools , err := session .Client .ListTools (ctx , mcp.ListToolsRequest {})
144
160
if err != nil {
145
161
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
149
165
var toolNames []string
150
166
151
167
for _ , tool := range tools .Tools {
168
+ if ! allToolsAllowed && ! slices .Contains (allowedTools , tool .Name ) {
169
+ continue
170
+ }
171
+
152
172
var schema openapi3.Schema
153
173
154
174
schemaData , err := json .Marshal (tool .InputSchema )
0 commit comments