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
访问服务器

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选