tutorialintermediate
The observability agent Sep 2025 • Claude Agent SDK Agent Patterns Connect agents to external systems via MCP servers for GitHub monitoring and CI workflows.
cookbook
View original on cookbookThis cookbook demonstrates how to connect Claude agents to external systems using MCP (Model Context Protocol) servers for GitHub monitoring and CI workflows. The guide covers integrating Git and GitHub MCP servers to enable agents to interact with repositories, manage workflows, and perform observability tasks. By leveraging MCP servers, agents gain access to specialized tools for Git operations, GitHub platform integration, and CI/CD monitoring without relying on command-line interfaces.
Key Points
- •MCP (Model Context Protocol) is an open-source standard enabling AI agents to connect with external systems like databases, APIs, and specialized services beyond basic filesystem access
- •Git MCP server provides 13 Git-specific tools allowing agents to examine commit history, check file changes, create branches, and make commits autonomously
- •GitHub MCP server offers 100+ tools for full GitHub ecosystem integration including issues, pull requests, CI/CD workflows, and security alerts management
- •GitHub token setup requires a fine-grained Personal Access Token configured in .env file as GITHUB_TOKEN for authentication
- •Docker is required for GitHub MCP server execution to provide security and isolation in a containerized environment
- •Use allowed_tools and disallowed_tools parameters to restrict agent access to specific MCP tools and prevent fallback to Bash commands
- •permission_mode='acceptEdits' enables agents to make modifications to external systems when authorized
- •Real-world use case: observability agents can analyze CI health, identify failing jobs, assess severity, and provide operational summaries for on-call engineers
- •Agents can automate complex GitHub workflows including pull request creation, code evolution analysis, and multi-repository management
- •Read-only analysis mode prevents agents from creating issues or PRs while still enabling comprehensive CI/CD monitoring and diagnostics
Found this useful? Add it to a playbook for a step-by-step implementation guide.
Workflow Diagram
Start Process
Step A
Step B
Step C
Complete
Concepts
Artifacts (5)
git_mcp_configurationpythonconfig
git_mcp: dict[str, Any] = {
"git": {
"command": "uv",
"args": [
"run",
"python",
"-m",
"mcp_server_git",
"--repository",
git_repo_root
],
}
}github_mcp_configurationpythonconfig
github_mcp: dict[str, Any] = {
"github": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"GITHUB_PERSONAL_ACCESS_TOKEN",
"ghcr.io/github/github-mcp-server",
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": os.environ.get("GITHUB_TOKEN")
},
}
}git_agent_querypythonscript
messages = []
async with ClaudeSDKClient(
options=ClaudeAgentOptions(
model="claude-opus-4-6",
mcp_servers=git_mcp,
allowed_tools=["mcp__git"],
disallowed_tools=["Bash", "Task", "WebSearch", "WebFetch"],
permission_mode="acceptEdits",
)
) as agent:
await agent.query(
"Explore this repo's git history and provide a brief summary of recent activity."
)
async for msg in agent.receive_response():
print_activity(msg)
messages.append(msg)github_observability_agentpythonscript
prompt = """Analyze the CI health for facebook/react repository. Examine the most recent runs of the 'CI' workflow and provide:
1. Current status and what triggered the run (push, PR, schedule, etc.)
2. If failing: identify the specific failing jobs/tests and assess severity
3. If passing: note any concerning patterns (long duration, flaky history)
4. Recommended actions with priority (critical/high/medium/low)
Provide a concise operational summary suitable for an on-call engineer.
Do not create issues or PRs - this is a read-only analysis."""
messages = []
async with ClaudeSDKClient(
options=ClaudeAgentOptions(
model="claude-opus-4-6",
mcp_servers=github_mcp,
allowed_tools=["mcp__github"],
disallowed_tools=["Bash", "Task", "WebSearch", "WebFetch"],
permission_mode="acceptEdits",
)
) as agent:
await agent.query(prompt)
async for msg in agent.receive_response():
print_activity(msg)
messages.append(msg)git_repo_root_detectionpythonscript
git_executable = shutil.which("git")
if git_executable is None:
raise RuntimeError("Git executable not found in PATH")
git_repo_root = subprocess.run(
[git_executable, "rev-parse", "--show-toplevel"],
capture_output=True,
text=True,
check=True,
).stdout.strip()