3月31日,谷歌CEO Sundar Pichai(劈柴哥)发出灵魂一问:
ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;margin: 8px;padding: 8px;line-height: 1.75em;">To MCP or not to MCP, that's the question.ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;margin: 8px;padding: 8px;line-height: 1.75em;">(MCP还是不MCP,这是个问题。)MCP的持续火爆,加上OpenAI在27日官宣对MCP的支持,终究还是让谷歌坐不住了。 劈柴哥让网友们给拿一拿主意。 OpenAI的工程师Steven Heidel很快回复道:「我们已经做了,现在到你们了。」 劈柴在线征求意见还不到4天,谷歌DeepMind的高级AI关系工程师Philipp Schmid,在X上宣布在Gemini API文档中添加了使用MCP的示例。 现在可以直接将MCP服务器与Gemini 模型搭配使用。 模型上下文协议 (MCP) 是开放标准,用于连接AI应用与外部工具、数据源和系统。 MCP为模型提供了一个通用协议,以便AI模型访问上下文,例如函数(工具)、数据源(资源)或预定义的提示。 可以使用工具调用功能将模型与MCP服务器搭配使用。 如下示例,了解如何将本地MCP服务器与Gemini、Python SDK和 mcp SDK搭配使用。 importasyncioimport osfromdatetimeimportdatetimefromgoogleimportgenaifromgoogle.genaiimporttypesfrommcpimportClientSession, StdioServerParametersfrommcp.client.stdioimportstdio_client
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
# Create server parameters for stdio connectionserver_params = StdioServerParameters(command="npx", # Executable args=["-y","@philschmid/weather-mcp"], # Weather MCP Server env=None, # Optional environment variables )
asyncdefrun(): asyncwithstdio_client(server_params)as(read, write): asyncwithClientSession(read, write)assession: # Prompt to get the weather for the current day in London. prompt =f"What is the weather in London in{datetime.now().strftime('%Y-%m-%d')}?" # Initialize the connection between client and server awaitsession.initialize() # Get tools from MCP session and convert to Gemini Tool objects mcp_tools =awaitsession.list_tools() tools = [ types.Tool( function_declarations=[ { "name": tool.name, "description": tool.description, "parameters": { k: v fork, vintool.inputSchema.items() ifknotin["additionalProperties","$schema"] }, } ] ) fortoolinmcp_tools.tools ] # Send request to the model with MCP function declarations response = client.models.generate_content( model="gemini-2.0-flash", contents=prompt, config=types.GenerateContentConfig( temperature=0, tools=tools, ), ) # Check for a function call ifresponse.candidates[0].content.parts[0].function_call: function_call = response.candidates[0].content.parts[0].function_call print(function_call) # Call the MCP server with the predicted tool result =awaitsession.call_tool( function_call.name, arguments=function_call.args ) print(result.content[0].text) # Continue as shown in step 4 of "How Function Calling Works" # and create a user friendly response else: print("No function call found in the response.") print(response.text)# Start the asyncio event loop and run the main functionasyncio.run(run())
但是,大如谷歌这样的科技巨头,做出任何决策都没那么容易。 几天前,Steven刚刚使用现在爆火的「吉卜力」风格图片解释了一下什么是MCP。 图片中展示了一个基于MCP协议的分布式系统架构。 简单的说,MCP协议可以使AI根据需求从不同的软件或者网页上获取到数据或者服务。 善于整活的网友还把劈柴哥的这个帖子也整成了「吉卜力」风。 紧跟潮流。 紧跟潮流的还有网友Adam Holt,他用漫画回复了劈柴哥。 漫画中,劈柴哥与Anthropic(MCP协议的推出者)CEO Dario Amodei微笑握手,奥特曼则站在中间,望着劈柴哥。 「为开发者而做。」Adam写道。 网友Jeffrey Emanuel还帮劈柴哥分析起了行业形势。 他表示,考虑到 Anthropic、OpenAI以及DeepSeek全都支持MCP协议,如果谷歌还不采用,将会错失应用开发的热潮。 「并且所有的Gemini模型都将不再那么有用。」他写道。 网友Kris Hansen则进一步表示,现在的MCP就相当于是1993年的HTTP。 「更多产品采用这个标准协议将会有助于所有人。」 综合来看,Kris将MCP比作1993年的HTTP确实比较合理。 两者都是其领域的基础协议,处于早期发展阶段,也都具有改变技术格局的潜力。 当然,在一片支持的评论中也不乏反对的声音。 网友Han就希望谷歌自己推出一个「更强大、更轻量级的MCP进化版本」。 标准化协议对于整个AI生态的构建都是至关重要的。 就像互联网需要HTTP协议奠定基础一样,AI时代同样需要像MCP这样的标准来促进互操作性和创新。 如果谷歌宣布支持MCP,那么Gemini可以作为MCP客户端,轻松连接到各种数据源和工具。 同时,谷歌也可以提供MCP服务器,让其他AI模型访问其服务,如Gmail、Google Calendar和Google Drive 。 但是,大如谷歌这样的科技巨头,做出任何决策都没那么容易。 其中重要的是,依赖外部标准可能带来的风险。 毕竟,MCP协议是由谷歌在AI领域的对手Anthropic推出和主导的。 谷歌很难影响其长期的发展方向。 虽说MCP协议现在是开源的,但以后怎样谷歌也拿不准。 毕竟谷歌自己刚把开源的安卓变得封闭起来。 |