{"id":114061,"date":"2026-10-08T08:18:13","date_gmt":"2026-10-08T00:18:13","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/114061.html"},"modified":"2026-10-08T08:18:13","modified_gmt":"2026-10-08T00:18:13","slug":"%e5%9c%a8-cloud-run-%e4%b8%8a%e9%83%a8%e7%bd%b2%e8%bf%9c%e7%a8%8b-mcp-%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%9apython-docs-samples-%e4%b8%ad-run-mcp-server-%e7%9a%84%e5%ae%8c%e6%95%b4%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/114061.html","title":{"rendered":"\u5728 Cloud Run \u4e0a\u90e8\u7f72\u8fdc\u7a0b MCP \u670d\u52a1\u5668\uff1apython-docs-samples \u4e2d run\/mcp-server \u7684\u5b8c\u6574\u5b9e\u6218\u6307\u5357"},"content":{"rendered":"<ul class=\"gcb-tag-list\">\n<li><span class=\"gcb-tag\">\u793a\u4f8b\u5de5\u7a0b<\/span><\/li>\n<\/ul>\n<h3 class=\"gcb-project-title\">\u3010\u514d\u8d39\u4e0b\u8f7d\u94fe\u63a5\u3011python-docs-samples<\/h3>\n<p class=\"gcb-project-desc\">Code samples used on cloud.google.com<\/p>\n<p>    <span class=\"gcb-project-addr-label\">\u9879\u76ee\u5730\u5740&#xff1a;<\/span><br \/>\n    <span class=\"gcb-project-addr-link\">https:\/\/gitcode.com\/GitHub_Trending\/py\/python-docs-samples<\/span> <\/p>\n<p>  <span class=\"gcb-project-btn\"> <span class=\"gcb-project-btn-main\">\u70b9\u51fb\u67e5\u770b<\/span> <span class=\"gcb-project-btn-sub\">\u514d\u8d39\u4e0b\u8f7d<\/span> <\/span> <\/p>\n<p>\u672c\u6587\u57fa\u4e8e python-docs-samples \u4ed3\u5e93\u4e2d\u7684 run\/mcp-server \u793a\u4f8b&#xff0c;\u7cfb\u7edf\u8bb2\u89e3\u5982\u4f55\u5c06\u4e00\u4e2a\u57fa\u4e8e FastMCP \u7684\u8fdc\u7a0b MCP&#xff08;Model Context Protocol&#xff09;\u670d\u52a1\u5668\u90e8\u7f72\u5230 Cloud Run&#xff0c;\u5e76\u901a\u8fc7 streamable-http \u4f20\u8f93\u3001IAM \u8ba4\u8bc1\u3001Cloud Run Proxy \u96a7\u9053\u4e0e OpenTelemetry \u89c2\u6d4b\u5b8c\u6210\u4ece\u5f00\u53d1\u5230\u4e0a\u7ebf\u7684\u5168\u6d41\u7a0b\u3002\u8bfb\u5b8c\u672c\u6587&#xff0c;\u4f60\u5c06\u638c\u63e1\u8fdc\u7a0b MCP \u670d\u52a1\u5668\u7684\u90e8\u7f72\u547d\u4ee4\u3001\u5ba2\u6237\u7aef\u8ba4\u8bc1\u673a\u5236\u3001\u672c\u5730\u4ee3\u7406\u6d4b\u8bd5\u65b9\u6cd5\u4ee5\u53ca\u53ef\u89c2\u6d4b\u6027\u914d\u7f6e&#xff0c;\u80fd\u591f\u76f4\u63a5\u590d\u73b0\u4e00\u4e2a\u53ef\u88ab\u56e2\u961f\u6210\u5458\u5171\u4eab\u8bbf\u95ee\u7684\u4e91\u7aef MCP \u670d\u52a1\u3002<\/p>\n<h3>\u4e3a\u4ec0\u4e48\u8981\u628a MCP \u670d\u52a1\u5668\u8fd0\u884c\u5728\u4e91\u7aef<\/h3>\n<p>MCP&#xff08;Model Context Protocol&#xff09;\u662f\u8ba9 LLM \u5e94\u7528\u4e0e\u5916\u90e8\u5de5\u5177\u3001\u6570\u636e\u6e90\u4ea4\u4e92\u7684\u5f00\u653e\u534f\u8bae\u3002\u4f20\u7edf\u4e0a&#xff0c;MCP \u670d\u52a1\u5668\u591a\u8fd0\u884c\u5728\u5f00\u53d1\u8005\u672c\u673a&#xff0c;\u4f46\u6b63\u5982 run\/mcp-server\/README.md \u6240\u8ff0&#xff0c;\u628a MCP \u670d\u52a1\u5668\u8fdc\u7a0b\u90e8\u7f72\u5230 Cloud Run \u53ef\u4ee5\u83b7\u5f97\u4e09\u4e2a\u6838\u5fc3\u6536\u76ca&#xff1a;<\/p>\n<ul>\n<li>\u5f39\u6027\u4f38\u7f29&#xff08;Scalability&#xff09;&#xff1a;Cloud Run \u57fa\u4e8e\u8bf7\u6c42\u91cf\u81ea\u52a8\u6269\u7f29\u5bb9&#xff0c;MCP \u670d\u52a1\u5668\u65e0\u9700\u9884\u7559\u8d44\u6e90\u5373\u53ef\u5e73\u6ed1\u5e94\u5bf9\u7a81\u53d1\u8c03\u7528&#xff0c;\u7a7a\u95f2\u65f6\u7f29\u5230\u96f6&#xff0c;\u4e0d\u4ea7\u751f\u591a\u4f59\u8d39\u7528\u3002<\/li>\n<li>\u96c6\u4e2d\u5f0f\u670d\u52a1\u5668&#xff08;Centralized server&#xff09;&#xff1a;\u56e2\u961f\u6210\u5458\u4e0d\u518d\u9700\u8981\u5404\u81ea\u5728\u672c\u673a\u7ef4\u62a4\u4e00\u5957 MCP \u670d\u52a1\u5668&#xff0c;\u800c\u662f\u901a\u8fc7 IAM \u6743\u9650\u5171\u4eab\u540c\u4e00\u4e2a\u96c6\u4e2d\u5f0f\u670d\u52a1\u3002\u5f53\u670d\u52a1\u5668\u66f4\u65b0\u4e86\u65b0\u5de5\u5177\u6216\u4fee\u590d\u4e86\u7f3a\u9677&#xff0c;\u6240\u6709\u6210\u5458\u7acb\u5373\u53d7\u76ca&#xff0c;\u907f\u514d\u4e86&#034;\u5404\u8dd1\u5404\u7684\u3001\u7248\u672c\u6f02\u79fb&#034;\u7684\u7ef4\u62a4\u6210\u672c\u3002<\/li>\n<li>\u5b89\u5168\u53ef\u63a7&#xff08;Security&#xff09;&#xff1a;Cloud Run \u539f\u751f\u652f\u6301\u5f3a\u5236\u8ba4\u8bc1\u8bf7\u6c42&#xff0c;\u53ef\u4ee5\u53ea\u5141\u8bb8\u7ecf\u8fc7\u6388\u6743\u7684\u8fde\u63a5\u8bbf\u95ee MCP \u670d\u52a1\u5668&#xff0c;\u9632\u6b62\u672a\u6388\u6743\u8bbf\u95ee\u548c\u6ee5\u7528\u3002<\/li>\n<\/ul>\n<p>[!IMPORTANT] \u5b89\u5168\u8fd9\u4e00\u70b9\u81f3\u5173\u91cd\u8981\u3002\u5982\u679c\u90e8\u7f72\u65f6\u4e0d\u5f3a\u5236\u8ba4\u8bc1&#xff0c;\u516c\u7f51\u4e0a\u7684\u4efb\u4f55\u4eba\u90fd\u53ef\u80fd\u8bbf\u95ee\u5e76\u8c03\u7528\u4f60\u7684 MCP \u670d\u52a1\u5668&#xff0c;\u8fdb\u800c\u89e6\u53d1\u5176\u4e2d\u7684\u5de5\u5177\u9020\u6210\u7cfb\u7edf\u635f\u5bb3\u3002\u56e0\u6b64\u672c\u793a\u4f8b\u7684\u6240\u6709\u90e8\u7f72\u547d\u4ee4\u90fd\u663e\u5f0f\u643a\u5e26\u4e86 &#8211;no-allow-unauthenticated \u53c2\u6570\u3002<\/p>\n<h3>\u793a\u4f8b\u6982\u89c8&#xff1a;\u4e00\u4e2a\u57fa\u4e8e FastMCP \u7684\u6570\u5b66 MCP \u670d\u52a1\u5668<\/h3>\n<h4>\u4e3a\u4ec0\u4e48\u9009\u62e9\u6570\u5b66\u5de5\u5177\u4f5c\u4e3a\u793a\u4f8b<\/h4>\n<p>LLM \u5728\u975e\u786e\u5b9a\u6027\u4efb\u52a1\u4e0a\u8868\u73b0\u51fa\u8272\u2014\u2014\u7406\u89e3\u610f\u56fe\u3001\u751f\u6210\u521b\u610f\u6587\u672c\u3001\u603b\u7ed3\u590d\u6742\u89c2\u70b9\u3001\u5bf9\u62bd\u8c61\u6982\u5ff5\u63a8\u7406&#xff1b;\u4f46\u5728\u786e\u5b9a\u6027\u4efb\u52a1\u4e0a\u5374\u6781\u4e0d\u53ef\u9760\u2014\u2014\u90a3\u4e9b\u53ea\u6709\u4e00\u4e2a\u4e14\u552f\u4e00\u6b63\u786e\u7b54\u6848\u7684\u8ba1\u7b97\u3002\u52a0\u51cf\u6cd5\u5c31\u662f\u5178\u578b\u4ee3\u8868\u3002<\/p>\n<p>\u672c\u793a\u4f8b\u901a\u8fc7\u628a add\u3001subtract \u4e24\u4e2a\u6570\u5b66\u5de5\u5177\u4ee5 MCP \u5de5\u5177\u7684\u5f62\u5f0f\u66b4\u9732\u7ed9 LLM&#xff0c;\u6f14\u793a\u4e86&#034;\u7528\u786e\u5b9a\u6027\u5de5\u5177\u8865\u507f LLM \u77ed\u677f&#034;\u8fd9\u4e00 MCP \u7684\u6838\u5fc3\u4ef7\u503c\u573a\u666f&#xff1a;LLM \u4e0d\u518d\u81ea\u5df1&#034;\u731c&#034;\u8ba1\u7b97\u7ed3\u679c&#xff0c;\u800c\u662f\u8c03\u7528\u7ecf\u8fc7\u9a8c\u8bc1\u7684\u5de5\u5177\u83b7\u5f97\u7cbe\u786e\u7b54\u6848\u3002<\/p>\n<h4>\u6838\u5fc3\u5b9e\u73b0&#xff1a;server.py<\/h4>\n<p>\u793a\u4f8b\u4f7f\u7528 FastMCP&#xff1a;<\/p>\n<p># [START cloudrun_mcpserver]<br \/>\nimport asyncio<br \/>\nimport logging<br \/>\nimport os<\/p>\n<p>from fastmcp import FastMCP<\/p>\n<p>logger &#061; logging.getLogger(__name__)<br \/>\nlogging.basicConfig(format&#061;&#034;[%(levelname)s]: %(message)s&#034;, level&#061;logging.INFO)<\/p>\n<p>mcp &#061; FastMCP(&#034;MCP Server on Cloud Run&#034;)<\/p>\n<p>&#064;mcp.tool()<br \/>\ndef add(a: int, b: int) -&gt; int:<br \/>\n    &#034;&#034;&#034;Use this to add two numbers together.<\/p>\n<p>    Args:<br \/>\n        a: The first number.<br \/>\n        b: The second number.<\/p>\n<p>    Returns:<br \/>\n        The sum of the two numbers.<br \/>\n    &#034;&#034;&#034;<br \/>\n    logger.info(f&#034;&gt;&gt;&gt; &#x1f6e0;\ufe0f Tool: &#039;add&#039; called with numbers &#039;{a}&#039; and &#039;{b}&#039;&#034;)<br \/>\n    return a &#043; b<\/p>\n<p>&#064;mcp.tool()<br \/>\ndef subtract(a: int, b: int) -&gt; int:<br \/>\n    &#034;&#034;&#034;Use this to subtract two numbers.<\/p>\n<p>    Args:<br \/>\n        a: The first number.<br \/>\n        b: The second number.<\/p>\n<p>    Returns:<br \/>\n        The difference of the two numbers.<br \/>\n    &#034;&#034;&#034;<br \/>\n    logger.info(f&#034;&gt;&gt;&gt; &#x1f6e0;\ufe0f Tool: &#039;subtract&#039; called with numbers &#039;{a}&#039; and &#039;{b}&#039;&#034;)<br \/>\n    return a &#8211; b<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    logger.info(f&#034;&#x1f680; MCP server started on port {os.getenv(&#039;PORT&#039;, 8080)}&#034;)<br \/>\n    # Could also use &#039;sse&#039; transport, host&#061;&#034;0.0.0.0&#034; required for Cloud Run.<br \/>\n    asyncio.run(<br \/>\n        mcp.run_async(<br \/>\n            transport&#061;&#034;streamable-http&#034;,<br \/>\n            host&#061;&#034;0.0.0.0&#034;,<br \/>\n            port&#061;os.getenv(&#034;PORT&#034;, 8080),<br \/>\n        )<br \/>\n    )<br \/>\n# [END cloudrun_mcpserver]<\/p>\n<p>\u4ece\u6e90\u7801&#xff08;server.py&#xff09;\u53ef\u4ee5\u770b\u5230\u51e0\u4e2a\u5173\u952e\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u901a\u8fc7 &#064;mcp.tool() \u88c5\u9970\u5668\u5c06\u666e\u901a Python \u51fd\u6570&#xff08;add\u3001subtract&#xff09;\u6ce8\u518c\u4e3a MCP \u5de5\u5177&#xff0c;\u51fd\u6570\u7684\u7c7b\u578b\u6ce8\u89e3&#xff08;a: int, b: int -&gt; int&#xff09;\u4e0e docstring \u4f1a\u88ab FastMCP \u81ea\u52a8\u8f6c\u6362\u4e3a\u5de5\u5177\u5143\u6570\u636e&#xff0c;\u4f9b LLM \u7406\u89e3\u8c03\u7528\u65b9\u5f0f\u3002<\/li>\n<li>\u6bcf\u4e2a\u5de5\u5177\u5185\u90e8\u8bb0\u5f55\u7ed3\u6784\u5316\u65e5\u5fd7&#xff0c;\u65b9\u4fbf\u5728 Cloud Logging \u4e2d\u8ffd\u8e2a\u6bcf\u6b21\u8c03\u7528\u53ca\u5176\u5165\u53c2\u3002<\/li>\n<li>\u5165\u53e3\u5904\u4f7f\u7528 transport&#061;&#034;streamable-http&#034;&#xff0c;\u8fd9\u662f\u8ba9 MCP \u670d\u52a1\u5668\u53ef\u8fdc\u7a0b\u8fd0\u884c\u7684\u5173\u952e\u4f20\u8f93\u5c42\u9009\u62e9&#xff1b;\u4ee3\u7801\u6ce8\u91ca\u540c\u65f6\u6307\u51fa\u4e5f\u53ef\u6539\u7528 sse \u4f20\u8f93\u3002\u65e0\u8bba\u54ea\u79cd\u4f20\u8f93&#xff0c;\u7ed1\u5b9a host&#061;&#034;0.0.0.0&#034; \u90fd\u662f Cloud Run \u5bb9\u5668\u73af\u5883\u6240\u5fc5\u9700\u7684&#xff0c;\u5426\u5219\u670d\u52a1\u65e0\u6cd5\u5bf9\u5916\u63a5\u6536\u6d41\u91cf\u3002<\/li>\n<li>\u7aef\u53e3\u901a\u8fc7\u73af\u5883\u53d8\u91cf PORT \u8bfb\u53d6&#xff0c;\u9ed8\u8ba4 8080&#xff0c;\u4e0e Cloud Run \u7684\u5bb9\u5668\u7aef\u53e3\u7ea6\u5b9a\u4fdd\u6301\u4e00\u81f4\u3002<\/li>\n<\/ul>\n<h4>\u4f9d\u8d56\u6e05\u5355&#xff1a;pyproject.toml<\/h4>\n<p>\u9879\u76ee\u7684\u4f9d\u8d56\u7531 pyproject.toml \u58f0\u660e&#xff0c;\u5e76\u4f7f\u7528 uv \u7ba1\u7406&#xff1a;<\/p>\n<p>[project]<br \/>\nname &#061; &#034;mcp-server&#034;<br \/>\nversion &#061; &#034;0.1.0&#034;<br \/>\ndescription &#061; &#034;Example of deploying an MCP server on Cloud Run&#034;<br \/>\nreadme &#061; &#034;README.md&#034;<br \/>\nrequires-python &#061; &#034;&gt;&#061;3.10&#034;<br \/>\ndependencies &#061; [<br \/>\n    &#034;fastmcp&#061;&#061;3.4.3&#034;,<br \/>\n    &#034;opentelemetry-api&#061;&#061;1.40.0&#034;,<br \/>\n    &#034;opentelemetry-sdk&#061;&#061;1.40.0&#034;,<br \/>\n    &#034;opentelemetry-exporter-otlp-proto-grpc&#061;&#061;1.40.0&#034;,<br \/>\n    &#034;google-auth&#061;&#061;2.49.1&#034;,<br \/>\n    &#034;grpcio&#061;&#061;1.80.0&#034;,<br \/>\n]<\/p>\n<p>\u5176\u4e2d requires-python &#061; &#034;&gt;&#061;3.10&#034; \u5bf9\u5e94 README \u4e2d Python 3.10&#043; \u7684\u524d\u7f6e\u8981\u6c42&#xff1b;opentelemetry-* \u4e0e google-auth\u3001grpcio \u4e3a\u53ef\u89c2\u6d4b\u6027\u6a21\u5757\u63d0\u4f9b\u652f\u6491&#xff08;\u8be6\u89c1\u540e\u6587&#034;OpenTelemetry \u89c2\u6d4b&#034;\u4e00\u8282&#xff09;\u3002\u4f9d\u8d56\u7248\u672c\u7684\u7cbe\u786e\u9501\u5b9a\u8bb0\u5f55\u5728 uv.lock \u4e2d&#xff0c;\u4fdd\u8bc1\u53ef\u590d\u73b0\u6784\u5efa\u3002<\/p>\n<h3>\u73af\u5883\u51c6\u5907\u4e0e\u9879\u76ee\u8bbe\u7f6e<\/h3>\n<h4>\u524d\u7f6e\u6761\u4ef6<\/h4>\n<p>\u6839\u636e run\/mcp-server\/README.md&#xff0c;\u90e8\u7f72\u524d\u9700\u8981\u51c6\u5907&#xff1a;<\/p>\n<ul>\n<li>Python 3.10&#043;&#xff1a;\u6ee1\u8db3 pyproject.toml \u4e2d requires-python &#061; &#034;&gt;&#061;3.10&#034; \u7684\u8981\u6c42&#xff1b;<\/li>\n<li>uv&#xff1a;\u7528\u4e8e\u5305\u7ba1\u7406\u4e0e\u9879\u76ee\u8fd0\u884c&#xff08;uv run\u3001uv sync \u7b49\u547d\u4ee4\u5747\u4f9d\u8d56\u5b83&#xff09;&#xff1b;<\/li>\n<li>Google Cloud SDK&#xff08;gcloud&#xff09;&#xff1a;\u7528\u4e8e\u8ba4\u8bc1\u3001\u90e8\u7f72\u4e0e\u4ee3\u7406\u3002<\/li>\n<\/ul>\n<h4>\u8bbe\u7f6e\u8ba4\u8bc1\u4e0e\u9879\u76ee<\/h4>\n<p>gcloud auth login<br \/>\nexport PROJECT_ID&#061;&lt;your-project-id&gt;<br \/>\ngcloud config set project $PROJECT_ID<\/p>\n<p>gcloud auth login \u5b8c\u6210\u7528\u6237\u8eab\u4efd\u8ba4\u8bc1&#xff1b;export PROJECT_ID \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf&#xff1b;gcloud config set project \u5c06\u5f53\u524d\u9879\u76ee\u5207\u6362\u4e3a\u76ee\u6807 GCP \u9879\u76ee\u3002\u540e\u7eed\u7684\u90e8\u7f72\u3001\u5efa\u4ed3\u3001\u4ee3\u7406\u547d\u4ee4\u90fd\u4f1a\u4f7f\u7528\u8be5\u914d\u7f6e\u3002<\/p>\n<h3>\u5c06 MCP \u670d\u52a1\u5668\u90e8\u7f72\u5230 Cloud Run<\/h3>\n<p>README \u63d0\u4f9b\u4e86\u4e24\u79cd\u90e8\u7f72\u65b9\u5f0f&#xff1a;\u4ece\u6e90\u7801\u76f4\u63a5\u90e8\u7f72\u4e0e\u901a\u8fc7\u5bb9\u5668\u955c\u50cf\u90e8\u7f72\u3002\u4e24\u6761\u8def\u5f84\u90fd\u4ee5 &#8211;no-allow-unauthenticated \u5f3a\u5236\u8981\u6c42\u8ba4\u8bc1\u2014\u2014\u8fd9\u662f\u51fa\u4e8e\u5b89\u5168\u8003\u8651\u7684\u5fc5\u8981\u8bbe\u7f6e&#xff1a;\u82e5\u4e0d\u7981\u7528\u533f\u540d\u8bbf\u95ee&#xff0c;\u4efb\u4f55\u4eba\u90fd\u80fd\u8c03\u7528\u4f60\u7684 MCP \u670d\u52a1\u5668&#xff0c;\u53ef\u80fd\u5bf9\u7cfb\u7edf\u9020\u6210\u635f\u5bb3\u3002<\/p>\n<h4>\u65b9\u5f0f\u4e00&#xff1a;\u4ece\u6e90\u7801\u76f4\u63a5\u90e8\u7f72<\/h4>\n<p>gcloud run deploy mcp-server &#8211;no-allow-unauthenticated &#8211;region&#061;us-central1 &#8211;source .<\/p>\n<p>&#8211;source . \u8ba9 Cloud Run \u57fa\u4e8e\u5f53\u524d\u76ee\u5f55\u6e90\u7801\u6784\u5efa\u5e76\u90e8\u7f72&#xff0c;\u540c\u65f6\u81ea\u52a8\u8bc6\u522b Dockerfile\u3002\u82e5\u672c\u5730\u5c1a\u672a\u5b89\u88c5 Docker&#xff0c;Cloud Run \u4e5f\u4f1a\u63d0\u793a\u5e76\u5f15\u5bfc\u4f7f\u7528 Cloud Build \u5b8c\u6210\u6784\u5efa\u3002<\/p>\n<h4>\u65b9\u5f0f\u4e8c&#xff1a;\u901a\u8fc7\u5bb9\u5668\u955c\u50cf\u90e8\u7f72<\/h4>\n<p>\u7b2c\u4e00\u6b65&#xff0c;\u521b\u5efa Artifact Registry \u4ed3\u5e93&#xff0c;\u7528\u4e8e\u5b58\u653e\u5bb9\u5668\u955c\u50cf&#xff1a;<\/p>\n<p>gcloud artifacts repositories create mcp-servers \\\\<br \/>\n  &#8211;repository-format&#061;docker \\\\<br \/>\n  &#8211;location&#061;us-central1 \\\\<br \/>\n  &#8211;description&#061;&#034;Repository for remote MCP servers&#034; \\\\<br \/>\n  &#8211;project&#061;$PROJECT_ID<\/p>\n<p>\u7b2c\u4e8c\u6b65&#xff0c;\u7528 Cloud Build \u6784\u5efa\u5e76\u63a8\u9001\u955c\u50cf&#xff1a;<\/p>\n<p>gcloud builds submit &#8211;region&#061;us-central1 &#8211;tag us-central1-docker.pkg.dev\/$PROJECT_ID\/mcp-servers\/mcp-server:latest<\/p>\n<p>\u7b2c\u4e09\u6b65&#xff0c;\u5c06\u955c\u50cf\u90e8\u7f72\u5230 Cloud Run&#xff1a;<\/p>\n<p>gcloud run deploy mcp-server \\\\<br \/>\n  &#8211;image us-central1-docker.pkg.dev\/$PROJECT_ID\/mcp-servers\/mcp-server:latest \\\\<br \/>\n  &#8211;region&#061;us-central1 \\\\<br \/>\n  &#8211;no-allow-unauthenticated<\/p>\n<h4>\u90e8\u7f72\u6210\u529f\u7684\u6807\u5fd7<\/h4>\n<p>\u670d\u52a1\u90e8\u7f72\u6210\u529f\u540e&#xff0c;gcloud \u4f1a\u8f93\u51fa\u7c7b\u4f3c\u4fe1\u606f&#xff1a;<\/p>\n<p>Service [mcp-server] revision [mcp-server-12345-abc] has been deployed and is serving 100 percent of traffic.<\/p>\n<p>\u6b64\u65f6\u6d41\u91cf\u5df2 100% \u7531\u65b0\u4fee\u8ba2\u7248\u672c\u627f\u8f7d&#xff0c;MCP \u670d\u52a1\u5668\u5bf9\u5916\u53ef\u7528\u3002<\/p>\n<h4>Dockerfile \u89e3\u6790<\/h4>\n<p>\u4e24\u79cd\u90e8\u7f72\u65b9\u5f0f\u6700\u7ec8\u90fd\u4f1a\u4f7f\u7528 Dockerfile \u6784\u5efa\u5bb9\u5668&#xff0c;\u5176\u5173\u952e\u6b65\u9aa4\u503c\u5f97\u7ec6\u8bfb&#xff1a;<\/p>\n<p># Use the official Python image<br \/>\nFROM python:3.14-slim<\/p>\n<p># Install uv<br \/>\nCOPY &#8211;from&#061;ghcr.io\/astral-sh\/uv:latest \/uv \/uvx \/bin\/<\/p>\n<p># Install the project into \/app<br \/>\nCOPY . \/app<br \/>\nWORKDIR \/app<\/p>\n<p># Allow statements and log messages to immediately appear in the logs<br \/>\nENV PYTHONUNBUFFERED&#061;1<\/p>\n<p># Install dependencies<br \/>\nRUN uv sync<\/p>\n<p>EXPOSE $PORT<\/p>\n<p># Run the FastMCP server<br \/>\nCMD [&#034;uv&#034;, &#034;run&#034;, &#034;server.py&#034;]<\/p>\n<ul>\n<li>\u57fa\u7840\u955c\u50cf\u9009\u7528 python:3.14-slim&#xff0c;\u4fdd\u6301\u8f7b\u91cf&#xff1b;<\/li>\n<li>\u901a\u8fc7\u591a\u9636\u6bb5 COPY &#8211;from&#061;ghcr.io\/astral-sh\/uv:latest \u76f4\u63a5\u5f15\u5165 uv \u4e8c\u8fdb\u5236&#xff0c;\u65e0\u9700\u989d\u5916\u5b89\u88c5\u6b65\u9aa4&#xff1b;<\/li>\n<li>ENV PYTHONUNBUFFERED&#061;1 \u8ba9\u65e5\u5fd7\u7acb\u5373\u8f93\u51fa&#xff0c;\u786e\u4fdd Cloud Run \u63a7\u5236\u53f0\u80fd\u5b9e\u65f6\u6355\u83b7\u670d\u52a1\u5668\u65e5\u5fd7&#xff1b;<\/li>\n<li>RUN uv sync \u4f9d\u636e pyproject.toml\/uv.lock \u5b89\u88c5\u7cbe\u786e\u7248\u672c\u7684\u4f9d\u8d56&#xff1b;<\/li>\n<li>EXPOSE $PORT \u4e0e CMD [&#034;uv&#034;, &#034;run&#034;, &#034;server.py&#034;] \u914d\u5408&#xff0c;\u5bb9\u5668\u542f\u52a8\u5373\u8fd0\u884c FastMCP \u670d\u52a1\u5668\u3002<\/li>\n<\/ul>\n<h3>\u8ba4\u8bc1 MCP \u5ba2\u6237\u7aef<\/h3>\n<p>\u7531\u4e8e\u90e8\u7f72\u65f6\u6307\u5b9a\u4e86 &#8211;no-allow-unauthenticated&#xff0c;\u4efb\u4f55\u8fde\u63a5\u8fdc\u7a0b MCP \u670d\u52a1\u5668\u7684\u5ba2\u6237\u7aef\u90fd\u5fc5\u987b\u5b8c\u6210\u8ba4\u8bc1\u3002Cloud Run \u5b98\u65b9\u6587\u6863&#034;Host MCP servers on Cloud Run&#034;\u4e00\u8282\u5bf9\u6b64\u6709\u66f4\u5168\u9762\u7684\u8bf4\u660e&#xff0c;\u5177\u4f53\u8ba4\u8bc1\u65b9\u5f0f\u53d6\u51b3\u4e8e MCP \u5ba2\u6237\u7aef\u8fd0\u884c\u7684\u4f4d\u7f6e\u3002<\/p>\n<h4>IAM \u89d2\u8272&#xff1a;roles\/run.invoker<\/h4>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;Cloud Run \u670d\u52a1\u7684 URL \u8981\u6c42\u6240\u6709\u8bf7\u6c42\u90fd\u5e26\u6709 Cloud Run Invoker&#xff08;roles\/run.invoker&#xff09;IAM \u89d2\u8272\u7684\u6388\u6743\u3002\u8fd9\u4e00\u7b56\u7565\u7ed1\u5b9a\u63d0\u4f9b\u4e86\u5f3a\u5b89\u5168\u673a\u5236&#xff0c;\u786e\u4fdd\u4f60\u7684\u672c\u5730 MCP \u5ba2\u6237\u7aef\u662f\u901a\u8fc7\u5408\u6cd5\u8eab\u4efd\u8bbf\u95ee\u670d\u52a1\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u4f60\u4ee5\u53ca\u4efb\u4f55\u8bd5\u56fe\u8bbf\u95ee\u8fdc\u7a0b MCP \u670d\u52a1\u5668\u7684\u56e2\u961f\u6210\u5458&#xff0c;\u90fd\u5fc5\u987b\u5728\u5176 Google Cloud \u8d26\u53f7\u4e0a\u7ed1\u5b9a roles\/run.invoker \u89d2\u8272&#xff0c;\u5426\u5219\u8bf7\u6c42\u4f1a\u88ab\u62d2\u7edd\u3002<\/p>\n<h4>\u4f7f\u7528 Cloud Run Proxy \u5efa\u7acb\u8ba4\u8bc1\u96a7\u9053<\/h4>\n<p>\u5bf9\u4e8e\u672c\u793a\u4f8b&#xff0c;\u6700\u76f4\u63a5\u7684\u8ba4\u8bc1\u65b9\u5f0f\u662f\u8fd0\u884c Cloud Run proxy&#xff0c;\u5728\u672c\u5730\u673a\u5668\u4e0e\u8fdc\u7a0b MCP \u670d\u52a1\u5668\u4e4b\u95f4\u5efa\u7acb\u4e00\u4e2a\u5df2\u8ba4\u8bc1\u7684\u52a0\u5bc6\u96a7\u9053&#xff1a;<\/p>\n<p>gcloud run services proxy mcp-server &#8211;region&#061;us-central1<\/p>\n<p>[!TIP] \u5982\u679c\u672c\u5730\u5c1a\u672a\u5b89\u88c5 Cloud Run proxy&#xff0c;\u4e0a\u8ff0\u547d\u4ee4\u53ef\u80fd\u4f1a\u63d0\u793a\u4e0b\u8f7d&#xff0c;\u6309\u63d0\u793a\u5b8c\u6210\u4e0b\u8f7d\u4e0e\u5b89\u88c5\u5373\u53ef\u3002<\/p>\n<p>\u8fd0\u884c\u6210\u529f\u540e\u8f93\u51fa\u5982\u4e0b&#xff1a;<\/p>\n<p>Proxying to Cloud Run service [mcp-server] in project [&lt;YOUR_PROJECT_ID&gt;] region [us-central1]<br \/>\nhttp:\/\/127.0.0.1:8080 proxies to https:\/\/mcp-server-abcdefgh-uc.a.run.app<\/p>\n<p>\u6b64\u540e&#xff0c;\u6240\u6709\u53d1\u5f80 http:\/\/127.0.0.1:8080 \u7684\u6d41\u91cf\u90fd\u4f1a\u88ab\u81ea\u52a8\u8ba4\u8bc1\u5e76\u8f6c\u53d1\u5230\u8fdc\u7a0b MCP \u670d\u52a1\u5668&#xff0c;\u672c\u5730\u5ba2\u6237\u7aef\u65e0\u9700\u81ea\u884c\u5904\u7406\u4ee4\u724c\u7b7e\u53d1\u4e0e IAM \u7b7e\u540d\u3002<\/p>\n<h3>\u6d4b\u8bd5\u8fdc\u7a0b MCP \u670d\u52a1\u5668<\/h3>\n<h4>\u6d4b\u8bd5\u5ba2\u6237\u7aef\u6e90\u7801\u89e3\u6790<\/h4>\n<p>\u4ed3\u5e93\u63d0\u4f9b\u4e86\u4e13\u95e8\u7684\u6d4b\u8bd5\u811a\u672c test_server.py&#xff0c;\u5b83\u4f7f\u7528 FastMCP \u5ba2\u6237\u7aef\u8fde\u63a5\u672c\u5730\u4ee3\u7406\u7aef\u53e3\u5e76\u9a8c\u8bc1\u5de5\u5177\u8c03\u7528&#xff1a;<\/p>\n<p># [START cloudrun_mcpserver_test]<br \/>\nimport asyncio<\/p>\n<p>from fastmcp import Client<\/p>\n<p>async def test_server():<br \/>\n    # Test the MCP server using streamable-http transport.<br \/>\n    # Use &#034;\/sse&#034; endpoint if using sse transport.<br \/>\n    async with Client(&#034;http:\/\/localhost:8080\/mcp&#034;) as client:<br \/>\n        # List available tools<br \/>\n        tools &#061; await client.list_tools()<br \/>\n        for tool in tools:<br \/>\n            print(f&#034;&gt;&gt;&gt; &#x1f6e0;\ufe0f  Tool found: {tool.name}&#034;)<br \/>\n        # Call add tool<br \/>\n        print(&#034;&gt;&gt;&gt; &#x1fa9b;  Calling add tool for 1 &#043; 2&#034;)<br \/>\n        result &#061; await client.call_tool(&#034;add&#034;, {&#034;a&#034;: 1, &#034;b&#034;: 2})<br \/>\n        print(f&#034;&lt;&lt;&lt; \u2705 Result: {result.content[0].text}&#034;)<br \/>\n        # Call subtract tool<br \/>\n        print(&#034;&gt;&gt;&gt; &#x1fa9b;  Calling subtract tool for 10 &#8211; 3&#034;)<br \/>\n        result &#061; await client.call_tool(&#034;subtract&#034;, {&#034;a&#034;: 10, &#034;b&#034;: 3})<br \/>\n        print(f&#034;&lt;&lt;&lt; \u2705 Result: {result.content[0].text}&#034;)<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    asyncio.run(test_server())<br \/>\n# [END cloudrun_mcpserver_test]<\/p>\n<p>\u4ece\u6e90\u7801&#xff08;test_server.py&#xff09;\u53ef\u4ee5\u770b\u5230\u5b8c\u6574\u8c03\u7528\u94fe&#xff1a;<\/p>\n<ul>\n<li>\u5ba2\u6237\u7aef\u8fde\u63a5\u5730\u5740\u4e3a http:\/\/localhost:8080\/mcp\u2014\u2014\u6ce8\u610f\u672b\u5c3e\u7684 \/mcp \u8def\u5f84&#xff0c;\u8fd9\u662f streamable-http \u4f20\u8f93\u7684\u7aef\u70b9\u7ea6\u5b9a&#xff1b;\u4ee3\u7801\u6ce8\u91ca\u8bf4\u660e\u82e5\u6539\u7528 sse \u4f20\u8f93&#xff0c;\u5219\u5e94\u8fde\u63a5 \/sse \u7aef\u70b9\u3002<\/li>\n<li>client.list_tools() \u5217\u51fa\u670d\u52a1\u5668\u516c\u5f00\u7684\u5168\u90e8\u5de5\u5177&#xff0c;\u7528\u4e8e\u6821\u9a8c\u5de5\u5177\u6ce8\u518c\u662f\u5426\u6b63\u786e\u3002<\/li>\n<li>client.call_tool(&#034;add&#034;, {&#034;a&#034;: 1, &#034;b&#034;: 2}) \u4ee5 JSON \u53c2\u6570\u5f62\u5f0f\u8c03\u7528\u5de5\u5177&#xff0c;\u8fd4\u56de\u7ed3\u679c\u901a\u8fc7 result.content[0].text \u8bfb\u53d6\u6587\u672c\u5185\u5bb9\u3002<\/li>\n<\/ul>\n<h4>\u8fd0\u884c\u6d4b\u8bd5<\/h4>\n<p>[!NOTE] \u8fd0\u884c\u6d4b\u8bd5\u524d&#xff0c;\u8bf7\u786e\u4fdd Cloud Run proxy \u6b63\u5728\u8fd0\u884c&#xff08;\u5373\u4e0a\u4e00\u6b65\u7684 gcloud run services proxy \u547d\u4ee4\u6ca1\u6709\u9000\u51fa&#xff09;\u3002<\/p>\n<p>\u5728\u65b0\u7684\u7ec8\u7aef\u4e2d\u8fd0\u884c&#xff1a;<\/p>\n<p>uv run test_server.py<\/p>\n<p>\u9884\u671f\u8f93\u51fa\u5982\u4e0b&#xff1a;<\/p>\n<p>&gt;&gt;&gt; &#x1f6e0;\ufe0f  Tool found: add<br \/>\n&gt;&gt;&gt; &#x1f6e0;\ufe0f  Tool found: subtract<br \/>\n&gt;&gt;&gt; &#x1fa9b;  Calling add tool for 1 &#043; 2<br \/>\n&lt;&lt;&lt; \u2705 Result: 3<br \/>\n&gt;&gt;&gt; &#x1fa9b;  Calling subtract tool for 10 &#8211; 3<br \/>\n&lt;&lt;&lt; \u2705 Result: 7<\/p>\n<p>add(1, 2) \u8fd4\u56de 3&#xff0c;subtract(10, 3) \u8fd4\u56de 7&#xff0c;\u8bf4\u660e\u8fdc\u7a0b MCP \u670d\u52a1\u5668\u5df2\u7ecf\u6210\u529f\u90e8\u7f72\u5e76\u901a\u8fc7 FastMCP \u5ba2\u6237\u7aef\u5b8c\u6210\u7aef\u5230\u7aef\u9a8c\u8bc1\u3002<\/p>\n<h3>\u4f7f\u7528 OpenTelemetry \u8fdb\u884c\u53ef\u89c2\u6d4b\u6027\u76d1\u63a7<\/h3>\n<h4>\u539f\u7406&#xff1a;FastMCP \u539f\u751f\u652f\u6301 OpenTelemetry<\/h4>\n<p>\u672c\u793a\u4f8b\u96c6\u6210\u4e86 OpenTelemetry&#xff0c;\u5c06 traces\u3001logs\u3001metrics \u53d1\u9001\u5230 Google Cloud Observability&#xff08;Cloud Trace\u3001Cloud Logging\u3001Cloud Monitoring&#xff09;\u3002\u7531\u4e8e FastMCP \u539f\u751f\u5185\u7f6e\u4e86 OpenTelemetry \u57cb\u70b9&#xff0c;\u53ea\u9700\u5b8c\u6210 SDK \u521d\u59cb\u5316\u5373\u53ef\u83b7\u5f97\u9065\u6d4b\u6570\u636e&#xff0c;\u65e0\u9700\u5728\u4e1a\u52a1\u4ee3\u7801\u4e2d\u624b\u5de5\u6253\u70b9\u3002<\/p>\n<h4>\u521d\u59cb\u5316\u4ee3\u7801\u89e3\u6790&#xff1a;otel_setup.py<\/h4>\n<p>\u9065\u6d4b\u521d\u59cb\u5316\u903b\u8f91\u4f4d\u4e8e otel_setup.py&#xff0c;server.py \u4e0e test_server.py \u90fd\u5728\u5bfc\u5165\u540e\u7acb\u5373\u8c03\u7528 setup_opentelemetry(&#8230;)&#xff1a;<\/p>\n<p>def setup_opentelemetry(service_name: str) -&gt; None:<br \/>\n    &#034;&#034;&#034;Sets up OpenTelemetry to send traces to Google Cloud Observability.&#034;&#034;&#034;<br \/>\n    credentials, project_id &#061; google.auth.default()<br \/>\n    if not project_id:<br \/>\n        raise Exception(&#034;Could not determine Google Cloud project ID.&#034;)<\/p>\n<p>    resource &#061; Resource.create(<br \/>\n        attributes&#061;{<br \/>\n            SERVICE_NAME: service_name,<br \/>\n            &#034;gcp.project_id&#034;: project_id,<br \/>\n        }<br \/>\n    )<\/p>\n<p>    # Set up OTLP auth<br \/>\n    request &#061; google.auth.transport.requests.Request()<br \/>\n    auth_metadata_plugin &#061; AuthMetadataPlugin(credentials&#061;credentials, request&#061;request)<br \/>\n    channel_creds &#061; grpc.composite_channel_credentials(<br \/>\n        grpc.ssl_channel_credentials(),<br \/>\n        grpc.metadata_call_credentials(auth_metadata_plugin),<br \/>\n    )<\/p>\n<p>    # Set up OpenTelemetry Python SDK<br \/>\n    tracer_provider &#061; TracerProvider(resource&#061;resource)<br \/>\n    tracer_provider.add_span_processor(<br \/>\n        BatchSpanProcessor(<br \/>\n            OTLPSpanExporter(<br \/>\n                credentials&#061;channel_creds,<br \/>\n                endpoint&#061;&#034;https:\/\/telemetry.googleapis.com:443\/v1\/traces&#034;,<br \/>\n            )<br \/>\n        )<br \/>\n    )<br \/>\n    trace.set_tracer_provider(tracer_provider)<br \/>\n    logger.info(&#034;OpenTelemetry successfully initialized.&#034;)<\/p>\n<p>\u5173\u952e\u5b9e\u73b0\u7ec6\u8282&#xff08;otel_setup.py&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u901a\u8fc7 google.auth.default() \u83b7\u53d6\u5e94\u7528\u9ed8\u8ba4\u51ed\u636e\u4e0e\u9879\u76ee ID&#xff0c;\u5728 Cloud Run \u73af\u5883\u4e2d\u4f1a\u81ea\u52a8\u4f7f\u7528\u670d\u52a1\u8d26\u53f7\u8eab\u4efd&#xff1b;<\/li>\n<li>Resource.create \u4e3a\u9065\u6d4b\u6570\u636e\u9644\u52a0 service.name \u4e0e gcp.project_id \u5c5e\u6027&#xff0c;\u4fbf\u4e8e\u5728 Cloud Trace \u4e2d\u6309\u670d\u52a1\u533a\u5206&#xff1b;<\/li>\n<li>\u4f7f\u7528 AuthMetadataPlugin \u628a Google Cloud \u51ed\u636e\u5305\u88c5\u4e3a gRPC \u5143\u6570\u636e\u8ba4\u8bc1\u63d2\u4ef6&#xff0c;\u4e0e TLS \u901a\u9053\u7ec4\u5408\u6210\u590d\u5408\u901a\u9053\u51ed\u636e&#xff0c;\u5b9e\u73b0 OTLP \u4e0a\u62a5\u7684\u514d\u624b\u52a8\u4ee4\u724c\u8ba4\u8bc1&#xff1b;<\/li>\n<li>OTLPSpanExporter \u5c06 span \u4e0a\u62a5\u5230 https:\/\/telemetry.googleapis.com:443\/v1\/traces&#xff08;Telemetry\/OTLP API \u7aef\u70b9&#xff09;&#xff1b;<\/li>\n<li>BatchSpanProcessor \u8d1f\u8d23\u6279\u91cf\u3001\u5f02\u6b65\u5730\u5bfc\u51fa span&#xff0c;\u964d\u4f4e\u5bf9\u670d\u52a1\u5668\u6027\u80fd\u7684\u5f71\u54cd\u3002<\/li>\n<\/ul>\n<h4>\u542f\u7528\u6240\u9700 API<\/h4>\n<p>\u5728\u8fd0\u884c\u89c2\u6d4b\u529f\u80fd\u524d&#xff0c;\u9700\u8981\u786e\u8ba4\u76ee\u6807 GCP \u9879\u76ee\u5df2\u542f\u7528 Telemetry&#xff08;OTLP&#xff09;API\u3001Cloud Logging API \u4e0e Cloud Monitoring API&#xff1a;<\/p>\n<p>gcloud services enable logging.googleapis.com monitoring.googleapis.com telemetry.googleapis.com<\/p>\n<h4>\u8fd0\u884c\u670d\u52a1\u5668\u5e76\u4ea7\u751f\u9065\u6d4b\u6570\u636e<\/h4>\n<p>\u793a\u4f8b\u5df2\u7ecf\u9884\u914d\u7f6e\u597d OpenTelemetry&#xff0c;\u53ef\u76f4\u63a5\u8fd0\u884c&#xff1a;<\/p>\n<ul>\n<li>\u672c\u5730\u8fd0\u884c&#xff1a;\u6267\u884c uv run server.py \u542f\u52a8\u670d\u52a1\u5668&#xff0c;\u7136\u540e\u5728\u53e6\u4e00\u4e2a\u7ec8\u7aef\u7528 uv run test_server.py \u8c03\u7528\u5de5\u5177\u4ea7\u751f trace&#xff1b;<\/li>\n<li>Cloud Run \u8fd0\u884c&#xff1a;\u6309\u4e0a\u6587&#034;\u90e8\u7f72&#034;\u4e00\u8282\u7684\u547d\u4ee4\u90e8\u7f72\u5373\u53ef&#xff0c;\u4ed3\u5e93\u9ed8\u8ba4\u7684 Dockerfile \u5df2\u7ecf\u914d\u7f6e\u4e3a\u8fd0\u884c\u63d2\u6869\u540e\u7684\u670d\u52a1\u5668&#xff08;CMD [&#034;uv&#034;, &#034;run&#034;, &#034;server.py&#034;]&#xff09;&#xff0c;\u65e0\u9700\u989d\u5916\u4fee\u6539\u3002<\/li>\n<\/ul>\n<h4>\u67e5\u770b Trace<\/h4>\n<p>\u4e0e\u670d\u52a1\u5668\u4ea4\u4e92\u4ea7\u751f trace \u540e&#xff0c;\u5373\u53ef\u5728 Google Cloud Console \u4e2d\u67e5\u770b\u3002Cloud Trace \u7684\u67e5\u627e\u4e0e\u68c0\u7d22\u64cd\u4f5c\u53ef\u53c2\u8003 Google Cloud Trace \u5b98\u65b9\u6587\u6863\u4e2d&#034;\u67e5\u627e traces&#034;\u7684\u6307\u5f15&#xff1a;\u6309\u670d\u52a1\u540d\u3001\u9879\u76ee ID\u3001\u65f6\u95f4\u8303\u56f4\u7b49\u6761\u4ef6\u8fc7\u6ee4&#xff0c;\u5373\u53ef\u5b9a\u4f4d mcp-server \u6bcf\u6b21\u5de5\u5177\u8c03\u7528\u7684\u5b8c\u6574\u8c03\u7528\u94fe\u4e0e\u8017\u65f6\u3002<\/p>\n<h3>\u5c0f\u7ed3<\/h3>\n<p>\u901a\u8fc7\u672c\u793a\u4f8b&#xff0c;\u4f60\u53ef\u4ee5\u5728 python-docs-samples \u4ed3\u5e93\u7684 run\/mcp-server \u76ee\u5f55\u4e2d\u5b8c\u6574\u590d\u73b0&#034;\u4e91\u7aef MCP \u670d\u52a1\u5668&#034;\u7684\u5168\u751f\u547d\u5468\u671f&#xff1a;<\/p>\n<li>\u5f00\u53d1&#xff1a;\u7528 FastMCP \u4ee5 &#064;mcp.tool() \u58f0\u660e\u5de5\u5177&#xff0c;\u9009\u62e9 streamable-http \u4f20\u8f93\u5e76\u7ed1\u5b9a 0.0.0.0:PORT&#xff08;server.py&#xff09;&#xff1b;<\/li>\n<li>\u6784\u5efa&#xff1a;\u4f9d\u8d56\u7531 pyproject.toml \u4e0e uv.lock \u7cbe\u786e\u9501\u5b9a&#xff0c;\u5bb9\u5668\u7531 Dockerfile \u5b9a\u4e49&#xff1b;<\/li>\n<li>\u90e8\u7f72&#xff1a;\u901a\u8fc7 gcloud run deploy \u4ece\u6e90\u7801\u6216\u955c\u50cf\u90e8\u7f72&#xff0c;\u52a1\u5fc5\u643a\u5e26 &#8211;no-allow-unauthenticated \u5f3a\u5236\u8ba4\u8bc1&#xff1b;<\/li>\n<li>\u8bbf\u95ee&#xff1a;\u7528 gcloud run services proxy \u5efa\u7acb\u672c\u5730\u8ba4\u8bc1\u96a7\u9053&#xff0c;\u5ba2\u6237\u7aef\u8fde\u63a5 http:\/\/127.0.0.1:8080\/mcp \u7aef\u70b9&#xff1b;<\/li>\n<li>\u9a8c\u8bc1\u4e0e\u89c2\u6d4b&#xff1a;\u7528 test_server.py \u7aef\u5230\u7aef\u9a8c\u8bc1\u5de5\u5177\u8c03\u7528&#xff0c;\u901a\u8fc7 otel_setup.py \u4e0e Cloud Trace \u89c2\u5bdf\u6bcf\u6b21\u8c03\u7528\u7684\u5168\u94fe\u8def\u6307\u6807\u3002<\/li>\n<p>\u8fd9\u4e00\u6a21\u5f0f\u5c06&#034;\u53ef\u4f38\u7f29\u3001\u96c6\u4e2d\u5171\u4eab\u3001\u5b89\u5168\u8ba4\u8bc1\u3001\u53ef\u89c2\u6d4b&#034;\u56db\u4e2a\u80fd\u529b\u7edf\u4e00\u5230\u4e86\u4e91\u7aef&#xff0c;\u4e3a\u56e2\u961f\u534f\u4f5c\u63d0\u4f9b\u4e86\u4e00\u5957\u4f4e\u6210\u672c\u3001\u53ef\u590d\u5236\u7684 MCP \u670d\u52a1\u5668\u90e8\u7f72\u8303\u5f0f\u3002<\/p>\n<p>  <img loading=\"lazy\" decoding=\"async\" class=\"gcb-icon-like\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261008001812-6ac6e1446e363.svg\" alt=\"\" width=\"16\" height=\"16\" \/> <span class=\"gcb-like-text\">\u8d5e<\/span>  <\/p>\n<p>   <span class=\"gcb-share-text\">\u5206\u4eab<\/span>  <\/p>\n<ul class=\"gcb-tag-list\">\n<li><span class=\"gcb-tag\">\u793a\u4f8b\u5de5\u7a0b<\/span><\/li>\n<\/ul>\n<h3 class=\"gcb-project-title\">\u3010\u514d\u8d39\u4e0b\u8f7d\u94fe\u63a5\u3011python-docs-samples<\/h3>\n<p class=\"gcb-project-desc\">Code samples used on cloud.google.com<\/p>\n<p>    <span class=\"gcb-project-addr-label\">\u9879\u76ee\u5730\u5740&#xff1a;<\/span><br \/>\n    <span class=\"gcb-project-addr-link\">https:\/\/gitcode.com\/GitHub_Trending\/py\/python-docs-samples<\/span> <\/p>\n<p>  <span class=\"gcb-project-btn\"> <span class=\"gcb-project-btn-main\">\u70b9\u51fb\u67e5\u770b<\/span> <span class=\"gcb-project-btn-sub\">\u514d\u8d39\u4e0b\u8f7d<\/span> <\/span> <\/p>\n<h4 class=\"gcb-related-title\">\u76f8\u5173\u63a8\u8350<\/h4>\n<ul class=\"gcb-related-list\">\n<li class=\"gcb-related-item\">\n<h5 class=\"gcb-related-item-title\">\u5728 Cloud Run \u4e0a\u8fd0\u884c Django \u5e94\u7528&#xff1a;python-docs-samples \u7684\u5b8c\u6574\u90e8\u7f72\u6307\u5357<\/h5>\n<p class=\"gcb-related-item-desc\">\u5728 Cloud Run \u4e0a\u8fd0\u884c Django \u5e94\u7528&#xff1a;python docs samples \u7684\u5b8c\u6574\u90e8\u7f72\u6307\u5357 \u672c\u6307\u5357\u4ee5 run\/django\/README.md <\/p>\n<p>     <span class=\"gcb-tag\">\u793a\u4f8b\u5de5\u7a0b<\/span>\n      <\/li>\n<li class=\"gcb-related-item\">\n<h5 class=\"gcb-related-item-title\">\u7528 Python \u5728 Cloud Run \u4e0a\u5904\u7406 Pub\/Sub \u63a8\u9001\u6d88\u606f&#xff1a;python-docs-samples \u4e2d pubsub-tutorial \u793a\u4f8b\u5b8c\u6574\u5b9e\u6218\u6307\u5357<\/h5>\n<p class=\"gcb-related-item-desc\">\u7528 Python \u5728 Cloud Run \u4e0a\u5904\u7406 Pub\/Sub \u63a8\u9001\u6d88\u606f&#xff1a;python docs samples \u4e2d pubsub tutorial \u793a\u4f8b\u5b8c\u6574<\/p>\n<p>     <span class=\"gcb-tag\">\u793a\u4f8b\u5de5\u7a0b<\/span>\n      <\/li>\n<li class=\"gcb-related-item\">\n<h5 class=\"gcb-related-item-title\">\u5728 Google Cloud Run \u4e0a\u90e8\u7f72 MCP Toolbox \u8fde\u63a5 Looker&#xff1a;OAuth \u8ba4\u8bc1\u4e0e Gemini CLI \u5b9e\u6218\u6307\u5357<\/h5>\n<p class=\"gcb-related-item-desc\">\u5728 Google Cloud Run \u4e0a\u90e8\u7f72 MCP Toolbox \u8fde\u63a5 Looker&#xff1a;OAuth \u8ba4\u8bc1\u4e0e Gemini CLI \u5b9e\u6218\u6307\u5357 \u672c\u7bc7\u6280\u672f\u6307\u5357\u4ee5 M<\/p>\n<p>     <span class=\"gcb-tag\">MCP \u670d\u52a1<\/span><br \/>\n     <span class=\"gcb-tag\">\u6570\u636e\u5e93<\/span><br \/>\n     <span class=\"gcb-tag\">\u540e\u7aef<\/span><br \/>\n     <span class=\"gcb-tag\">AI \u5e94\u7528<\/span>\n      <\/li>\n<\/ul>\n<p>  <span class=\"gcb-prev-next-label\">\u4e0a\u4e00\u7bc7&#xff1a;<\/span><br \/>\n  Mac\u7ec8\u6781NTFS\u8bfb\u5199\u89e3\u51b3\u65b9\u6848&#xff1a;Nigate\u5de5\u5177\u5b8c\u6574\u4f7f\u7528\u6307\u5357 <\/p>\n<p>  <span class=\"gcb-prev-next-label\">\u4e0b\u4e00\u7bc7&#xff1a;<\/span><br \/>\n  APIs-made-in-Iran\u4eba\u5de5\u667a\u80fdAPI&#xff1a;\u6ce2\u65af\u8bedNLP\u4e0eOCR\u6280\u672f\u5b8c\u5168\u624b\u518c <\/p>\n<p>\u521b\u4f5c\u58f0\u660e\uff1a\u672c\u6587\u90e8\u5206\u5185\u5bb9\u7531AI\u8f85\u52a9\u751f\u6210\uff08AIGC\uff09\uff0c\u4ec5\u4f9b\u53c2\u8003<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u793a\u4f8b\u5de5\u7a0b \u3010\u514d\u8d39\u4e0b\u8f7d\u94fe\u63a5\u3011python-docs-samples Code samples used on cloud.google.com \u9879\u76ee\u5730\u5740&#xff1a; https:\/\/gitcode.com\/GitHub_Trending\/py\/python-docs-samples \u70b9\u51fb\u67e5\u770b \u514d\u8d39\u4e0b\u8f7d  \u672c\u6587\u57fa\u4e8e python-docs-samples \u4ed3\u5e93\u4e2d\u7684 run\/mcp-server \u793a\u4f8b&#xff0c;\u7cfb\u7edf\u8bb2\u89e3\u5982\u4f55\u5c06\u4e00\u4e2a\u57fa\u4e8e FastMCP \u7684\u8fdc\u7a0b MCP&amp;#xf<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-114061","post","type-post","status-publish","format-standard","hentry","category-server"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5728 Cloud Run \u4e0a\u90e8\u7f72\u8fdc\u7a0b MCP \u670d\u52a1\u5668\uff1apython-docs-samples \u4e2d run\/mcp-server \u7684\u5b8c\u6574\u5b9e\u6218\u6307\u5357 - \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\/114061.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5728 Cloud Run \u4e0a\u90e8\u7f72\u8fdc\u7a0b MCP \u670d\u52a1\u5668\uff1apython-docs-samples \u4e2d run\/mcp-server \u7684\u5b8c\u6574\u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u793a\u4f8b\u5de5\u7a0b \u3010\u514d\u8d39\u4e0b\u8f7d\u94fe\u63a5\u3011python-docs-samples Code samples used on cloud.google.com \u9879\u76ee\u5730\u5740&#xff1a; https:\/\/gitcode.com\/GitHub_Trending\/py\/python-docs-samples \u70b9\u51fb\u67e5\u770b \u514d\u8d39\u4e0b\u8f7d \u672c\u6587\u57fa\u4e8e python-docs-samples \u4ed3\u5e93\u4e2d\u7684 run\/mcp-server \u793a\u4f8b&#xff0c;\u7cfb\u7edf\u8bb2\u89e3\u5982\u4f55\u5c06\u4e00\u4e2a\u57fa\u4e8e FastMCP \u7684\u8fdc\u7a0b MCP&amp;#xf\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/114061.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-08T00:18:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261008001812-6ac6e1446e363.svg\" \/>\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=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/114061.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/114061.html\",\"name\":\"\u5728 Cloud Run \u4e0a\u90e8\u7f72\u8fdc\u7a0b MCP \u670d\u52a1\u5668\uff1apython-docs-samples \u4e2d run\/mcp-server \u7684\u5b8c\u6574\u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-08T00:18:13+00:00\",\"dateModified\":\"2026-10-08T00:18:13+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/114061.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/114061.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/114061.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5728 Cloud Run \u4e0a\u90e8\u7f72\u8fdc\u7a0b MCP \u670d\u52a1\u5668\uff1apython-docs-samples \u4e2d run\/mcp-server \u7684\u5b8c\u6574\u5b9e\u6218\u6307\u5357\"}]},{\"@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":"\u5728 Cloud Run \u4e0a\u90e8\u7f72\u8fdc\u7a0b MCP \u670d\u52a1\u5668\uff1apython-docs-samples \u4e2d run\/mcp-server \u7684\u5b8c\u6574\u5b9e\u6218\u6307\u5357 - \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\/114061.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5728 Cloud Run \u4e0a\u90e8\u7f72\u8fdc\u7a0b MCP \u670d\u52a1\u5668\uff1apython-docs-samples \u4e2d run\/mcp-server \u7684\u5b8c\u6574\u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u793a\u4f8b\u5de5\u7a0b \u3010\u514d\u8d39\u4e0b\u8f7d\u94fe\u63a5\u3011python-docs-samples Code samples used on cloud.google.com \u9879\u76ee\u5730\u5740&#xff1a; https:\/\/gitcode.com\/GitHub_Trending\/py\/python-docs-samples \u70b9\u51fb\u67e5\u770b \u514d\u8d39\u4e0b\u8f7d \u672c\u6587\u57fa\u4e8e python-docs-samples \u4ed3\u5e93\u4e2d\u7684 run\/mcp-server \u793a\u4f8b&#xff0c;\u7cfb\u7edf\u8bb2\u89e3\u5982\u4f55\u5c06\u4e00\u4e2a\u57fa\u4e8e FastMCP \u7684\u8fdc\u7a0b MCP&amp;#xf","og_url":"https:\/\/www.wsisp.com\/helps\/114061.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-08T00:18:13+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261008001812-6ac6e1446e363.svg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/114061.html","url":"https:\/\/www.wsisp.com\/helps\/114061.html","name":"\u5728 Cloud Run \u4e0a\u90e8\u7f72\u8fdc\u7a0b MCP \u670d\u52a1\u5668\uff1apython-docs-samples \u4e2d run\/mcp-server \u7684\u5b8c\u6574\u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-08T00:18:13+00:00","dateModified":"2026-10-08T00:18:13+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/114061.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/114061.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/114061.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5728 Cloud Run \u4e0a\u90e8\u7f72\u8fdc\u7a0b MCP \u670d\u52a1\u5668\uff1apython-docs-samples \u4e2d run\/mcp-server \u7684\u5b8c\u6574\u5b9e\u6218\u6307\u5357"}]},{"@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\/114061","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=114061"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/114061\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=114061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=114061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=114061"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=114061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}