FastAPI Hello World Application

FastAPI Hello World Application

By xxradar GitHub

A test repository created using the GitHub MCP server

fastapi api
Overview

What is FastAPI Hello World Application?

The FastAPI Hello World Application is a simple API built using FastAPI that demonstrates basic API functionality and integrates with OpenAI's GPT-4o for advanced chat completions.

How to use FastAPI Hello World Application?

To use the application, you can either run it locally or in a Docker container. Follow the setup instructions provided in the documentation to get started.

Key features of FastAPI Hello World Application?

  • Root endpoint that returns a Hello World message.
  • Dynamic greeting endpoint that takes a name parameter.
  • Integration with OpenAI's GPT-4o for AI-powered chat completions.
  • Automatic API documentation available via Swagger UI.

Use cases of FastAPI Hello World Application?

  1. Building simple APIs for testing and learning purposes.
  2. Integrating AI functionalities into applications using OpenAI.
  3. Demonstrating FastAPI capabilities for educational purposes.

FAQ from FastAPI Hello World Application?

  • What are the prerequisites to run the application?

You need Python 3.7+, pip, and an OpenAI API key for the /openai endpoint.

  • Is Docker required to run the application?

No, Docker is optional; you can run the application locally without it.

  • How can I access the API documentation?

The API documentation is available at /docs for Swagger UI and /redoc for ReDoc.

Content

FastAPI Hello World Application

A simple Hello World API built with FastAPI and MCP SSE support.

Features

  • Root endpoint that returns a Hello World message
  • Dynamic greeting endpoint that takes a name parameter
  • OpenAI integration with GPT-4o for advanced AI-powered chat completions
  • Automatic API documentation with Swagger UI

Prerequisites

  • Python 3.7+ (for local setup)
  • pip (Python package installer)
  • OpenAI API key (for the /openai endpoint)
  • Docker (optional, for containerized setup)

Setup Instructions

You can run this application either locally or using Docker.

Local Setup

1. Clone the repository

git clone https://github.com/xxradar/mcp-test-repo.git
cd mcp-test-repo
# On macOS/Linux
python -m venv venv
source venv/bin/activate

# On Windows
python -m venv venv
venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

4. Run the application

uvicorn main:app --reload

The application will start and be available at http://127.0.0.1:8000

Alternatively, you can run the application directly with Python:

python main.py

Docker Setup

1. Clone the repository

git clone https://github.com/xxradar/mcp-test-repo.git
cd mcp-test-repo

2. Build the Docker image

docker build -t fastapi-hello-world .

3. Run the Docker container

docker run -p 8000:8000 fastapi-hello-world

The application will be available at http://localhost:8000

API Endpoints

  • GET /: Returns a simple Hello World message
  • GET /hello/{name}: Returns a personalized greeting with the provided name
  • GET /openai: Returns a response from OpenAI's GPT-4o model (accepts an optional prompt query parameter)
  • GET /docs: Swagger UI documentation
  • GET /redoc: ReDoc documentation

OpenAI Integration

The /openai endpoint uses OpenAI's GPT-4o model and requires an OpenAI API key to be set as an environment variable:

Local Setup

# Set the OpenAI API key as an environment variable
export OPENAI_API_KEY=your_api_key_here

# Run the application
uvicorn main:app --reload

Docker Setup

# Run the Docker container with the OpenAI API key
docker run -p 8000:8000 -e OPENAI_API_KEY=your_api_key_here fastapi-hello-world

Example Usage

Using curl

# Get Hello World message
curl http://127.0.0.1:8000/

# Get personalized greeting
curl http://127.0.0.1:8000/hello/John

# Get OpenAI chat completion with default prompt
curl http://127.0.0.1:8000/openai

# Get OpenAI chat completion with custom prompt
curl "http://127.0.0.1:8000/openai?prompt=Tell%20me%20a%20joke%20about%20programming"

Using MCP

Connect to MCP Inspector

npx @modelcontextprotocol/inspector

Using a web browser

Development

To make changes to the application, edit the main.py file. The server will automatically reload if you run it with the --reload flag.

No tools information available.

-

chembl api
View Details
MCP Server Demo
MCP Server Demo by raycao871218

一个基于MCP框架的服务器演示项目,提供了简单的API接口实现,包括数字运算、时间查询、订单信息查询等功能。

mcp-server api
View Details

-

mcp-server api
View Details

Vufind Api for Bibliotecas.uncuyo.edu.ar

vufind api
View Details

-

backlinks-mcp api
View Details

An MCP server for interacting with Wikimedia APIs. Access Wikipedia and other Wikimedia project content programmatically.

wikimedia api
View Details