{"id":46789,"date":"2025-07-30T04:07:31","date_gmt":"2025-07-29T20:07:31","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/46789.html"},"modified":"2025-07-30T04:07:31","modified_gmt":"2025-07-29T20:07:31","slug":"%e9%87%87%e7%94%a8langgraph%e9%9b%86%e6%88%90%e5%a4%9a%e4%b8%aamcp%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/46789.html","title":{"rendered":"\u91c7\u7528LangGraph\u96c6\u6210\u591a\u4e2aMCP\u670d\u52a1\u5668\u7684\u5e94\u7528"},"content":{"rendered":"<p style=\"text-align: start\">\u73b0\u4ee3\u4eba\u5de5\u667a\u80fd\u5e94\u7528\u7a0b\u5e8f\u901a\u5e38\u9700\u8981\u5bf9\u4e0d\u540c\u7684\u8bed\u8a00\u6a21\u578b\u548c\u4e13\u95e8\u7684\u670d\u52a1\u5668\u8fdb\u884c\u590d\u6742\u7684\u7f16\u6392&#xff0c;\u6bcf\u4e2a\u670d\u52a1\u5668\u5728\u66f4\u5927\u7684\u5de5\u4f5c\u6d41\u4e2d\u5904\u7406\u7279\u5b9a\u7684\u4efb\u52a1\u3002\u7136\u800c&#xff0c;\u8fd9\u79cd\u5206\u5e03\u5f0f\u65b9\u6cd5\u5f15\u5165\u4e86\u4e00\u4e2a\u5173\u952e\u7684\u6311\u6218&#xff1a; \u4fdd\u6301\u4e0a\u4e0b\u6587\u7684\u8fde\u7eed\u6027\u3002<\/p>\n<p style=\"text-align: start\">\u5f53\u4f1a\u8bdd\u6216\u4efb\u52a1\u5728\u4e0d\u540c\u7684\u6a21\u578b\u6216\u670d\u52a1\u5668\u4e4b\u95f4\u8f6c\u6362\u65f6&#xff0c;\u4e0a\u4e0b\u6587\u4fe1\u606f\u5f88\u5bb9\u6613\u4e22\u5931\u3002\u7528\u6237\u4f53\u9a8c\u5230\u7684\u662f&#xff0c;\u4eba\u5de5\u667a\u80fd\u7cfb\u7edf\u4f3c\u4e4e \u201c\u5fd8\u8bb0\u201d \u4e86\u5bf9\u8bdd\u7684\u65e9\u671f\u90e8\u5206&#xff0c;\u5bfc\u81f4\u4f53\u9a8c\u652f\u79bb\u7834\u788e&#xff0c;\u6548\u7528\u964d\u4f4e\u3002<\/p>\n<h3>1. MCP \u7684\u6838\u5fc3<\/h3>\n<p style=\"text-align: start\">\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae&#xff08;Model Context Protocol, MCP&#xff09;\u4e3a\u5728\u5206\u5e03\u5f0f\u4eba\u5de5\u667a\u80fd\u7cfb\u7edf\u4e2d\u5404\u7ec4\u4ef6\u4e4b\u95f4\u4e00\u81f4\u5730\u4fdd\u5b58\u548c\u9ad8\u6548\u4f20\u8f93\u4e30\u5bcc\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f&#xff0c;\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6807\u51c6\u5316\u7684\u6846\u67b6\u3002MCP \u7684\u6838\u5fc3\u8bbe\u8ba1\u56f4\u7ed5\u4ee5\u4e0b\u4e09\u5927\u8981\u7d20\u5c55\u5f00&#xff1a;<\/p>\n<li>\n<p>\u5b83\u5b9a\u4e49\u4e86\u4e00\u79cd\u7edf\u4e00\u7684\u4e0a\u4e0b\u6587\u5bb9\u5668\u683c\u5f0f&#xff0c;\u7528\u4e8e\u5c01\u88c5\u5305\u62ec\u4f1a\u8bdd\u5386\u53f2\u8bb0\u5f55\u3001\u7528\u6237\u504f\u597d\u8bbe\u7f6e\u4ee5\u53ca\u4efb\u52a1\u76f8\u5173\u5143\u6570\u636e\u5728\u5185\u7684\u591a\u79cd\u4e0a\u4e0b\u6587\u4fe1\u606f\u3002\u8fd9\u79cd\u7ed3\u6784\u5316\u7684\u5bb9\u5668\u4f7f\u5f97\u4e0a\u4e0b\u6587\u5177\u5907\u826f\u597d\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u64cd\u4f5c\u6027&#xff0c;\u80fd\u591f\u51c6\u786e\u53cd\u6620\u4ea4\u4e92\u8fc7\u7a0b\u4e2d\u7684\u72b6\u6001\u4e0e\u610f\u56fe\u3002<\/p>\n<\/li>\n<li>\n<p>MCP \u63d0\u4f9b\u4e86\u4e00\u5957\u89c4\u8303\u7684\u5e8f\u5217\u5316\u6807\u51c6&#xff0c;\u786e\u4fdd\u4e0a\u4e0b\u6587\u80fd\u591f\u5728\u4e0d\u540c\u7684\u7cfb\u7edf\u3001\u670d\u52a1\u6216 Agent \u4e4b\u95f4\u9ad8\u6548\u3001\u53ef\u9760\u5730\u4f20\u8f93\u3002\u8be5\u6807\u51c6\u4e0d\u4ec5\u652f\u6301\u591a\u79cd\u6570\u636e\u683c\u5f0f\u7684\u8f6c\u6362\u4e0e\u89e3\u6790&#xff0c;\u8fd8\u517c\u987e\u4e86\u6027\u80fd\u4e0e\u517c\u5bb9\u6027&#xff0c;\u9002\u7528\u4e8e\u4ece\u672c\u5730\u8c03\u7528\u5230\u8de8\u7f51\u7edc\u901a\u4fe1\u7684\u591a\u79cd\u573a\u666f\u3002<\/p>\n<\/li>\n<li>\n<p>MCP \u8fd8\u5305\u542b\u4e00\u5957\u5b8c\u6574\u7684\u4e0a\u4e0b\u6587\u7ba1\u7406\u64cd\u4f5c&#xff0c;\u652f\u6301\u4e0a\u4e0b\u6587\u7684\u521b\u5efa\u3001\u66f4\u65b0\u3001\u5408\u5e76\u4e0e\u88c1\u526a\u7b49\u5173\u952e\u64cd\u4f5c\u3002\u8fd9\u4e9b\u64cd\u4f5c\u4f7f\u5f97\u7cfb\u7edf\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u52a8\u6001\u8c03\u6574\u4e0a\u4e0b\u6587\u5185\u5bb9&#xff0c;\u5728\u4fdd\u969c\u4fe1\u606f\u5b8c\u6574\u6027\u7684\u540c\u65f6\u907f\u514d\u5197\u4f59&#xff0c;\u63d0\u5347\u5904\u7406\u6548\u7387\u4e0e\u8d44\u6e90\u5229\u7528\u7387\u3002<\/p>\n<\/li>\n<p style=\"text-align: start\">MCP \u67b6\u6784\u7684\u6838\u5fc3\u7531\u4e0a\u4e0b\u6587\u5bb9\u5668\u7ec4\u6210&#xff1a;<\/p>\n<p> class ContextContainer:<br \/>\n\u00a0 \u00a0 &#034;&#034;&#034;Container for model context information.&#034;&#034;&#034;<\/p>\n<p>\u00a0 \u00a0 def __init__(self, conversation_id&#061;None):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.conversation_id &#061; conversation_id or str(uuid.uuid4())<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.messages &#061; []<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.metadata &#061; {}<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.created_at &#061; datetime.now()<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.updated_at &#061; datetime.now()<\/p>\n<p>\u00a0 \u00a0 def add_message(self, role, content, metadata&#061;None):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;&#034;&#034;Add a message to the context.&#034;&#034;&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 message &#061; {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;id&#034;: str(uuid.uuid4()),<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;role&#034;: role,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;content&#034;: content,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;timestamp&#034;: datetime.now().isoformat(),<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;metadata&#034;: metadata or {}<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 }<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.messages.append(message)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.updated_at &#061; datetime.now()<\/p>\n<p>\u00a0 \u00a0 def to_dict(self):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;&#034;&#034;Serialize the container to a dictionary.&#034;&#034;&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;conversation_id&#034;: self.conversation_id,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;messages&#034;: self.messages,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;metadata&#034;: self.metadata,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;created_at&#034;: self.created_at.isoformat(),<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;updated_at&#034;: self.updated_at.isoformat()<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 &#064;classmethod<br \/>\n\u00a0 \u00a0 def from_dict(cls, data):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;&#034;&#034;Create a container from a dictionary.&#034;&#034;&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 container &#061; cls(data.get(&#034;conversation_id&#034;))<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 container.messages &#061; data.get(&#034;messages&#034;, [])<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 container.metadata &#061; data.get(&#034;metadata&#034;, {})<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 container.created_at &#061; datetime.fromisoformat(data.get(&#034;created_at&#034;))<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 container.updated_at &#061; datetime.fromisoformat(data.get(&#034;updated_at&#034;))<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return container<\/p>\n<h3>2. LangGraph \u96c6\u6210<\/h3>\n<p style=\"text-align: start\">LangGraph \u5df2\u9010\u6e10\u6210\u4e3a\u6784\u5efa\u590d\u6742\u4eba\u5de5\u667a\u80fd\u5de5\u4f5c\u6d41\u7684\u9996\u9009\u6846\u67b6&#xff0c;\u5c24\u5176\u9002\u7528\u4e8e\u9700\u8981\u591a\u6b65\u9aa4\u63a8\u7406\u3001\u72b6\u6001\u7ba1\u7406\u4ee5\u53ca\u591a Agent \u534f\u4f5c\u7684\u573a\u666f\u3002\u901a\u8fc7\u5c06\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae&#xff08;MCP&#xff09;\u4e0e LangGraph \u6df1\u5ea6\u96c6\u6210&#xff0c;\u5f00\u53d1\u8005\u80fd\u591f\u6784\u5efa\u8d77\u7ed3\u6784\u66f4\u590d\u6742\u3001\u5206\u5e03\u66f4\u5e7f\u6cdb\u7684\u591a\u670d\u52a1\u7cfb\u7edf&#xff0c;\u540c\u65f6\u4fdd\u6301\u4e0a\u4e0b\u6587\u5728\u5404\u7ec4\u4ef6\u4e4b\u95f4\u7684\u65e0\u7f1d\u6d41\u8f6c\u4e0e\u4e00\u81f4\u6027\u3002<\/p>\n<p style=\"text-align: start\">\u4ee5\u4e0b\u662f MCP \u5728 LangGraph \u73af\u5883\u4e2d\u7684\u5b9e\u73b0\u65b9\u5f0f&#xff1a;<\/p>\n<p> import os<br \/>\nfrom typing import Dict, List, Any<br \/>\nimport requests<br \/>\nfrom langchain_core.language_models import BaseLLM<br \/>\nfrom langchain_core.messages import HumanMessage, AIMessage<br \/>\nfrom langgraph.graph import END, StateGraph<br \/>\nfrom langgraph.prebuilt import ToolNode<br \/>\n# MCP Context Manager<br \/>\nclass MCPContextManager:<br \/>\n\u00a0 \u00a0 def __init__(self, mcp_server_url):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.mcp_server_url &#061; mcp_server_url<\/p>\n<p>\u00a0 \u00a0 def create_context(self, initial_data&#061;None):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;&#034;&#034;Create a new context container.&#034;&#034;&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 response &#061; requests.post(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 f&#034;{self.mcp_server_url}\/contexts&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 json&#061;initial_data or {}<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 )<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return response.json()<\/p>\n<p>\u00a0 \u00a0 def get_context(self, context_id):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;&#034;&#034;Retrieve a context container.&#034;&#034;&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 response &#061; requests.get(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 f&#034;{self.mcp_server_url}\/contexts\/{context_id}&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 )<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return response.json()<\/p>\n<p>\u00a0 \u00a0 def update_context(self, context_id, data):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;&#034;&#034;Update a context container.&#034;&#034;&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 response &#061; requests.patch(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 f&#034;{self.mcp_server_url}\/contexts\/{context_id}&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 json&#061;data<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 )<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return response.json()<br \/>\n# MCP-aware LLM Node<br \/>\nclass MCPLLMNode:<br \/>\n\u00a0 \u00a0 def __init__(self, llm: BaseLLM, context_manager: MCPContextManager):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.llm &#061; llm<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.context_manager &#061; context_manager<\/p>\n<p>\u00a0 \u00a0 def __call__(self, state: Dict[str, Any]) -&gt; Dict[str, Any]:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 # Extract the context ID from state<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 context_id &#061; state.get(&#034;context_id&#034;)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 if not context_id:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 # Create new context if none exists<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 context &#061; self.context_manager.create_context()<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 context_id &#061; context[&#034;conversation_id&#034;]<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 state[&#034;context_id&#034;] &#061; context_id<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 else:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 # Retrieve existing context<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 context &#061; self.context_manager.get_context(context_id)<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 # Convert MCP messages to LangChain messages<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 messages &#061; []<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 for msg in context.get(&#034;messages&#034;, []):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if msg[&#034;role&#034;] &#061;&#061; &#034;user&#034;:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 messages.append(HumanMessage(content&#061;msg[&#034;content&#034;]))<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 elif msg[&#034;role&#034;] &#061;&#061; &#034;assistant&#034;:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 messages.append(AIMessage(content&#061;msg[&#034;content&#034;]))<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 # Add the current message if present<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 if &#034;current_input&#034; in state:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 messages.append(HumanMessage(content&#061;state[&#034;current_input&#034;]))<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 # Update MCP context with the user message<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 self.context_manager.update_context(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 context_id,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {&#034;add_message&#034;: {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;role&#034;: &#034;user&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;content&#034;: state[&#034;current_input&#034;]<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }}<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 )<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 # Generate response<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 response &#061; self.llm.generate_response(messages)<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 # Update MCP context with the assistant response<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.context_manager.update_context(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 context_id,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {&#034;add_message&#034;: {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;role&#034;: &#034;assistant&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;content&#034;: response.content<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }}<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 )<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 # Update state<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 state[&#034;current_output&#034;] &#061; response.content<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return state<br \/>\n# Building a multi-server LangGraph with MCP<br \/>\ndef build_mcp_graph(llm_servers: List[Dict], mcp_server_url: str):<br \/>\n\u00a0 \u00a0 &#034;&#034;&#034;<br \/>\n\u00a0 \u00a0 Build a LangGraph using multiple LLM servers with MCP integration.<\/p>\n<p>\u00a0 \u00a0 llm_servers: List of server configurations with name, url, and routing_criteria<br \/>\n\u00a0 \u00a0 mcp_server_url: URL of the MCP server<br \/>\n\u00a0 \u00a0 &#034;&#034;&#034;<br \/>\n\u00a0 \u00a0 context_manager &#061; MCPContextManager(mcp_server_url)<\/p>\n<p>\u00a0 \u00a0 # Create LLM nodes for each server<br \/>\n\u00a0 \u00a0 llm_nodes &#061; {}<br \/>\n\u00a0 \u00a0 for server in llm_servers:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 llm &#061; RemoteLLM(server[&#034;url&#034;])<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 llm_nodes[server[&#034;name&#034;]] &#061; MCPLLMNode(llm, context_manager)<\/p>\n<p>\u00a0 \u00a0 # Router function to determine which LLM to use<br \/>\n\u00a0 \u00a0 def router(state: Dict[str, Any]) -&gt; str:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 input_text &#061; state.get(&#034;current_input&#034;, &#034;&#034;)<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 for server in llm_servers:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 criteria &#061; server.get(&#034;routing_criteria&#034;, &#034;&#034;)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if criteria in input_text:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 return server[&#034;name&#034;]<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 # Default to the first server<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return llm_servers[0][&#034;name&#034;]<\/p>\n<p>\u00a0 \u00a0 # Build the graph<br \/>\n\u00a0 \u00a0 workflow &#061; StateGraph()<\/p>\n<p>\u00a0 \u00a0 # Add nodes<br \/>\n\u00a0 \u00a0 workflow.add_node(&#034;router&#034;, router)<br \/>\n\u00a0 \u00a0 for name, node in llm_nodes.items():<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 workflow.add_node(name, node)<\/p>\n<p>\u00a0 \u00a0 # Add edges<br \/>\n\u00a0 \u00a0 workflow.add_edge(&#034;router&#034;, dynamic&#061;True)<br \/>\n\u00a0 \u00a0 for name in llm_nodes.keys():<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 workflow.add_edge(name, END)<\/p>\n<p>\u00a0 \u00a0 # Set the entry point<br \/>\n\u00a0 \u00a0 workflow.set_entry_point(&#034;router&#034;)<\/p>\n<p>\u00a0 \u00a0 return workflow.compile()<\/p>\n<p style=\"text-align: start\">\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u57fa\u4e8e LangGraph \u548c MCP&#xff08;Model Context Protocol&#xff0c;\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae&#xff09;\u7684\u591a\u670d\u52a1\u5668 AI \u5de5\u4f5c\u6d41\u7cfb\u7edf\u3002\u5b83\u5c55\u793a\u4e86\u5982\u4f55\u5c06 MCP \u4e0e LangGraph \u96c6\u6210&#xff0c;\u4ece\u800c\u5728\u591a\u4e2a LLM&#xff08;\u8bed\u8a00\u6a21\u578b&#xff09;\u670d\u52a1\u4e4b\u95f4\u534f\u8c03\u4efb\u52a1&#xff0c;\u5e76\u4fdd\u6301\u7edf\u4e00\u7684\u4f1a\u8bdd\u4e0a\u4e0b\u6587\u72b6\u6001\u3002<\/p>\n<h3>3. \u521b\u5efa\u591a\u670d\u52a1\u5668\u90e8\u7f72<\/h3>\n<p style=\"text-align: start\">\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u770b\u770b\u5982\u4f55\u5728\u73b0\u5b9e\u4e16\u754c\u4e2d\u90e8\u7f72\u8fd9\u4e2a\u67b6\u6784&#xff1a;<\/p>\n<p> from fastapi import FastAPI, HTTPException<br \/>\nfrom pydantic import BaseModel<br \/>\nimport uvicorn<br \/>\napp &#061; FastAPI()<br \/>\n# Configuration for our LLM servers<br \/>\nllm_servers &#061; [<br \/>\n\u00a0 \u00a0 {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;name&#034;: &#034;general_llm&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;url&#034;: &#034;http:\/\/general-llm-server:8000\/generate&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;routing_criteria&#034;: &#034;&#034; \u00a0# Default server<br \/>\n\u00a0 \u00a0 },<br \/>\n\u00a0 \u00a0 {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;name&#034;: &#034;code_llm&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;url&#034;: &#034;http:\/\/code-llm-server:8001\/generate&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;routing_criteria&#034;: &#034;code&#034;<br \/>\n\u00a0 \u00a0 },<br \/>\n\u00a0 \u00a0 {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;name&#034;: &#034;creative_llm&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;url&#034;: &#034;http:\/\/creative-llm-server:8002\/generate&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;routing_criteria&#034;: &#034;write&#034;\u00a0<br \/>\n\u00a0 \u00a0 }<br \/>\n]<br \/>\n# MCP server URL<br \/>\nmcp_server_url &#061; &#034;http:\/\/mcp-server:9000&#034;<br \/>\n# Build our graph<br \/>\ngraph &#061; build_mcp_graph(llm_servers, mcp_server_url)<br \/>\nclass ChatRequest(BaseModel):<br \/>\n\u00a0 \u00a0 message: str<br \/>\n\u00a0 \u00a0 context_id: str &#061; None<br \/>\nclass ChatResponse(BaseModel):<br \/>\n\u00a0 \u00a0 response: str<br \/>\n\u00a0 \u00a0 context_id: str<br \/>\n&#064;app.post(&#034;\/chat&#034;, response_model&#061;ChatResponse)<br \/>\nasync def chat(request: ChatRequest):<br \/>\n\u00a0 \u00a0 # Initialize state<br \/>\n\u00a0 \u00a0 state &#061; {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;current_input&#034;: request.message<br \/>\n\u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 # Add context ID if provided<br \/>\n\u00a0 \u00a0 if request.context_id:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 state[&#034;context_id&#034;] &#061; request.context_id<\/p>\n<p>\u00a0 \u00a0 # Process through the graph<br \/>\n\u00a0 \u00a0 result &#061; graph.invoke(state)<\/p>\n<p>\u00a0 \u00a0 return ChatResponse(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 response&#061;result[&#034;current_output&#034;],<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 context_id&#061;result[&#034;context_id&#034;]<br \/>\n\u00a0 \u00a0 )<br \/>\nif __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n\u00a0 \u00a0 uvicorn.run(app, host&#061;&#034;0.0.0.0&#034;, port&#061;8080)<\/p>\n<h3>4. MCP \u670d\u52a1\u5668\u7684\u5b9e\u73b0<\/h3>\n<p style=\"text-align: start\">\u8fd9\u79cd\u67b6\u6784\u7684\u4e00\u4e2a\u5173\u952e\u7ec4\u4ef6\u662f\u7ba1\u7406\u4e0a\u4e0b\u6587\u5bb9\u5668\u7684\u4e13\u7528 MCP \u670d\u52a1\u5668&#xff1a;<\/p>\n<p> from fastapi import FastAPI, HTTPException<br \/>\nfrom pydantic import BaseModel<br \/>\nimport uvicorn<br \/>\nfrom typing import Dict, List, Optional, Any<br \/>\nimport uuid<br \/>\nfrom datetime import datetime<br \/>\nimport json<br \/>\nimport redis<\/p>\n<p>app &#061; FastAPI()<br \/>\n# Use Redis for persistence<br \/>\nredis_client &#061; redis.Redis(host&#061;&#034;redis&#034;, port&#061;6379, db&#061;0)<br \/>\nclass Message(BaseModel):<br \/>\n\u00a0 \u00a0 role: str<br \/>\n\u00a0 \u00a0 content: str<br \/>\n\u00a0 \u00a0 metadata: Optional[Dict[str, Any]] &#061; {}<br \/>\nclass CreateContextRequest(BaseModel):<br \/>\n\u00a0 \u00a0 metadata: Optional[Dict[str, Any]] &#061; {}<br \/>\n\u00a0 \u00a0 messages: Optional[List[Dict[str, Any]]] &#061; []<br \/>\nclass UpdateContextRequest(BaseModel):<br \/>\n\u00a0 \u00a0 metadata: Optional[Dict[str, Any]] &#061; None<br \/>\n\u00a0 \u00a0 add_message: Optional[Dict[str, Any]] &#061; None<br \/>\n\u00a0 \u00a0 replace_messages: Optional[List[Dict[str, Any]]] &#061; None<br \/>\n&#064;app.post(&#034;\/contexts&#034;)<br \/>\nasync def create_context(request: CreateContextRequest):<br \/>\n\u00a0 \u00a0 context_id &#061; str(uuid.uuid4())<br \/>\n\u00a0 \u00a0 now &#061; datetime.now().isoformat()<\/p>\n<p>\u00a0 \u00a0 context &#061; {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;conversation_id&#034;: context_id,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;messages&#034;: request.messages,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;metadata&#034;: request.metadata,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;created_at&#034;: now,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;updated_at&#034;: now<br \/>\n\u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 redis_client.set(f&#034;context:{context_id}&#034;, json.dumps(context))<br \/>\n\u00a0 \u00a0 return context<br \/>\n&#064;app.get(&#034;\/contexts\/{context_id}&#034;)<br \/>\nasync def get_context(context_id: str):<br \/>\n\u00a0 \u00a0 context_data &#061; redis_client.get(f&#034;context:{context_id}&#034;)<br \/>\n\u00a0 \u00a0 if not context_data:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 raise HTTPException(status_code&#061;404, detail&#061;&#034;Context not found&#034;)<\/p>\n<p>\u00a0 \u00a0 return json.loads(context_data)<br \/>\n&#064;app.patch(&#034;\/contexts\/{context_id}&#034;)<br \/>\nasync def update_context(context_id: str, request: UpdateContextRequest):<br \/>\n\u00a0 \u00a0 context_data &#061; redis_client.get(f&#034;context:{context_id}&#034;)<br \/>\n\u00a0 \u00a0 if not context_data:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 raise HTTPException(status_code&#061;404, detail&#061;&#034;Context not found&#034;)<\/p>\n<p>\u00a0 \u00a0 context &#061; json.loads(context_data)<br \/>\n\u00a0 \u00a0 context[&#034;updated_at&#034;] &#061; datetime.now().isoformat()<\/p>\n<p>\u00a0 \u00a0 # Update metadata if provided<br \/>\n\u00a0 \u00a0 if request.metadata is not None:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 context[&#034;metadata&#034;].update(request.metadata)<\/p>\n<p>\u00a0 \u00a0 # Add a message if provided<br \/>\n\u00a0 \u00a0 if request.add_message is not None:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 message &#061; {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;id&#034;: str(uuid.uuid4()),<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;role&#034;: request.add_message[&#034;role&#034;],<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;content&#034;: request.add_message[&#034;content&#034;],<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;timestamp&#034;: datetime.now().isoformat(),<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;metadata&#034;: request.add_message.get(&#034;metadata&#034;, {})<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 }<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 context[&#034;messages&#034;].append(message)<\/p>\n<p>\u00a0 \u00a0 # Replace messages if provided<br \/>\n\u00a0 \u00a0 if request.replace_messages is not None:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 context[&#034;messages&#034;] &#061; request.replace_messages<\/p>\n<p>\u00a0 \u00a0 redis_client.set(f&#034;context:{context_id}&#034;, json.dumps(context))<br \/>\n\u00a0 \u00a0 return context<br \/>\nif __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n\u00a0 \u00a0 uvicorn.run(app, host&#061;&#034;0.0.0.0&#034;, port&#061;9000)<\/p>\n<h3>5. \u4e3a\u90e8\u7f72\u64b0\u5199 Docker<\/h3>\n<p style=\"text-align: start\">\u4e3a\u4e86\u628a\u4e00\u5207\u8054\u7cfb\u8d77\u6765&#xff0c;\u53ef\u4ee5\u4f7f\u7528 Docker Compose \u6765\u90e8\u7f72\u6211\u4eec\u7684\u591a\u670d\u52a1\u5668\u7cfb\u7edf&#xff1a;<\/p>\n<p> version: &#039;3&#039;<br \/>\nservices:<br \/>\n\u00a0 # Main API Gateway<br \/>\n\u00a0 api_gateway:<br \/>\n\u00a0 \u00a0 build: .\/api_gateway<br \/>\n\u00a0 \u00a0 ports:<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; &#034;8080:8080&#034;<br \/>\n\u00a0 \u00a0 environment:<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; MCP_SERVER_URL&#061;http:\/\/mcp_server:9000<br \/>\n\u00a0 \u00a0 depends_on:<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; mcp_server<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; general_llm<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; code_llm<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; creative_llm<br \/>\n\u00a0 # MCP Server<br \/>\n\u00a0 mcp_server:<br \/>\n\u00a0 \u00a0 build: .\/mcp_server<br \/>\n\u00a0 \u00a0 ports:<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; &#034;9000:9000&#034;<br \/>\n\u00a0 \u00a0 depends_on:<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; redis<br \/>\n\u00a0 # Redis for MCP persistence<br \/>\n\u00a0 redis:<br \/>\n\u00a0 \u00a0 image: redis:alpine<br \/>\n\u00a0 \u00a0 ports:<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; &#034;6379:6379&#034;<br \/>\n\u00a0 # LLM Servers<br \/>\n\u00a0 general_llm:<br \/>\n\u00a0 \u00a0 build: .\/llm_servers\/general<br \/>\n\u00a0 \u00a0 ports:<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; &#034;8000:8000&#034;<br \/>\n\u00a0 code_llm:<br \/>\n\u00a0 \u00a0 build: .\/llm_servers\/code<br \/>\n\u00a0 \u00a0 ports:<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; &#034;8001:8000&#034;<br \/>\n\u00a0 creative_llm:<br \/>\n\u00a0 \u00a0 build: .\/llm_servers\/creative<br \/>\n\u00a0 \u00a0 ports:<br \/>\n\u00a0 \u00a0 \u00a0 &#8211; &#034;8002:8000&#034;<\/p>\n<h3>6. \u6027\u80fd\u5173\u6ce8<\/h3>\n<p style=\"text-align: start\">\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u90e8\u7f72\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae&#xff08;MCP&#xff09;\u65f6&#xff0c;\u6027\u80fd\u4f18\u5316\u662f\u786e\u4fdd\u7cfb\u7edf\u9ad8\u6548\u7a33\u5b9a\u8fd0\u884c\u7684\u5173\u952e\u3002\u4ee5\u4e0b\u662f\u51e0\u4e2a\u9700\u8981\u91cd\u70b9\u5173\u6ce8\u7684\u6027\u80fd\u8003\u91cf\u53ca\u5e94\u5bf9\u7b56\u7565&#xff1a;<\/p>\n<p style=\"text-align: start\">\u4e0a\u4e0b\u6587\u5927\u5c0f\u7ba1\u7406\u968f\u7740\u4f1a\u8bdd\u6301\u7eed\u8fdb\u884c&#xff0c;\u4e0a\u4e0b\u6587\u5bb9\u5668\u53ef\u80fd\u4f1a\u4e0d\u65ad\u589e\u957f&#xff0c;\u5bfc\u81f4\u5b58\u50a8\u5f00\u9500\u548c\u4f20\u8f93\u5ef6\u8fdf\u589e\u52a0\u3002\u4e3a\u907f\u514d\u8fd9\u4e00\u95ee\u9898&#xff0c;\u5e94\u5b9e\u65bd\u6709\u6548\u7684\u526a\u679d\u7b56\u7565&#xff0c;\u4f8b\u5982\u4ec5\u4fdd\u7559\u6700\u8fd1\u7684\u51e0\u8f6e\u5bf9\u8bdd\u6216\u901a\u8fc7\u8bed\u4e49\u5206\u6790\u63d0\u53d6\u5173\u952e\u4fe1\u606f&#xff0c;\u4ece\u800c\u4fdd\u6301\u4e0a\u4e0b\u6587\u7684\u7cbe\u7b80\u4e0e\u76f8\u5173\u6027\u3002<\/p>\n<p style=\"text-align: start\">\u5e8f\u5217\u5316\u6548\u7387\u5728\u9ad8\u541e\u5410\u91cf\u7684\u7cfb\u7edf\u4e2d&#xff0c;\u9891\u7e41\u7684\u4e0a\u4e0b\u6587\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\u53ef\u80fd\u6210\u4e3a\u6027\u80fd\u74f6\u9888\u3002\u5efa\u8bae\u91c7\u7528\u66f4\u9ad8\u6548\u7684\u5e8f\u5217\u5316\u683c\u5f0f&#xff0c;\u5982 Protocol Buffers\u3001MessagePack \u6216 FlatBuffers&#xff0c;\u4ee5\u66ff\u4ee3\u4f20\u7edf\u7684 JSON&#xff0c;\u4ece\u800c\u51cf\u5c11\u6570\u636e\u4f53\u79ef\u5e76\u52a0\u5feb\u7f16\u89e3\u7801\u901f\u5ea6&#xff0c;\u63d0\u5347\u6574\u4f53\u5904\u7406\u6548\u7387\u3002<\/p>\n<p style=\"text-align: start\">\u7f13\u5b58\u7b56\u7565\u4e3a\u4e86\u964d\u4f4e\u5bf9\u540e\u7aef MCP \u670d\u52a1\u7684\u8bbf\u95ee\u9891\u7387&#xff0c;\u51cf\u5c11\u91cd\u590d\u67e5\u8be2\u5e26\u6765\u7684\u5ef6\u8fdf&#xff0c;\u5e94\u5728\u591a\u4e2a\u5c42\u7ea7&#xff08;\u5982\u5ba2\u6237\u7aef\u3001\u7f51\u5173\u6216\u670d\u52a1\u7aef&#xff09;\u5f15\u5165\u7f13\u5b58\u673a\u5236\u3002\u53ef\u7f13\u5b58\u5f53\u524d\u6d3b\u8dc3\u7684\u4e0a\u4e0b\u6587\u7247\u6bb5&#xff0c;\u4ec5\u5728\u5fc5\u8981\u65f6\u540c\u6b65\u66f4\u65b0\u6216\u62c9\u53d6\u6700\u65b0\u72b6\u6001&#xff0c;\u4ece\u800c\u663e\u8457\u63d0\u5347\u54cd\u5e94\u901f\u5ea6\u5e76\u51cf\u8f7b\u7cfb\u7edf\u8d1f\u8f7d\u3002<\/p>\n<p style=\"text-align: start\">\u901a\u8fc7\u5408\u7406\u8bbe\u8ba1\u8fd9\u4e9b\u6027\u80fd\u4f18\u5316\u7b56\u7565&#xff0c;\u53ef\u4ee5\u6709\u6548\u4fdd\u969c MCP \u5728\u5927\u89c4\u6a21\u3001\u9ad8\u5e76\u53d1 AI \u5e94\u7528\u573a\u666f\u4e0b\u7684\u7a33\u5b9a\u6027\u4e0e\u53ef\u6269\u5c55\u6027&#xff0c;\u4f7f\u5176\u66f4\u597d\u5730\u670d\u52a1\u4e8e\u590d\u6742\u7684\u667a\u80fd\u5de5\u4f5c\u6d41\u9700\u6c42\u3002<\/p>\n<p> class CachedMCPContextManager(MCPContextManager):<br \/>\n\u00a0 \u00a0 def __init__(self, mcp_server_url, cache_ttl&#061;300):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 super().__init__(mcp_server_url)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.cache &#061; {}<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.cache_ttl &#061; cache_ttl<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.last_access &#061; {}<\/p>\n<p>\u00a0 \u00a0 def get_context(self, context_id):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 current_time &#061; time.time()<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 # Check cache<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 if context_id in self.cache:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 self.last_access[context_id] &#061; current_time<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 return self.cache[context_id]<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 # Retrieve from server<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 context &#061; super().get_context(context_id)<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 # Update cache<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.cache[context_id] &#061; context<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.last_access[context_id] &#061; current_time<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 # Prune cache if needed<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self._prune_cache()<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 return context<\/p>\n<p>\u00a0 \u00a0 def _prune_cache(self):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 current_time &#061; time.time()<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 expired_keys &#061; [<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 k for k, v in self.last_access.items()\u00a0<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if current_time &#8211; v &gt; self.cache_ttl<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 ]<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 for key in expired_keys:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if key in self.cache:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 del self.cache[key]<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if key in self.last_access:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 del self.last_access[key]<\/p>\n<h3>7. \u5b89\u5168\u6027\u8003\u91cf<\/h3>\n<p style=\"text-align: start\">\u5728\u5b9e\u65bd\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae&#xff08;MCP&#xff09;\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u5b89\u5168\u6027\u662f\u4e00\u4e2a\u4e0d\u53ef\u5ffd\u89c6\u7684\u5173\u952e\u73af\u8282\u3002\u7531\u4e8e\u4e0a\u4e0b\u6587\u5bb9\u5668\u53ef\u80fd\u5305\u542b\u7528\u6237\u7684\u654f\u611f\u4fe1\u606f&#xff0c;\u5982\u5bf9\u8bdd\u5386\u53f2\u3001\u4e2a\u4eba\u504f\u597d\u6216\u4e1a\u52a1\u6570\u636e&#xff0c;\u56e0\u6b64\u5fc5\u987b\u91c7\u53d6\u5168\u9762\u7684\u5b89\u5168\u63aa\u65bd\u6765\u4fdd\u969c\u7cfb\u7edf\u7684\u53ef\u9760\u6027\u548c\u7528\u6237\u9690\u79c1\u3002<\/p>\n<p style=\"text-align: start\">\u5728\u6570\u636e\u4fdd\u62a4\u65b9\u9762&#xff0c;\u5e94\u786e\u4fdd\u4e0a\u4e0b\u6587\u6570\u636e\u5728\u5b58\u50a8\u548c\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u59cb\u7ec8\u5904\u4e8e\u52a0\u5bc6\u72b6\u6001\u3002\u540c\u65f6&#xff0c;\u5efa\u7acb\u4e25\u683c\u7684\u8bbf\u95ee\u63a7\u5236\u673a\u5236&#xff0c;\u4ec5\u5141\u8bb8\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u548c\u6388\u6743\u7684\u5b9e\u4f53\u8bfb\u53d6\u6216\u4fee\u6539\u4e0a\u4e0b\u6587\u5185\u5bb9\u3002\u6b64\u5916&#xff0c;\u8fd8\u9700\u5236\u5b9a\u5408\u7406\u7684\u6570\u636e\u4fdd\u7559\u7b56\u7565&#xff0c;\u660e\u786e\u4e0a\u4e0b\u6587\u4fe1\u606f\u7684\u5b58\u50a8\u65f6\u9650&#xff0c;\u5e76\u5728\u4efb\u52a1\u5b8c\u6210\u540e\u53ca\u65f6\u6e05\u7406\u6216\u5f52\u6863&#xff0c;\u4ee5\u964d\u4f4e\u6570\u636e\u6cc4\u9732\u7684\u98ce\u9669\u3002<\/p>\n<p style=\"text-align: start\">\u8eab\u4efd\u9a8c\u8bc1\u4e0e\u6388\u6743\u662f\u4fdd\u969c\u7cfb\u7edf\u5b89\u5168\u7684\u6838\u5fc3\u73af\u8282\u3002\u6240\u6709\u8bd5\u56fe\u8bbf\u95ee\u6216\u66f4\u65b0\u4e0a\u4e0b\u6587\u7684\u8bf7\u6c42\u90fd\u5fc5\u987b\u901a\u8fc7\u53ef\u4fe1\u7684\u8eab\u4efd\u8ba4\u8bc1\u6d41\u7a0b&#xff0c;\u4f8b\u5982\u4f7f\u7528 API \u5bc6\u94a5\u3001OAuth \u4ee4\u724c\u6216\u57fa\u4e8e\u89d2\u8272\u7684\u8bbf\u95ee\u63a7\u5236&#xff08;RBAC&#xff09;\u3002\u8fd9\u53ef\u4ee5\u6709\u6548\u9632\u6b62\u672a\u7ecf\u6388\u6743\u7684\u7cfb\u7edf\u6216\u7528\u6237\u7be1\u6539\u4e0a\u4e0b\u6587\u5185\u5bb9&#xff0c;\u4ece\u800c\u4fdd\u969c\u6574\u4e2a MCP \u7cfb\u7edf\u7684\u6570\u636e\u5b8c\u6574\u6027\u548c\u64cd\u4f5c\u5408\u6cd5\u6027\u3002<\/p>\n<p style=\"text-align: start\">\u4e3a\u9632\u8303\u6f5c\u5728\u7684\u653b\u51fb\u884c\u4e3a&#xff0c;\u8fd8\u5fc5\u987b\u91cd\u89c6\u8f93\u5165\u9a8c\u8bc1\u4e0e\u5185\u5bb9\u6d88\u6bd2\u3002\u4efb\u4f55\u8fdb\u5165\u4e0a\u4e0b\u6587\u7684\u6570\u636e\u90fd\u5e94\u7ecf\u8fc7\u4e25\u683c\u6821\u9a8c&#xff0c;\u907f\u514d\u6076\u610f\u6784\u9020\u7684\u5185\u5bb9\u5f15\u53d1\u6ce8\u5165\u653b\u51fb\u6216\u5176\u4ed6\u5b89\u5168\u6f0f\u6d1e\u3002\u5efa\u8bae\u5728\u6570\u636e\u5199\u5165\u4e0a\u4e0b\u6587\u4e4b\u524d\u8fdb\u884c\u683c\u5f0f\u68c0\u67e5\u3001\u8f6c\u4e49\u5904\u7406\u6216\u4f7f\u7528\u6c99\u7bb1\u673a\u5236&#xff0c;\u4ece\u6e90\u5934\u4e0a\u675c\u7edd\u5b89\u5168\u9690\u60a3\u3002<\/p>\n<p style=\"text-align: start\">\u901a\u8fc7\u5728\u6570\u636e\u4fdd\u62a4\u3001\u8bbf\u95ee\u63a7\u5236\u548c\u8f93\u5165\u8fc7\u6ee4\u7b49\u65b9\u9762\u6784\u5efa\u591a\u5c42\u6b21\u7684\u5b89\u5168\u9632\u62a4\u4f53\u7cfb&#xff0c;\u53ef\u4ee5\u6709\u6548\u63d0\u5347 MCP \u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u5b89\u5168\u6027&#xff0c;\u4e3a\u5176\u5728\u590d\u6742\u3001\u9ad8\u8981\u6c42\u7684\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u90e8\u7f72\u63d0\u4f9b\u575a\u5b9e\u4fdd\u969c\u3002<\/p>\n<p> class SecureMCPContextManager(MCPContextManager):<br \/>\n\u00a0 \u00a0 def __init__(self, mcp_server_url, api_key):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 super().__init__(mcp_server_url)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 self.api_key &#061; api_key<\/p>\n<p>\u00a0 \u00a0 def _get_headers(self):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;Authorization&#034;: f&#034;Bearer {self.api_key}&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#034;Content-Type&#034;: &#034;application\/json&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 def create_context(self, initial_data&#061;None):<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 &#034;&#034;&#034;Create a new context container with authentication.&#034;&#034;&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 response &#061; requests.post(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 f&#034;{self.mcp_server_url}\/contexts&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 headers&#061;self._get_headers(),<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 json&#061;initial_data or {}<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 )<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return response.json()<\/p>\n<p>\u00a0 \u00a0 # Similarly update other methods to use authentication<\/p>\n<h3>\u5c0f\u7ed3<\/h3>\n<p style=\"text-align: start\">MCP\u7684\u51fa\u73b0&#xff0c;\u6807\u5fd7\u7740\u5206\u5e03\u5f0f\u4eba\u5de5\u667a\u80fd\u7cfb\u7edf\u4f53\u7cfb\u67b6\u6784\u53d6\u5f97\u4e86\u91cd\u5927\u7684\u7a81\u7834\u4e0e\u8fdb\u5c55\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u6807\u51c6\u5316\u7684\u65b9\u6cd5&#xff0c;\u7528\u4e8e\u7ba1\u7406\u548c\u4f20\u8f93\u4e0d\u540c\u7ec4\u4ef6\u4e4b\u95f4\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f&#xff0c;\u4ece\u800c\u4e3a\u521b\u5efa\u80fd\u591f\u4fdd\u6301\u4e0a\u4e0b\u6587\u8fde\u7eed\u6027\u7684\u590d\u6742\u591a\u670d\u52a1\u5668\u7cfb\u7edf\u63d0\u4f9b\u4e86\u6709\u529b\u652f\u6301\u3002<\/p>\n<p style=\"text-align: start\">\u5728\u5f53\u4eca\u65f6\u4ee3&#xff0c;\u4eba\u5de5\u667a\u80fd\u7cfb\u7edf\u6b63\u53d8\u5f97\u6108\u53d1\u590d\u6742\u3002\u5728\u8fd9\u6837\u7684\u80cc\u666f\u4e0b&#xff0c;\u50cfMCP\u8fd9\u6837\u7684\u534f\u8bae\u5bf9\u4e8e\u6253\u9020\u65e0\u7f1d\u7684\u7528\u6237\u4f53\u9a8c\u800c\u8a00&#xff0c;\u5176\u91cd\u8981\u6027\u5c06\u65e5\u76ca\u51f8\u663e\u3002\u5f00\u53d1\u4eba\u5458\u901a\u8fc7\u5b9e\u73b0\u672c\u6587\u6240\u9610\u8ff0\u7684\u6a21\u5f0f\u548c\u4ee3\u7801&#xff0c;\u4fbf\u80fd\u591f\u6784\u5efa\u51fa\u5065\u58ee\u7684\u5206\u5e03\u5f0fAI\u7cfb\u7edf&#xff0c;\u8fdb\u800c\u786e\u4fdd\u8de8\u670d\u52a1\u5668\u548c\u6a21\u578b\u7684\u4e0a\u4e0b\u6587\u5f97\u4ee5\u6709\u6548\u7ef4\u62a4\u3002<\/p>\n<p style=\"text-align: start\">MCP\u7684\u771f\u6b63\u4f18\u52bf\u5728\u4e8e\u5b83\u7684\u7b80\u6d01\u6027\u4e0e\u7075\u6d3b\u6027\u3002\u5b83\u5c06\u4e0a\u4e0b\u6587\u7ba1\u7406\u4e0e\u5355\u4e2aAI\u7ec4\u4ef6\u76f8\u5206\u79bb&#xff0c;\u8fd9\u4f7f\u5f97\u66f4\u6a21\u5757\u5316\u3001\u6613\u4e8e\u7ef4\u62a4\u4e14\u5177\u5907\u53ef\u4f38\u7f29\u6027\u7684\u4f53\u7cfb\u67b6\u6784\u6210\u4e3a\u53ef\u80fd\u3002\u968f\u7740\u4eba\u5de5\u667a\u80fd\u751f\u6001\u7cfb\u7edf\u7684\u6301\u7eed\u53d1\u5c55&#xff0c;\u6211\u4eec\u6709\u7406\u7531\u671f\u5f85\u770b\u5230\u66f4\u591a\u7c7b\u4f3c\u7684\u6807\u51c6\u5316\u534f\u8bae\u51fa\u73b0\u3002<\/p>\n<p>\u3010\u5173\u8054\u9605\u8bfb\u3011<\/p>\n<ul>\n<li>\n<p style=\"text-align: justify\">\u4ec0\u4e48\u53ef\u80fd\u4f1a\u5b9a\u4e49\u4eba\u5de5\u667a\u80fd\u7684\u4e0b\u4e00\u4e2a\u5341\u5e74&#xff1f;<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u5e94\u7528\u7cfb\u5217&#xff1a;\u4e24\u4e07\u5b57\u89e3\u8bfbMCP<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u62c6\u89e3OpenAI\u6700\u5927\u5bf9\u624b\u7684\u6740\u624b\u950f&#xff1a;\u4e3a\u4ec0\u4e48\u4f1a\u662fMCP&#xff1f;<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u4e07\u5b57\u89e3\u8bfb&#xff1a;8\u79cd\u5e38\u89c1\u6846\u67b6&#xff0c;\u9009\u62e9\u54ea\u4e00\u79cd\u6765\u5f00\u53d1MCP\u5462&#xff1f;<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">MCP\u89c4\u8303\u5b8c\u6574\u4e2d\u8bd1\u7a3f&#xff1a;2025-3-26\u7248<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u667a\u80fd\u4f53\u95f4\u534f\u4f5c\u7684&#034;\u5df4\u522b\u5854\u56f0\u5883&#034;\u5982\u4f55\u7834\u89e3&#xff1f;\u89e3\u8bfbAgent\u901a\u4fe14\u5927\u534f\u8bae&#xff1a;MCP\/ACP\/A2A\/ANP<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u5e94\u7528\u768410\u79cd\u67b6\u6784\u6a21\u5f0f<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">7B&#xff1f;13B&#xff1f;175B&#xff1f;\u89e3\u8bfb\u5927\u6a21\u578b\u7684\u53c2\u6570<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u5e94\u7528\u7cfb\u5217&#xff1a;\u4eceRanking\u5230Reranking<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u5e94\u7528\u7cfb\u5217&#xff1a;Query \u53d8\u6362\u7684\u793a\u4f8b\u6d45\u6790<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u4ece\u96f6\u6784\u5efa\u5927\u6a21\u578b\u4e4bTransformer\u516c\u5f0f\u89e3\u8bfb<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5982\u4f55\u9009\u62e9Embedding Model&#xff1f;\u5173\u4e8e\u5d4c\u5165\u6a21\u578b\u768410\u4e2a\u601d\u8003<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfb\u6587\u672c\u5d4c\u5165&#xff1a;\u8bed\u4e49\u8868\u8fbe\u7684\u7ec3\u4e60<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfb\u77e5\u8bc6\u56fe\u8c31\u7684\u81ea\u52a8\u6784\u5efa<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u201c\u63d0\u793a\u5de5\u7a0b\u201d\u7684\u6280\u672f\u5206\u7c7b<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u7cfb\u5217&#xff1a;\u63d0\u793a\u8bcd\u7ba1\u7406<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u63d0\u793a\u5de5\u7a0b\u4e2d\u768410\u4e2a\u8bbe\u8ba1\u6a21\u5f0f<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfb&#xff1a;\u57fa\u4e8e\u56fe\u7684\u5927\u6a21\u578b\u63d0\u793a\u6280\u672f<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u5fae\u8c03&#xff1a;RHLF\u4e0eDPO\u6d45\u6790<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">Chunking&#xff1a;\u57fa\u4e8e\u5927\u6a21\u578bRAG\u7cfb\u7edf\u4e2d\u7684\u6587\u6863\u5206\u5757<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u5e94\u7528\u6846\u67b6&#xff1a;LangChain\u4e0eLlamaIndex\u7684\u5bf9\u6bd4\u9009\u62e9<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfb\u5927\u6a21\u578b\u5e94\u7528\u7684\u53ef\u89c2\u6d4b\u6027<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u7cfb\u5217\u4e4b\u89e3\u8bfbMoE<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5728\u5927\u6a21\u578bRAG\u7cfb\u7edf\u4e2d\u5e94\u7528\u77e5\u8bc6\u56fe\u8c31<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u9762\u5411\u77e5\u8bc6\u56fe\u8c31\u7684\u5927\u6a21\u578b\u5e94\u7528<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u8ba9\u77e5\u8bc6\u56fe\u8c31\u6210\u4e3a\u5927\u6a21\u578b\u7684\u4f34\u4fa3<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5982\u4f55\u6784\u5efa\u57fa\u4e8e\u5927\u6a21\u578b\u7684App<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">Qcon2023: \u5927\u6a21\u578b\u65f6\u4ee3\u7684\u6280\u672f\u4eba\u6210\u957f&#xff08;\u7b80&#xff09;<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u8bba\u6587\u5b66\u4e60\u7b14\u8bb0&#xff1a;\u589e\u5f3a\u5b66\u4e60\u5e94\u7528\u4e8eOS\u8c03\u5ea6<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u300a\u6df1\u5165\u6d45\u51faEmbedding\u300b\u968f\u7b14<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">LLM\u7684\u5de5\u7a0b\u5b9e\u8df5\u601d\u8003<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u5e94\u7528\u8bbe\u8ba1\u768410\u4e2a\u601d\u8003<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u57fa\u4e8e\u5927\u6a21\u578b&#xff08;LLM&#xff09;\u7684Agent \u5e94\u7528\u5f00\u53d1<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfb\u5927\u6a21\u578b\u7684\u5fae\u8c03<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfb\u5411\u91cf\u6570\u636e\u5e93<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfb\u5411\u91cf\u7d22\u5f15<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfbChatGPT\u4e2d\u7684RLHF<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfb\u5927\u6a21\u578b&#xff08;LLM&#xff09;\u7684token<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfb\u63d0\u793a\u8bcd\u5de5\u7a0b&#xff08;Prompt Engineering&#xff09;<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfbToolformer<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfbTaskMatrix.AI<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfbLangChain<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfbLoRA<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u89e3\u8bfbRAG<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u5e94\u7528\u6846\u67b6\u4e4bSemantic Kernel<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u6d45\u6790\u591a\u6a21\u6001\u673a\u5668\u5b66\u4e60<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u5927\u6a21\u578b\u5e94\u7528\u4e8e\u6570\u5b57\u4eba<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u6df1\u5ea6\u5b66\u4e60\u67b6\u6784\u7684\u5bf9\u6bd4\u5206\u6790<\/p>\n<\/li>\n<li>\n<p style=\"text-align: justify\">\u8001\u7801\u519c\u773c\u4e2d\u7684\u5927\u6a21\u578b&#xff08;LLM&#xff09;<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb727\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf30\u6b21\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u5236\u5b9a\u5408\u7406\u7684\u6570\u636e\u4fdd\u7559\u7b56\u7565\uff0c\u660e\u786e\u4e0a\u4e0b\u6587\u4fe1\u606f\u7684\u5b58\u50a8\u65f6\u9650\uff0c\u5e76\u5728\u4efb\u52a1\u5b8c\u6210\u540e\u53ca\u65f6\u6e05\u7406\u6216\u5f52\u6863\uff0c\u4ee5\u964d\u4f4e\u6570\u636e\u6cc4\u9732\u7684\u98ce\u9669\u3002\u4e3a\u907f\u514d\u8fd9\u4e00\u95ee\u9898\uff0c\u5e94\u5b9e\u65bd\u6709\u6548\u7684\u526a\u679d\u7b56\u7565\uff0c\u4f8b\u5982\u4ec5\u4fdd\u7559\u6700\u8fd1\u7684\u51e0\u8f6e\u5bf9\u8bdd\u6216\u901a\u8fc7\u8bed\u4e49\u5206\u6790\u63d0\u53d6\u5173\u952e\u4fe1\u606f\uff0c\u4ece\u800c\u4fdd\u6301\u4e0a\u4e0b\u6587\u7684\u7cbe\u7b80\u4e0e\u76f8\u5173\u6027\u3002\u73b0\u4ee3\u4eba\u5de5\u667a\u80fd\u5e94\u7528\u7a0b\u5e8f\u901a\u5e38\u9700\u8981\u5bf9\u4e0d\u540c\u7684\u8bed\u8a00\u6a21\u578b\u548c\u4e13\u95e8\u7684\u670d\u52a1\u5668\u8fdb\u884c\u590d\u6742\u7684\u7f16\u6392\uff0c\u6bcf\u4e2a\u670d\u52a1\u5668\u5728\u66f4\u5927\u7684\u5de5\u4f5c\u6d41\u4e2d\u5904\u7406\u7279\u5b9a\u7684\u4efb\u52a1\u3002\u901a\u8fc7\u5728\u6570\u636e\u4fdd\u62a4\u3001\u8bbf\u95ee\u63a7\u5236\u548c\u8f93\u5165\u8fc7\u6ee4\u7b49\u65b9\u9762\u6784\u5efa\u591a\u5c42\u6b21\u7684\u5b89\u5168\u9632\u62a4\u4f53\u7cfb\uff0c\u53ef\u4ee5\u6709\u6548\u63d0\u5347 MCP \u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u5b89\u5168\u6027\uff0c\u4e3a\u5176\u5728\u590d\u6742\u3001\u9ad8\u8981\u6c42\u7684\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u90e8\u7f72\u63d0\u4f9b\u575a\u5b9e\u4fdd\u969c\u3002<\/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":[43,44],"topic":[],"class_list":["post-46789","post","type-post","status-publish","format-standard","hentry","category-server","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u91c7\u7528LangGraph\u96c6\u6210\u591a\u4e2aMCP\u670d\u52a1\u5668\u7684\u5e94\u7528 - \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\/46789.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u91c7\u7528LangGraph\u96c6\u6210\u591a\u4e2aMCP\u670d\u52a1\u5668\u7684\u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb727\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf30\u6b21\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u5236\u5b9a\u5408\u7406\u7684\u6570\u636e\u4fdd\u7559\u7b56\u7565\uff0c\u660e\u786e\u4e0a\u4e0b\u6587\u4fe1\u606f\u7684\u5b58\u50a8\u65f6\u9650\uff0c\u5e76\u5728\u4efb\u52a1\u5b8c\u6210\u540e\u53ca\u65f6\u6e05\u7406\u6216\u5f52\u6863\uff0c\u4ee5\u964d\u4f4e\u6570\u636e\u6cc4\u9732\u7684\u98ce\u9669\u3002\u4e3a\u907f\u514d\u8fd9\u4e00\u95ee\u9898\uff0c\u5e94\u5b9e\u65bd\u6709\u6548\u7684\u526a\u679d\u7b56\u7565\uff0c\u4f8b\u5982\u4ec5\u4fdd\u7559\u6700\u8fd1\u7684\u51e0\u8f6e\u5bf9\u8bdd\u6216\u901a\u8fc7\u8bed\u4e49\u5206\u6790\u63d0\u53d6\u5173\u952e\u4fe1\u606f\uff0c\u4ece\u800c\u4fdd\u6301\u4e0a\u4e0b\u6587\u7684\u7cbe\u7b80\u4e0e\u76f8\u5173\u6027\u3002\u73b0\u4ee3\u4eba\u5de5\u667a\u80fd\u5e94\u7528\u7a0b\u5e8f\u901a\u5e38\u9700\u8981\u5bf9\u4e0d\u540c\u7684\u8bed\u8a00\u6a21\u578b\u548c\u4e13\u95e8\u7684\u670d\u52a1\u5668\u8fdb\u884c\u590d\u6742\u7684\u7f16\u6392\uff0c\u6bcf\u4e2a\u670d\u52a1\u5668\u5728\u66f4\u5927\u7684\u5de5\u4f5c\u6d41\u4e2d\u5904\u7406\u7279\u5b9a\u7684\u4efb\u52a1\u3002\u901a\u8fc7\u5728\u6570\u636e\u4fdd\u62a4\u3001\u8bbf\u95ee\u63a7\u5236\u548c\u8f93\u5165\u8fc7\u6ee4\u7b49\u65b9\u9762\u6784\u5efa\u591a\u5c42\u6b21\u7684\u5b89\u5168\u9632\u62a4\u4f53\u7cfb\uff0c\u53ef\u4ee5\u6709\u6548\u63d0\u5347 MCP \u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u5b89\u5168\u6027\uff0c\u4e3a\u5176\u5728\u590d\u6742\u3001\u9ad8\u8981\u6c42\u7684\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u90e8\u7f72\u63d0\u4f9b\u575a\u5b9e\u4fdd\u969c\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/46789.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T20:07:31+00:00\" \/>\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=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46789.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/46789.html\",\"name\":\"\u91c7\u7528LangGraph\u96c6\u6210\u591a\u4e2aMCP\u670d\u52a1\u5668\u7684\u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T20:07:31+00:00\",\"dateModified\":\"2025-07-29T20:07:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/46789.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/46789.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46789.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u91c7\u7528LangGraph\u96c6\u6210\u591a\u4e2aMCP\u670d\u52a1\u5668\u7684\u5e94\u7528\"}]},{\"@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":"\u91c7\u7528LangGraph\u96c6\u6210\u591a\u4e2aMCP\u670d\u52a1\u5668\u7684\u5e94\u7528 - \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\/46789.html","og_locale":"zh_CN","og_type":"article","og_title":"\u91c7\u7528LangGraph\u96c6\u6210\u591a\u4e2aMCP\u670d\u52a1\u5668\u7684\u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb727\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf30\u6b21\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u5236\u5b9a\u5408\u7406\u7684\u6570\u636e\u4fdd\u7559\u7b56\u7565\uff0c\u660e\u786e\u4e0a\u4e0b\u6587\u4fe1\u606f\u7684\u5b58\u50a8\u65f6\u9650\uff0c\u5e76\u5728\u4efb\u52a1\u5b8c\u6210\u540e\u53ca\u65f6\u6e05\u7406\u6216\u5f52\u6863\uff0c\u4ee5\u964d\u4f4e\u6570\u636e\u6cc4\u9732\u7684\u98ce\u9669\u3002\u4e3a\u907f\u514d\u8fd9\u4e00\u95ee\u9898\uff0c\u5e94\u5b9e\u65bd\u6709\u6548\u7684\u526a\u679d\u7b56\u7565\uff0c\u4f8b\u5982\u4ec5\u4fdd\u7559\u6700\u8fd1\u7684\u51e0\u8f6e\u5bf9\u8bdd\u6216\u901a\u8fc7\u8bed\u4e49\u5206\u6790\u63d0\u53d6\u5173\u952e\u4fe1\u606f\uff0c\u4ece\u800c\u4fdd\u6301\u4e0a\u4e0b\u6587\u7684\u7cbe\u7b80\u4e0e\u76f8\u5173\u6027\u3002\u73b0\u4ee3\u4eba\u5de5\u667a\u80fd\u5e94\u7528\u7a0b\u5e8f\u901a\u5e38\u9700\u8981\u5bf9\u4e0d\u540c\u7684\u8bed\u8a00\u6a21\u578b\u548c\u4e13\u95e8\u7684\u670d\u52a1\u5668\u8fdb\u884c\u590d\u6742\u7684\u7f16\u6392\uff0c\u6bcf\u4e2a\u670d\u52a1\u5668\u5728\u66f4\u5927\u7684\u5de5\u4f5c\u6d41\u4e2d\u5904\u7406\u7279\u5b9a\u7684\u4efb\u52a1\u3002\u901a\u8fc7\u5728\u6570\u636e\u4fdd\u62a4\u3001\u8bbf\u95ee\u63a7\u5236\u548c\u8f93\u5165\u8fc7\u6ee4\u7b49\u65b9\u9762\u6784\u5efa\u591a\u5c42\u6b21\u7684\u5b89\u5168\u9632\u62a4\u4f53\u7cfb\uff0c\u53ef\u4ee5\u6709\u6548\u63d0\u5347 MCP \u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u5b89\u5168\u6027\uff0c\u4e3a\u5176\u5728\u590d\u6742\u3001\u9ad8\u8981\u6c42\u7684\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u90e8\u7f72\u63d0\u4f9b\u575a\u5b9e\u4fdd\u969c\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/46789.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T20:07:31+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/46789.html","url":"https:\/\/www.wsisp.com\/helps\/46789.html","name":"\u91c7\u7528LangGraph\u96c6\u6210\u591a\u4e2aMCP\u670d\u52a1\u5668\u7684\u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T20:07:31+00:00","dateModified":"2025-07-29T20:07:31+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/46789.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/46789.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/46789.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u91c7\u7528LangGraph\u96c6\u6210\u591a\u4e2aMCP\u670d\u52a1\u5668\u7684\u5e94\u7528"}]},{"@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\/46789","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=46789"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46789\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=46789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=46789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=46789"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=46789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}