Skip to main content
Glama
sejalpatole

Simple-Tool-Server-Fastapi

by sejalpatole

🚀 FastAPI を使用したシンプルなツールサーバー

REST API エンドポイントを通じてシンプルなユーティリティ関数を公開する、FastAPI ベースのツールサーバー

このプロジェクトは、Python 関数を FastAPI エンドポイントの背後にラップし、HTTP リクエストを通じてアクセスする方法を示しています。また、将来的に同様のツールを Model Context Protocol(MCP) を通じて公開する方法を理解するための基礎も提供します。


📌 特徴

  • ➕ 2つの数値の加算

  • 🕐 現在の日時を取得

  • 📝 指定されたテキスト内の単語数をカウント

  • ⚡ FastAPI を使用した高速な API 開発

  • ✅ Pydantic を使用したリクエスト検証

  • 📦 JSON ベースの API レスポンス

  • 📖 自動対話型 API ドキュメント

  • 🔌 後で MCP ベースのツールアーキテクチャに拡張可能なシンプルな設計


Related MCP server: SENTRA MCP

🏗️ プロジェクト構造

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

🔄 動作の仕組み

このプロジェクトはシンプルなフローに従います:

Client
   ↓
FastAPI Endpoint
   ↓
Python Tool Function
   ↓
JSON Response

例:

GET /add
   ↓
add_numbers()
   ↓
JSON response

同じコンセプトは、後で MCP アーキテクチャに向けて拡張できます:

AI Assistant
     ↓
MCP Client
     ↓
MCP Server
     ↓
Python Tools

🛠️ 使用技術

  • Python

  • FastAPI

  • Pydantic

  • Uvicorn

  • REST API

  • JSON

  • Model Context Protocol(MCP)のコンセプト


⚙️ インストール

1. リポジトリのクローン

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

2. プロジェクトディレクトリへ移動

cd simple-tool-server-fastapi

3. 仮想環境の作成

python -m venv venv

4. 仮想環境の有効化

Windows

venv\Scripts\activate

macOS / Linux

source venv/bin/activate

5. 依存関係のインストール

pip install -r requirements.txt

▶️ アプリケーションの実行

Uvicorn を使用して FastAPI サーバーを起動します:

uvicorn main:app --reload

サーバーは次の場所で起動します:

http://127.0.0.1:8000

📖 API ドキュメント

FastAPI は対話型の API ドキュメントを自動的に提供します。

Swagger UI

開く:

http://127.0.0.1:8000/docs

ReDoc

開く:

http://127.0.0.1:8000/redoc

🔌 API エンドポイント

1. ホーム

エンドポイント

GET /

利用可能なエンドポイントに関する情報を返します。

レスポンス例

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

2. 2つの数値の加算

エンドポイント

GET /add

パラメータ

パラメータ

説明

a

float

1つ目の数値

b

float

2つ目の数値

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

レスポンス例

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

3. 現在時刻の取得

エンドポイント

GET /time

http://127.0.0.1:8000/time

レスポンス例

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

4. 単語数のカウント

エンドポイント

POST /wordcount

リクエストボディ

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

レスポンス例

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

🧩 プロジェクトコンポーネント

main.py

FastAPI アプリケーションと API ルートを含みます。

以下のエンドポイントを定義しています:

  • /

  • /add

  • /time

  • /wordcount


tools.py

コアとなる Python ユーティリティ関数を含みます:

add_numbers()
get_current_time()
word_count()

ツールのロジックを API 層から分離することで、プロジェクトの保守と拡張が容易になります。


model.py

/wordcount リクエストを検証するために使用される Pydantic モデルを含みます。

class WordCountRequest(BaseModel):
    text: str

これにより、API が期待通りのリクエスト構造を受け取ることが保証されます。


🧪 テスト

API は以下を使用してテストできます:

  • Swagger UI

  • Postman

  • ブラウザ

  • cURL

  • 任意の REST API クライアント

Swagger UI は次の場所で利用可能です:

http://127.0.0.1:8000/docs

🌱 今後の改善案

考えられる拡張には以下が含まれます:

  • より多くのユーティリティツールの追加

  • 認証の追加

  • ロギングの追加

  • Pytest を使用した自動テストの追加

  • Docker サポートの追加

  • MCP プロトコルサポートの追加

  • MCP サーバーを通じた Python ツールの公開

  • データベース対応ツールの追加

  • クラウドプラットフォームへのサーバーデプロイ


🎯 学習成果

このプロジェクトを通じて、以下のコンセプトを学ぶことができます:

  • FastAPI を使用した API の構築

  • GET および POST エンドポイントの作成

  • Pydantic を使用したリクエスト検証

  • API ロジックとビジネスロジックの分離

  • JSON リクエストとレスポンスの処理

  • Uvicorn を使用したアプリケーションの実行

  • ツールベースの AI システムの基礎の理解

  • API、ツール、MCP の関係の理解


👩💻 著者

Sejal Patole


⭐ 謝辞

このプロジェクトは、FastAPI、REST API、Python ユーティリティツール、および MCP ベースのツールアーキテクチャの基礎を学ぶための演習として開発されました。

このプロジェクトが役に立ったと思われた場合は、リポジトリに ⭐ を付けることをご検討ください。

F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A minimal FastAPI-based MCP server that provides basic utility tools like ping and time functions. Designed for easy deployment with Docker support, authentication, and extensible architecture for future tool additions.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A minimal FastMCP server implementation that provides basic mathematical and greeting tools. Enables users to perform simple operations like adding numbers and greeting people by name through a lightweight MCP interface.
    MIT

View all related MCP servers

Related MCP Connectors

  • MCP server exposing the Backtest360 engine API as tools for AI agents.

  • MCP server providing access to the Scorecard API to evaluate and optimize LLM systems.

  • Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sejalpatole/Simple-Tool-Server-Fastapi'

If you have feedback or need assistance with the MCP directory API, please join our Discord server