MCPTest
MCPTest
https://github.com/fanqingsong/MCPTest
MCP功能测试,编写LLM(支持OpenAI接口风格的大模型)应用程序调用MCP。MCP(模型上下文协议)是Claude开源的一种开放协议,可实现LLM应用程序与外部数据源和工具之间的无缝集成。
本期系列相关视频如下,按照发布的先后顺序:
(第一期)[2024.12.10]Claude重大突破!发布MCP(模型上下文协议),带你在LLM应用程序脚本中感受它,无需使用Claude Desktop桌面软件,支持类OpenAI风格大模型
主要内容:MCP介绍、MCP功能测试,LLM(支持OpenAI接口风格的大模型)应用程序调用MCP
https://www.bilibili.com/video/BV1HBquYbE7t/
https://youtu.be/Jmo7rgb_OXQ
https://mcp.so/server/filesystem
https://www.bilibili.com/video/BV1HBquYbE7t/?vd_source=57e261300f39bf692de396b55bf8c41b
https://github.com/fanqingsong/MCPTest/blob/main/nangeAGICode/filesystem_basic/client.py
# Node.js 服务器为文件系统操作实现模型上下文协议 (MCP) # ClientSession 表示客户端会话,用于与服务器交互 # StdioServerParameters 定义与服务器的 stdio 连接参数 from mcp import ClientSession, StdioServerParameters # 提供与服务器的 stdio 连接上下文管理器 from mcp.client.stdio import stdio_client import asyncio # 定义与 mcp 协议相关的类型 import mcp.types as types # 为 stdio 连接创建服务器参数 server_params = StdioServerParameters( # 服务器执行的命令,这里是 python command="npx", # 启动命令的附加参数,这里是运行 example_server.py args=["-y", "@modelcontextprotocol/server-filesystem", "/home/song/workspace/me/MCPTest/nangeAGICode/filesystem_basic"], # 环境变量,默认为 None,表示使用当前环境变量 env=None ) async def run(): # 创建与服务器的标准输入/输出连接,并返回 read 和 write 流 async with stdio_client(server_params) as (read, write): # 创建一个客户端会话对象,通过 read 和 write 流与服务器交互 async with ClientSession(read, write) as session: # 向服务器发送初始化请求,确保连接准备就绪 # 建立初始状态,并让服务器返回其功能和版本信息 capabilities = await session.initialize() # print("capabilities:", capabilities) # print("Supported capabilities:", capabilities.capabilities) # 请求服务器列出所有支持的 tools tools = await session.list_tools() print("tools:",tools) # 文件相关功能测试 result = await session.call_tool("list_allowed_directories") result = await session.call_tool("create_directory", arguments={"path": "test"}) # result = await session.call_tool("write_file", arguments={"path": "test/test1.txt","content": "这里是南哥AGI研习社。测试1。" }) # result = await session.call_tool("write_file", arguments={"path": "test/test1.txt","content": "这里是南哥AGI研习社。测试1plus。" }) # result = await session.call_tool("write_file", arguments={"path": "test/test2.txt","content": "这里是南哥AGI研习社。测试2。" }) # result = await session.call_tool("list_directory", arguments={"path": "test"}) # result = await session.call_tool("read_file", arguments={"path": "test/test1.txt"}) # result = await session.call_tool("read_multiple_files", arguments={"paths": ["test/test1.txt","test/test2.txt"]}) # result = await session.call_tool("search_files", arguments={"path": "test","pattern": "test1" }) # result = await session.call_tool("get_file_info", arguments={"path": "test/test1.txt"}) print("result:",result) if __name__ == "__main__": # 使用 asyncio 启动异步的 run() 函数 asyncio.run(run())
探索大世界
https://github.com/modelcontextprotocol/servers
https://www.mcphub.ai/servers
出处:http://www.cnblogs.com/lightsong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。

浙公网安备 33010602011771号