新一代大模型数据传输模型MCP的demo
不要用postman调用了. 用mcp库的代码来调用.
server.py
from fastmcp import FastMCP
mcp = FastMCP("My MCP Server")
# @mcp.custom_route("/health", methods=["GET"])
@mcp.tool()
def greet(name: str) -> str:
print(1111)
return f"Hello, {name}!"
if __name__ == "__main__":
mcp.run(transport="streamable-http", host="127.0.0.1", port=9000)
client.py
import asyncio
from fastmcp import Client
async def example():
async with Client("http://127.0.0.1:9000/mcp") as client:
await client.ping()
b=await client.call_tool('greet',{'name':'1111'})
print(b)
if __name__ == "__main__":
asyncio.run(example())