{"id":75440,"date":"2026-02-12T10:06:59","date_gmt":"2026-02-12T02:06:59","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/75440.html"},"modified":"2026-02-12T10:06:59","modified_gmt":"2026-02-12T02:06:59","slug":"%e5%9c%a8lambda%e5%87%bd%e6%95%b0%e4%b8%ad%e7%bc%96%e5%86%99%e5%92%8c%e9%83%a8%e7%bd%b2mcp%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/75440.html","title":{"rendered":"\u5728Lambda\u51fd\u6570\u4e2d\u7f16\u5199\u548c\u90e8\u7f72MCP\u670d\u52a1\u5668\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u53c2\u8003\u8d44\u6599<\/p>\n<ul>\n<li>https:\/\/github.com\/awslabs\/run-model-context-protocol-servers-with-aws-lambda<\/li>\n<li>https:\/\/aws.amazon.com\/cn\/blogs\/china\/deploy-streamable-http-github-mcp-server-using-amazon-lambda\/<\/li>\n<li>https:\/\/modelcontextprotocol.io\/specification\/2025-06-18\/basic\/transports<\/li>\n<li>https:\/\/dev.to\/aws-builders\/mcp-server-with-aws-lambda-and-http-api-gateway-1j49<\/li>\n<\/ul>\n<h3>MCP Transports \u57fa\u7840\u7406\u8bba<\/h3>\n<p>\u53c2\u8003\u5b98\u65b9\u6587\u6863&#xff08;https:\/\/modelcontextprotocol.io\/specification\/2025-06-18\/basic\/transports&#xff09;MCP \u7684\u4f20\u8f93\u673a\u5236&#xff08;Transport&#xff09;\u6307\u7684\u662f\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u4e4b\u95f4\u7684\u901a\u4fe1\u673a\u5236\u3002MCP \u7684\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u4e4b\u95f4\u7684\u901a\u4fe1&#xff0c;\u9700\u9075\u5faa\u4ee5\u4e0b\u539f\u5219&#xff1a;<\/p>\n<ul>\n<li>\u6d88\u606f\u683c\u5f0f&#xff1a;\u6240\u6709 MCP \u6d88\u606f\u90fd\u5fc5\u987b\u662f JSON-RPC \u683c\u5f0f&#xff1b;\u6240\u6709 JSON-RPC \u6d88\u606f\u5fc5\u987b\u4f7f\u7528 UTF-8 \u7f16\u7801<\/li>\n<li>\u4e24\u79cd\u6807\u51c6\u5316\u7684\u4f20\u8f93\u65b9\u5f0f&#xff1a;stdio (\u6807\u51c6\u8f93\u5165\/\u8f93\u51fa)\u3001Streamable HTTP \u3002\u5728\u53ef\u80fd\u7684\u60c5\u51b5\u4e0b&#xff0c;\u5ba2\u6237\u7aef\u5e94\u5f53\u652f\u6301\u6807\u51c6\u8f93\u5165\u8f93\u51fa (stdio)<\/li>\n<li>\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u53ef\u4ee5\u901a\u8fc7\u6a21\u5757\u5316\u7684\u65b9\u5f0f\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u4f20\u8f93\u673a\u5236<\/li>\n<\/ul>\n<p>\u65e9\u671f MCP \u89c4\u8303\u662f\u57fa\u4e8e HTTP &#043; SSE&#xff08;Server-Sent Events&#xff09;\u7ec4\u5408\u7684\u4f20\u8f93\u65b9\u5f0f\u3002\u5176\u4e2dSSE \u662f\u4e00\u79cd\u57fa\u4e8e HTTP \u7684\u6807\u51c6\u534f\u8bae&#xff0c;\u5141\u8bb8\u670d\u52a1\u5668\u5411\u5ba2\u6237\u7aef\u63a8\u9001\u5b9e\u65f6\u6570\u636e\u3002\u5ba2\u6237\u7aef\u53d1\u8d77\u4e00\u4e2a\u6807\u51c6 HTTP \u8bf7\u6c42&#xff0c;\u670d\u52a1\u5668\u4fdd\u6301\u8fde\u63a5\u4e0d\u4e2d\u65ad&#xff0c;\u5e76\u4ee5 text\/event-stream \u683c\u5f0f\u6301\u7eed\u53d1\u9001\u6570\u636e\u5757\u3002\u7531\u4e8e\u5b9e\u73b0\u590d\u6742&#xff08;\u9700\u8981\u5b9e\u73b0\u4e24\u4e2a\u4e0d\u540c\u7aef\u70b9&#xff09;&#xff0c;\u5e76\u4e14\u5728\u4ee3\u7406&#xff0c;\u8d1f\u8f7d\u5747\u8861&#xff0c;\u8d85\u65f6\u91cd\u8fde\u7b49\u65b9\u9762\u96be\u4ee5\u5904\u7406&#xff0c;\u73b0\u5728 \u88ab\u6807\u8bb0\u4e3a\u8fc7\u65f6 (deprecated) \u3002HTTP &#043; SSE\u7684\u8bf7\u6c42\u6d41\u7a0b\u5982\u4e0b<\/p>\n<ul>\n<li>\u5ba2\u6237\u7aef\u901a\u8fc7 HTTP GET \u8bf7\u6c42\u8fde\u63a5\u4e00\u4e2a SSE \u7aef\u70b9&#xff08;\u5982 \/events&#xff09;&#xff0c;\u670d\u52a1\u5668\u5728\u8fd9\u4e2a\u8fde\u63a5\u4e0a\u6301\u7eed\u63a8\u9001\u4e8b\u4ef6&#xff08;server \u2192 client&#xff09;\u3002\u6574\u4e2a\u8c03\u7528\u671f\u95f4 MCP Client \u9700\u8981\u4e00\u76f4\u548c MCP Server \u4fdd\u6301\/sse \u7aef\u70b9\u7684\u957f\u94fe\u63a5\u4e0d\u80fd\u65ad\u5f00&#xff0c;\u5426\u5219\u4f1a\u53ef\u80fd\u4e22\u5931\u67d0\u6b21\u8c03\u7528\u7684\u6570\u636e\u3002<\/li>\n<li>\u5ba2\u6237\u7aef\u901a\u8fc7 HTTP POST \u5230\u4e00\u4e2a\u6d88\u606f\u7aef\u70b9&#xff08;\u5982 \/message&#xff09;\u5411\u670d\u52a1\u5668\u53d1\u6d88\u606f&#xff08;client \u2192 server&#xff09;<\/li>\n<\/ul>\n<p>Streamable HTTP (Response Streaming) \u5219\u63d0\u4f9b\u4e00\u4e2a \u5355\u4e00 HTTP \u7aef\u70b9&#xff0c;\u670d\u52a1\u5668\u5fc5\u987b\u63d0\u4f9b\u4e00\u4e2a\u652f\u6301 POST \u548c GET \u65b9\u6cd5\u7684\u5355\u4e2a HTTP \u7aef\u70b9\u8def\u5f84<\/p>\n<ul>\n<li>\u5ba2\u6237\u7aef\u5411\u8be5\u7aef\u70b9\u7528 POST \u53d1\u9001 JSON-RPC \u8bf7\u6c42&#xff0f;\u901a\u77e5&#xff0f;\u54cd\u5e94&#xff0c;POST \u8bf7\u6c42\u7684\u6b63\u6587\u5fc5\u987b\u662f\u5355\u4e2a JSON-RPC \u8bf7\u6c42\u3001\u901a\u77e5\u6216\u54cd\u5e94\u3002\u5ba2\u6237\u7aef\u5fc5\u987b\u5728 Accept \u5934\u90e8\u4e2d\u5305\u542b&#xff0c;\u5217\u51fa application\/json \u548c text\/event-stream \u4f5c\u4e3a\u652f\u6301\u7684\u5185\u5bb9\u7c7b\u578b\u3002<\/li>\n<li>\u5982\u679c\u5ba2\u6237\u7aef\u8f93\u5165\u662f\u4e00\u4e2a JSON-RPC \u8bf7\u6c42&#xff0c;\u670d\u52a1\u5668\u5fc5\u987b\u8fd4\u56de Content-Type: text\/event-stream \u4ee5\u542f\u52a8 SSE \u6d41&#xff0c;\u6216\u8005\u8fd4\u56de Content-Type: application\/json \u4ee5\u8fd4\u56de\u4e00\u4e2a JSON \u5bf9\u8c61\u3002<\/li>\n<li>\u4e3a\u4e86\u5411\u4e0b\u517c\u5bb9 SSE&#xff0c;\u5ba2\u6237\u7aef\u53ef\u4ee5\u53d1\u9001\u4e00\u4e2a HTTP GET \u8bf7\u6c42\u5230 MCP \u7aef\u70b9\u3002\u8fd9\u53ef\u4ee5\u7528\u6765\u6253\u5f00\u4e00\u4e2a SSE \u6d41&#xff0c;\u5141\u8bb8\u670d\u52a1\u5668\u5411\u5ba2\u6237\u7aef\u901a\u4fe1&#xff0c;\u800c\u65e0\u9700\u5ba2\u6237\u7aef\u5148\u901a\u8fc7 HTTP POST \u53d1\u9001\u6570\u636e<\/li>\n<li>\u6b64\u5916MCP \u670d\u52a1\u5668\u53ef\u4ee5\u662f\u65e0\u72b6\u6001\u7684&#xff0c;\u6216\u8005\u53ef\u4ee5\u4f7f\u7528\u8bf7\u6c42\u5934\u4e2d\u7684 sessionId \u6765\u5904\u7406\u72b6\u6001<\/li>\n<\/ul>\n<p>MCP\u7684HTTP&#043;SSE \u548c Streamable HTTP\u89c4\u8303\u7684\u6bd4\u8f83\u548c\u533a\u522b&#xff0c;\u7f51\u7edc\u4e0a\u5df2\u7ecf\u6709\u5f88\u597d\u7684\u89e3\u91ca\u53ef\u4ee5\u53c2\u8003&#xff0c;https:\/\/zhuanlan.zhihu.com\/p\/1932231185808994798<\/p>\n<p>\u5173\u4e8e\u901a\u8fc7lambda\u51fd\u6570\u5b9e\u73b0mcp\u7684\u4f7f\u7528\u65b9\u6cd5\u6709\u5982\u4e0b\u51e0\u79cd<\/p>\n<h4>\u5728 Lambda \u51fd\u6570\u4e2d\u7f16\u5199\u81ea\u5b9a\u4e49 MCP \u670d\u52a1\u5668<\/h4>\n<p>\u53ef\u4ee5\u53c2\u8003MCP Lambda Handler Module&#xff0c;\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6781\u7b80\u3001\u53ef\u6269\u5c55\u7684\u6846\u67b6&#xff0c;\u7528\u4e8e\u6784\u5efa\u5177\u6709\u53ef\u63d2\u62d4\u4f1a\u8bdd\u7ba1\u7406\u652f\u6301\u7684 MCP HTTP \u7aef\u70b9\u3002\u4f5c\u8005\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u793a\u4f8bDeploy MCP Server in AWS Lambda Without Containers: A Complete Guide&#xff0c;\u4e3b\u8981\u7684\u4f5c\u7528\u662f\u901a\u8fc7\u81ea\u5b9a\u4e49\u7684 MCP \u5904\u7406\u5668&#xff0c;\u5c06 MCP \u534f\u8bae\u9002\u914d\u5230 Lambda \u7684\u8bf7\u6c42-\u54cd\u5e94\u6a21\u578b&#xff0c;\u540c\u65f6\u4fdd\u6301\u5b8c\u5168\u7684\u534f\u8bae\u517c\u5bb9\u6027\u3002<\/p>\n<p>\u4e4b\u6240\u4ee5\u6ca1\u6709\u4f7f\u7528\u5bb9\u5668\u5b9e\u73b0\u662f\u7531\u4e8e\u51b7\u542f\u52a8\u65f6\u95f4\u8f83\u957f&#xff0c;\u4ee5\u53ca\u7ef4\u62a4\u5bb9\u5668\u955c\u50cf\u5e26\u6765\u7684\u66f4\u590d\u6742\u7684\u90e8\u7f72\u548c\u7ba1\u7406\u6210\u672c<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">_handle_http_post<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> parsed_event<span class=\"token punctuation\">:<\/span> Any<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> Any<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    method_handlers <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        MCPMethod<span class=\"token punctuation\">.<\/span>INITIALIZE<span class=\"token punctuation\">:<\/span> self<span class=\"token punctuation\">.<\/span>_handle_initialize<span class=\"token punctuation\">,<\/span><br \/>\n        MCPMethod<span class=\"token punctuation\">.<\/span>TOOLS_LIST<span class=\"token punctuation\">:<\/span> self<span class=\"token punctuation\">.<\/span>_handle_tools_list<span class=\"token punctuation\">,<\/span><br \/>\n        MCPMethod<span class=\"token punctuation\">.<\/span>TOOLS_CALL<span class=\"token punctuation\">:<\/span> self<span class=\"token punctuation\">.<\/span>_handle_tools_call<span class=\"token punctuation\">,<\/span><br \/>\n        MCPMethod<span class=\"token punctuation\">.<\/span>PING<span class=\"token punctuation\">:<\/span> self<span class=\"token punctuation\">.<\/span>_handle_ping<span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    method <span class=\"token operator\">&#061;<\/span> parsed_event<span class=\"token punctuation\">.<\/span>body<span class=\"token punctuation\">.<\/span>method<br \/>\n    <span class=\"token keyword\">if<\/span> method <span class=\"token keyword\">in<\/span> method_handlers<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> method_handlers<span class=\"token punctuation\">[<\/span>method<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span>parsed_event<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> self<span class=\"token punctuation\">.<\/span>_create_error_response<span class=\"token punctuation\">(<\/span><br \/>\n        ERROR_METHOD_NOT_FOUND<span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Method not found: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>method<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><br \/>\n    <span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd8\u6709\u65b9\u6848\u76f4\u63a5\u5728lambda\u4e2d\u8fd0\u884cstdio mcp\u670d\u52a1\u5668&#xff0c;https:\/\/github.com\/awslabs\/run-model-context-protocol-servers-with-aws-lambda&#xff0c;\u4e3b\u8981\u76ee\u7684\u662f\u5c06\u73b0\u6709\u7684stdio\u7684mcp\u670d\u52a1\u76f4\u63a5\u8fc1\u79fb\u5230lambda\u4e2d\u3002Lambda \u51fd\u6570\u88ab\u89e6\u53d1\u65f6&#xff0c;\u4f1a\u5728\u5185\u90e8\u542f\u52a8 MCP \u670d\u52a1\u5668\u8fdb\u7a0b&#xff0c;\u5c06\u8bf7\u6c42\u8f6c\u6362\u4e3a stdio \u8f93\u5165&#xff0c;\u83b7\u53d6\u54cd\u5e94\u540e\u518d\u5c01\u88c5\u56de Lambda \u8fd4\u56de\u503c\u3002<\/p>\n<p>lambda\u51fd\u6570\u7684\u5165\u53e3\u4ee3\u7801\u5982\u4e0b<\/p>\n<p><span class=\"token keyword\">import<\/span> sys<br \/>\n<span class=\"token keyword\">from<\/span> mcp<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>stdio <span class=\"token keyword\">import<\/span> StdioServerParameters<br \/>\n<span class=\"token keyword\">from<\/span> mcp_lambda <span class=\"token keyword\">import<\/span> stdio_server_adapter<\/p>\n<p>server_params <span class=\"token operator\">&#061;<\/span> StdioServerParameters<span class=\"token punctuation\">(<\/span><br \/>\n    command<span class=\"token operator\">&#061;<\/span>sys<span class=\"token punctuation\">.<\/span>executable<span class=\"token punctuation\">,<\/span><br \/>\n    args<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">[<\/span><br \/>\n        <span class=\"token string\">&#034;-m&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#034;my_mcp_server_python_module&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#034;&#8211;my-server-command-line-parameter&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#034;some_value&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">handler<\/span><span class=\"token punctuation\">(<\/span>event<span class=\"token punctuation\">,<\/span> context<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> stdio_server_adapter<span class=\"token punctuation\">(<\/span>server_params<span class=\"token punctuation\">,<\/span> event<span class=\"token punctuation\">,<\/span> context<span class=\"token punctuation\">)<\/span><\/p>\n<h4>\u901a\u8fc7 stdio \u8c03\u7528\u73b0\u6709\u7684 Lambda \u51fd\u6570<\/h4>\n<p>\u53ef\u4ee5\u53c2\u8003AWS Lambda MCP Server\u3002MCP \u670d\u52a1\u5668\u5145\u5f53 MCP \u5ba2\u6237\u7aef\u548cLambda \u51fd\u6570\u4e4b\u95f4\u7684\u6865\u6881&#xff0c;\u53ef\u4ee5\u5728\u4e0d\u4fee\u6539\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u5c06Lambda \u51fd\u6570\u4f5c\u4e3a MCP \u5de5\u5177\u8c03\u7528\u3002\u56fe\u793a\u5982\u4e0b<\/p>\n<p>  #mermaid-svg-6VUFrqq716QycJo2{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-6VUFrqq716QycJo2 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-6VUFrqq716QycJo2 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-6VUFrqq716QycJo2 .error-icon{fill:#552222;}#mermaid-svg-6VUFrqq716QycJo2 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-6VUFrqq716QycJo2 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-6VUFrqq716QycJo2 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-6VUFrqq716QycJo2 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-6VUFrqq716QycJo2 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-6VUFrqq716QycJo2 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-6VUFrqq716QycJo2 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-6VUFrqq716QycJo2 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-6VUFrqq716QycJo2 .marker.cross{stroke:#333333;}#mermaid-svg-6VUFrqq716QycJo2 svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-6VUFrqq716QycJo2 p{margin:0;}#mermaid-svg-6VUFrqq716QycJo2 .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-6VUFrqq716QycJo2 .cluster-label text{fill:#333;}#mermaid-svg-6VUFrqq716QycJo2 .cluster-label span{color:#333;}#mermaid-svg-6VUFrqq716QycJo2 .cluster-label span p{background-color:transparent;}#mermaid-svg-6VUFrqq716QycJo2 .label text,#mermaid-svg-6VUFrqq716QycJo2 span{fill:#333;color:#333;}#mermaid-svg-6VUFrqq716QycJo2 .node rect,#mermaid-svg-6VUFrqq716QycJo2 .node circle,#mermaid-svg-6VUFrqq716QycJo2 .node ellipse,#mermaid-svg-6VUFrqq716QycJo2 .node polygon,#mermaid-svg-6VUFrqq716QycJo2 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-6VUFrqq716QycJo2 .rough-node .label text,#mermaid-svg-6VUFrqq716QycJo2 .node .label text,#mermaid-svg-6VUFrqq716QycJo2 .image-shape .label,#mermaid-svg-6VUFrqq716QycJo2 .icon-shape .label{text-anchor:middle;}#mermaid-svg-6VUFrqq716QycJo2 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-6VUFrqq716QycJo2 .rough-node .label,#mermaid-svg-6VUFrqq716QycJo2 .node .label,#mermaid-svg-6VUFrqq716QycJo2 .image-shape .label,#mermaid-svg-6VUFrqq716QycJo2 .icon-shape .label{text-align:center;}#mermaid-svg-6VUFrqq716QycJo2 .node.clickable{cursor:pointer;}#mermaid-svg-6VUFrqq716QycJo2 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-6VUFrqq716QycJo2 .arrowheadPath{fill:#333333;}#mermaid-svg-6VUFrqq716QycJo2 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-6VUFrqq716QycJo2 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-6VUFrqq716QycJo2 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-6VUFrqq716QycJo2 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-6VUFrqq716QycJo2 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-6VUFrqq716QycJo2 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-6VUFrqq716QycJo2 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-6VUFrqq716QycJo2 .cluster text{fill:#333;}#mermaid-svg-6VUFrqq716QycJo2 .cluster span{color:#333;}#mermaid-svg-6VUFrqq716QycJo2 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-6VUFrqq716QycJo2 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-6VUFrqq716QycJo2 rect.text{fill:none;stroke-width:0;}#mermaid-svg-6VUFrqq716QycJo2 .icon-shape,#mermaid-svg-6VUFrqq716QycJo2 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-6VUFrqq716QycJo2 .icon-shape p,#mermaid-svg-6VUFrqq716QycJo2 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-6VUFrqq716QycJo2 .icon-shape rect,#mermaid-svg-6VUFrqq716QycJo2 .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-6VUFrqq716QycJo2 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-6VUFrqq716QycJo2 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-6VUFrqq716QycJo2 :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>Model<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>MCP Client<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>MCP2Lambda(MCP Server)<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>Lambda Function<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>Other AWS Services<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>Internet<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>VPC<\/p>\n<p><\/span><\/p>\n<p>mcp\u7684\u914d\u7f6e\u793a\u4f8b\u5982\u4e0b<\/p>\n<p><span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token string-property property\">&#034;mcpServers&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token string-property property\">&#034;awslabs.lambda-tool-mcp-server&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n      <span class=\"token string-property property\">&#034;command&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;uvx&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n      <span class=\"token string-property property\">&#034;args&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;awslabs.lambda-tool-mcp-server&#064;latest&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n      <span class=\"token string-property property\">&#034;env&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string-property property\">&#034;AWS_PROFILE&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;your-aws-profile&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string-property property\">&#034;AWS_REGION&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;us-east-1&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string-property property\">&#034;FUNCTION_LIST&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;your-first-function, your-second-function&#034;<\/span><br \/>\n      <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n  <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u4f7f\u7528Lambda Web Adapter\u8f6c\u53d1\u8bf7\u6c42<\/h4>\n<p>Lambda Web Adapter \u662f\u4e00\u4e2a\u7528 Rust \u7f16\u5199\u7684\u6269\u5c55&#xff0c;\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6&#xff0c;\u4f5c\u4e3a Lambda \u5c42\u7684\u6269\u5c55\u8fd0\u884c\u3002\u5b83\u4f1a\u5c06 Lambda \u7684 HTTP \u8bf7\u6c42\u8f6c\u6362\u4e3a\u6807\u51c6\u7684 HTTP \u8c03\u7528\u53d1\u9001\u7ed9 Python \u8fdb\u7a0b&#xff08;\u5982 FastAPI \u6216\u76f4\u63a5\u8fd0\u884c\u7684 MCP Server&#xff09;\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212020654-698d35bef2097.png\" alt=\"Lambda Web Adapter\" \/><\/p>\n<p>\u5177\u4f53\u6d41\u7a0b\u5982\u4e0b<\/p>\n<ul>\n<li>HTTP \u8bf7\u6c42 \u2192 API Gateway \/ ALB \u5411 Lambda \u51fd\u6570\u53d1\u9001\u4e8b\u4ef6<\/li>\n<li>Lambda runtime \u2192 \u63a5\u6536\u4e8b\u4ef6<\/li>\n<li>Lambda adapter \u2192 \u5c06 Lambda \u4e8b\u4ef6\u8f6c\u6362\u4e3a HTTP \u8bf7\u6c42<\/li>\n<li>\u4e1a\u52a1 Web \u5e94\u7528 \u2192 \u5728 8080 \u7aef\u53e3\u63a5\u6536\u6807\u51c6 HTTP \u8bf7\u6c42<\/li>\n<li>\u54cd\u5e94\u6d41\u7a0b \u2192 adapter \u5c06 HTTP \u54cd\u5e94\u8fd8\u539f\u4e3a Lambda \u683c\u5f0f<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u548c\u81ea\u5b9a\u4e49\u7684MCP\u9002\u914d\u5668\u7684\u505a\u6cd5\u6bd4\u8f83\u7c7b\u4f3c<\/p>\n<h3>\u901a\u8fc7Lambda Web Adapter\u5b9e\u73b0MCP\u670d\u52a1<\/h3>\n<p>Lambda Web Adapter (LWA) \u662f\u4e00\u4e2a\u7531 AWS \u5b98\u65b9\u63a8\u51fa\u7684\u5f00\u6e90\u9879\u76ee&#xff0c;\u80fd\u5728\u4e0d\u4fee\u6539\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b&#xff0c;\u628a\u4efb\u4f55\u4f7f\u7528\u6807\u51c6 HTTP \u534f\u8bae\u7684 Web \u5e94\u7528\u76f4\u63a5\u8dd1\u5728 AWS Lambda \u4e0a\u3002Model Context Protocol (MCP) \u4f20\u7edf\u4e0a\u591a\u7528\u4e8e\u672c\u5730 stdio \u901a\u4fe1&#xff0c;\u4f46\u8981\u90e8\u7f72\u5230Lambda\u9700\u8981\u4f7f\u7528 Streamable HTTP\u6a21\u5f0f\u3002\u8fd9\u91cc\u4f7f\u7528 FastAPI &#043; FastMCP &#xff0c;\u5e76\u901a\u8fc7 LWA \u6253\u5305\u6210 Docker \u955c\u50cf\u90e8\u7f72\u3002<\/p>\n<p>\u5f53\u4e00\u4e2a\u65b0\u7684 Lambda \u6267\u884c\u73af\u5883\u542f\u52a8\u65f6&#xff0c;Lambda Web Adapter \u4f1a\u4f5c\u4e3a Lambda \u6269\u5c55\u542f\u52a8&#xff0c;\u968f\u540e\u662f Web \u5e94\u7528\u7a0b\u5e8f\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;Lambda Web Adapter \u4f1a\u5411 Web \u5e94\u7528\u7a0b\u5e8f\u53d1\u9001 HTTP GET \u8bf7\u6c42\u5230 http:\/\/127.0.0.1:8080\/\u3002\u7aef\u53e3\u53f7\u548c\u8def\u5f84\u53ef\u4ee5\u901a\u8fc7\u4e24\u4e2a\u73af\u5883\u53d8\u91cf AWS_LWA_READINESS_CHECK_PORT \u548c AWS_LWA_READINESS_CHECK_PATH \u8fdb\u884c\u81ea\u5b9a\u4e49\u3002<\/p>\n<p>Lambda Web Adapter \u5c06\u6bcf\u9694 10 \u6beb\u79d2\u91cd\u8bd5\u6b64\u8bf7\u6c42&#xff0c;\u76f4\u5230 Web \u5e94\u7528\u8fd4\u56de HTTP \u54cd\u5e94&#xff08; \u72b6\u6001\u7801 &gt;&#061; 100 \u4e14 &lt; 500&#xff09;\u6216\u51fd\u6570\u8d85\u65f6\u3002\u6b64\u5916&#xff0c;\u60a8\u53ef\u4ee5\u901a\u8fc7\u5c06 AWS_LWA_READINESS_CHECK_PROTOCOL \u8bbe\u7f6e\u4e3a tcp \u6765\u914d\u7f6e\u9002\u914d\u5668\u4f7f\u7528 TCP \u8fde\u63a5\u8fdb\u884c\u5c31\u7eea\u68c0\u67e5\u3002\u901a\u8fc7\u5c31\u7eea\u68c0\u67e5\u540e&#xff0c;Lambda Web Adapter \u5c06\u542f\u52a8 Lambda \u8fd0\u884c\u65f6\u5e76\u5c06\u8c03\u7528\u8f6c\u53d1\u5230 Web \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u8981\u4f7f\u7528 Lambda Web Adapter \u4e0e Docker \u955c\u50cf\u4e00\u8d77\u4f7f\u7528&#xff0c;\u9700\u8981\u5728 Dockerfile \u4e2d\u6253\u5305\u7684 Web \u5e94\u7528&#xff08;HTTP API&#xff09;&#xff0c;\u5e76\u5728\u5bb9\u5668\u5185\u7684 \/opt\/extensions \u4e2d\u6dfb\u52a0\u4e00\u884c\u6765\u590d\u5236 Lambda Web Adapter \u4e8c\u8fdb\u5236\u6587\u4ef6<\/p>\n<p>COPY &#8211;from&#061;public.ecr.aws\/awsguru\/aws-lambda-adapter:0.9.1 \/lambda-adapter \/opt\/extensions\/lambda-adapter<\/p>\n<p>\u4e2d\u56fd\u533a\u4e5f\u63d0\u4f9b\u4e86\u4e8b\u5148\u6253\u5305\u597d\u7684layer\u4f9b\u7528\u6237\u4f7f\u7528<\/p>\n<p>arn:aws-cn:lambda:cn-north-1:041581134020:layer:LambdaAdapterLayerX86:25<br \/>\narn:aws-cn:lambda:cn-northwest-1:069767869989:layer:LambdaAdapterLayerX86:25<\/p>\n<p>\u9996\u5148\u7f16\u5199mcp\u670d\u52a1\u903b\u8f91\u5982\u4e0b&#xff0c;\u5b9e\u73b0\u4e00\u4e2a\u67e5\u8be2\u662f\u5426\u4e3a\u8282\u5047\u65e5\u7684\u670d\u52a1<\/p>\n<p><span class=\"token keyword\">from<\/span> fastmcp <span class=\"token keyword\">import<\/span> FastMCP<br \/>\n<span class=\"token keyword\">import<\/span> holidays<br \/>\n<span class=\"token keyword\">from<\/span> datetime <span class=\"token keyword\">import<\/span> date<br \/>\nmcp <span class=\"token operator\">&#061;<\/span> FastMCP<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;HolidayChecker&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token decorator annotation punctuation\">&#064;mcp<span class=\"token punctuation\">.<\/span>tool<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">check_holiday<\/span><span class=\"token punctuation\">(<\/span>country<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;CN&#034;<\/span><span class=\"token punctuation\">,<\/span> date_str<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;<br \/>\n    \u68c0\u67e5\u6307\u5b9a\u65e5\u671f\u662f\u5426\u4e3a\u516c\u5171\u8282\u5047\u65e5\u3002<br \/>\n    :param country: ISO\u56fd\u5bb6\u4ee3\u7801 (\u5982 &#039;CN&#039;, &#039;US&#039;)<br \/>\n    :param date_str: \u65e5\u671f\u683c\u5f0f &#039;YYYY-MM-DD&#039;&#xff0c;\u4e0d\u4f20\u5219\u9ed8\u8ba4\u4e3a\u4eca\u5929<br \/>\n    &#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token comment\"># \u5982\u679c\u4e0d\u4f20\u65e5\u671f&#xff0c;\u9ed8\u8ba4\u53d6\u4eca\u5929<\/span><br \/>\n        target_date <span class=\"token operator\">&#061;<\/span> date<span class=\"token punctuation\">.<\/span>fromisoformat<span class=\"token punctuation\">(<\/span>date_str<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">if<\/span> date_str <span class=\"token keyword\">else<\/span> date<span class=\"token punctuation\">.<\/span>today<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\"># \u83b7\u53d6\u8be5\u56fd\u5bb6\u7684\u8282\u65e5\u5217\u8868<\/span><br \/>\n        country_holidays <span class=\"token operator\">&#061;<\/span> holidays<span class=\"token punctuation\">.<\/span>country_holidays<span class=\"token punctuation\">(<\/span>country<span class=\"token punctuation\">)<\/span><br \/>\n        holiday_name <span class=\"token operator\">&#061;<\/span> country_holidays<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>target_date<span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token keyword\">if<\/span> holiday_name<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>target_date<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> \u662f <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>country<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> \u7684\u8282\u5047\u65e5: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>holiday_name<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>target_date<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> \u4e0d\u662f <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>country<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> \u7684\u516c\u5171\u8282\u5047\u65e5&#034;<\/span><\/span><br \/>\n    <span class=\"token keyword\">except<\/span> Exception <span class=\"token keyword\">as<\/span> e<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;\u67e5\u8be2\u5931\u8d25: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><br \/>\nmcp<span class=\"token punctuation\">.<\/span>run<span class=\"token punctuation\">(<\/span>transport<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;http&#034;<\/span><span class=\"token punctuation\">,<\/span> host<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;0.0.0.0&#034;<\/span><span class=\"token punctuation\">,<\/span> port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">8080<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u672c\u5730\u542f\u52a8\u540e\u68c0\u67e5\u8fde\u63a5\u6b63\u5e38<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212020656-698d35c0c1f3c.png\" alt=\"image-20260126194544514\" \/><\/p>\n<p>\u521b\u5efadockerfile\u6253\u5305\u955c\u50cf<\/p>\n<p>FROM public.ecr.aws\/docker\/library\/python:3.12-slim<\/p>\n<p># \u4ece LWA \u955c\u50cf\u4e2d\u590d\u5236\u9002\u914d\u5668\u4e8c\u8fdb\u5236\u6587\u4ef6<br \/>\nCOPY &#8211;from&#061;public.ecr.aws\/awsguru\/aws-lambda-adapter:0.9.1 \/lambda-adapter \/opt\/extensions\/lambda-adapter<\/p>\n<p>WORKDIR \/var\/task<br \/>\nCOPY requirements.txt .<br \/>\nRUN pip install -r requirements.txt<br \/>\nCOPY app.py .<br \/>\nENV PORT&#061;8080<br \/>\nEXPOSE 8080<br \/>\nCMD [&#034;uvicorn&#034;, &#034;app:app&#034;, &#034;&#8211;host&#034;, &#034;0.0.0.0&#034;, &#034;&#8211;port&#034;, &#034;8080&#034;]<\/p>\n<p>\u6784\u5efa\u955c\u50cf\u5e76\u63a8\u9001\u5230ECR\u4ed3\u5e93\u968f\u540e\u90e8\u7f72lambda\u51fd\u6570\u3002\u901a\u8fc7alb\u5c06lambda\u66b4\u9732\u51fa\u6765&#xff0c;\u8fd9\u91cclambda\u4e0d\u9700\u8981\u914d\u7f6evpc\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212020657-698d35c16647e.png\" alt=\"image-20260126203614763\" \/><\/p>\n<p>\u5728\u5c1d\u8bd5\u5ba2\u6237\u7aef\u4ee3\u7801\u51fa\u73b0\u62a5\u9519<\/p>\n<p>Error <span class=\"token keyword\">from<\/span> <span class=\"token constant\">MCP<\/span> <span class=\"token literal-property property\">server<\/span><span class=\"token operator\">:<\/span> StreamableHTTPError<span class=\"token operator\">:<\/span> Streamable <span class=\"token constant\">HTTP<\/span> <span class=\"token literal-property property\">error<\/span><span class=\"token operator\">:<\/span> Error POSTing to endpoint<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string-property property\">&#034;jsonrpc&#034;<\/span><span class=\"token operator\">:<\/span><span class=\"token string\">&#034;2.0&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string-property property\">&#034;id&#034;<\/span><span class=\"token operator\">:<\/span><span class=\"token string\">&#034;server-error&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string-property property\">&#034;error&#034;<\/span><span class=\"token operator\">:<\/span><span class=\"token punctuation\">{<\/span><span class=\"token string-property property\">&#034;code&#034;<\/span><span class=\"token operator\">:<\/span><span class=\"token operator\">&#8211;<\/span><span class=\"token number\">32600<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string-property property\">&#034;message&#034;<\/span><span class=\"token operator\">:<\/span><span class=\"token string\">&#034;Session not found&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">}<\/span><br \/>\n    at StreamableHTTPClientTransport<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span> <span class=\"token punctuation\">(<\/span>file<span class=\"token operator\">:<\/span><span class=\"token operator\">\/<\/span><span class=\"token comment\">\/\/home\/ec2-user\/.npm\/_npx\/5a9d879542beca3a\/node_modules\/&#064;modelcontextprotocol\/sdk\/dist\/esm\/client\/streamableHttp.js:364:23)<\/span><br \/>\n    at process<span class=\"token punctuation\">.<\/span><span class=\"token function\">processTicksAndRejections<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\"><span class=\"token literal-property property\">node<\/span><span class=\"token operator\">:<\/span>internal<span class=\"token operator\">\/<\/span>process<span class=\"token operator\">\/<\/span>task_queues<span class=\"token operator\">:<\/span><span class=\"token number\">105<\/span><span class=\"token operator\">:<\/span><span class=\"token number\">5<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token literal-property property\">code<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">404<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u68c0\u67e5\u53d1\u73b0FastMCP \u5b9e\u9645\u4e0a\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5173\u952e\u7684\u53c2\u6570&#xff1a;stateless_http\u3002\u5728 Lambda \u8fd9\u79cd\u65e0\u72b6\u6001\u7684\u73af\u5883\u4e2d&#xff0c;\u9ed8\u8ba4\u7684\u6709\u72b6\u6001&#xff08;Stateful&#xff09;SSE \u4f1a\u56e0\u4e3a\u627e\u4e0d\u5230 sessionId \u800c\u5d29\u6e83\u3002\u8981\u89e3\u51b3 Session not found \u9519\u8bef&#xff0c;\u9700\u8981\u5728 mcp.run \u4e2d\u5f00\u542f \u65e0\u72b6\u6001\u6a21\u5f0f&#xff0c;\u660e\u786e\u6307\u5b9a stateless_http&#061;True<\/p>\n<p>mcp.run(transport&#061;&#034;http&#034;, host&#061;&#034;0.0.0.0&#034;, port&#061;8080, stateless_http&#061;True)<\/p>\n<p>\u6709\u72b6\u6001\u548c\u65e0\u72b6\u6001\u670d\u52a1\u7684\u533a\u522b&#xff1f;<\/p>\n<ul>\n<li>\u6709\u72b6\u6001\u6a21\u5f0f&#xff08;\u9ed8\u8ba4&#xff09;\n<ul>\n<li>\u5ba2\u6237\u7aef\u5efa\u7acb SSE \u8fde\u63a5&#xff0c;\u670d\u52a1\u5668\u5728\u5185\u5b58\u4e2d\u521b\u5efa\u4e00\u4e2a Session\u3002<\/li>\n<li>\u5ba2\u6237\u7aef\u53d1\u9001 POST \u8bf7\u6c42\u6267\u884c Tool\u3002<\/li>\n<li>\u670d\u52a1\u5668\u6839\u636e POST \u91cc\u7684 sessionId \u53bb\u5185\u5b58\u627e\u90a3\u4e2a\u8fde\u63a5\u3002\u7531\u4e8e Lambda \u4f1a\u81ea\u52a8\u9500\u6bc1\u6216\u6269\u5c55&#xff0c;POST \u8bf7\u6c42\u53ef\u80fd\u6253\u5230\u4e86\u5b9e\u4f8b B&#xff0c;\u800c SSE \u8fde\u63a5\u5728\u5b9e\u4f8b A&#xff0c;\u5bfc\u81f4 Session not found\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u65e0\u72b6\u6001\u6a21\u5f0f (stateless_http&#061;True)\n<ul>\n<li>\u670d\u52a1\u5668\u4e0d\u518d\u5f3a\u4f9d\u8d56\u5185\u5b58\u4e2d\u7684 Session \u7ed1\u5b9a\u3002<\/li>\n<li>\u5b83\u5141\u8bb8\u8bf7\u6c42\u4ee5\u66f4\u6807\u51c6\u3001\u72ec\u7acb\u7684\u65b9\u5f0f\u5904\u7406&#xff0c;\u975e\u5e38\u9002\u5408 Lambda \u8fd9\u79cd\u4e00\u6b21\u6027\u7684\u6267\u884c\u903b\u8f91\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u52a0\u4e0a\u53c2\u6570\u540e\u4f7f\u7528strands\u786e\u5b9e\u8c03\u7528\u6210\u529f\u4e86&#xff0c;\u4f46\u662fmcp inspector\u4f1a\u51fa\u73b0\u8d85\u65f6\u76ee\u524d\u8fd8\u4e0d\u77e5\u9053\u539f\u56e0\u3002\u5ba2\u6237\u7aef\u4ee3\u7801\u5982\u4e0b<\/p>\n<p><span class=\"token keyword\">from<\/span> mcp<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>streamable_http <span class=\"token keyword\">import<\/span> streamablehttp_client<br \/>\n<span class=\"token keyword\">from<\/span> strands<span class=\"token punctuation\">.<\/span>tools<span class=\"token punctuation\">.<\/span>mcp<span class=\"token punctuation\">.<\/span>mcp_client <span class=\"token keyword\">import<\/span> MCPClient<br \/>\n<span class=\"token keyword\">from<\/span> strands <span class=\"token keyword\">import<\/span> Agent<br \/>\n<span class=\"token keyword\">from<\/span> strands<span class=\"token punctuation\">.<\/span>models<span class=\"token punctuation\">.<\/span>openai <span class=\"token keyword\">import<\/span> OpenAIModel<br \/>\n<span class=\"token keyword\">import<\/span> logging<br \/>\nlogging<span class=\"token punctuation\">.<\/span>basicConfig<span class=\"token punctuation\">(<\/span>level<span class=\"token operator\">&#061;<\/span>logging<span class=\"token punctuation\">.<\/span>DEBUG<span class=\"token punctuation\">)<\/span><\/p>\n<p>streamable_http_mcp_client <span class=\"token operator\">&#061;<\/span> MCPClient<span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token keyword\">lambda<\/span><span class=\"token punctuation\">:<\/span> streamablehttp_client<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;http:\/\/172.31.2.178:8090\/mcp&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p>litellm_model <span class=\"token operator\">&#061;<\/span> OpenAIModel<span class=\"token punctuation\">(<\/span><br \/>\n    model_id<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;gpt-4o-mini&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    client_args<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string\">&#034;api_key&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;sk-uzpq0u0n5FN14HorW45hUw&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#034;base_url&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;http:\/\/localhost:4000&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># Create an agent with MCP tools<\/span><br \/>\n<span class=\"token keyword\">with<\/span> streamable_http_mcp_client<span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        tools <span class=\"token operator\">&#061;<\/span> streamable_http_mcp_client<span class=\"token punctuation\">.<\/span>list_tools_sync<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> tool <span class=\"token keyword\">in<\/span> tools<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>tool<span class=\"token punctuation\">.<\/span>tool_name<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token comment\"># print(&#034;Tools:&#034;, tools)<\/span><br \/>\n        agent <span class=\"token operator\">&#061;<\/span> Agent<span class=\"token punctuation\">(<\/span><br \/>\n            model<span class=\"token operator\">&#061;<\/span>litellm_model<span class=\"token punctuation\">,<\/span><br \/>\n            tools<span class=\"token operator\">&#061;<\/span>tools<span class=\"token punctuation\">,<\/span><br \/>\n            system_prompt<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;You are a helpful assistant.&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><br \/>\n        response <span class=\"token operator\">&#061;<\/span> agent<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;What festival is on October 18st?&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">except<\/span> Exception <span class=\"token keyword\">as<\/span> e<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Connection failed:&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token builtin\">repr<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212020657-698d35c1c4d0d.png\" alt=\"image-20260126204723209\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\u8d44\u6599<br \/>\nhttps:\/\/github.com\/awslabs\/run-model-context-protocol-servers-with-aws-lambdahttps:\/\/aws.amazon.com\/cn\/blogs\/china\/deploy-streamable-http-github-mcp-server-using-amazon-lambda\/https:\/\/modelcontextprotocol.io\/specification\/2025-06-18\/b<\/p>\n","protected":false},"author":2,"featured_media":75436,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[66,593,44],"topic":[],"class_list":["post-75440","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-ai","tag-aws","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5728Lambda\u51fd\u6570\u4e2d\u7f16\u5199\u548c\u90e8\u7f72MCP\u670d\u52a1\u5668\u7684\u65b9\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/75440.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5728Lambda\u51fd\u6570\u4e2d\u7f16\u5199\u548c\u90e8\u7f72MCP\u670d\u52a1\u5668\u7684\u65b9\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u53c2\u8003\u8d44\u6599 https:\/\/github.com\/awslabs\/run-model-context-protocol-servers-with-aws-lambdahttps:\/\/aws.amazon.com\/cn\/blogs\/china\/deploy-streamable-http-github-mcp-server-using-amazon-lambda\/https:\/\/modelcontextprotocol.io\/specification\/2025-06-18\/b\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/75440.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-12T02:06:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212020654-698d35bef2097.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/75440.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/75440.html\",\"name\":\"\u5728Lambda\u51fd\u6570\u4e2d\u7f16\u5199\u548c\u90e8\u7f72MCP\u670d\u52a1\u5668\u7684\u65b9\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-12T02:06:59+00:00\",\"dateModified\":\"2026-02-12T02:06:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/75440.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/75440.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/75440.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5728Lambda\u51fd\u6570\u4e2d\u7f16\u5199\u548c\u90e8\u7f72MCP\u670d\u52a1\u5668\u7684\u65b9\u6cd5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5728Lambda\u51fd\u6570\u4e2d\u7f16\u5199\u548c\u90e8\u7f72MCP\u670d\u52a1\u5668\u7684\u65b9\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/75440.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5728Lambda\u51fd\u6570\u4e2d\u7f16\u5199\u548c\u90e8\u7f72MCP\u670d\u52a1\u5668\u7684\u65b9\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u53c2\u8003\u8d44\u6599 https:\/\/github.com\/awslabs\/run-model-context-protocol-servers-with-aws-lambdahttps:\/\/aws.amazon.com\/cn\/blogs\/china\/deploy-streamable-http-github-mcp-server-using-amazon-lambda\/https:\/\/modelcontextprotocol.io\/specification\/2025-06-18\/b","og_url":"https:\/\/www.wsisp.com\/helps\/75440.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-12T02:06:59+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212020654-698d35bef2097.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/75440.html","url":"https:\/\/www.wsisp.com\/helps\/75440.html","name":"\u5728Lambda\u51fd\u6570\u4e2d\u7f16\u5199\u548c\u90e8\u7f72MCP\u670d\u52a1\u5668\u7684\u65b9\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-12T02:06:59+00:00","dateModified":"2026-02-12T02:06:59+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/75440.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/75440.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/75440.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5728Lambda\u51fd\u6570\u4e2d\u7f16\u5199\u548c\u90e8\u7f72MCP\u670d\u52a1\u5668\u7684\u65b9\u6cd5"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/75440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=75440"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/75440\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/75436"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=75440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=75440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=75440"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=75440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}