
mcp server agent example
A powerful NestJS backend that bridges OpenAI's Agent framework with MCP (Model Context Protocol) servers, enabling AI assistants to execute real-world actions through natural language requests.
Repository Info
About This Server
A powerful NestJS backend that bridges OpenAI's Agent framework with MCP (Model Context Protocol) servers, enabling AI assistants to execute real-world actions through natural language requests.
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
🔎 OpenAI Agent Server - MCP Bridge
!OpenAI API !NestJS !TypeScript
A powerful NestJS backend that bridges OpenAI's Agent framework with MCP (Model Context Protocol) servers, enabling AI assistants to execute real-world actions through natural language requests.
🌟 Key Features
- AI-Powered Chat Interface: Seamless integration with OpenAI's latest models
- Function Calling: Intelligent mapping of natural language to executable functions
- MCP Tool Execution: Bridge between AI models and MCP-compatible tools
- Task Management API: Complete CRUD operations for task management
- Stateless Architecture: Designed for scalability and reliability
- Developer-Friendly: Comprehensive documentation and type safety
🛠️ Tech Stack
- NestJS framework for robust backend architecture
- TypeScript for type-safe development
- OpenAI API with advanced function calling capabilities
- Axios for efficient HTTP requests
- MCP Protocol compatibility for tool execution
🔗 How It Works
This server acts as an intelligent bridge between your frontend application and MCP-compatible tools:
- User Request: The frontend sends a natural language request
- AI Processing: OpenAI models interpret the request and identify required actions
- Function Mapping: The server maps AI intentions to appropriate MCP tools
- Tool Execution: MCP tools are executed with the necessary parameters
- Response Generation: Results are processed and returned to the user
🚀 Getting Started
Prerequisites
- Node.js (v16 or later)
- npm or yarn
- MCP server running (see the
mcp-serverproject) - OpenAI API key
Installation
- Clone the repository:
git clone https://github.com/yourusername/mcp-agent-server-example.git
cd agent-server-example
- Install dependencies:
npm install
- Configure the environment:
Create a .env file based on the provided .env.example:
PORT=4000
OPENAI_API_KEY=your_openai_api_key
MCP_SERVER_URL=http://localhost:3001
- Start the development server:
npm run start:dev
The server will be available at http://localhost:4000.
💻 API Endpoints
Chat API
POST /chat
Enables natural language interaction with the AI assistant.
Request body:
{
"message": "Create a task to finish the report by Friday",
"history": [
{ "role": "user", "content": "Hello" },
{ "role": "assistant", "content": "Hi there! How can I help you today?" }
]
}
Task Management API
GET /tasks?status=[all|pending|completed] # List tasks with optional filtering
POST /tasks # Create a new task
PATCH /tasks/:id/complete # Mark a task as completed
📂 Project Structure
src/controllers/- API endpoints and request handlingsrc/services/- Business logic and integration with OpenAI and MCPsrc/interfaces/- TypeScript type definitionssrc/config/- Application configuration
🔧 Building for Production
To build the application for production:
npm run build
The compiled files will be in the dist directory.
🔄 Integration with Frontend
This server pairs perfectly with the mcp-agent-client-example project, which provides a web interface for interacting with this backend.
📋 Future Enhancements
- Authentication and user management
- Support for multiple MCP servers
- Streaming responses for real-time interactions
- Advanced context management for improved AI understanding
- Performance metrics and monitoring
📄 License
MIT
Bridging the gap between natural language and executable actions 🤖⚒️
Quick Start
Clone the repository
git clone https://github.com/leandrozapata/mcp-server-agent-exampleInstall dependencies
cd mcp-server-agent-example
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.