FastMCP Integration Application Demo
About
A modular application API interface based on FastMCP, integrating a demo of the MCP server, FastAPI interface and LLM Agent processing capabilities | 一个基于FastMCP的模块化应用,集成了MCP服务器、FastAPI接口和LLM Agent 处理能力的 demo
Details
- Author
- ZhouhaoJiang
- GitHub stars
- 10
- Downloads
- 337
- Categories
- AI
Jump to
- Modular design with clear separation of concerns
- Dual run modes: API server and standalone MCP server
- LLM integration with OpenAI (extensible)
- Agent mode for autonomous tool selection by the LLM
- Complete RESTful API for tools, resources, and agent
- Persistent SSE connection between servers
Setting up with Highlight
This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:
- Download and install Highlight from highlightai.com/download
- Navigate to the plugins tab and select "Add Custom Plugin"
-
Configure the plugin with the settings below
Plugin Name
FastMCP Integration Application DemoCommand (node, npx, python, etc.)Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.
- Enable "Start Automatically" if you want the plugin to start when Highlight launches
From the repository
Install dependencies (uv/pip recommended) and set the OPENAI_API_KEY environment variable. First start the MCP server with python main.py --mode mcp, then start the API server with python main.py --mode api. The API server connects to the MCP server via SSE and provides HTTP endpoints.
Claude Desktop / Cursor
Paste into your MCP client config file to install this server.
{
"mcpServers": {
"fastmcp integration application demo": {
"fastapi-with-fatmcp-agent": {
"command": "uv",
"args": [
"pip",
"install",
"-e",
"."
]
}
}
}
}
McpServers
{
"fastapi-with-fatmcp-agent": {
"command": "uv",
"args": [
"pip",
"install",
"-e",
"."
]
}
}
FastMCP Integration Application Demo
This project demonstrates a modular application built with FastMCP, integrating an MCP server, a FastAPI interface, and LLM Agent capabilities.
Project Architecture
The project utilizes a modular design, separating different functionalities into distinct packages:
app/
├── __init__.py
├── api/ # FastAPI Application Layer
│ ├── __init__.py
│ ├── main.py # FastAPI main application entry point
│ └── routers/ # API route definitions
│ ├── __init__.py
│ ├── agent.py # Agent mode routes
│ ├── mcp_resources.py # MCP resource routes
│ └── mcp_tools.py # MCP tool routes
├── llm/ # LLM (Large Language Model) Processing Layer
│ ├── __init__.py
│ ├── base.py # Base LLM class
│ └── openai.py # OpenAI implementation
└── mcp_server/ # MCP Server Definition Layer
├── __init__.py
├── base.py # Base MCP Server class
├── run.py # Script for internal Client connection or direct execution
└── simple.py # Simple MCP Server implementation (with tools & resources)
main.py # Main entry point (runs API or MCP server)
Core Workflow (API Mode):
1. Run MCP Server Independently: Start a separate MCP server process using python main.py --mode mcp, listening on a specified port (default: 8001) with SSE transport.
2. Run API Server: Start the FastAPI server using python main.py --mode api (listens on 8080).
3. Connection: The mcp_client within the FastAPI server connects to the independently running MCP server via SSE.
4. Request Handling: Frontend or other clients interact with the application through the HTTP API provided by FastAPI.
5. Tool/Resource/Agent Calls: FastAPI routes forward requests to the mcp_client (communicating with the MCP server) or the llm module (communicating with the LLM API).
Features
- Modular Design: Clear separation of concerns (API, LLM, MCP) for easy extension and maintenance.
- Dual Run Modes:
- api mode: Runs the FastAPI server, requires a separately running MCP server.
- mcp mode: Runs the MCP server directly for testing or connection by other clients.
- LLM Integration: Supports using OpenAI (or other extensible LLMs) to process tool outputs or execute in Agent mode.
- Agent Mode: Provides an /api/agent/process endpoint for the LLM to autonomously select and call MCP tools.
- Complete API: Offers RESTful endpoints for MCP tools, resources, and Agent functionality via FastAPI.
- Persistent Connection: The API server maintains a long-lived SSE connection to the MCP server for efficiency.
Installation
1. Clone the repository (if needed).
2. Install dependencies (using uv or pip):
# Recommended: use uv
uv pip install -e .
# Alternatively, use pip
# pip install -e .
3. Set Environment Variables:
- The
OPENAI_API_KEY environment variable is required to use LLM features.- You can create a
.env file in the project root and define it there: OPENAI_API_KEY=sk-...
Usage
Running the API Server (Recommended)
This mode requires first starting the standalone MCP server.
1. Start the MCP Server (in one terminal):
# Uses SSE transport, listening on 127.0.0.1:8001 (default)
python main.py --mode mcp
# Or specify a different host and port
# python main.py --mode mcp --mcp-host 0.0.0.0 --mcp-port 8002
2. Start the API Server (in another terminal):
# Listens on 0.0.0.0:8080 (default)
python main.py --mode api
# Use a different port or enable hot-reloading (for development)
# python main.py --mode api --port 9000 --reload
The API server is now accessible at http://localhost:8080 (or your specified port). It will automatically connect to the MCP server started in step 1 (default connection: http://localhost:8001/sse).
Running the MCP Server Directly
If you only need to run the MCP server (e.g., for direct connection by other FastMCP clients):
```bash
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.
