Skip to content

Commit f3c98c0

Browse files
Merge pull request #141 from intelligentnode/validate-gpt5-support
Validate gpt5 support
2 parents 302013f + 669ec2e commit f3c98c0

21 files changed

Lines changed: 2565 additions & 743 deletions

IntelliNode/MCP_IMPLEMENTATION.md

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
# MCP (Model Context Protocol) Implementation in IntelliNode
2+
3+
## Overview
4+
Added support for Model Context Protocol (MCP) to IntelliNode. MCP allows IntelliNode to connect to external tools and data sources via MCP servers. This is implemented as a "nice to have" feature with **zero additional dependencies** - only using existing `cross-fetch` package.
5+
6+
## What Was Added
7+
8+
### 1. Core Implementation: `utils/MCPClient.js`
9+
A lightweight HTTP-based MCP client for connecting to MCP servers.
10+
11+
**Features:**
12+
- ✅ Connect to MCP servers via HTTP
13+
- ✅ Fetch available tools from MCP server
14+
- ✅ Call tools with parameters
15+
- ✅ Tool discovery and listing
16+
- ✅ Error handling
17+
-**No external dependencies** (uses cross-fetch which is already a dependency)
18+
19+
**Key Methods:**
20+
```javascript
21+
class MCPClient {
22+
constructor(serverUrl) // Initialize with MCP server URL
23+
async initialize() // Connect and fetch tools
24+
async getTools() // Get all tools from server
25+
async callTool(toolName, input) // Execute a tool
26+
getTool(toolName) // Get specific tool
27+
getToolNames() // List all tool names
28+
hasTool(toolName) // Check if tool exists
29+
listTools() // Get formatted tool list
30+
}
31+
```
32+
33+
### 2. Test Suite: `test/integration/MCPClient.test.js`
34+
Comprehensive test coverage with **2 mock tests + 2 optional real server tests**:
35+
36+
**Mock Tests (Always Run - No Server Needed):**
37+
- ✅ Test 1: Tool management methods (getToolNames, getTool, hasTool, listTools)
38+
- ✅ Test 2: Error handling for non-existent tools
39+
40+
**Real Server Tests (Optional - Requires MCP Server):**
41+
- ✅ Test 3: Initialize connection with real MCP server
42+
- ✅ Test 4: Fetch and list tools from real server
43+
44+
**Run tests:**
45+
```bash
46+
# Mock tests only (CI/CD ready, always passes)
47+
node test/integration/MCPClient.test.js
48+
49+
# With real server (optional)
50+
MCPClient_REAL_SERVER=true node test/integration/MCPClient.test.js
51+
```
52+
53+
**Setup Real Server Tests:**
54+
```bash
55+
# Terminal 1: Start MCP server
56+
npx @modelcontextprotocol/server-filesystem /tmp
57+
58+
# Terminal 2: Run tests with real server
59+
MCPClient_REAL_SERVER=true node test/integration/MCPClient.test.js
60+
```
61+
62+
All mock tests pass ✓
63+
64+
### 3. Updated Files
65+
66+
#### `index.js` (Line 78, 138)
67+
- Added MCPClient import
68+
- Added MCPClient to module.exports
69+
70+
#### `package.json`
71+
- Version bumped: `2.3.0``2.4.0`
72+
- Added keywords: "mcp", "model-context-protocol"
73+
74+
#### `README.md`
75+
- Added new "Model Context Protocol (MCP)" section in Utilities
76+
- Includes example code and reference to MCP documentation
77+
78+
## No Dependencies Added! 🎉
79+
This implementation uses **only existing dependencies**:
80+
- `cross-fetch` (already in package.json) - for HTTP requests
81+
- No need for `@modelcontextprotocol/sdk` (can be added later if full SDK features needed)
82+
- No need for `zod` (not required for basic tool communication)
83+
84+
## Usage Examples
85+
86+
### Basic Usage
87+
```javascript
88+
const { MCPClient } = require('intellinode');
89+
90+
// Connect to MCP server
91+
const mcpClient = new MCPClient('http://localhost:3000');
92+
93+
// Initialize and get tools
94+
const tools = await mcpClient.initialize();
95+
console.log('Available tools:', mcpClient.getToolNames());
96+
97+
// Call a tool
98+
const result = await mcpClient.callTool('get_weather', {
99+
location: 'New York',
100+
units: 'celsius'
101+
});
102+
```
103+
104+
### With Chatbot Integration
105+
```javascript
106+
const { Chatbot, ChatGPTInput } = require('intellinode');
107+
const { MCPClient } = require('intellinode');
108+
109+
// Initialize MCP client
110+
const mcpClient = new MCPClient('http://localhost:3000');
111+
await mcpClient.initialize();
112+
113+
// Create chat input with tool context
114+
const input = new ChatGPTInput('You are an assistant with access to tools');
115+
116+
// Add tools information to context
117+
const toolsContext = mcpClient.listTools()
118+
.map(t => `- ${t.name}: ${t.description}`)
119+
.join('\n');
120+
121+
input.addSystemMessage(`Available tools:\n${toolsContext}`);
122+
input.addUserMessage('What is the weather in New York?');
123+
124+
// Get response from chatbot
125+
const bot = new Chatbot(openaiKey);
126+
const responses = await bot.chat(input);
127+
```
128+
129+
### Mock Tools (for testing without server)
130+
```javascript
131+
const mcpClient = new MCPClient('http://localhost:3000');
132+
133+
// Simulate tools locally (useful for development)
134+
mcpClient.tools = [
135+
{
136+
name: 'tool_name',
137+
description: 'What this tool does',
138+
inputSchema: { /* schema */ }
139+
}
140+
];
141+
142+
// Now you can use the client without running a server
143+
console.log(mcpClient.listTools());
144+
```
145+
146+
## MCP Servers to Try
147+
148+
### Built-in Servers (from Anthropic)
149+
```bash
150+
# Filesystem server
151+
npx @modelcontextprotocol/server-filesystem /path/to/root
152+
153+
# GitHub server
154+
npm install -g @modelcontextprotocol/server-github
155+
156+
# Slack server
157+
npm install -g @modelcontextprotocol/server-slack
158+
```
159+
160+
### Other Available Servers
161+
- Google Drive
162+
- Notion
163+
- GitLab
164+
- Linear
165+
- And many more at: https://modelcontextprotocol.io
166+
167+
## Architecture
168+
169+
```
170+
┌─────────────────────────────────────┐
171+
│ IntelliNode Application │
172+
├─────────────────────────────────────┤
173+
│ │
174+
│ Chatbot + MCPClient │
175+
│ │ │
176+
└─────────────────────────┼───────────┘
177+
178+
HTTP/JSON-RPC
179+
180+
┌─────▼─────┐
181+
MCP Server │
182+
│ (Tools) │
183+
└────────────┘
184+
```
185+
186+
## Design Decisions
187+
188+
1. **Minimal Dependencies**: No new npm packages required
189+
- Only uses existing `cross-fetch`
190+
- Can upgrade to full SDK if needed later
191+
192+
2. **Simple HTTP Transport**:
193+
- Easy to debug
194+
- Works with any HTTP-based MCP server
195+
- Can be extended for WebSocket/SSE later
196+
197+
3. **Flexible Tool Integration**:
198+
- Tools can be loaded from server or mocked locally
199+
- Easy to integrate into Chatbot prompts
200+
- No breaking changes to existing code
201+
202+
4. **Good to Have Philosophy**:
203+
- Doesn't affect core library functionality
204+
- Can be used optionally
205+
- No required setup or configuration
206+
207+
## Future Enhancements
208+
209+
1. **WebSocket/SSE Transport**: For streaming responses
210+
2. **Tool Caching**: Cache tool definitions to reduce calls
211+
3. **Retry Logic**: Auto-retry with exponential backoff
212+
4. **Request Timeout**: Add configurable timeout handling
213+
5. **Authentication**: Support for API keys and OAuth
214+
6. **Batch Tool Calls**: Execute multiple tools in parallel
215+
7. **SDK Integration**: Optional `@modelcontextprotocol/sdk` for full features
216+
217+
## Testing
218+
219+
✅ All mock tests pass (CI/CD ready)
220+
```
221+
✓ Test 1: Mock Tool Management Methods
222+
✓ Test 2: Mock Error Handling
223+
```
224+
225+
Optional real server tests (require running MCP server):
226+
```
227+
✓ Test 3: Real Server - Initialize
228+
✓ Test 4: Real Server - List Tools
229+
```
230+
231+
**Run tests:**
232+
```bash
233+
# Default: Mock tests only
234+
node test/integration/MCPClient.test.js
235+
236+
# With real server (set environment variable)
237+
MCPClient_REAL_SERVER=true node test/integration/MCPClient.test.js
238+
239+
# Setup real server before running
240+
npx @modelcontextprotocol/server-filesystem /tmp
241+
```
242+
243+
## Version Info
244+
245+
- **IntelliNode Version**: 2.4.0 (increased from 2.3.0)
246+
- **MCP Implementation**: v1.0 (Basic HTTP client)
247+
- **Node.js Support**: 14+
248+
249+
## References
250+
251+
- [Model Context Protocol Documentation](https://modelcontextprotocol.io)
252+
- [MCP GitHub Repository](https://github.com/modelcontextprotocol)
253+
- [LlamaIndex MCP Integration](https://developers.llamaindex.ai/typescript/framework/modules/agents/tool/#mcp-tools)
254+
- [OpenAI MCP Support](https://platform.openai.com/docs/mcp)
255+
- [Anthropic MCP Announcement](https://www.anthropic.com/news/model-context-protocol)

IntelliNode/README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Integrate your data with the latest language models and deep learning frameworks using intellinode **javascript**. The library provides intuitive functions for sending input to models like ChatGPT, WaveNet and Stable diffusion, and receiving generated text, speech, or images. With just a few lines of code, you can easily access the power of cutting-edge AI models to enhance your projects.
1919

2020
# Latest Updates
21+
- Add support for OpenAI GPT-5 with reasoning effort control. 🧠
2122
- Add support for self-hosted vLLM models.
2223
- Generate frontend version from intellinode.
2324
- Integrated Nvidia-hosted models (DeepSeek and Llama3 🦙).
@@ -39,13 +40,25 @@ Chat with your docs via Intellinode one key at [app.intellinode.ai](https://app.
3940
```js
4041
const { Chatbot, ChatGPTInput } = require('intellinode');
4142
```
42-
2. call:
43+
2. call with GPT-5 (default):
4344
```js
44-
// set chatGPT system mode and the user message.
45+
// GPT-5 is now the default model with medium reasoning effort
4546
const input = new ChatGPTInput('You are a helpful assistant.');
4647
input.addUserMessage('What is the distance between the Earth and the Moon?');
4748

48-
// get chatGPT responses.
49+
// get GPT-5 responses.
50+
const bot = new Chatbot(openaiKey);
51+
const responses = await bot.chat(input);
52+
```
53+
3. control GPT-5 reasoning effort:
54+
```js
55+
// customize reasoning effort: minimal, low, medium, high
56+
const input = new ChatGPTInput('You are a helpful assistant.', {
57+
model: 'gpt-5',
58+
effort: 'high'
59+
});
60+
input.addUserMessage('Explain quantum computing');
61+
4962
const bot = new Chatbot(openaiKey);
5063
const responses = await bot.chat(input);
5164
```
@@ -174,6 +187,30 @@ ProxyHelper.getInstance().setAzureOpenai(resourceName);
174187
### Custom proxy
175188
Check the code to access the chatbot through a proxy: [proxy chatbot](https://github.com/Barqawiz/IntelliNode/blob/main/samples/command_sample/test_chatbot_proxy.js).
176189

190+
### Model Context Protocol (MCP)
191+
Connect to external tools and data sources via MCP servers (good to have, not core):
192+
```js
193+
const { MCPClient } = require('intellinode');
194+
195+
// Initialize MCP client pointing to your MCP server
196+
const mcpClient = new MCPClient('http://localhost:3000');
197+
198+
// Fetch available tools from MCP server
199+
const tools = await mcpClient.initialize();
200+
console.log('Available tools:', mcpClient.getToolNames());
201+
202+
// Call a tool
203+
const result = await mcpClient.callTool('get_weather', {
204+
location: 'New York',
205+
units: 'celsius'
206+
});
207+
208+
// Use tools with your chatbot prompts
209+
const toolsList = mcpClient.listTools();
210+
console.log('Tools:', toolsList);
211+
```
212+
213+
Supported MCP servers include: Filesystem, GitHub, Slack, Google Drive, and more. See [MCP Documentation](https://modelcontextprotocol.io) for available servers.
177214

178215
# :closed_book: Documentation
179216
- [IntelliNode Docs](https://doc.intellinode.ai/docs/npm): Detailed documentation about IntelliNode.

IntelliNode/config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"base": "https://api.openai.com",
99
"completions": "/v1/completions",
1010
"chatgpt": "/v1/chat/completions",
11+
"responses": "/v1/responses",
1112
"imagegenerate": "/v1/images/generations",
1213
"embeddings": "/v1/embeddings",
1314
"audiotranscriptions": "/v1/audio/transcriptions",
@@ -20,6 +21,7 @@
2021
"base": "https://{resource-name}.openai.azure.com/openai",
2122
"completions": "/deployments/{deployment-id}/completions?api-version={api-version}",
2223
"chatgpt": "/deployments/{deployment-id}/chat/completions?api-version={api-version}",
24+
"responses": "/deployments/{deployment-id}/responses?api-version={api-version}",
2325
"imagegenerate": "/images/generations:submit?api-version={api-version}",
2426
"embeddings": "/deployments/{deployment-id}/embeddings?api-version={api-version}",
2527
"audiotranscriptions": "/deployments/{deployment-id}/audio/transcriptions?api-version={api-version}",

0 commit comments

Comments
 (0)