# I built an open-source Agentic Workspace with LangGraph & FastMCP (12+ tools, real-time SSE, 99.99% SLA) — retained record

> Retained reddit record from reddit:selfhosted.

Canonical: https://highsignal.app/data/records/be15e59e486a052b

[← sources](https://highsignal.app/data)


source: [reddit](https://highsignal.app/data/reddit) (reddit:selfhosted)  published 2026-10-12 08:16 ingested 2026-10-13 02:39

[original source ↗](https://www.reddit.com/r/selfhosted/comments/1x3w8d2/i_built_an_opensource_agentic_workspace_with/)

## retained text



```
Most agent tutorials show a short linear chain in a notebook. I wanted to see what it takes to run an agent with real tools, live streaming and safety checks in production, so I built **Agentic AI Workspace**: a LangGraph (ReAct loop) agent with an MCP tool server (FastMCP), FastAPI and Next.js 14. It is live and open source.

**Transparency:** I built this with AI assistance. I designed the architecture, the tool set and the safety gates, and I deployed and tested it myself.

# 4 patterns I used (simplified excerpts)

# 1. A cyclic ReAct loop as a state machine

Instead of a hand-written `while` loop, LangGraph models the cycle as a graph. The `add_messages` reducer appends every tool turn to the state.

    class AgentState(TypedDict):
        messages: Annotated[list[BaseMessage], add_messages]
    
    # If the LLM asks for a tool, run it; otherwise finish
    graph.add_conditional_edges("agent", should_continue, {"tools": "tools", END: END})
    graph.add_edge("tools", "agent")  # tool results go back to the model

# 2. Discovering MCP tools at runtime

The backend connects to MCP servers over SSE, lists their tools and wraps each one as a LangChain tool, so I don't hardcode every integration.

    async with sse_client(url) as (read_stream, write_stream):
        async with ClientSession(read_stream, write_stream) as session:
            await session.initialize()
            result = await session.list_tools()
            for t in result.tools:
                # wrap the remote MCP tool as a LangChain StructuredTool
                lc_tool = StructuredTool.from_function(coroutine=_call, name=f"{server}__{t.name}")

The same FastMCP server can also be plugged into Claude Desktop and Cursor (config in the first comment).

# 3. Streaming tokens and tool events over SSE

Nobody likes staring at a loader for 10 seconds, so FastAPI streams LangGraph events as they happen.

    async for event in agent.astream_events({"messages": history}, version="v2"):
        if event["event"] == "on_chat_model_stream":
            yield f"data: {json.dumps({'type': 'token', 'content': token})}\n\n"
        elif event["event"] == "on_tool_start":
            yield f"data: {json.dumps({'type': 'tool_start', 'name': event['name']})}\n\n"

# 4. Human-in-the-loop and no eval()

* **Approval gate:** actions like sending email through Gmail SMTP need explicit approval. The agent produces a draft card in the UI and execution stops until the user clicks **Approve & Send**.
* **Math without** `eval()`\*\*:\*\* expressions are parsed with Python's `ast` module and a custom operator whitelist, so no arbitrary code is executed.

# 3 things that broke in production

1. **Message role alternation (Gemini):** in my setup, consecutive messages with the same role were rejected. After a dropped SSE connection the next query failed silently. I added an interceptor that merges consecutive same-role messages before they reach the graph.
2. **MCP stdio corruption:** if anything writes to `stdout` in an MCP stdio server, the JSON-RPC stream breaks. The fix was to send all logging to `sys.stderr`.
3. **512MB RAM on Render's free tier:** Next.js SSR plus a Python backend ran out of memory. I switched to a multi-stage Docker build that statically exports the Next.js bundle and serves frontend and API from one FastAPI process (\[idle memory you measured\]).

# Tech stack

`LangGraph` · `FastMCP` · `FastAPI` · `Next.js 14` · `MongoDB (TTL memory)` · `Docker`

Feedback is welcome, especially on the tool design.

**What is your biggest pain point with LangGraph or MCP in production right now?**
```



document fetched 2026-10-13 00:31 · canonical https://reddit.com/r/selfhosted/comments/1x3w8d2/i_built_an_opensource_agentic_workspace_with
