MCP FastAPI Server

MCP FastAPI Server

By karthikv2k GitHub

-

Overview

what is MCP FastAPI Server?

MCP FastAPI Server is an asynchronous API server built with FastAPI that facilitates communication with Model Context Protocol (MCP) servers.

how to use MCP FastAPI Server?

To use the MCP FastAPI Server, clone the repository, set up a virtual environment, install the dependencies, configure the .env file with your MCP server details, and run the server using Uvicorn.

key features of MCP FastAPI Server?

  • Lists available MCP servers.
  • Lists tools available from MCP servers.
  • Invokes tools on MCP servers.

use cases of MCP FastAPI Server?

  1. Integrating with various MCP servers for tool management.
  2. Automating tasks by invoking tools on MCP servers.
  3. Developing applications that require interaction with multiple MCP servers.

FAQ from MCP FastAPI Server?

  • What are the prerequisites for using MCP FastAPI Server?

You need Python 3.8 or higher and access to an MCP server.

  • How do I run the server?

You can run the server using the command uvicorn app.main:app --reload after setting it up.

  • Where can I find the API documentation?

The interactive API documentation can be accessed at http://localhost:8000/docs after the server is running.

Content

MCP FastAPI Server

A FastAPI-based async API server that communicates with Model Context Protocol (MCP) servers.

Features

  • List available MCP servers
  • List tools available from MCP servers
  • Invoke tools on MCP servers

API Endpoints

  • POST /api/list-mcp-servers: List all available MCP servers
  • POST /api/list-tools: List all tools available from an MCP server
  • POST /api/invoke-tool: Invoke a tool on an MCP server

Prerequisites

  • Python 3.8 or higher
  • An accessible MCP server (local or remote)

Installation

  1. Clone this repository:

    git clone <repository-url>
    cd mcp-fastapi-server
    
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # For Windows: venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Create a .env file from the example:

    cp .env.example .env
    

    Edit the .env file to configure your MCP server URL and other settings.

Running the Server

Start the server with:

uvicorn app.main:app --reload

This will start the server on http://localhost:8000.

API Usage Examples

List MCP Servers

curl -X POST http://localhost:8000/api/list-mcp-servers -H "Content-Type: application/json" -d '{}'

List Tools from an MCP Server

curl -X POST http://localhost:8000/api/list-tools -H "Content-Type: application/json" -d '{"server_url": "http://localhost:5000"}'

Invoke a Tool

curl -X POST http://localhost:8000/api/invoke-tool -H "Content-Type: application/json" -d '{
  "server_url": "http://localhost:5000",
  "tool_name": "example_tool",
  "params": {
    "parameter1": "value1",
    "parameter2": "value2"
  }
}'

Documentation

Once the server is running, you can access the interactive API documentation at:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

License

MIT # chat-mcp

No tools information available.
No content found.