Skip to content

MCP + Deep Agents

This is the smallest useful version of the integration implemented by this repository: start WorkIQ as a local MCP server, adapt its discovered tools for LangChain, apply policy, and give the approved tools to a Deep Agent.

The user asks a workplace question. A Deep Agent sends an approved call through the MCP adapter and WorkIQ child to Microsoft 365. Permission-trimmed results return through the same boundaries, and the Deep Agent synthesizes the answer for the user.

The Python process never receives the WorkIQ bearer token. The @microsoft/workiq child owns its interactive sign-in and communicates with Python through MCP messages over stdio.

Run the example

Prerequisites are Python 3.11+, Node.js with npx, uv, Azure CLI, and a WorkIQ-enabled Microsoft 365 tenant. The repository setup accepts the WorkIQ EULA and configures WORKIQ_AGENT_MODEL_BASE_URL and WORKIQ_AGENT_MODEL_TENANT_ID. Review the delegated authentication boundary, then run the included read-only example:

uv run python examples/mcp_deepagents.py \
  "What decisions did my team make yesterday?"

Core integration

async def ask_workiq(question: str) -> str:
    settings = Settings()
    client = MultiServerMCPClient({"workiq": settings.workiq_connection()})

    async with client.session("workiq") as session:
        discovered_tools = await load_mcp_tools(session, server_name="workiq")
        tools = select_workiq_tools(discovered_tools, allow_writes=False)

        agent = create_deep_agent(
            model=create_model(settings),
            tools=tools,
            system_prompt=READ_ONLY_PROMPT,
            checkpointer=InMemorySaver(),
            name="workiq_example",
        )
        state = await agent.ainvoke(
            {"messages": [{"role": "user", "content": question}]},
            config={"configurable": {"thread_id": str(uuid4())}},
        )

    return response_text(state)

The MCP session encloses agent.ainvoke. Closing it earlier would leave the Deep Agent with tool descriptors whose underlying stdio transport is gone.

What each boundary owns

Boundary Responsibility
Settings.workiq_connection() Describes npx -y @microsoft/workiq mcp as an MCP stdio server.
load_mcp_tools() Converts discovered MCP tools into LangChain tools.
select_workiq_tools() Removes mutation and blob tools before the model sees them.
create_model() Creates the caller-owned Azure Responses model.
create_deep_agent() Runs the model/tool loop and checkpoints thread state.
response_text() Extracts display text from the final agent state.

Production delta

The full CLI adds streamed model and tool lifecycle events, usage and cost metrics, chat thread reuse, prerequisite diagnostics, and explicit write enablement. For durable deployment, replace InMemorySaver with a persistent checkpointer and key every thread by tenant and user.

Keep write tools disabled by default. Enabling them requires both WorkIQ tenant/path policy and an application-controlled approval step immediately before mutation. --allow-writes exposes the discovered write tools and changes the system prompt; it does not implement that trusted approval gate. A production host must interrupt tool execution, display the exact operation and arguments, and require fresh user confirmation before sending the call.

Sources: Deep Agents customization, LangChain MCP adapters, and the Work IQ MCP overview.