Skip to content

Commit 7ce13bf

Browse files
committed
Add optional headers to restrict GitHub mcp server toolsets
1 parent 115ddda commit 7ce13bf

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

mcp_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,17 @@ 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+
remove_key = {}
320+
if optional_headers and isinstance(optional_headers, dict):
321+
for k, v in dict(optional_headers).items():
322+
try:
323+
optional_headers[k] = swap_env(v)
324+
except LookupError as e:
325+
del optional_headers[k]
326+
pass
327+
headers.update(optional_headers)
317328
# if None will default to float(5) in client code
318329
timeout = available_toolboxes[tb]['server_params'].get('timeout')
319330
server_params['url'] = available_toolboxes[tb]['server_params'].get('url')
@@ -329,6 +340,16 @@ def mcp_client_params(available_toolboxes: dict, requested_toolboxes: list):
329340
if headers and isinstance(headers, dict):
330341
for k, v in headers.items():
331342
headers[k] = swap_env(v)
343+
optional_headers = available_toolboxes[tb]['server_params'].get('optional_headers')
344+
# support {{ env SOMETHING }} for header values as well for e.g. tokens
345+
if optional_headers and isinstance(optional_headers, dict):
346+
for k, v in dict(optional_headers).items():
347+
try:
348+
optional_headers[k] = swap_env(v)
349+
except LookupError as e:
350+
del optional_headers[k]
351+
pass
352+
headers.update(optional_headers)
332353
# if None will default to float(5) in client code
333354
timeout = available_toolboxes[tb]['server_params'].get('timeout')
334355
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ server_params:
66
kind: streamable
77
url: https://api.githubcopilot.com/mcp/
88
headers:
9-
Authorization: "{{ env GITHUB_AUTH_HEADER }}"
9+
Authorization: "{{ env GITHUB_AUTH_HEADER }}"
10+
optional_headers:
11+
X-MCP-Toolsets: "{{ env GITHUB_MCP_TOOLSETS }}"
12+
X-MCP-Readonly: "{{ env GITHUB_MCP_READONLY }}"

0 commit comments

Comments
 (0)