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

Function demo_complete_then_partial

examples/tools/tool_args_flow_demo.py:72–118  ·  view source on GitHub ↗

Demo what happens when model sends complete JSON then partial update.

()

Source from the content-addressed store, hash-verified

70
71
72def demo_complete_then_partial():
73 """Demo what happens when model sends complete JSON then partial update."""
74 print("\n" + "=" * 60)
75 print("COMPLETE THEN PARTIAL DEMO - Same ID scenario")
76 print("=" * 60)
77 print("Same call_id means chunks should merge (preserving first values)")
78
79 acc = ToolCallAccumulator()
80
81 # Same ID - these should merge
82 chunk1 = [
83 {
84 "id": "call_456",
85 "index": 0,
86 "function": {
87 "name": "call_tool",
88 "arguments": '{"tool_name": "normal_cdf", "x": 9.067}',
89 },
90 }
91 ]
92
93 chunk2 = [
94 {
95 "id": "call_456", # SAME ID - will merge
96 "index": 0,
97 "function": {
98 "name": "",
99 "arguments": '{"x": 4.617}', # Different x value - should be ignored
100 },
101 }
102 ]
103
104 print("\n1. CHUNK 1 (id=call_456, x=9.067):")
105 acc.process_chunk_tool_calls(chunk1)
106
107 print("\n2. CHUNK 2 (id=call_456, x=4.617) - same ID, should merge:")
108 acc.process_chunk_tool_calls(chunk2)
109
110 print("\n3. RESULT (should have x=9.067 - first value preserved):")
111 result = acc.finalize()
112 for tc in result:
113 parsed = json.loads(tc["function"]["arguments"])
114 print(f" x = {parsed.get('x')}")
115 if parsed.get("x") == 9.067:
116 print(" ✓ CORRECT: First value preserved")
117 else:
118 print(" ✗ WRONG: Expected 9.067")
119
120
121def demo_different_ids():

Callers 1

mainFunction · 0.85

Calls 4

finalizeMethod · 0.95
ToolCallAccumulatorClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected