Agents · MCP · Cloud Run · 2026

Tool-Using MCP Agent

A LangGraph agent that picks tools across four real MCP servers, remembers each session, and survives broken servers. Deployed on Cloud Run.

Type
Agent · MCP · Cloud Deployment
Stack
LangGraph · FastAPI · langchain-mcp-adapters · NVIDIA NIM · Cloud Run
MCP servers
Filesystem · Tavily · Fetch · Open-Meteo weather
Date
2026

Overview

An LLM agent that reasons over each query, decides which tools it needs, and calls them through the Model Context Protocol. Four existing MCP servers are connected: filesystem, Tavily search, fetch and Open-Meteo weather. They compose into real chains, such as reading a CSV of cities, fetching the weather for each, and saving a summary to a file. A session id keeps the conversation across turns, and the service runs on Cloud Run behind a single POST /chat.

Design

The graph is a hand-built LangGraph loop, llm then tools then back, rather than the prebuilt agent, because the prebuilt one exposed no way to turn tool exceptions into messages the model can act on. Tools are discovered per server with tools/list, and an allowlist hands the model 13 of the 28 available tools: fewer wrong picks, fewer prompt tokens, and no costly crawl tools it never needs.

When servers misbehave

A server that fails to start is skipped and reported as degraded instead of taking the app down. Transport drops, tool errors and schema-breaking replies come back to the model as readable error messages, so it can explain or try another tool. One failure mode was silent: the MCP SDK drops an unparsable line without failing the request, so a malformed reply would hang forever without a 30 second read timeout. A hand-written broken MCP server, which returns isError, garbage, invalid results or dies mid-call, drives 21 offline tests, and a 12-check smoke test passes locally, in the container and on the live service.