Introduction to FastMCP
39%
Testing the Server with a FastMCP Client
MCP clients can be implemented in any programming language that can send JSON-RPC messages over the chosen transport.
In this section, we're not going to build a fully-fledged client, but just a simple one to test some tool calls to our server. Here's how we can quickly test with a FastMCP client in Python:
import asyncio
from fastmcp import Client
client = Client(<URL>)
async def call_tool(name: str):
async with client:
result = await client.call_tool(<tool_name>, <arguments>)
print(result)
asyncio.run(call_tool(<tool_arguments>))
Let's fill in the placeholders to call the sum tool we defined in our server:
cat > $HOME/workspace/fastmcp_demo/client.py << 'EOF'
import asyncio
from fastmcp import Client
client = Client("http://localhost:8000/mcp")
async def call_sum(a: int, b: intPractical MCP with FastMCP & LangChain
Engineering the Agentic ExperienceEnroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!
