濮阳市网站建设_网站建设公司_MongoDB_seo优化
2026/1/21 16:43:10 网站建设 项目流程

先写一个工具

点击查看代码
import subprocess
import shlex
from mcp.server.fastmcp import FastMCP
from typing import Annotated
from pydantic import Field, BaseModelmcp = FastMCP()@mcp.tool(name="run_shell",description="run a shell command")
def run_shell_command(command: Annotated[str, Field(description="shell command will be executed", examples="ls -al")], timeout: Annotated[int, Field(description="expired time command faile")]) -> str:try:# shell=True 只能执行第一个命令,无法处理数组ret = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=timeout)if ret.returncode != 0:return ret.stderrreturn ret.stdoutexcept Exception as e:print(e)if __name__ == "__main__":mcp.run(transport="stdio")

Client launches server as a subprocess and communicates via standard input/output. Best for local tools and simple setups.

点击查看代码
from langchain_mcp_adapters.client import MultiServerMCPClientclient = MultiServerMCPClient({"给工具起个名字": {"transport": "stdio","command": "python","args": ["工具的路径"],}}
)tools = await client.get_tools()  
agent = create_agent("claude-sonnet-4-5-20250929", tools)

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询