A lightweight FastAPI-based tool server that exposes simple utility functions through REST API endpoints.
This project demonstrates how Python functions can be wrapped behind FastAPI endpoints and accessed through HTTP requests. It also provides a basic foundation for understanding how similar tools can later be exposed through Model Context Protocol (MCP).
- ➕ Add two numbers
- 🕐 Get the current date and time
- 📝 Count words in a given text
- ⚡ Fast API development using FastAPI
- ✅ Request validation using Pydantic
- 📦 JSON-based API responses
- 📖 Automatic interactive API documentation
- 🔌 Simple architecture that can be extended into an MCP-based tool server
simple-tool-server-fastapi/
│
├── main.py # FastAPI application and API endpoints
├── model.py # Pydantic request models
├── tools.py # Core utility functions
├── requirements.txt # Project dependencies
├── .gitignore # Files excluded from Git
└── README.md # Project documentation
The project follows a simple flow:
Client
↓
FastAPI Endpoint
↓
Python Tool Function
↓
JSON Response
For example:
GET /add
↓
add_numbers()
↓
JSON response
The same concept can later be extended toward an MCP architecture:
AI Assistant
↓
MCP Client
↓
MCP Server
↓
Python Tools
- Python
- FastAPI
- Pydantic
- Uvicorn
- REST API
- JSON
- Model Context Protocol (MCP) concepts
git clone https://github.com/sejalpatole/simple-tool-server-fastapi.gitcd simple-tool-server-fastapipython -m venv venvvenv\Scripts\activatesource venv/bin/activatepip install -r requirements.txtStart the FastAPI server using Uvicorn:
uvicorn main:app --reloadThe server will start at:
http://127.0.0.1:8000
FastAPI automatically provides interactive API documentation.
Open:
http://127.0.0.1:8000/docs
Open:
http://127.0.0.1:8000/redoc
GET /Returns information about the available endpoints.
{
"message": "Welcome to the Simple Tool Server",
"available_endpoints": [
"/add",
"/time",
"/wordcount"
]
}GET /add| Parameter | Type | Description |
|---|---|---|
a |
float | First number |
b |
float | Second number |
http://127.0.0.1:8000/add?a=10&b=20
{
"operation": "Addition",
"a": 10,
"b": 20,
"result": 30
}GET /timehttp://127.0.0.1:8000/time
{
"current_time": "2026-08-20 21:00:00"
}POST /wordcount{
"text": "FastAPI is easy to use"
}{
"text": "FastAPI is easy to use",
"word_count": 5
}Contains the FastAPI application and API routes.
It defines endpoints for:
//add/time/wordcount
Contains the core Python utility functions:
add_numbers()
get_current_time()
word_count()Keeping the tool logic separate from the API layer makes the project easier to maintain and extend.
Contains the Pydantic model used to validate the /wordcount request.
class WordCountRequest(BaseModel):
text: strThis ensures that the API receives the expected request structure.
The APIs can be tested using:
- Swagger UI
- Postman
- Browser
- cURL
- Any REST API client
Swagger UI is available at:
http://127.0.0.1:8000/docs
Possible future extensions include:
- Add more utility tools
- Add authentication
- Add logging
- Add automated tests using Pytest
- Add Docker support
- Add MCP protocol support
- Expose the Python tools through an MCP server
- Add database-backed tools
- Deploy the server to a cloud platform
Through this project, the following concepts are demonstrated:
- Building APIs with FastAPI
- Creating GET and POST endpoints
- Request validation with Pydantic
- Separating API logic from business logic
- Working with JSON requests and responses
- Running applications with Uvicorn
- Understanding the foundation of tool-based AI systems
- Understanding the relationship between APIs, tools, and MCP
Sejal Patole
This project was developed as a learning exercise to understand FastAPI, REST APIs, Python utility tools, and the fundamentals of MCP-based tool architecture.
If you found this project useful, consider giving the repository a ⭐.