Skip to content

Latest commit

 

History

History
161 lines (128 loc) · 2.93 KB

File metadata and controls

161 lines (128 loc) · 2.93 KB

MCP Client API Usage Guide

Sending Messages

To send a message to the API, you'll need to make a POST request to the /message endpoint with a JSON body containing a message field.

Request Format

POST /message HTTP/1.1
Host: localhost:8000
Content-Type: application/json

{
    "message": "Your message goes here"
}

cURL Example

curl -X POST http://localhost:8000/message \
  -H "Content-Type: application/json" \
  -d '{"message": "What is the weather in Paris?"}'

Python Example

import requests

response = requests.post(
    "http://localhost:8000/message",
    json={"message": "Tell me about machine learning"}
)
print(response.json())

Response Format

The API will respond with a JSON object containing either:

Successful Response

{
    "response": {
        "messages": [
            {
                "content": "The detailed answer to your question...",
                "type": "ai",
                "tool_calls": [],
                "tool_call_id": null
            }
        ],
        "return_values": {
            "output": "Final answer from the agent..."
        }
    },
    "status": "success"
}

The response format follows LangGraph's structure:

  • messages: Contains the conversation history and agent's reasoning
  • return_values.output: Contains the final answer

Error Response

If an error occurs, the API will return:

{
    "detail": {
        "error": "Error message describing what went wrong",
        "traceback": "Detailed error information (only in DEBUG_MODE)"
    }
}

Common error status codes:

  • 503: Ollama model is not available
  • 500: Error processing the request or running the agent

Additional Endpoints

List Available Tools

To retrieve a list of all available tools without invoking the agent:

GET /tools HTTP/1.1
Host: localhost:8000

Response:

{
    "status": "success",
    "count": 14,
    "tools": [
        {
            "name": "math_add",
            "description": "Add two numbers",
            "parameters": "{'a': 'first number', 'b': 'second number'}"
        }
    ],
    "server_config": {
        "math": { /* server configuration */ },
        "joke": { /* server configuration */ },
        "gatherings": { /* server configuration */ }
    }
}

Health Check

To check if the API is running:

GET /health HTTP/1.1
Host: localhost:8000

Response:

{
    "status": "ok"
}

Examples

Example Request

{
    "message": "What's the capital of France?"
}

Example Response

{
    "response": {
        "messages": [
            {
                "content": "The capital of France is Paris.",
                "type": "ai",
                "tool_calls": [],
                "tool_call_id": null
            }
        ],
        "return_values": {
            "output": "The capital of France is Paris."
        }
    },
    "status": "success"
}