MCPcopy Create free account
hub / github.com/IBM/mcp-cli / demo_streaming_handler

Function demo_streaming_handler

examples/streaming/mcp_cli_working_demo.py:21–235  ·  view source on GitHub ↗

Demonstrate the streaming handler as it works in MCP-CLI.

()

Source from the content-addressed store, hash-verified

19
20
21async def demo_streaming_handler():
22 """Demonstrate the streaming handler as it works in MCP-CLI."""
23 output = get_output()
24 set_theme("default")
25 console = Console()
26
27 output.print("\n" + "=" * 70)
28 output.print("MCP-CLI STREAMING HANDLER DEMO", style="bold cyan")
29 output.print("Shows how streaming works in actual MCP-CLI", style="dim")
30 output.print("=" * 70)
31
32 # Create the streaming handler (as used in conversation.py)
33 handler = StreamingResponseHandler(console)
34
35 # Mock a simple streaming client
36 class MockStreamingClient:
37 async def create_completion(self, messages, tools=None, stream=True, **kwargs):
38 """Simulate an LLM that streams responses."""
39
40 # Different responses based on the question
41 user_msg = messages[-1]["content"] if messages else ""
42
43 if "code" in user_msg.lower():
44 # Code response
45 chunks = [
46 {"response": "I'll"},
47 {"response": "I'll help"},
48 {"response": "I'll help you"},
49 {"response": "I'll help you with"},
50 {"response": "I'll help you with a"},
51 {"response": "I'll help you with a Python"},
52 {"response": "I'll help you with a Python function"},
53 {"response": "I'll help you with a Python function:\n\n```python"},
54 {
55 "response": "I'll help you with a Python function:\n\n```python\ndef"
56 },
57 {
58 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci"
59 },
60 {
61 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n"
62 },
63 {
64 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):"
65 },
66 {
67 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if"
68 },
69 {
70 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n"
71 },
72 {
73 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n <="
74 },
75 {
76 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n <= 1"
77 },
78 {

Callers 1

mainFunction · 0.85

Calls 5

stream_responseMethod · 0.95
MockStreamingClientClass · 0.85
user_messageMethod · 0.80
successMethod · 0.80

Tested by

no test coverage detected