MCP ExplorerExplorer

Mcp Client With Openai

@anisirjion a year ago
1 MIT
FreeCommunity
AI Systems
A TypeScript framework integrating OpenAI's GPT-4o with MCP Tool Servers for real-time reasoning.

Overview

What is Mcp Client With Openai

mcp-client-with-openai is a TypeScript framework that integrates OpenAI’s GPT-4o with MCP Tool Servers, enabling real-time reasoning through a structured approach.

Use cases

Use cases include building intelligent chatbots, creating automated data analysis tools, developing real-time monitoring systems, and enhancing user interactions in applications.

How to use

To use mcp-client-with-openai, install the dependencies using npm, configure the environment variables including the OpenAI API key, and set up your MCP tool servers in the mcp-config.json file. Finally, build and run the application.

Key features

Key features include seamless tool-calling via MCP Protocol, structured reasoning with the ReAct Planning Loop, real-time streaming with Server-Sent Events, dynamic system prompting, easy extensibility, and session management.

Where to use

mcp-client-with-openai can be used in various fields such as AI development, real-time data processing, interactive applications, and any scenario requiring integration with MCP-compatible tools.

Content

MCP Client TypeScript

A Node.js client for Model Context Protocol (MCP) servers with TypeScript.

Project Architecture

This project follows Clean Code and SOLID principles with a modular architecture:

src/
├── config/         # Configuration management
│   └── environment.ts
├── controllers/    # Request handling logic
│   └── ConversationController.ts
├── middleware/     # Express middleware
│   └── errorHandler.ts
├── routes/         # API routes
│   └── apiRoutes.ts
├── services/       # Core business logic 
│   ├── MCPService.ts
│   ├── OpenAIService.ts
│   └── SessionManager.ts
├── types/          # TypeScript type definitions
│   └── index.ts
├── utils/          # Utility functions
│   ├── helpers.ts
│   └── sse.ts
└── server.ts       # Express server setup

Core Components

  • Environment: Centralized configuration management
  • MCPService: Handles connections to MCP servers and tool execution
  • OpenAIService: Manages OpenAI API interactions
  • SessionManager: Manages user chat sessions and active streams
  • ConversationController: Implements conversation handling logic
  • API Routes: Defines HTTP endpoints for the application

Design Principles Applied

  • Single Responsibility Principle: Each class has a single reason to change
  • Open/Closed Principle: Components are open for extension but closed for modification
  • Dependency Inversion: High-level modules depend on abstractions
  • DRY (Don’t Repeat Yourself): Code duplication is minimized
  • KISS (Keep It Simple, Stupid): Logic is simple and straightforward
  • Separation of Concerns: Clear boundaries between components

Getting Started

Prerequisites

  • Node.js (v16+)
  • npm or yarn

Installation

  1. Clone the repository
  2. Install dependencies:
    npm install
    
  3. Set up environment variables in .env:
    PORT=3000
    OPENAI_API_KEY=your_openai_api_key
    
  4. Configure MCP servers in config/mcp-config.json

Running the Application

Development mode:

npm run dev

Production mode:

npm run build
npm start

API Endpoints

  • GET /api/stream-sse - Server-Sent Events endpoint for real-time chat
  • POST /api/tool-permission - Approve/deny tool usage
  • POST /api/inject-message - Inject an assistant message
  • GET /api/clear-session - Clear a chat session

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers