Fastmcp Claude Tools
Example of using a FastMCP server with Claude API in a Python client
Ask AI about Fastmcp Claude Tools
Powered by Claude · Grounded in docs
I know everything about Fastmcp Claude Tools. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
FastMCP with Claude Tool Integration Example
This repository demonstrates how to implement a web server that integrates Claude's tools capabilities with the FastMCP (Model Control Protocol) framework. It provides a complete example of defining custom tools that Claude can use to perform calculations and retrieve information.
Key Features
- Claude Tool Integration: Uses Claude's tool use capabilities with proper conversation flow and tool_use_id matching
- FastMCP Tool Definitions: Utilizes FastMCP to define and manage tool schemas and implementations
- Asynchronous Web Server: Built with Quart for high-performance async handling of requests
- Complete Conversation Flow: Demonstrates the full conversation loop with tool calls and tool results
- Error Handling: Robust error handling for tool execution and API communication
- Example Tools: Includes sample calculator and weather lookup tools
How It Works
- Tool Definition: Tools are defined using the FastMCP decorators, which automatically generate the appropriate schemas
- API Integration: The server converts FastMCP tool definitions to Claude's expected format
- Conversation Flow: Manages the complete conversation flow, including preserving tool_use_id references
- Tool Execution: Executes the appropriate tool functions when Claude calls them
- Result Handling: Formats and returns tool results in the format Claude expects
Getting Started
Prerequisites
- Python 3.8+
- Anthropic API key
- Docker (optional, for running with PostgreSQL for the memory example)
Installation
- Clone this repository:
git clone https://github.com/yourusername/fastmcp-claude-tools.git
cd fastmcp-claude-tools
- Install dependencies:
pip install -r requirements.txt
- Set your Anthropic API key as an environment variable:
Windows PowerShell:
$env:ANTHROPIC_API_KEY="your-api-key-here"
Windows CMD:
set ANTHROPIC_API_KEY=your-api-key-here
Linux/macOS:
export ANTHROPIC_API_KEY="your-api-key-here"
Running the Example
- Start the server:
python app.py
- In another terminal, run the client:
python client.py
Implementation Details
The repository demonstrates several key aspects of integrating Claude with FastMCP:
- Tool Schema Generation: The application properly extracts tool schemas from FastMCP, avoiding hardcoded definitions
- Proper Tool Use Handling: Implements the Claude API's expected format for tool use and tool results
- Conversation Context Preservation: Maintains the conversation context with proper tool_use references
- Error Handling: Gracefully handles errors in tool execution and API communication
- Python Type Hints: Uses Python's type hints for automatic schema generation
Important Components
- app.py: Main server implementation with tool definitions and Claude API integration
- client.py: Simple client to demonstrate how to interact with the server
- memory_app.py and memory_system.py: Advanced example with a memory system (optional)
Claude Tool Use Control
The implementation demonstrates various methods to control Claude's tool use behavior:
- Tool Choice: Configure whether Claude should use tools, which tools to use, etc.
- Chain of Thought: Encourage Claude to explain its reasoning in thinking tags
- Tool Use Structure: Properly structure the conversation to maintain tool context
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
