Skip to main content

Building a chat loop

With mcp-use you can build interactive interface where users can have conversations with your MCPAgent, maintaining context and memory across multiple queries.

Basic chat loop

Here’s a basic chat-loop with conversation memory enabled:

Streaming Chat Loop

Here’s a chat loop with streaming responses enabled:

Chat Loop with Structured I/O

It’s possible to create a chat loop that can handle both natural language and structured inputs, allowing users to request specific tasks or analyses in a structured format. Here’s an example of how to implement this:

Next Steps

Agent Configuration

Learn more about configuring agents for optimal streaming performance

Multi-Server Setup

Stream output from agents using multiple MCP servers

Security Best Practices

Learn how to secure your MCP deployments