What is FastAPI MCP Server + LangChain Client Example?
This project demonstrates how to expose FastAPI endpoints as Model Context Protocol (MCP) tools using fastapi-mcp. It includes a basic LangChain agent that connects to the local FastAPI server via HTTP/SSE to discover and use the exposed tools.
How to use the project?
To use this project, clone the repository, install the required dependencies, set up your environment with an OpenAI API key, and run the FastAPI server followed by the LangChain client to interact with the exposed tools.
Key features of the project?
- Exposes FastAPI endpoints as MCP tools.
- Integrates with LangChain for enhanced functionality.
- Supports real-time communication via HTTP/SSE.
Use cases of the project?
- Building a local FastAPI server with MCP capabilities.
- Testing and learning about MCP tools and their integration with LangChain.
- Developing applications that require dynamic tool discovery and usage.
FAQ from the project?
-
What are the prerequisites?
Python 3.10+,
uv, Node.js, npm, Git, and an OpenAI API key are required. -
How do I run the server?
Use
uvicorn main:app --reload --port 8000to start the FastAPI server. -
Can I test the server with an inspector?
Yes, you can use the MCP Inspector tool to test the server and discover tools.