Skip to main content

routes.mcp_ui

MCP-UI routes for agent-runtimes server.

MCPUIRequest Objects

class MCPUIRequest(BaseModel)

MCP-UI chat request.

MCPUIResponse Objects

class MCPUIResponse(BaseModel)

MCP-UI chat response.

register_mcp_ui_agent

def register_mcp_ui_agent(agent_id: str, adapter: MCPUITransport) -> None

Register an MCP-UI adapter.

Arguments:

  • agent_id - Unique identifier for the agent.
  • adapter - The MCPUITransport instance.

get_mcp_ui_adapter

def get_mcp_ui_adapter(agent_id: str) -> MCPUITransport | None

Get an MCP-UI adapter by ID.

Arguments:

  • agent_id - The agent identifier.

Returns:

The MCPUITransport if found, None otherwise.

unregister_mcp_ui_agent

def unregister_mcp_ui_agent(agent_id: str) -> bool

Unregister an MCP-UI adapter.

Arguments:

  • agent_id - The agent identifier.

Returns:

True if agent was unregistered, False if not found.

mcp_ui_info

@router.get("/")
async def mcp_ui_info() -> dict[str, Any]

Get MCP-UI service information.

Returns:

Information about the MCP-UI service.

list_agents

@router.get("/agents")
async def list_agents() -> dict[str, Any]

List available MCP-UI agents.

Returns:

Dictionary with list of agent IDs and their endpoints.

chat

@router.post("/chat/{agent_id:path}")
async def chat(agent_id: str, request: MCPUIRequest) -> MCPUIResponse

Handle MCP-UI chat request (non-streaming).

This endpoint processes a chat message and returns a response that may include interactive UI resources.

Arguments:

  • agent_id - The agent to use.
  • request - The chat request with message and options.

Returns:

Chat response with potential UI resources.

Example:

```python
# Client request
response = requests.post(
"http://localhost:8000/api/v1/mcp-ui/chat/demo-agent",
json={
"message": "Show me a visualization",
"session_id": "session-123"
}
)

# Response may include UI resources
# {
# "role": "assistant",
# "content": [
# {"type": "text", "text": "Here's the visualization:"},
# {
# "type": "resource",
# "resource": {
# "uri": "ui://viz/chart",
# "mimeType": "text/html",
# "text": "<div>...</div>"
# }
# }
# ]
# }
```

stream

@router.post("/stream/{agent_id:path}")
async def stream(agent_id: str, request: MCPUIRequest) -> StreamingResponse

Handle MCP-UI streaming chat request.

This endpoint streams agent responses and UI resources as they become available, providing a real-time interactive experience.

Arguments:

  • agent_id - The agent to use.
  • request - The chat request with message and options.

Returns:

Streaming response with text deltas and UI resources.

Example:

```python
# Client request with streaming
import requests

response = requests.post(
"http://localhost:8000/api/v1/mcp-ui/stream/demo-agent",
json={"message": "Generate a report"},
stream=True
)

for line in response.iter_lines():
if line:
event = json.loads(line)
if event["type"] == "delta":
print(event["delta"], end="")
elif event["type"] == "resource":
# Render UI resource
render_ui_resource(event["resource"])
```