Get the FREE Ultimate OpenClaw Setup Guide →

openai -client

A rudimentary implementation of Anthropic's Model Context Protocol with OpenAIs Model

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio resoluteerror-openai-mcp-client deno run dev \
  --env DEBUG="true" \
  --env OPENAI_API_KEY="your-openai-api-key"

How to use

This MCP server is a simple example of using the Model Context Protocol (MCP) with OpenAI's API to run a chat-based agent that operates within a conversational context. It forwards chat messages to OpenAI, and supports tool-call responses of type text. The server saves the latest messages to messages.json for debugging, and can be run in debug mode to print extra information about messages and tool calls. To start, ensure you have a working OpenAI API key and provide it via the environment (OPENAI_API_KEY). Once running, you can interact with the agent through the MCP-compatible client, observe how tool calls are proposed in responses, and review the saved messages in messages.json for troubleshooting and development.

The server exposes the standard MCP workflow: a chat context is maintained across turns, prompts are shaped with the current messages, and OpenAI returns a response that may include a tool call. If a tool call is emitted, the server will apply it (where supported) and continue the conversation. Debug mode can help you understand how messages are constructed and how tool calls are chosen, which is useful when integrating additional tools or refining the tool call behavior.

How to install

Prerequisites:

  • Deno v2 or newer installed on your machine
  • An OpenAI API key
  • Access to the repository (clone or download)

Step-by-step installation:

  1. Clone the repository or set up the project files:
git clone <repository-url>
cd <repository-folder>
  1. Copy the example environment configuration and customize it:
cp .env.example .env

Edit .env and set your OpenAI API key and any other needed settings. In this MCP example, at minimum you should provide OPENAI_API_KEY and can enable DEBUG for verbose output:

OPENAI_API_KEY=your-openai-api-key
DEBUG=true
  1. Install dependencies and start the server:
deno install
  1. Run the server in development mode:
deno run dev
  1. Verify the server starts and is listening for MCP clients. You can connect using an MCP client configured to the server’s entry point (as defined in mcp_config below).

Additional notes

Tips and notes:

  • Chat history is saved to messages.json for debugging; this file will be overwritten each run unless you copy it elsewhere.
  • The example currently only supports tool calls of type text. If you plan to extend tool integrations, you can implement additional tool call handling in the codebase where applyToolCallIfExists is referenced.
  • If you need more verbose output, enable DEBUG in the .env file to print detailed information about messages and tool calls.
  • Ensure your OPENAI_API_KEY is kept secret and not committed to version control.
  • For longer conversations, be mindful of token usage and associated costs when using OpenAI models.

Related MCP Servers

Sponsor this space

Reach thousands of developers