Skip to content

djkapoor/mcp-crash-course

Repository files navigation

MCP Agent API

A FastAPI application that provides an API for querying an LLM agent with tools for math and weather, using LangChain and MCP (Model Consumption Protocol).

Configuration

The application uses environment variables for configuration. You can set these in a .env file in the root directory.

Copy the example file to create your own configuration:

cp .env.example .env

Then edit the .env file to suit your needs. Here are the available configuration options:

Variable Description Default
API_HOST Host to bind the API server 0.0.0.0
API_PORT Port for the API server 8006
OPENAI_API_KEY Your OpenAI API key -
OPENAI_MODEL The OpenAI model to use gpt-3.5-turbo
MATH_SERVER_PATH Path to the math server script servers/math_server.py
WEATHER_SERVER_HOST Host of the weather server localhost
WEATHER_SERVER_PORT Port of the weather server ``
WEATHER_SERVER_TRANSPORT Transport protocol for the weather server sse

Running the Application

API Server

Run the API server:

python langchain_client.py

Then access the Swagger UI at: http://localhost:8006/docs

Test Function

To test the agent directly without the API:

python langchain_client.py test

Running the Weather Server

The weather server needs to be running separately:

python servers/weather_server.py

Development

Using VSCode

VSCode launch configurations are provided in the .vscode directory:

  • FastAPI Server: Runs the standard FastAPI server
  • FastAPI with Weather Server: Runs the FastAPI server and starts the weather server
  • FastAPI Debug Server: Runs the server with hot reloading using uvicorn directly
  • Run Test Function: Runs the test function

Debugging

To debug the application in VSCode:

  1. Open the debug panel (Ctrl+Shift+D)
  2. Select "FastAPI with Weather Server" from the dropdown
  3. Press F5 to start debugging

Architecture

The application consists of:

  • A FastAPI server that provides an API
  • A math server that handles mathematical operations
  • A weather server that provides weather information
  • A LangChain agent that uses both tools

API Endpoints

  • GET /: Information about the API
  • GET /ask?query=...: Ask a question to the agent (returns a streaming response)

Example Queries

  • "What is 2 + 2?"
  • "What's the weather in New York?"
  • "If it's 20 degrees in New York and 15 degrees in London, what's the average temperature?"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages