ဒီနေရာမှာ classic HTTP streaming server နဲ့ client, နောက်ပြီး MCP streaming server နဲ့ client ကို Python အသုံးပြုပြီး အလုပ်လုပ်ပုံကို ပြသထားပါတယ်။
- သင် MCP server တစ်ခုကို စတင်ပြီး၊ အရာဝတ္ထုများကို ဆောင်ရွက်နေစဉ် client ထံသို့ progress notifications များကို stream လုပ်ပေးမည်။
- Client က notification တစ်ခုချင်းစီကို အချိန်နှင့်တပြေးညီ ပြသမည်။
- ဒီလမ်းညွှန်စာအုပ်မှာ လိုအပ်ချက်များ၊ စတင်ခြင်း၊ အလုပ်လုပ်ပုံနဲ့ ပြဿနာရှာဖွေခြင်းတို့ကို ဖော်ပြထားပါတယ်။
- Python 3.9 သို့မဟုတ် အထက်
mcpPython package (သင့်ရဲ့ terminal မှာpip install mcpဖြင့် install လုပ်ပါ)
-
Repository ကို clone လုပ်ပါ သို့မဟုတ် solution ဖိုင်များကို download လုပ်ပါ။
git clone https://github.com/microsoft/mcp-for-beginners
-
Virtual environment တစ်ခု ဖန်တီးပြီး အလုပ်လုပ်ပါ (အကြံပြုသည်):
python -m venv venv .\venv\Scripts\Activate.ps1 # On Windows # or source venv/bin/activate # On Linux/macOS
-
လိုအပ်သော dependencies များကို install လုပ်ပါ:
pip install "mcp[cli]" fastapi requests
-
Solution directory သို့ သွားပါ:
cd 03-GettingStarted/06-http-streaming/solution
-
Classic HTTP streaming server ကို စတင်ပါ:
python server.py
-
Server က စတင်ပြီး အောက်ပါအတိုင်း ပြသမည်:
Starting FastAPI server for classic HTTP streaming... INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
-
Terminal အသစ်တစ်ခု ဖွင့်ပါ (တူညီသော virtual environment နဲ့ directory ကို activate လုပ်ပါ):
cd 03-GettingStarted/06-http-streaming/solution python client.py
-
Streamed messages များ sequentially ပြသမည်:
Running classic HTTP streaming client... Connecting to http://localhost:8000/stream with message: hello --- Streaming Progress --- Processing file 1/3... Processing file 2/3... Processing file 3/3... Here's the file content: hello --- Stream Ended ---
- Solution directory သို့ သွားပါ:
cd 03-GettingStarted/06-http-streaming/solution
- Streamable-http transport ဖြင့် MCP server ကို စတင်ပါ:
python server.py mcp
- Server က စတင်ပြီး အောက်ပါအတိုင်း ပြသမည်:
Starting MCP server with streamable-http transport... INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
- Terminal အသစ်တစ်ခု ဖွင့်ပါ (တူညီသော virtual environment နဲ့ directory ကို activate လုပ်ပါ):
cd 03-GettingStarted/06-http-streaming/solution python client.py mcp
- Server က အရာဝတ္ထုတစ်ခုချင်းစီကို ဆောင်ရွက်နေစဉ် real-time notifications များကို ပြသမည်:
Running MCP client... Starting client... Session ID before init: None Session ID after init: a30ab7fca9c84f5fa8f5c54fe56c9612 Session initialized, ready to call tools. Received message: root=LoggingMessageNotification(...) NOTIFICATION: root=LoggingMessageNotification(...) ... Tool result: meta=None content=[TextContent(type='text', text='Processed files: file_1.txt, file_2.txt, file_3.txt | Message: hello from client')]
- FastMCP ကို အသုံးပြုပြီး MCP server တစ်ခု ဖန်တီးပါ။
- List တစ်ခုကို ဆောင်ရွက်ပြီး
ctx.info()သို့မဟုတ်ctx.log()ဖြင့် notifications များ ပေးပို့သော tool တစ်ခု သတ်မှတ်ပါ။ transport="streamable-http"ဖြင့် server ကို အလုပ်လုပ်ပါ။- Notifications များ ရောက်လာသည်နှင့်တပြေးညီ ပြသရန် message handler တစ်ခုပါရှိသော client ကို အကောင်အထည်ဖော်ပါ။
- Server က async functions နဲ့ MCP context ကို အသုံးပြုပြီး progress updates များ ပေးပို့သည်။
- Client က async message handler တစ်ခုကို အသုံးပြုပြီး notifications နဲ့ နောက်ဆုံးရလဒ်ကို print လုပ်သည်။
- Non-blocking operations များအတွက်
async/awaitကို အသုံးပြုပါ။ - Server နဲ့ client နှစ်ခုစလုံးမှာ exception များကို အမြဲ handle လုပ်ပါ။
- Multiple clients များဖြင့် စမ်းသပ်ပြီး real-time updates များကို ကြည့်ရှုပါ။
- အမှားများ ကြုံတွေ့ပါက သင့် Python version ကို စစ်ဆေးပြီး၊ လိုအပ်သော dependencies များ install လုပ်ထားကြောင်း သေချာပါ။
အကြောင်းကြားချက်:
ဤစာရွက်စာတမ်းကို AI ဘာသာပြန်ဝန်ဆောင်မှု Co-op Translator ကို အသုံးပြု၍ ဘာသာပြန်ထားပါသည်။ ကျွန်ုပ်တို့သည် တိကျမှုအတွက် ကြိုးစားနေသော်လည်း၊ အလိုအလျောက် ဘာသာပြန်မှုများတွင် အမှားများ သို့မဟုတ် မတိကျမှုများ ပါဝင်နိုင်သည်ကို သတိပြုပါ။ မူရင်းစာရွက်စာတမ်းကို ၎င်း၏ မူရင်းဘာသာစကားဖြင့် အာဏာတရားရှိသော အရင်းအမြစ်အဖြစ် သတ်မှတ်သင့်ပါသည်။ အရေးကြီးသော အချက်အလက်များအတွက် လူ့ဘာသာပြန်ပညာရှင်များမှ ပရော်ဖက်ရှင်နယ် ဘာသာပြန်မှုကို အကြံပြုပါသည်။ ဤဘာသာပြန်မှုကို အသုံးပြုခြင်းမှ ဖြစ်ပေါ်လာသော အလွဲအမှားများ သို့မဟုတ် အနားလွဲမှုများအတွက် ကျွန်ုပ်တို့သည် တာဝန်မယူပါ။