Simple-Tool-Server-Fastapi

Simple-Tool-Server-Fastapi

MCP server exposing basic utility functions like addition, current time, and word counting via FastAPI endpoints, designed for learning and extending toward MCP architecture.

Category
Visit Server

README

๐Ÿš€ Simple Tool Server with FastAPI

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).


๐Ÿ“Œ Features

  • โž• 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

๐Ÿ—๏ธ Project Structure

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

๐Ÿ”„ How It Works

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

๐Ÿ› ๏ธ Technologies Used

  • Python
  • FastAPI
  • Pydantic
  • Uvicorn
  • REST API
  • JSON
  • Model Context Protocol (MCP) concepts

โš™๏ธ Installation

1. Clone the repository

git clone https://github.com/sejalpatole/simple-tool-server-fastapi.git

2. Navigate to the project

cd simple-tool-server-fastapi

3. Create a virtual environment

python -m venv venv

4. Activate the virtual environment

Windows

venv\Scripts\activate

macOS / Linux

source venv/bin/activate

5. Install dependencies

pip install -r requirements.txt

โ–ถ๏ธ Running the Application

Start the FastAPI server using Uvicorn:

uvicorn main:app --reload

The server will start at:

http://127.0.0.1:8000

๐Ÿ“– API Documentation

FastAPI automatically provides interactive API documentation.

Swagger UI

Open:

http://127.0.0.1:8000/docs

ReDoc

Open:

http://127.0.0.1:8000/redoc

๐Ÿ”Œ API Endpoints

1. Home

Endpoint

GET /

Returns information about the available endpoints.

Example Response

{
  "message": "Welcome to the Simple Tool Server",
  "available_endpoints": [
    "/add",
    "/time",
    "/wordcount"
  ]
}

2. Add Two Numbers

Endpoint

GET /add

Parameters

Parameter Type Description
a float First number
b float Second number

Example

http://127.0.0.1:8000/add?a=10&b=20

Example Response

{
  "operation": "Addition",
  "a": 10,
  "b": 20,
  "result": 30
}

3. Get Current Time

Endpoint

GET /time

Example

http://127.0.0.1:8000/time

Example Response

{
  "current_time": "2026-08-20 21:00:00"
}

4. Count Words

Endpoint

POST /wordcount

Request Body

{
  "text": "FastAPI is easy to use"
}

Example Response

{
  "text": "FastAPI is easy to use",
  "word_count": 5
}

๐Ÿงฉ Project Components

main.py

Contains the FastAPI application and API routes.

It defines endpoints for:

  • /
  • /add
  • /time
  • /wordcount

tools.py

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.


model.py

Contains the Pydantic model used to validate the /wordcount request.

class WordCountRequest(BaseModel):
    text: str

This ensures that the API receives the expected request structure.


๐Ÿงช Testing

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

๐ŸŒฑ Future Improvements

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

๐ŸŽฏ Learning Outcomes

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

๐Ÿ‘ฉโ€๐Ÿ’ป Author

Sejal Patole


โญ Acknowledgement

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 โญ.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured