tc-ai-experiments

Agent tools and MCP (LangChain)

A learning prototype for how a LangChain agent uses tools: two local Python tools and two MCP servers, with a page that steps through each LLM call, tool call and message.

What turned up

See the results

Flow: six recorded questions, from no tools to parallel MCP calls, replayed step by step. It shows a flow diagram, every LLM and tool call with inputs and outputs, and the messages in the agent’s state. Nothing is sent to a model when you use it.

In the “Leave across two years” example, the two calculator steps are illustrative: in the real run the model did those subtractions itself. The page marks them.

Setup

This project is Python, not Node like the others.

The MCP servers start automatically as subprocesses; you don’t run them yourself.

Command What it does
uv run uvicorn server:app --reload The live version at http://localhost:8000: ask your own questions and watch them run.
uv run python cli.py "question" The same steps printed in the terminal.
uv run python record.py Runs the six example questions, saves output/runs.json and builds output/flow.html.
uv run python record.py --render Rebuilds output/flow.html from output/runs.json, without API calls.

Files

File What’s in it
agent.py The agent: create_agent() with the two local tools (calculator, current_time) and the MCP tools. run_steps() turns LangChain’s astream_events into one event per step.
mcp_servers/weather_server.py MCP server with made-up weather: get_current_weather, get_forecast.
mcp_servers/handbook_server.py MCP server with a made-up team handbook: list_policies, get_policy, search_handbook, and calculate_leave, which counts the working days a holiday needs, split by year, using public-holiday data from the holidays package.
server.py, static/index.html The live web version. Steps are streamed with server-sent events.
record.py, static/flow-template.html Recording and the static replay page.

The weather and handbook data are invented for this project.