This project demonstrates a complete FastMCP (Model Context Protocol) setup with both a server and client implementation.
The server (fastmcp_echo_server.py) provides:
echo_tool: Takes text input and returns it unchanged
echo://static: Static resource that returns "Echo!"echo://{text}: Template resource that echoes the input text
echo: Takes text input and returns it as a prompt
The client (mcp_client.py) demonstrates how to:
- Initialize connection with MCP server
- List and call tools
- List and read resources
- List and get prompts
- Handle MCP protocol communication
# Install dependencies
pip install fastmcp
# Run the server
python fastmcp_echo_server.pyThe server will start on http://localhost:8000 by default.
In a separate terminal:
# Run the client (make sure server is running first)
python mcp_client.pyThe client will demonstrate:
- Server Connection: Initialize and connect to the MCP server
- Tool Discovery: Find the
echo_tool - Tool Execution: Call
echo_toolwith "Hello from MCP Client!" - Resource Discovery: Find both static and template resources
- Resource Reading: Read
echo://staticandecho://hello - Prompt Discovery: Find the
echoprompt - Prompt Execution: Get prompt with "Hello from MCP Client!"
🚀 Starting FastMCP Echo Server Demonstration
📡 Server URL: http://localhost:8000
🔄 Initializing connection with MCP server...
✅ Successfully connected to FastMCP server
Server: Echo Server
Version: 1.0.0
🛠️ Discovering tools...
✅ Found 1 tools
• echo_tool: Echo the input text
🔧 Calling echo_tool...
✅ Tool call successful: Hello from MCP Client!
📁 Discovering resources...
✅ Found 2 resources
• Static Echo Resource: echo://static
• Template Echo Resource: echo://{text}
📖 Reading static resource: echo://static
✅ Resource read successful: Echo!
📖 Reading template resource: echo://hello
✅ Resource read successful: Echo: hello
💬 Discovering prompts...
✅ Found 1 prompts
• echo: Echo prompt
💬 Getting echo prompt...
✅ Prompt get successful: Hello from MCP Client!
✅ Demonstration completed successfully!
The client uses the Model Context Protocol (MCP) with JSON-RPC 2.0 over HTTP to communicate with the server. It demonstrates:
- Initialization: Handshake and capability negotiation
- Tool Calling: Remote procedure calls to server tools
- Resource Access: Reading server-provided resources
- Prompt Generation: Getting structured prompts from the server
To connect to a different server URL, modify BASE_URL in mcp_client.py:
BASE_URL = "http://your-server-url:port"The server uses the fastmcp library. Make sure it's installed:
pip install fastmcp- Python 3.8+
fastmcplibraryrequestslibrary (for the client)
Install all dependencies:
pip install fastmcp requests