Skip to content

Instantly share code, notes, and snippets.

View KyMidd's full-sized avatar

Kyler Middleton KyMidd

View GitHub Profile
@KyMidd
KyMidd / after_worker_agent_append.py
Created December 4, 2025 03:21
After: Append client in worker_agent.py
github_mcp_client = build_github_mcp_client(...)
tools.append(github_mcp_client)
@KyMidd
KyMidd / before_worker_agent_tuples.py
Created December 4, 2025 03:21
Before: Unpacking tuples in worker_agent.py
github_mcp_client, github_tools = build_github_mcp_client(...)
github_tools = add_prefix_to_mcp_tools(github_tools, "github")
tools.extend(github_tools)
@KyMidd
KyMidd / after_toolprovider.py
Created December 4, 2025 03:21
After: Return unstarted client (ToolProvider)
# Build client
github_mcp_client = MCPClient(...)
# Return it unstarted
return github_mcp_client
@KyMidd
KyMidd / before_manual_lifecycle.py
Created December 4, 2025 03:20
Before: Manual client lifecycle management
# Build client
github_mcp_client = MCPClient(...)
# Manually start it
github_client = github_mcp_client.__enter__()
# Extract tools
all_github_tools = github_client.list_tools_sync()
# Return tuple
return github_mcp_client, all_github_tools
@KyMidd
KyMidd / after_mcp_filters.py
Created December 4, 2025 03:20
After: MCPClient tool_filters parameter
# MCPClient filters declaratively
TOOLS_PREFIX = "github"
READ_ONLY_PREFIXES = ["download_", "get_", "list_", "search_"]
github_mcp_client = MCPClient(
lambda: streamablehttp_client(...),
tool_filters={
"allowed": [lambda tool: tool.tool_name.startswith(tuple(
f"{TOOLS_PREFIX}_{p}" for p in READ_ONLY_PREFIXES
))]
},
@KyMidd
KyMidd / before_manual_filter.py
Created December 4, 2025 03:20
Before: Manual tool filtering
# Manually loop and filter
filtered_tools = []
for tool in all_github_tools:
tool_name = tool.tool_spec["name"]
if tool_name.startswith(("download_", "get_", "list_", "search_")):
filtered_tools.append(tool)
@KyMidd
KyMidd / after_mcp_prefix.py
Created December 4, 2025 03:20
After: MCPClient prefix parameter
# MCPClient handles it
github_mcp_client = MCPClient(
lambda: streamablehttp_client(...),
prefix="github",
)
@KyMidd
KyMidd / before_manual_prefix.py
Created December 4, 2025 03:20
Before: Manual tool prefixing
# Wrap every tool manually
github_tools = add_prefix_to_mcp_tools(github_tools, "github")
@KyMidd
KyMidd / worker_agent_old.py
Created December 4, 2025 03:17
worker_agent.py MCP consumption (old pattern)
# Build GitHub MCP client with only read-only tools
github_mcp_client, github_tools = build_github_mcp_client(
secrets_json["GITHUB_TOKEN"], "read_only"
)
opened_clients["GitHub"] = github_mcp_client
# Prefix tool names
github_tools = add_prefix_to_mcp_tools(github_tools, "github")
# Extend tools list
tools.extend(github_tools)
@KyMidd
KyMidd / build_github_mcp_client_old.py
Created December 4, 2025 03:16
build_github_mcp_client function (old pattern)
def build_github_mcp_client(github_token, mode="read_only"):
# Build client
github_mcp_client = MCPClient(
lambda: streamablehttp_client(
"https://api.githubcopilot.com/mcp/",
headers={"Authorization": f"Bearer {github_token}"},
)
)
# Manually start the client
github_client = github_mcp_client.__enter__()