@@ -104,6 +104,31 @@ func TestInventoryFiltersForRequest(t *testing.T) {
104104 },
105105 expectedTools : []string {"get_file_contents" , "create_repository" , "list_issues" },
106106 },
107+ {
108+ name : "disallowed tools removes specific tools" ,
109+ contextSetup : func (ctx context.Context ) context.Context {
110+ return ghcontext .WithDisallowedTools (ctx , []string {"create_repository" , "issue_write" })
111+ },
112+ expectedTools : []string {"get_file_contents" , "list_issues" },
113+ },
114+ {
115+ name : "disallowed tools overrides explicit tools" ,
116+ contextSetup : func (ctx context.Context ) context.Context {
117+ ctx = ghcontext .WithTools (ctx , []string {"list_issues" , "create_repository" })
118+ ctx = ghcontext .WithDisallowedTools (ctx , []string {"create_repository" })
119+ return ctx
120+ },
121+ expectedTools : []string {"list_issues" },
122+ },
123+ {
124+ name : "disallowed tools combines with readonly" ,
125+ contextSetup : func (ctx context.Context ) context.Context {
126+ ctx = ghcontext .WithReadonly (ctx , true )
127+ ctx = ghcontext .WithDisallowedTools (ctx , []string {"list_issues" })
128+ return ctx
129+ },
130+ expectedTools : []string {"get_file_contents" },
131+ },
107132 }
108133
109134 for _ , tt := range tests {
@@ -267,6 +292,40 @@ func TestHTTPHandlerRoutes(t *testing.T) {
267292 },
268293 expectedTools : []string {"get_file_contents" , "create_repository" , "list_issues" , "create_issue" , "list_pull_requests" , "create_pull_request" , "hidden_by_holdback" },
269294 },
295+ {
296+ name : "X-MCP-Disallowed-Tools header removes specific tools" ,
297+ path : "/" ,
298+ headers : map [string ]string {
299+ headers .MCPDisallowedToolsHeader : "create_issue,create_pull_request" ,
300+ },
301+ expectedTools : []string {"get_file_contents" , "create_repository" , "list_issues" , "list_pull_requests" , "hidden_by_holdback" },
302+ },
303+ {
304+ name : "X-MCP-Disallowed-Tools with toolset header" ,
305+ path : "/" ,
306+ headers : map [string ]string {
307+ headers .MCPToolsetsHeader : "issues" ,
308+ headers .MCPDisallowedToolsHeader : "create_issue" ,
309+ },
310+ expectedTools : []string {"list_issues" },
311+ },
312+ {
313+ name : "X-MCP-Disallowed-Tools overrides X-MCP-Tools" ,
314+ path : "/" ,
315+ headers : map [string ]string {
316+ headers .MCPToolsHeader : "list_issues,create_issue" ,
317+ headers .MCPDisallowedToolsHeader : "create_issue" ,
318+ },
319+ expectedTools : []string {"list_issues" },
320+ },
321+ {
322+ name : "X-MCP-Disallowed-Tools with readonly path" ,
323+ path : "/readonly" ,
324+ headers : map [string ]string {
325+ headers .MCPDisallowedToolsHeader : "list_issues" ,
326+ },
327+ expectedTools : []string {"get_file_contents" , "list_pull_requests" , "hidden_by_holdback" },
328+ },
270329 }
271330
272331 for _ , tt := range tests {
0 commit comments