@myatkyawthu/mcp-connect 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +170 -308
- package/package.json +3 -3
- package/src/cli.js +227 -170
- package/src/defineMCP.js +56 -72
- package/src/index.js +3 -35
- package/src/server/mcpServer.js +279 -236
- package/src/types/mcp.js +38 -108
- package/src/utils/configValidation.js +448 -381
- package/src/utils/logger.js +163 -290
- package/src/utils/validation.js +50 -78
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 myat-kyaw-thu
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 myat-kyaw-thu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,308 +1,170 @@
|
|
|
1
|
-
# mcp-connect
|
|
2
|
-
|
|
3
|
-
> Dead simple MCP (Model Context Protocol) server for exposing your app functions to AI agents
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/mcp-connect)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
|
|
8
|
-
## 🚀
|
|
9
|
-
|
|
10
|
-
###
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Create
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
```json
|
|
172
|
-
{
|
|
173
|
-
"mcpServers": {
|
|
174
|
-
"my-app": {
|
|
175
|
-
"command": "mcp-connect",
|
|
176
|
-
"cwd": "/path/to/your/project"
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
#### Local Installation
|
|
183
|
-
|
|
184
|
-
```json
|
|
185
|
-
{
|
|
186
|
-
"mcpServers": {
|
|
187
|
-
"my-app": {
|
|
188
|
-
"command": "npx",
|
|
189
|
-
"args": ["mcp-connect"],
|
|
190
|
-
"cwd": "/path/to/your/project"
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
#### Alternative: Package Script
|
|
197
|
-
|
|
198
|
-
Add to your project's `package.json`:
|
|
199
|
-
|
|
200
|
-
```json
|
|
201
|
-
{
|
|
202
|
-
"scripts": {
|
|
203
|
-
"mcp": "mcp-connect"
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
Then in Claude Desktop config:
|
|
209
|
-
|
|
210
|
-
```json
|
|
211
|
-
{
|
|
212
|
-
"mcpServers": {
|
|
213
|
-
"my-app": {
|
|
214
|
-
"command": "npm",
|
|
215
|
-
"args": ["run", "mcp"],
|
|
216
|
-
"cwd": "/path/to/your/project"
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
### Other MCP Clients
|
|
223
|
-
|
|
224
|
-
Any MCP-compliant client can connect using the STDIO transport. The server implements the full MCP specification with:
|
|
225
|
-
|
|
226
|
-
- `tools/list` - List available tools
|
|
227
|
-
- `tools/call` - Execute tool functions
|
|
228
|
-
- Proper JSON-RPC 2.0 messaging
|
|
229
|
-
- Standard MCP lifecycle management
|
|
230
|
-
|
|
231
|
-
## 📁 Examples
|
|
232
|
-
|
|
233
|
-
### Todo App Example
|
|
234
|
-
|
|
235
|
-
```javascript
|
|
236
|
-
import { defineMCP } from "mcp-connect";
|
|
237
|
-
|
|
238
|
-
const todos = [{ id: 1, title: "Buy milk", completed: false }];
|
|
239
|
-
|
|
240
|
-
export default defineMCP({
|
|
241
|
-
name: "Todo App",
|
|
242
|
-
version: "1.0.0",
|
|
243
|
-
description: "Simple todo list management via MCP",
|
|
244
|
-
tools: [
|
|
245
|
-
// Simple tuple format
|
|
246
|
-
["getTodos", async () => todos],
|
|
247
|
-
|
|
248
|
-
// Object format with schema validation
|
|
249
|
-
{
|
|
250
|
-
name: "addTodo",
|
|
251
|
-
description: "Add a new todo item",
|
|
252
|
-
schema: {
|
|
253
|
-
type: "object",
|
|
254
|
-
properties: {
|
|
255
|
-
title: { type: "string", description: "Todo title" }
|
|
256
|
-
},
|
|
257
|
-
required: ["title"]
|
|
258
|
-
},
|
|
259
|
-
handler: async ({ title }) => {
|
|
260
|
-
const newTodo = { id: Date.now(), title, completed: false };
|
|
261
|
-
todos.push(newTodo);
|
|
262
|
-
return newTodo;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
]
|
|
266
|
-
});
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
Check out the [examples](./examples) directory for complete working examples.
|
|
270
|
-
|
|
271
|
-
## 🛠 Development
|
|
272
|
-
|
|
273
|
-
```bash
|
|
274
|
-
# Clone and install
|
|
275
|
-
git clone https://github.com/myat-kyaw-thu/MCP_Indigration_Package-NPM.git
|
|
276
|
-
cd mcp-connect
|
|
277
|
-
npm install
|
|
278
|
-
|
|
279
|
-
# Run example with debug logging
|
|
280
|
-
cd examples/todo-app
|
|
281
|
-
MCP_DEBUG=1 node ../../src/cli.js
|
|
282
|
-
|
|
283
|
-
# Test global installation locally
|
|
284
|
-
npm link
|
|
285
|
-
cd /path/to/test/project
|
|
286
|
-
mcp-connect
|
|
287
|
-
|
|
288
|
-
# Run tests
|
|
289
|
-
npm test
|
|
290
|
-
|
|
291
|
-
# Lint and format code
|
|
292
|
-
npm run lint
|
|
293
|
-
npm run format
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## 🏗️ Architecture
|
|
297
|
-
|
|
298
|
-
- **Pure JavaScript** with JSDoc type annotations
|
|
299
|
-
- **ESM modules** with Node.js 18+ support
|
|
300
|
-
- **Express.js** HTTP server integration
|
|
301
|
-
- **Official MCP SDK** integration
|
|
302
|
-
- **Structured logging** with performance metrics
|
|
303
|
-
- **Comprehensive validation** with user-friendly errors
|
|
304
|
-
- **Pure MCP implementation** focused on STDIO transport
|
|
305
|
-
|
|
306
|
-
## 📄 License
|
|
307
|
-
|
|
308
|
-
MIT © [myat-kyaw-thu](https://github.com/myat-kyaw-thu)
|
|
1
|
+
# mcp-connect
|
|
2
|
+
|
|
3
|
+
> Dead simple MCP (Model Context Protocol) server for exposing your app functions to AI agents
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/mcp-connect)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## 🚀 Claude Desktop Setup (5 Minutes)
|
|
9
|
+
|
|
10
|
+
### Step 1: Install mcp-connect
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -g @myatkyawthu/mcp-connect
|
|
14
|
+
```
|
|
15
|
+
### Step 2: Create mcp.config.js
|
|
16
|
+
|
|
17
|
+
### Step 2: Create Your MCP Server
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Navigate to your project directory
|
|
21
|
+
cd your-project
|
|
22
|
+
|
|
23
|
+
# Generate sample config
|
|
24
|
+
mcp-connect init
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This creates `mcp.config.js` with example tools:
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
import { defineMCP } from "@myatkyawthu/mcp-connect";
|
|
31
|
+
|
|
32
|
+
export default defineMCP({
|
|
33
|
+
name: "My MCP App",
|
|
34
|
+
version: "1.0.0",
|
|
35
|
+
tools: [
|
|
36
|
+
["hello", async ({ name = "World" }) => `Hello ${name}!`],
|
|
37
|
+
["echo", async ({ message }) => `Echo: ${message}`]
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
### Step 3: Test Locally
|
|
42
|
+
|
|
43
|
+
### Step 3: Configure Claude Desktop
|
|
44
|
+
|
|
45
|
+
Open Claude Desktop config file:
|
|
46
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
47
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
48
|
+
|
|
49
|
+
Add your MCP server:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"mcpServers": {
|
|
54
|
+
"my-app": {
|
|
55
|
+
"command": "mcp-connect",
|
|
56
|
+
"args": ["C:/full/path/to/your/mcp.config.js"]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Important**: Use the full absolute path to your `mcp.config.js` file.
|
|
63
|
+
|
|
64
|
+
### Step 4: Start & Test
|
|
65
|
+
|
|
66
|
+
1. **Restart Claude Desktop** completely
|
|
67
|
+
2. **Test connection**: Ask Claude *"What tools do you have available?"*
|
|
68
|
+
3. **Use your tools**: Try *"Hello there!"* or *"Echo this message"*
|
|
69
|
+
|
|
70
|
+
✅ **Done!** Your functions are now available to Claude Desktop.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 📖 Tool Definition Guide
|
|
75
|
+
|
|
76
|
+
### Simple Format (Recommended)
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
// Just name and function
|
|
80
|
+
["toolName", async (args) => "result"]
|
|
81
|
+
```
|
|
82
|
+
## 🔧 CLI Usage
|
|
83
|
+
|
|
84
|
+
### Advanced Format (With Validation)
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
{
|
|
88
|
+
name: "toolName",
|
|
89
|
+
description: "What this tool does",
|
|
90
|
+
schema: {
|
|
91
|
+
type: "object",
|
|
92
|
+
properties: {
|
|
93
|
+
param: { type: "string", description: "Parameter description" }
|
|
94
|
+
},
|
|
95
|
+
required: ["param"]
|
|
96
|
+
},
|
|
97
|
+
handler: async ({ param }) => `Result: ${param}`
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 🛠 Development Commands
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Start with auto-reload during development
|
|
105
|
+
npm run dev
|
|
106
|
+
|
|
107
|
+
# Start server with specific config file
|
|
108
|
+
mcp-connect /path/to/your/mcp.config.js
|
|
109
|
+
|
|
110
|
+
# Format code
|
|
111
|
+
npm run format
|
|
112
|
+
|
|
113
|
+
# Lint code
|
|
114
|
+
npm run lint
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 🔧 Troubleshooting
|
|
118
|
+
|
|
119
|
+
### Config File Not Found
|
|
120
|
+
```bash
|
|
121
|
+
# Create sample config
|
|
122
|
+
mcp-connect init
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Claude Desktop Not Connecting
|
|
126
|
+
1. Check config file path is absolute
|
|
127
|
+
2. Restart Claude Desktop completely
|
|
128
|
+
3. Check Claude Desktop logs for errors
|
|
129
|
+
|
|
130
|
+
### Tool Not Working
|
|
131
|
+
1. Verify tool syntax in `mcp.config.js`
|
|
132
|
+
2. Check server logs for errors
|
|
133
|
+
3. Test with simple tools first
|
|
134
|
+
|
|
135
|
+
## 📋 Examples
|
|
136
|
+
|
|
137
|
+
### File Operations
|
|
138
|
+
```javascript
|
|
139
|
+
["readFile", async ({ path }) => {
|
|
140
|
+
const fs = await import('fs/promises');
|
|
141
|
+
return await fs.readFile(path, 'utf8');
|
|
142
|
+
}]
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### API Calls
|
|
146
|
+
```javascript
|
|
147
|
+
["getWeather", async ({ city }) => {
|
|
148
|
+
const response = await fetch(`https://api.weather.com/${city}`);
|
|
149
|
+
return await response.json();
|
|
150
|
+
}]
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Database Queries
|
|
154
|
+
```javascript
|
|
155
|
+
["getUser", async ({ id }) => {
|
|
156
|
+
// Your database logic here
|
|
157
|
+
return { id, name: "John Doe", email: "john@example.com" };
|
|
158
|
+
}]
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## 🌐 Other MCP Clients
|
|
162
|
+
|
|
163
|
+
Claude Desktop setup is covered above. Tutorials for other MCP clients coming soon:
|
|
164
|
+
- VS Code extensions
|
|
165
|
+
- Custom applications
|
|
166
|
+
- Other AI platforms
|
|
167
|
+
|
|
168
|
+
## 📄 License
|
|
169
|
+
|
|
170
|
+
MIT © [myat-kyaw-thu](https://github.com/myat-kyaw-thu)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myatkyawthu/mcp-connect",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Dead simple MCP (Model Context Protocol) server for exposing your app functions to AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"bin": {
|
|
15
|
-
"mcp-connect": "
|
|
15
|
+
"mcp-connect": "src/cli.js"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"src",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
|
-
"url": "https://github.com/myat-kyaw-thu/MCP_Indigration_Package-NPM.git"
|
|
46
|
+
"url": "git+https://github.com/myat-kyaw-thu/MCP_Indigration_Package-NPM.git"
|
|
47
47
|
},
|
|
48
48
|
"bugs": {
|
|
49
49
|
"url": "https://github.com/myat-kyaw-thu/MCP_Indigration_Package-NPM/issues"
|