Skip to content

Commit e1b4fae

Browse files
authored
Merge pull request #3 from gregra81/support_remote_tools
support loading remote tools
2 parents a452dd0 + d8c0e0c commit e1b4fae

File tree

10 files changed

+1299
-299
lines changed

10 files changed

+1299
-299
lines changed

README.md

Lines changed: 159 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# MCP Tools Demo
22

3-
A **Model Context Protocol (MCP)** implementation showcasing clean, modular tool architecture with multiple server options and an interactive browser client.
3+
A **Model Context Protocol (MCP)** implementation showcasing clean, modular tool architecture with **local and remote tools** support and an interactive browser client.
44

55
## 🌟 Features
66

77
- **🏗️ Clean Architecture**: Modular tool design with `MCPToolsManager`
8-
- **🔧 4 Demo Tools**: HTTP POST, Weather API, Create Post, and Greg Test tools
9-
- **🌐 Browser Client**: Interactive web interface for testing tools
10-
- **📡 Multiple Server Options**: Stdio and Simple HTTP
11-
- **🧪 Comprehensive Testing**: Automated test suites and manual testing options
12-
- **🔒 Type Safety**: Full TypeScript implementation with proper validation
8+
- **🔧 8 Demo Tools**: 4 local + 4 remote tools working seamlessly together
9+
- **🌐 Remote Tools Support**: Load tools dynamically from external APIs
10+
- **🌐 Browser Client**: Interactive web interface for testing all tools
11+
- **📡 Multiple Server Options**: Stdio, Simple HTTP, and Remote Tools servers
12+
- **🔒 Type Safety**: Full TypeScript implementation with Zod validation
1313

1414
## 🚀 Quick Start
1515

@@ -21,124 +21,212 @@ cd mcp-hello-world
2121
npm install
2222
```
2323

24-
### 2. Browser Demo (Recommended)
24+
### 2. Full Demo (Local + Remote Tools)
2525

26-
Start the HTTP server and open the browser client:
26+
Start both servers for the complete experience:
2727

2828
```bash
29+
# Terminal 1: Start remote tools server (4 remote tools)
30+
npm run start:remote
31+
32+
# Terminal 2: Start HTTP server (4 local + 4 remote = 8 total tools)
2933
npm run start:http
3034
```
3135

3236
Then open: **http://localhost:3000/examples/client.html**
3337

34-
### 3. Command Line Usage
38+
### 3. Local Tools Only
39+
40+
```bash
41+
# Just local tools (4 tools)
42+
REMOTE_TOOLS_ENABLED=false npm run start:http
43+
```
44+
45+
### 4. Command Line Usage (Cursor/Claude)
3546

3647
```bash
37-
# Build the project
3848
npm run build
49+
node dist/index.js # Stdio MCP server
50+
```
3951

40-
# Test tools directly
41-
node dist/index.js # Stdio MCP server (for Cursor/Claude)
52+
## 🏗️ Architecture
53+
54+
### Modular Structure
55+
56+
```
57+
mcp-hello-world/
58+
├── src/
59+
│ ├── index.ts # Main MCP stdio server
60+
│ ├── mcp-tools-manager.ts # Generic tools manager (local + remote)
61+
│ ├── simple-http-server.ts # HTTP wrapper with remote tools support
62+
│ ├── tools/ # 🏠 Local tools directory
63+
│ │ ├── index.ts # Tools exports and registry
64+
│ │ ├── greg-test-tool.ts # Mood testing tool
65+
│ │ ├── http-post-tool.ts # Generic HTTP POST
66+
│ │ ├── weather-tool.ts # Weather API integration
67+
│ │ └── create-post-tool.ts # JSONPlaceholder posts
68+
│ └── types/mcp.ts # TypeScript definitions
69+
├── examples/
70+
│ ├── client.html # 🌐 Interactive browser client
71+
│ ├── remote-tools-api-example.json # Remote tools definition
72+
│ └── remote-tool-server-example.js # 🌐 Remote tools server
73+
└── dist/ # Compiled JavaScript
4274
```
4375

44-
## Key Design Principles
76+
### Key Design Principles
4577

46-
- **Single Source of Truth**: All tools defined in `src/tools/` directory
78+
- **Single Source of Truth**: Local tools in `src/tools/`, remote tools via API
4779
- **Generic Manager**: `MCPToolsManager` automatically loads all tools
48-
- **Modular Tools**: Each tool is self-contained with handler and schema
49-
- **Multiple Interfaces**: Same tools work with stdio, HTTP, SSE, and streaming
80+
- **Hot-loadable**: Remote tools can be added/updated without restart
81+
- **Multiple Interfaces**: Same tools work with stdio, HTTP, and browser
5082

5183
## 🔧 Available Tools
5284

53-
### 1. 🎭 Greg Test Tool (`greg-test`)
54-
Your amazing mood testing tool!
85+
### 🏠 Local Tools (4)
86+
1. **🎭 Greg Test** (`greg-test`) - Mood testing tool
87+
2. **🌐 HTTP POST** (`http_post`) - Generic HTTP requests
88+
3. **🌤️ Weather** (`get_weather`) - Weather API with OpenWeatherMap
89+
4. **📄 Create Post** (`create_post`) - JSONPlaceholder integration
5590

56-
**Parameters**:
57-
- `feeling` (string, required): Your current mood
91+
### 🌐 Remote Tools (4)
92+
1. **🧮 Calculate Tax** (`calculate_tax`) - Tax calculations
93+
2. **📧 Send Email** (`send_email`) - Mock email sending
94+
3. **🖼️ Image OCR** (`image_ocr`) - Mock text extraction
95+
4. **🗄️ Database Query** (`database_query`) - Mock SQL queries
5896

59-
**Example**:
60-
```json
61-
{
62-
"tool": "greg-test",
63-
"parameters": {
64-
"feeling": "excited about the new architecture"
65-
}
66-
}
67-
```
97+
## 🌐 Remote Tools Support
6898

69-
### 2. 🌐 HTTP POST Tool (`http_post`)
70-
Make HTTP POST requests to any API.
99+
Load tools dynamically from external APIs alongside local tools.
71100

72-
**Parameters**:
73-
- `url` (string, required): Target URL
74-
- `data` (object, required): JSON data to send
75-
- `headers` (object, optional): Additional headers
76-
- `timeout` (number, optional): Request timeout in ms
101+
### Quick Configuration
77102

78-
### 3. 🌤️ Weather Tool (`get_weather`)
79-
Get weather information using OpenWeatherMap API (or mock data).
103+
```typescript
104+
const toolsManager = new MCPToolsManager({
105+
enabled: true,
106+
toolsUrl: 'http://localhost:3001/mcp/tools',
107+
timeout: 5000,
108+
retryAttempts: 2,
109+
});
80110

81-
**Parameters**:
82-
- `city` (string, required): City name
83-
- `apiKey` (string, optional): OpenWeatherMap API key
84-
- `units` (string, optional): Temperature units (metric/imperial/kelvin)
111+
await toolsManager.initialize();
112+
```
85113

86-
### 4. 📄 Create Post Tool (`create_post`)
87-
Create posts using JSONPlaceholder API.
114+
### Remote Tools API Format
88115

89-
**Parameters**:
90-
- `title` (string, required): Post title
91-
- `body` (string, required): Post content
92-
- `userId` (number, optional): User ID
116+
Your remote API should return:
117+
118+
```json
119+
{
120+
"tools": [
121+
{
122+
"name": "calculate_tax",
123+
"description": "Calculate tax for given amount",
124+
"executeUrl": "https://api.example.com/tools/calculate-tax",
125+
"method": "POST",
126+
"inputSchema": {
127+
"type": "object",
128+
"properties": {
129+
"amount": {"type": "number"},
130+
"rate": {"type": "number"}
131+
},
132+
"required": ["amount", "rate"]
133+
}
134+
}
135+
]
136+
}
137+
```
138+
139+
### Environment Configuration
140+
141+
```bash
142+
export REMOTE_TOOLS_ENABLED=true # Enable/disable remote tools
143+
export REMOTE_TOOLS_URL=http://localhost:3001/mcp/tools
144+
export REMOTE_TOOLS_TIMEOUT=5000
145+
export REMOTE_TOOLS_RETRY_ATTEMPTS=2
146+
```
93147

94148
## 🌐 Browser Client
95149

96-
The interactive web client provides a beautiful interface for testing all tools:
150+
The interactive web client dynamically loads and displays **ALL available tools**:
97151

98152
### Features
99-
- **🔍 Auto-Discovery**: Automatically loads all available tools
100-
- **🎯 Quick Tests**: One-click testing with default parameters
101-
- **📋 Individual Forms**: Detailed input forms for each tool
102-
- **📊 Real-time Logging**: Activity log with timestamps
103-
- **✅ Health Monitoring**: Server connection status
153+
- **🔍 Auto-Discovery**: Loads all tools from server (local + remote)
154+
- **🎯 Quick Tests**: One-click testing for all 8 tools
155+
- **📊 Tool Statistics**: Shows local vs remote breakdown
156+
- **✅ Health Monitoring**: Real-time server status
157+
- **🔄 Dynamic Updates**: Reflects tool availability in real-time
104158

105159
### Usage
106-
1. Start the HTTP server: `npm run start:http`
160+
1. Start servers: `npm run start:remote && npm run start:http`
107161
2. Open: http://localhost:3000/examples/client.html
108-
3. Click "Check Server Health" to connect
109-
4. Use "Load Available Tools" to see all tools
110-
5. Test tools with quick buttons or detailed forms
162+
3. Click "Load Available Tools" to see all 8 tools
163+
4. Use quick test buttons or detailed tool information
111164

112165
## 🚀 Running the Servers
113166

114-
### 1. HTTP Server (Browser Demo)
167+
### HTTP Server (Browser Demo)
115168
```bash
116-
npm run start:http # Production build + start
169+
npm run start:http # Local tools only
170+
# OR with remote tools:
171+
npm run start:remote # Terminal 1: Remote tools server
172+
npm run start:http # Terminal 2: HTTP server (8 tools total)
117173
```
118-
**URL**: http://localhost:3000
119174

120-
### 2. Stdio Server (Cursor/Claude Integration)
175+
### Stdio Server (Cursor/Claude Integration)
121176
```bash
122177
npm run build
178+
node dist/index.js
123179
```
124180

125-
Then in your mcp servers setup add the following:
126-
127-
```
181+
Then add to your MCP configuration:
182+
```json
128183
{
129184
"mcpServers": {
130-
"demo-mcp": {
131-
"command": "node",
132-
"args": [
133-
"~/Development/dead-simple-mcp-server/dist/index.js"
134-
]
135-
}
185+
"demo-tools": {
186+
"command": "node",
187+
"args": ["path/to/dead-simple-mcp-server/dist/index.js"]
136188
}
189+
}
137190
}
191+
```
192+
193+
## 🧪 Testing
194+
195+
### Quick API Tests
196+
```bash
197+
# Test tool endpoints
198+
curl http://localhost:3000/mcp/tools # All tools
199+
curl http://localhost:3000/mcp/tools/local # Local tools only
200+
curl http://localhost:3000/mcp/tools/remote # Remote tools only
201+
202+
# Test specific tools
203+
curl http://localhost:3000/mcp/test/greg-test
204+
curl http://localhost:3000/mcp/test/calculate_tax # Remote tool
205+
```
138206

207+
### Tool Calls
208+
```bash
209+
curl -X POST http://localhost:3000/mcp/call-tool \
210+
-H "Content-Type: application/json" \
211+
-d '{"tool": "calculate_tax", "parameters": {"amount": 100, "rate": 0.08}}'
139212
```
140213

214+
## 🔧 Adding New Tools
215+
216+
### Local Tools
217+
1. Create `src/tools/my-tool.ts`
218+
2. Export from `src/tools/index.ts`
219+
3. Done! Auto-loaded everywhere.
220+
221+
### Remote Tools
222+
1. Add tool definition to your remote API
223+
2. Implement the execution endpoint
224+
3. Tools appear automatically when server loads
225+
141226
## 📄 License
142227

143228
MIT License - see LICENSE file for details.
144229

230+
---
231+
232+
**🎉 Enjoy your dynamic, distributed MCP tools architecture!**

0 commit comments

Comments
 (0)