Skip to content

Commit 2c8d07b

Browse files
authored
Merge pull request #15 from GitHubSecurityLab/restrict_gh_mcp_toolset
Add optional headers to restrict GitHub mcp server toolsets
2 parents 115ddda + a0d83e6 commit 2c8d07b

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

mcp_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,19 @@ def mcp_client_params(available_toolboxes: dict, requested_toolboxes: list):
314314
if headers and isinstance(headers, dict):
315315
for k, v in headers.items():
316316
headers[k] = swap_env(v)
317+
optional_headers = available_toolboxes[tb]['server_params'].get('optional_headers')
318+
# support {{ env SOMETHING }} for header values as well for e.g. tokens
319+
if optional_headers and isinstance(optional_headers, dict):
320+
for k, v in dict(optional_headers).items():
321+
try:
322+
optional_headers[k] = swap_env(v)
323+
except LookupError as e:
324+
del optional_headers[k]
325+
if isinstance(headers, dict):
326+
if isinstance(optional_headers, dict):
327+
headers.update(optional_headers)
328+
elif isinstance(optional_headers, dict):
329+
headers = optional_headers
317330
# if None will default to float(5) in client code
318331
timeout = available_toolboxes[tb]['server_params'].get('timeout')
319332
server_params['url'] = available_toolboxes[tb]['server_params'].get('url')
@@ -329,6 +342,19 @@ def mcp_client_params(available_toolboxes: dict, requested_toolboxes: list):
329342
if headers and isinstance(headers, dict):
330343
for k, v in headers.items():
331344
headers[k] = swap_env(v)
345+
optional_headers = available_toolboxes[tb]['server_params'].get('optional_headers')
346+
# support {{ env SOMETHING }} for header values as well for e.g. tokens
347+
if optional_headers and isinstance(optional_headers, dict):
348+
for k, v in dict(optional_headers).items():
349+
try:
350+
optional_headers[k] = swap_env(v)
351+
except LookupError as e:
352+
del optional_headers[k]
353+
if isinstance(headers, dict):
354+
if isinstance(optional_headers, dict):
355+
headers.update(optional_headers)
356+
elif isinstance(optional_headers, dict):
357+
headers = optional_headers
332358
# if None will default to float(5) in client code
333359
timeout = available_toolboxes[tb]['server_params'].get('timeout')
334360
server_params['url'] = available_toolboxes[tb]['server_params'].get('url')

taskflows/examples/example_large_list_result_iter.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ taskflow:
1313
You do not need to provide a summary of the results.
1414
toolboxes:
1515
- github_official
16+
env:
17+
GITHUB_MCP_TOOLSETS: pull_requests
1618
- task:
1719
must_complete: true
1820
repeat_prompt: true

toolboxes/github_official.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@ seclab-taskflow-agent:
55
server_params:
66
kind: streamable
77
url: https://api.githubcopilot.com/mcp/
8+
#See https://github.com/github/github-mcp-server/blob/main/docs/remote-server.md
89
headers:
9-
Authorization: "{{ env GITHUB_AUTH_HEADER }}"
10+
Authorization: "{{ env GITHUB_AUTH_HEADER }}"
11+
optional_headers:
12+
X-MCP-Toolsets: "{{ env GITHUB_MCP_TOOLSETS }}"
13+
X-MCP-Readonly: "{{ env GITHUB_MCP_READONLY }}"

0 commit comments

Comments
 (0)