Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created September 25, 2025 19:37
Show Gist options
  • Select an option

  • Save KyMidd/2cd6ee505b27ef60431bfa2fd4b6369f to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/2cd6ee505b27ef60431bfa2fd4b6369f to your computer and use it in GitHub Desktop.
GitHub MCP client setup with read-only access filtering for the Slack bot
def build_github_mcp_client(github_token, access_level="read_only"):
"""Build GitHub MCP client with specified access level"""
# Set up environment for GitHub MCP
github_env = {
"GITHUB_TOKEN": github_token,
}
# Build the GitHub MCP client using streamable HTTP client
github_mcp_client = MCPClient(
server_factory=lambda: streamablehttp_client("http://localhost:8000/mcp"),
server_env=github_env,
)
# List available tools from GitHub MCP
available_tools = github_mcp_client.list_tools()
print(f"🟡 Available GitHub MCP tools: {[tool.name for tool in available_tools]}")
# Filter tools based on access level
if access_level == "read_only":
# Only include read-only operations
read_only_patterns = [
"get_", "list_", "search_", "download_", "read_",
"mcp__github__get", "mcp__github__list", "mcp__github__search"
]
filtered_tools = [
tool for tool in available_tools
if any(pattern in tool.name for pattern in read_only_patterns)
]
else:
# Include all tools for full access
filtered_tools = available_tools
# Convert to Strands-compatible tools
github_tools = [
github_mcp_client.create_tool(tool) for tool in filtered_tools
]
print(f"🟢 Using {len(github_tools)} GitHub tools in {access_level} mode")
return github_mcp_client, github_tools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment