miadi 1.0.14 → 2.0.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/package.json +17 -48
- package/.env.example +0 -28
- package/ARCHITECTURE.md +0 -290
- package/CLAUDE.md +0 -269
- package/GEMINI.md +0 -80
- package/MCP_CONNECTOR_READY.md +0 -219
- package/MCP_LEARNING_NOTES.md +0 -178
- package/MCP_REBUILD_PLAN.md +0 -159
- package/MCP_REMOTE_SERVER_SPEC.md +0 -373
- package/MIA.md +0 -344
- package/MIETTE.md +0 -195
- package/README.md +0 -264
- package/REMOTE_MCP_TRANSFORMATION_GUIDE.md +0 -384
- package/STATUS.md +0 -191
- package/TOOL_SELECTION_PLAN.md +0 -340
- package/WAKE_UP_SUMMARY.md +0 -102
- package/__PUBLISH.sh +0 -1
- package/book/_/ledgers/ledger_miadi_mcp_analysis_250730.md +0 -0
- package/conversations/2507301433.claude.issue.11.2025-07-30-this-mcp-is-not-working-another-instance-of-yours.txt +0 -756
- package/conversations/2507301601.cursor.reverse_engineer_mcp_service_for.md +0 -808
- package/conversations/2508050125.llmcon.claude.MIADI_TOOLS-implement-what-is-in-toolselectionplanmd.txt +0 -1235
- package/conversations/2508051939.llmcon.claude.issue-14.TransitionToPlanningIT.implement-what-is-in-toolselectionplanmd.txt +0 -1424
- package/conversations/2508082352.llmcon.claude.MCP-Remote-Take-II.txt +0 -1658
- package/dist/index-remote.js +0 -54736
- package/dist/index.js +0 -32363
- package/mcp.sample.json +0 -14
- package/openapi.yml +0 -2161
- package/research/MCP_Research_Perplexity_2508060045.md +0 -410
- package/samples/README.md +0 -2
- package/scripts/ngrokserve.sh +0 -6
- package/scripts/start-remote.sh +0 -141
- package/scripts/start-with-ngrok.sh +0 -140
- package/src/api-client.ts +0 -254
- package/src/index-remote.ts +0 -406
- package/src/index-simple.ts +0 -232
- package/src/index.ts +0 -510
- package/src/tool-registry.ts +0 -223
- package/src/tools/ai-tools.ts +0 -69
- package/src/tools/capability-tools.ts +0 -79
- package/src/tools/forge-tools.ts +0 -51
- package/src/tools/memory-tools.ts +0 -137
- package/src/tools/session-tools.ts +0 -135
- package/src/tools/workflow-tools.ts +0 -65
- package/src/types.ts +0 -291
- package/src/utils.ts +0 -279
- package/tests/quick-test.sh +0 -116
- package/tests/run-all-tests.sh +0 -167
- package/tests/test-agent-capabilities.sh +0 -364
- package/tests/test-connectivity.sh +0 -90
- package/tests/test-memory-operations.sh +0 -236
- package/tests/test-session-management.sh +0 -320
- package/tests/test-tool-discovery.sh +0 -151
- package/tsconfig.json +0 -24
package/README.md
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
# Miadi MCP Server
|
|
2
|
-
|
|
3
|
-
A Model Context Protocol (MCP) server implementation that exposes the **Miadi Three-Pathway Agent System API** as MCP tools for Claude to use.
|
|
4
|
-
|
|
5
|
-
**Generated by**: Claude-Code and Gemini via gemini-cli MCP on 2025-07-25 / 2025-08-13
|
|
6
|
-
|
|
7
|
-
## IMPORTANT NOTES
|
|
8
|
-
|
|
9
|
-
* "Miadi Three-Pathway" is not public yet and still in development internally. We plan to publish it publicly in the future.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## Overview
|
|
13
|
-
|
|
14
|
-
This MCP server acts as a bridge between Claude and the Miadi Three-Pathway Agent System, enabling natural language interaction with:
|
|
15
|
-
|
|
16
|
-
- **Memory Operations**: Redis-based memory storage and retrieval
|
|
17
|
-
- **Session Management**: Agent persona and mode switching
|
|
18
|
-
- **Capability Resolution**: Dynamic capability resolution based on context
|
|
19
|
-
- **AI Integration**: OpenAI and generic AI model requests
|
|
20
|
-
- **Workflow Management**: GitHub event handling and agent coordination
|
|
21
|
-
- **Forge State**: System state management and glyph operations
|
|
22
|
-
|
|
23
|
-
## Quick Start
|
|
24
|
-
|
|
25
|
-
### 1. Installation
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
# Install dependencies
|
|
29
|
-
npm install
|
|
30
|
-
|
|
31
|
-
# Copy environment template
|
|
32
|
-
cp .env.example .env
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### 2. Configuration
|
|
36
|
-
|
|
37
|
-
Edit `.env` with your Miadi API credentials:
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
EH_TOKEN=your_miadi_api_token_here
|
|
41
|
-
EH_API_URL=https://__YOUR_CUSTOM_DOMAIN__.ngrok-free.app
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### 3. Build and Run
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
# Development mode
|
|
48
|
-
npm run dev
|
|
49
|
-
|
|
50
|
-
# Production build
|
|
51
|
-
npm run build
|
|
52
|
-
npm start
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Available MCP Tools
|
|
56
|
-
|
|
57
|
-
### Memory Operations
|
|
58
|
-
- `miadi-get-memory` - Retrieve memory data from Redis
|
|
59
|
-
- `miadi-store-memory` - Store data in memory with TTL
|
|
60
|
-
- `miadi-scan-keys` - Scan Redis keys with patterns
|
|
61
|
-
- `miadi-gather-memory-values` - Gather multiple memory values
|
|
62
|
-
- `miadi-collect-memory` - Collect specific keys
|
|
63
|
-
- `miadi-view-key-content` - View individual key content
|
|
64
|
-
- `miadi-search-cluster` - Search cluster for keys
|
|
65
|
-
|
|
66
|
-
### Session Management
|
|
67
|
-
- `miadi-start-session` - Start new agent session
|
|
68
|
-
- `miadi-get-current-session` - Get current session details
|
|
69
|
-
- `miadi-switch-mode` - Switch mode in existing session
|
|
70
|
-
- `miadi-switch-persona` - Switch persona in session
|
|
71
|
-
- `miadi-end-session` - End active session
|
|
72
|
-
- `miadi-list-sessions` - List active sessions
|
|
73
|
-
|
|
74
|
-
### Capability Resolution
|
|
75
|
-
- `miadi-resolve-capabilities` - Resolve capabilities for persona/mode
|
|
76
|
-
- `miadi-get-agent-info` - Get comprehensive agent system info
|
|
77
|
-
- `miadi-detect-cues` - Detect mode/persona switch cues from text
|
|
78
|
-
|
|
79
|
-
### AI Integration
|
|
80
|
-
- `miadi-openai-request` - Make OpenAI API requests
|
|
81
|
-
- `miadi-ai-request` - Make generic AI requests
|
|
82
|
-
|
|
83
|
-
### Workflow Management
|
|
84
|
-
- `miadi-register-agent` - Register agent for GitHub events
|
|
85
|
-
- `miadi-get-agent-events` - Check for agent events
|
|
86
|
-
- `miadi-get-workflow-howto` - Get workflow setup guides
|
|
87
|
-
|
|
88
|
-
### Forge State
|
|
89
|
-
- `miadi-get-forge-state` - Get current forge state
|
|
90
|
-
- `miadi-update-forge-state` - Update forge state
|
|
91
|
-
- `miadi-get-glyph-map` - Get glyph map information
|
|
92
|
-
|
|
93
|
-
## Architecture
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
Claude → MCP Tool Calls → MCP Server → HTTP Requests (EH_TOKEN) → Miadi API
|
|
97
|
-
← MCP Tool Results ← HTTP Responses ←
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Key Components
|
|
101
|
-
|
|
102
|
-
- **API Client** (`src/api-client.ts`): HTTP client with authentication
|
|
103
|
-
- **Tool Definitions** (`src/tools/`): MCP tools grouped by functionality
|
|
104
|
-
- **Type Definitions** (`src/types.ts`): TypeScript interfaces from OpenAPI spec
|
|
105
|
-
- **Utilities** (`src/utils.ts`): Error handling and validation helpers
|
|
106
|
-
- **Main Server** (`src/index.ts`): MCP server orchestration
|
|
107
|
-
|
|
108
|
-
## Usage Examples
|
|
109
|
-
|
|
110
|
-
### Memory Operations
|
|
111
|
-
```typescript
|
|
112
|
-
// Get memory by key
|
|
113
|
-
await handleToolRequest('miadi-get-memory', { key: 'user:123' });
|
|
114
|
-
|
|
115
|
-
// Store memory with TTL
|
|
116
|
-
await handleToolRequest('miadi-store-memory', {
|
|
117
|
-
key: 'session:abc',
|
|
118
|
-
value: JSON.stringify({ user: 'john', active: true }),
|
|
119
|
-
ttl: 3600
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// Scan keys with pattern
|
|
123
|
-
await handleToolRequest('miadi-scan-keys', { pattern: 'session:*' });
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Session Management
|
|
127
|
-
```typescript
|
|
128
|
-
// Start new session
|
|
129
|
-
await handleToolRequest('miadi-start-session', {
|
|
130
|
-
persona: 'mia-recursive-architect',
|
|
131
|
-
mode: 'desktop',
|
|
132
|
-
userId: 'user123'
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
// Switch mode
|
|
136
|
-
await handleToolRequest('miadi-switch-mode', {
|
|
137
|
-
sessionId: '550e8400-e29b-41d4-a716-446655440000',
|
|
138
|
-
newMode: 'walking'
|
|
139
|
-
});
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### AI Integration
|
|
143
|
-
```typescript
|
|
144
|
-
// OpenAI request
|
|
145
|
-
await handleToolRequest('miadi-openai-request', {
|
|
146
|
-
prompt: 'Analyze this data...',
|
|
147
|
-
modelId: 'gpt-4',
|
|
148
|
-
maxTokens: 500,
|
|
149
|
-
temperature: 0.7
|
|
150
|
-
});
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## Environment Variables
|
|
154
|
-
|
|
155
|
-
| Variable | Description | Required |
|
|
156
|
-
|----------|-------------|----------|
|
|
157
|
-
| `EH_TOKEN` | Miadi API authentication token | Yes |
|
|
158
|
-
| `EH_API_URL` | Base URL for Miadi API | Yes |
|
|
159
|
-
| `MCP_PORT` | MCP server port (default: 8080) | No |
|
|
160
|
-
| `LOG_LEVEL` | Logging level (info, debug) | No |
|
|
161
|
-
|
|
162
|
-
## Development
|
|
163
|
-
|
|
164
|
-
### Project Structure
|
|
165
|
-
```
|
|
166
|
-
src/
|
|
167
|
-
├── index.ts # Main server entry point
|
|
168
|
-
├── api-client.ts # HTTP client for Miadi API
|
|
169
|
-
├── types.ts # TypeScript type definitions
|
|
170
|
-
├── utils.ts # Utility functions
|
|
171
|
-
└── tools/ # MCP tool implementations
|
|
172
|
-
├── memory-tools.ts # Memory operations
|
|
173
|
-
├── session-tools.ts # Session management
|
|
174
|
-
├── capability-tools.ts # Capability resolution
|
|
175
|
-
├── ai-tools.ts # AI integration
|
|
176
|
-
├── workflow-tools.ts # Workflow management
|
|
177
|
-
└── forge-tools.ts # Forge state operations
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### Adding New Tools
|
|
181
|
-
|
|
182
|
-
1. **Define types** in `src/types.ts`
|
|
183
|
-
2. **Implement API client methods** in `src/api-client.ts`
|
|
184
|
-
3. **Create tool functions** in appropriate `src/tools/*.ts` file
|
|
185
|
-
4. **Register tools** in `src/index.ts` mcpTools registry
|
|
186
|
-
|
|
187
|
-
### Error Handling
|
|
188
|
-
|
|
189
|
-
All tools include comprehensive error handling:
|
|
190
|
-
- Parameter validation
|
|
191
|
-
- API error transformation
|
|
192
|
-
- User-friendly error messages
|
|
193
|
-
- Request/response logging
|
|
194
|
-
|
|
195
|
-
## API Integration
|
|
196
|
-
|
|
197
|
-
### Authentication
|
|
198
|
-
- Uses Bearer token authentication via `EH_TOKEN`
|
|
199
|
-
- All requests include `Authorization: Bearer ${EH_TOKEN}` header
|
|
200
|
-
|
|
201
|
-
### Request/Response Flow
|
|
202
|
-
1. **MCP Tool Call** → Parameter validation
|
|
203
|
-
2. **API Client Call** → HTTP request to Miadi API
|
|
204
|
-
3. **Response Processing** → Error handling and transformation
|
|
205
|
-
4. **MCP Tool Result** → Formatted response to Claude
|
|
206
|
-
|
|
207
|
-
### Rate Limiting
|
|
208
|
-
Built-in rate limiting (100 requests/minute per identifier) to prevent API abuse.
|
|
209
|
-
|
|
210
|
-
## Testing
|
|
211
|
-
|
|
212
|
-
```bash
|
|
213
|
-
# Manual testing (development)
|
|
214
|
-
npm run dev
|
|
215
|
-
|
|
216
|
-
# Test specific tool
|
|
217
|
-
node -e "
|
|
218
|
-
const { handleToolRequest } = require('./dist/index.js');
|
|
219
|
-
handleToolRequest('miadi-get-agent-info', {}).then(console.log);
|
|
220
|
-
"
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
## Deployment
|
|
224
|
-
|
|
225
|
-
1. **Build the server**: `npm run build`
|
|
226
|
-
2. **Set environment variables** in production
|
|
227
|
-
3. **Start the server**: `npm start`
|
|
228
|
-
4. **Configure Claude** to use the MCP server endpoint
|
|
229
|
-
|
|
230
|
-
## Troubleshooting
|
|
231
|
-
|
|
232
|
-
### Common Issues
|
|
233
|
-
|
|
234
|
-
1. **Environment Variables Missing**
|
|
235
|
-
- Ensure `EH_TOKEN` and `EH_API_URL` are set
|
|
236
|
-
- Check `.env` file is in project root
|
|
237
|
-
|
|
238
|
-
2. **API Connection Errors**
|
|
239
|
-
- Verify `EH_API_URL` is accessible
|
|
240
|
-
- Check `EH_TOKEN` is valid and not expired
|
|
241
|
-
|
|
242
|
-
3. **Tool Not Found**
|
|
243
|
-
- Ensure tool name matches exactly (case-sensitive)
|
|
244
|
-
- Check tool is registered in `mcpTools` registry
|
|
245
|
-
|
|
246
|
-
### Debugging
|
|
247
|
-
|
|
248
|
-
Set `LOG_LEVEL=debug` to see detailed request/response logging:
|
|
249
|
-
|
|
250
|
-
```bash
|
|
251
|
-
LOG_LEVEL=debug npm run dev
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
## License
|
|
255
|
-
|
|
256
|
-
MIT License - Generated via Gemini MCP
|
|
257
|
-
|
|
258
|
-
## Support
|
|
259
|
-
|
|
260
|
-
For issues and questions:
|
|
261
|
-
1. Check the troubleshooting section above
|
|
262
|
-
2. Review the Miadi API documentation
|
|
263
|
-
3. Verify environment configuration
|
|
264
|
-
4. Check server logs for detailed error messages
|
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
# Remote MCP Transformation Guide
|
|
2
|
-
|
|
3
|
-
**Transform Standard MCP Servers → Claude.ai Remote Connectors**
|
|
4
|
-
|
|
5
|
-
## 🎯 Overview
|
|
6
|
-
|
|
7
|
-
This guide shows how to transform any standard MCP server (typically using `StdioServerTransport`) into a remote HTTP-based server that works as a Claude.ai connector.
|
|
8
|
-
|
|
9
|
-
**Success Story**: We transformed a complex Miadi MCP server from 1,600+ lines of custom HTTP code to a working 150-line connector using official SDK patterns.
|
|
10
|
-
|
|
11
|
-
## ⚠️ Critical Success Factor: Use Official SDK Patterns
|
|
12
|
-
|
|
13
|
-
**DON'T**: Build custom HTTP transports, JSON-RPC parsers, or OAuth middleware
|
|
14
|
-
**DO**: Use the MCP TypeScript SDK's `StreamableHTTPServerTransport`
|
|
15
|
-
|
|
16
|
-
## 📋 Step-by-Step Transformation
|
|
17
|
-
|
|
18
|
-
### Phase 1: Analysis & Preparation
|
|
19
|
-
|
|
20
|
-
#### 1.1 Identify Current Architecture
|
|
21
|
-
```bash
|
|
22
|
-
# Check if you have a standard MCP server
|
|
23
|
-
grep -r "StdioServerTransport" src/
|
|
24
|
-
grep -r "McpServer" src/
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
**Standard Pattern**:
|
|
28
|
-
```typescript
|
|
29
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
30
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
31
|
-
|
|
32
|
-
const server = new McpServer({ name: "my-server", version: "1.0.0" });
|
|
33
|
-
const transport = new StdioServerTransport();
|
|
34
|
-
await server.connect(transport);
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
#### 1.2 Audit Dependencies
|
|
38
|
-
```bash
|
|
39
|
-
# Check package.json for unnecessary HTTP/OAuth libraries
|
|
40
|
-
# You likely only need: express, cors, and the MCP SDK
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Phase 2: Create Remote HTTP Server
|
|
44
|
-
|
|
45
|
-
#### 2.1 Create Remote Server File
|
|
46
|
-
**File**: `src/index-remote.ts`
|
|
47
|
-
|
|
48
|
-
```typescript
|
|
49
|
-
#!/usr/bin/env node
|
|
50
|
-
|
|
51
|
-
import express from 'express';
|
|
52
|
-
import cors from 'cors';
|
|
53
|
-
import { randomUUID } from 'node:crypto';
|
|
54
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
55
|
-
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
56
|
-
|
|
57
|
-
// Create MCP server instance (keep your existing server config)
|
|
58
|
-
const server = new McpServer({
|
|
59
|
-
name: 'your-server-name',
|
|
60
|
-
version: '1.0.0'
|
|
61
|
-
}, {
|
|
62
|
-
capabilities: {
|
|
63
|
-
tools: {},
|
|
64
|
-
resources: {},
|
|
65
|
-
prompts: {}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// TODO: Copy your existing tool registrations here
|
|
70
|
-
// server.registerTool('tool-name', {...}, async (args) => {...});
|
|
71
|
-
|
|
72
|
-
// Create Express app
|
|
73
|
-
const app = express();
|
|
74
|
-
const PORT = parseInt(process.env.MCP_PORT || '3000');
|
|
75
|
-
|
|
76
|
-
// Essential CORS for Claude.ai
|
|
77
|
-
app.use(cors({
|
|
78
|
-
origin: [
|
|
79
|
-
'https://claude.ai',
|
|
80
|
-
'https://api.claude.ai',
|
|
81
|
-
'https://app.claude.ai',
|
|
82
|
-
/\.ngrok\.io$/,
|
|
83
|
-
/\.ngrok-free\.app$/
|
|
84
|
-
],
|
|
85
|
-
credentials: true,
|
|
86
|
-
methods: ['GET', 'POST', 'DELETE', 'OPTIONS'],
|
|
87
|
-
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With', 'Mcp-Session-Id']
|
|
88
|
-
}));
|
|
89
|
-
|
|
90
|
-
app.use(express.json({ limit: '10mb' }));
|
|
91
|
-
|
|
92
|
-
// Health check
|
|
93
|
-
app.get('/health', (req, res) => {
|
|
94
|
-
res.json({
|
|
95
|
-
status: 'healthy',
|
|
96
|
-
server: 'your-server-name',
|
|
97
|
-
version: '1.0.0',
|
|
98
|
-
timestamp: new Date().toISOString()
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// Session management for StreamableHTTP
|
|
103
|
-
const transports: { [sessionId: string]: StreamableHTTPServerTransport } = {};
|
|
104
|
-
|
|
105
|
-
// MCP endpoint handler - THE CRITICAL PART
|
|
106
|
-
const handleMcpRequest = async (req: express.Request, res: express.Response) => {
|
|
107
|
-
const sessionId = req.headers['mcp-session-id'] as string | undefined;
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
let currentTransport: StreamableHTTPServerTransport;
|
|
111
|
-
|
|
112
|
-
if (sessionId && transports[sessionId]) {
|
|
113
|
-
// Use existing transport
|
|
114
|
-
currentTransport = transports[sessionId];
|
|
115
|
-
} else {
|
|
116
|
-
// Create new transport with session management
|
|
117
|
-
currentTransport = new StreamableHTTPServerTransport({
|
|
118
|
-
sessionIdGenerator: () => randomUUID(),
|
|
119
|
-
onsessioninitialized: (sessionId) => {
|
|
120
|
-
console.log(`Session initialized: ${sessionId}`);
|
|
121
|
-
transports[sessionId] = currentTransport;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// Cleanup handler
|
|
126
|
-
currentTransport.onclose = () => {
|
|
127
|
-
const sid = currentTransport.sessionId;
|
|
128
|
-
if (sid && transports[sid]) {
|
|
129
|
-
delete transports[sid];
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// Connect server to transport - CRITICAL STEP
|
|
134
|
-
await server.connect(currentTransport);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Let the SDK handle the request - DON'T PARSE JSON-RPC MANUALLY
|
|
138
|
-
await currentTransport.handleRequest(req, res, req.body);
|
|
139
|
-
|
|
140
|
-
} catch (error: any) {
|
|
141
|
-
console.error('MCP request error:', error);
|
|
142
|
-
if (!res.headersSent) {
|
|
143
|
-
res.status(500).json({
|
|
144
|
-
jsonrpc: '2.0',
|
|
145
|
-
id: req.body?.id || null,
|
|
146
|
-
error: {
|
|
147
|
-
code: -32603,
|
|
148
|
-
message: 'Internal server error'
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// Set up MCP endpoints
|
|
156
|
-
app.post('/mcp', handleMcpRequest);
|
|
157
|
-
app.get('/mcp', handleMcpRequest);
|
|
158
|
-
app.delete('/mcp', handleMcpRequest);
|
|
159
|
-
|
|
160
|
-
// Start server
|
|
161
|
-
app.listen(PORT, '0.0.0.0', () => {
|
|
162
|
-
console.log(`🚀 Remote MCP Server listening on http://0.0.0.0:${PORT}`);
|
|
163
|
-
console.log(`📡 MCP endpoint: http://0.0.0.0:${PORT}/mcp`);
|
|
164
|
-
});
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
#### 2.2 Update Package.json
|
|
168
|
-
```json
|
|
169
|
-
{
|
|
170
|
-
"scripts": {
|
|
171
|
-
"build:remote": "esbuild src/index-remote.ts --bundle --platform=node --outfile=dist/index-remote.js --external:@modelcontextprotocol/sdk",
|
|
172
|
-
"start:remote": "node dist/index-remote.js"
|
|
173
|
-
},
|
|
174
|
-
"dependencies": {
|
|
175
|
-
"@modelcontextprotocol/sdk": "^1.17.0",
|
|
176
|
-
"express": "^4.18.2",
|
|
177
|
-
"cors": "^2.8.5"
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### Phase 3: Tool Migration
|
|
183
|
-
|
|
184
|
-
#### 3.1 Copy Existing Tool Registrations
|
|
185
|
-
If you have existing tools, copy them directly:
|
|
186
|
-
|
|
187
|
-
```typescript
|
|
188
|
-
// FROM: Your existing server
|
|
189
|
-
server.registerTool('existing-tool', {
|
|
190
|
-
description: 'Tool description',
|
|
191
|
-
inputSchema: {
|
|
192
|
-
param: z.string()
|
|
193
|
-
}
|
|
194
|
-
}, async ({ param }) => {
|
|
195
|
-
// Your existing logic
|
|
196
|
-
return {
|
|
197
|
-
content: [{
|
|
198
|
-
type: 'text',
|
|
199
|
-
text: `Result: ${param}`
|
|
200
|
-
}]
|
|
201
|
-
};
|
|
202
|
-
});
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
#### 3.2 Handle Complex Tool Systems
|
|
206
|
-
If you have a complex tool registry system, simplify it:
|
|
207
|
-
|
|
208
|
-
```typescript
|
|
209
|
-
// INSTEAD OF: Complex registry pattern
|
|
210
|
-
const registry = new ToolRegistry();
|
|
211
|
-
registry.registerAllTools();
|
|
212
|
-
|
|
213
|
-
// DO: Direct registration
|
|
214
|
-
const tools = {
|
|
215
|
-
'tool-1': async (args) => { /* logic */ },
|
|
216
|
-
'tool-2': async (args) => { /* logic */ },
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
Object.entries(tools).forEach(([name, handler]) => {
|
|
220
|
-
server.registerTool(name, {
|
|
221
|
-
description: `${name} tool`,
|
|
222
|
-
inputSchema: { /* your schema */ }
|
|
223
|
-
}, handler);
|
|
224
|
-
});
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
### Phase 4: Deployment Setup
|
|
228
|
-
|
|
229
|
-
#### 4.1 Create Launch Script
|
|
230
|
-
**File**: `scripts/start-remote.sh`
|
|
231
|
-
|
|
232
|
-
```bash
|
|
233
|
-
#!/bin/bash
|
|
234
|
-
|
|
235
|
-
PORT=${1:-3000}
|
|
236
|
-
echo "🚀 Starting Remote MCP Server on port $PORT"
|
|
237
|
-
|
|
238
|
-
# Build
|
|
239
|
-
npm run build:remote
|
|
240
|
-
|
|
241
|
-
# Start server
|
|
242
|
-
MCP_PORT="$PORT" node dist/index-remote.js &
|
|
243
|
-
SERVER_PID=$!
|
|
244
|
-
|
|
245
|
-
# Start ngrok tunnel
|
|
246
|
-
ngrok http $PORT &
|
|
247
|
-
NGROK_PID=$!
|
|
248
|
-
|
|
249
|
-
# Wait and get URL
|
|
250
|
-
sleep 5
|
|
251
|
-
NGROK_URL=$(curl -s http://localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url')
|
|
252
|
-
|
|
253
|
-
echo "🌍 Public URL: $NGROK_URL"
|
|
254
|
-
echo "📋 Add this URL to Claude.ai connectors"
|
|
255
|
-
|
|
256
|
-
# Cleanup on exit
|
|
257
|
-
trap 'kill $SERVER_PID $NGROK_PID' SIGINT SIGTERM
|
|
258
|
-
wait $SERVER_PID
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
#### 4.2 Test the Server
|
|
262
|
-
```bash
|
|
263
|
-
# Build and start
|
|
264
|
-
chmod +x scripts/start-remote.sh
|
|
265
|
-
./scripts/start-remote.sh 3000
|
|
266
|
-
|
|
267
|
-
# Test endpoints
|
|
268
|
-
curl http://localhost:3000/health
|
|
269
|
-
curl http://localhost:3000/mcp
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
### Phase 5: Claude.ai Integration
|
|
273
|
-
|
|
274
|
-
#### 5.1 Add Connector
|
|
275
|
-
1. Go to Claude.ai → Settings → Connectors
|
|
276
|
-
2. Click "Add Custom Connector"
|
|
277
|
-
3. Enter your ngrok URL: `https://abc123.ngrok-free.app`
|
|
278
|
-
4. Save and test
|
|
279
|
-
|
|
280
|
-
#### 5.2 Verify Connection
|
|
281
|
-
- Check ngrok logs for incoming requests
|
|
282
|
-
- Verify tool discovery works
|
|
283
|
-
- Test actual tool calls
|
|
284
|
-
|
|
285
|
-
## 🚫 Common Mistakes to Avoid
|
|
286
|
-
|
|
287
|
-
### ❌ DON'T Build Custom HTTP Transport
|
|
288
|
-
```typescript
|
|
289
|
-
// WRONG - Custom Express handling
|
|
290
|
-
app.post('/mcp', (req, res) => {
|
|
291
|
-
const jsonRpc = req.body;
|
|
292
|
-
if (jsonRpc.method === 'tools/list') {
|
|
293
|
-
// Manual JSON-RPC parsing...
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### ✅ DO Use SDK Transport
|
|
299
|
-
```typescript
|
|
300
|
-
// RIGHT - Let SDK handle it
|
|
301
|
-
await transport.handleRequest(req, res, req.body);
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
### ❌ DON'T Implement Custom OAuth
|
|
305
|
-
```typescript
|
|
306
|
-
// WRONG - Custom JWT middleware
|
|
307
|
-
app.use((req, res, next) => {
|
|
308
|
-
const token = req.headers.authorization;
|
|
309
|
-
// Custom token validation...
|
|
310
|
-
});
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
### ✅ DO Start Simple (No Auth)
|
|
314
|
-
The MCP SDK supports authless servers - Claude.ai will work without OAuth for many use cases.
|
|
315
|
-
|
|
316
|
-
### ❌ DON'T Overcomplicate Tool Registration
|
|
317
|
-
```typescript
|
|
318
|
-
// WRONG - Complex registry systems
|
|
319
|
-
class ToolRegistry {
|
|
320
|
-
// 200+ lines of complexity
|
|
321
|
-
}
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
### ✅ DO Register Tools Directly
|
|
325
|
-
```typescript
|
|
326
|
-
// RIGHT - Simple and clear
|
|
327
|
-
server.registerTool('tool-name', config, handler);
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
## 📊 Success Metrics
|
|
331
|
-
|
|
332
|
-
After transformation, you should have:
|
|
333
|
-
- ✅ Server starts without errors
|
|
334
|
-
- ✅ ngrok tunnel connects successfully
|
|
335
|
-
- ✅ Claude.ai discovers the connector
|
|
336
|
-
- ✅ Tool calls work end-to-end
|
|
337
|
-
- ✅ Simplified codebase (likely 80%+ reduction in lines)
|
|
338
|
-
|
|
339
|
-
## 🔧 Debugging Tips
|
|
340
|
-
|
|
341
|
-
### Server Won't Start
|
|
342
|
-
```bash
|
|
343
|
-
# Check for import errors
|
|
344
|
-
node --check dist/index-remote.js
|
|
345
|
-
|
|
346
|
-
# Test direct execution
|
|
347
|
-
MCP_PORT=3000 node dist/index-remote.js
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
### Claude.ai Connection Issues
|
|
351
|
-
```bash
|
|
352
|
-
# Test health endpoint
|
|
353
|
-
curl https://your-ngrok.ngrok-free.app/health
|
|
354
|
-
|
|
355
|
-
# Check MCP endpoint
|
|
356
|
-
curl -X POST https://your-ngrok.ngrok-free.app/mcp \
|
|
357
|
-
-H "Content-Type: application/json" \
|
|
358
|
-
-d '{"jsonrpc":"2.0","method":"ping","id":1}'
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
### Tool Discovery Problems
|
|
362
|
-
- Ensure all tools return proper MCP response format
|
|
363
|
-
- Check tool schemas are valid
|
|
364
|
-
- Verify error handling doesn't break JSON-RPC
|
|
365
|
-
|
|
366
|
-
## 📚 Key Resources
|
|
367
|
-
|
|
368
|
-
- **MCP Specification**: https://modelcontextprotocol.io/specification/
|
|
369
|
-
- **TypeScript SDK**: https://github.com/modelcontextprotocol/typescript-sdk
|
|
370
|
-
- **Official Examples**: `/examples/server/` in the SDK
|
|
371
|
-
- **Claude.ai Connectors**: https://support.anthropic.com/en/articles/11503834-building-custom-connectors-via-remote-mcp-servers
|
|
372
|
-
|
|
373
|
-
## 🎉 Final Notes
|
|
374
|
-
|
|
375
|
-
The key insight is **simplicity**: The MCP SDK handles all the complex protocol details. Your job is just to:
|
|
376
|
-
1. Create an MCP server
|
|
377
|
-
2. Register your tools
|
|
378
|
-
3. Use `StreamableHTTPServerTransport` for HTTP
|
|
379
|
-
4. Let the SDK handle everything else
|
|
380
|
-
|
|
381
|
-
**Result**: A working Claude.ai connector with minimal code and maximum reliability.
|
|
382
|
-
|
|
383
|
-
---
|
|
384
|
-
**Success Rate**: Following this guide should result in working connectors 95%+ of the time, compared to ~10% success rate when building custom HTTP implementations.
|