This example demonstrates integrating the Model Context Protocol (MCP) with Inference Gateway, enabling LLMs to access external tools and data through multiple MCP servers.
- ✨ Server-Sent Events (SSE): Real-time streaming with dual JSON-RPC and SSE protocol support
- 🔍 MCP Inspector: Web-based debugging tool for exploring and testing MCP servers
- 🛠️ Multiple Tools: Time, search, filesystem, and pizza-related tools
- 🔧 Easy Setup: Docker Compose configuration with CORS support
- Quick Start
- Components
- MCP Inspector
- Usage
- How It Works
- Available Tools
- Adding Your Own MCP Servers
- Learn More
- Docker and Docker Compose
- Groq API key
export GROQ_API_KEY=your_groq_api_key
docker-compose upUse the MCP Inspector at http://localhost:6274 to explore servers, test tools, and troubleshoot any issues.
- Inference Gateway: Main service that proxies requests to LLM providers
- MCP Time Server: Provides time data tools
- MCP Search Server: Provides web search functionality
- MCP Filesystem Server: Provides file operations (read, write, delete, list directories)
- MCP Pizza Server: TypeScript MCP server providing pizza-related tools using
@modelcontextprotocol/sdk - MCP Inspector: Web-based debugging tool for exploring MCP servers
Debug and explore your MCP servers with the web interface at http://localhost:6274.
Capabilities:
- View all connected servers and their tools
- Browse tool schemas and parameters
- Execute tool calls and see responses
- Monitor protocol messages and debug issues
Connected Servers:
- Time Server:
http://mcp-time-server:8081/mcp - Search Server:
http://mcp-search-server:8082/mcp - Filesystem Server:
http://mcp-filesystem-server:8083/mcp - Pizza Server:
http://mcp-pizza-server:8084/mcp
Once the services are running, you can make requests to the Inference Gateway using the MCP middleware:
curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "groq/meta-llama/llama-4-scout-17b-16e-instruct",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hi, whats the current time?"
}
]
}'curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "groq/meta-llama/llama-4-scout-17b-16e-instruct",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Find me information about the Model Context Protocol."
}
],
"stream": true
}'curl -X POST http://localhost:8080/v1/chat/completions -d '{
"model": "groq/meta-llama/llama-4-scout-17b-16e-instruct",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the current time and also find me information about the Model Context Protocol."
}
]
}'curl -X POST http://localhost:8080/v1/chat/completions -d '{
"model": "groq/meta-llama/llama-4-scout-17b-16e-instruct",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the current time? and also find me information about the Model Context Protocol."
}
],
"stream": true
}'curl -X POST http://localhost:8080/v1/chat/completions -d '{
"model": "groq/meta-llama/llama-4-scout-17b-16e-instruct",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant with access to filesystem operations."
},
{
"role": "user",
"content": "Create a file called hello.txt with the content \"Hello, MCP World!\" and then read it back to me."
}
]
}'Notice the file was created in filesystem-data directory.
curl -X POST http://localhost:8080/v1/chat/completions -d '{
"model": "groq/meta-llama/llama-4-scout-17b-16e-instruct",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant with access to filesystem operations."
},
{
"role": "user",
"content": "Create a directory called projects, then create a subdirectory called mcp-demo, and list the contents of the projects directory."
}
]
}'curl -X POST http://localhost:8080/v1/chat/completions -d '{
"model": "groq/meta-llama/llama-4-scout-17b-16e-instruct",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant with access to filesystem operations."
},
{
"role": "user",
"content": "Check if a file called config.json exists, and if not, create it with some sample JSON configuration data. Then show me the file information."
}
]
}'You can also query the Inference Gateway to see all available tools from connected MCP servers:
curl -X GET http://localhost:8080/v1/mcp/toolsThis endpoint returns a JSON response containing all available tools from all connected MCP servers, including:
- Tool names and descriptions
- Required and optional parameters
- Input/output schemas
- Which MCP server provides each tool
Example response:
{
"tools": [
{
"name": "time",
"description": "Get the current time",
"server": "http://mcp-time-server:8081/mcp",
"inputSchema": {
"type": "object",
"properties": {
"format": {
"type": "string",
"description": "Time format (ISO, human-readable, etc.)"
}
}
}
},
{
"name": "search",
"description": "Perform web search",
"server": "http://mcp-search-server:8082/mcp",
"inputSchema": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search query"
}
},
"required": ["query"]
}
},
{
"name": "write_file",
"description": "Write content to a file",
"server": "http://mcp-filesystem-server:8083/mcp",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "File path"
},
"content": {
"type": "string",
"description": "File content"
}
},
"required": ["path", "content"]
}
}
]
}This example demonstrates using tools from the official TypeScript MCP server built with @modelcontextprotocol/sdk. The pizza server provides pizza-related tools:
curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "groq/meta-llama/llama-4-scout-17b-16e-instruct",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Top 5 pizzas in the world. Go!"
}
]
}'When you send a request to the Inference Gateway, it will:
- Discover the tools available from all MCP servers (time, search, and filesystem)
- Inject these tools into the LLM request
- Process any tool calls made by the LLM
- Return the complete response with tool results
- time: Get the current time in various formats
- search: Perform web searches for information
- write_file: Write content to a file (supports overwrite and append modes)
- read_file: Read content from a file
- delete_file: Delete a file
- list_directory: List directory contents (supports recursive listing)
- create_directory: Create a directory
- file_exists: Check if a file or directory exists
- file_info: Get detailed information about a file or directory
All filesystem operations are sandboxed to /tmp/mcp-files for security.
- get-top-pizzas: Returns mock data of the top 5 pizzas in the world with detailed information
The pizza server showcases best practices using the @modelcontextprotocol/sdk and includes comprehensive session management, type validation with Zod schemas, and dual transport support.
It's incredibly easy to add more MCP servers! Simply follow these steps:
-
Add your server URL to the
MCP_SERVERSenvironment variable:MCP_SERVERS=http://mcp-time-server:8081/mcp,http://mcp-search-server:8082/mcp,http://your-new-server:8085/mcp
-
Include your server in the docker-compose.yml file (if running in Docker)
-
Restart the services - that's it! Your tools will automatically be available.
- Implements the MCP specification
- Responds to HTTP requests on the
/mcpendpoint - Supports CORS for web clients (if using the MCP Inspector)
This example includes four pre-configured servers:
- Time Server:
http://mcp-time-server:8081/mcp- Get current time - Search Server:
http://mcp-search-server:8082/mcp- Web search functionality - Filesystem Server:
http://mcp-filesystem-server:8083/mcp- File operations - TypeScript Server:
http://official-ts-server:8084/mcp- Math and utility functions
Environment variables you can configure:
MCP_ENABLE: Set to "true" to enable MCP middlewareMCP_EXPOSE: Set to "true" to expose MCP endpointsMCP_SERVERS: Comma-separated list of MCP server URLs