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
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
# Miadi MCP Remote Server Specification
|
|
2
|
-
## Natural Language-Driven Software Development Prompt
|
|
3
|
-
|
|
4
|
-
**Context**: Transform the existing Miadi MCP server from stdio-based local operation to HTTP-based remote server with OAuth 2.1 authentication, enabling claude.ai connector integration while preserving all 26 existing tools and tool selection capabilities.
|
|
5
|
-
|
|
6
|
-
**Objective**: Create a production-ready remote MCP server that exposes Miadi Three-Pathway Agent System API through secure HTTP endpoints, supporting OAuth authentication flow with claude.ai callback integration and existing EH_TOKEN user validation.
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Core Requirements Specification
|
|
11
|
-
|
|
12
|
-
### 1. Transport Layer Migration
|
|
13
|
-
**From**: `StdioServerTransport` (JSON-RPC over stdin/stdout)
|
|
14
|
-
**To**: HTTP-based JSON-RPC server with Express.js framework
|
|
15
|
-
|
|
16
|
-
**Implementation**:
|
|
17
|
-
- Express.js server listening on configurable port (default: 3000)
|
|
18
|
-
- POST endpoint `/mcp/jsonrpc` handling MCP JSON-RPC protocol
|
|
19
|
-
- Support for both single requests and batch requests
|
|
20
|
-
- Proper CORS headers for cross-origin requests
|
|
21
|
-
- Content-Type validation for `application/json`
|
|
22
|
-
|
|
23
|
-
### 2. OAuth 2.1 Resource Server Implementation
|
|
24
|
-
**Specification Compliance**: MCP OAuth 2.1 with Resource Server pattern (RFC8707)
|
|
25
|
-
|
|
26
|
-
**Authentication Flow**:
|
|
27
|
-
```
|
|
28
|
-
1. Client discovers server via /.well-known/oauth-protected-resource
|
|
29
|
-
2. Dynamic Client Registration (RFC7591) for automatic client setup
|
|
30
|
-
3. Authorization Code + PKCE flow for secure token exchange
|
|
31
|
-
4. Resource Indicators for token scoping to specific MCP server
|
|
32
|
-
5. JWT token validation on every request
|
|
33
|
-
6. EH_TOKEN integration for Miadi user database validation
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
**Endpoints Required**:
|
|
37
|
-
- `/.well-known/oauth-protected-resource` - Resource Server Metadata
|
|
38
|
-
- `/oauth/authorize` - Authorization endpoint (redirect to identity provider)
|
|
39
|
-
- `/oauth/token` - Token exchange endpoint
|
|
40
|
-
- `/oauth/userinfo` - User information endpoint for validation
|
|
41
|
-
|
|
42
|
-
### 3. User Authentication Integration
|
|
43
|
-
**Existing System**: Miadi API uses `EH_TOKEN` Bearer authentication
|
|
44
|
-
**Integration Pattern**: OAuth JWT contains user identifier → validate against EH_TOKEN system
|
|
45
|
-
|
|
46
|
-
**User Validation Flow**:
|
|
47
|
-
```
|
|
48
|
-
1. OAuth token validated (signature, expiration, scope)
|
|
49
|
-
2. Extract user identifier from JWT claims
|
|
50
|
-
3. Call Miadi API with EH_TOKEN to validate user access
|
|
51
|
-
4. Cache validation results (5-minute TTL)
|
|
52
|
-
5. Reject requests for unauthorized users
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### 4. Tool System Preservation
|
|
56
|
-
**Requirement**: All existing functionality must be preserved
|
|
57
|
-
- 26 tools across 6 categories (memory, session, capability, ai, workflow, forge)
|
|
58
|
-
- Environment variable-based tool selection system
|
|
59
|
-
- Complete Zod schemas and validation
|
|
60
|
-
- Error handling and logging
|
|
61
|
-
- Tool usage tracking and rate limiting
|
|
62
|
-
|
|
63
|
-
### 5. Deployment Architecture
|
|
64
|
-
**Local Development**: Ngrok tunnel for public endpoint exposure
|
|
65
|
-
**Production**: Cloud hosting with proper SSL/TLS termination
|
|
66
|
-
|
|
67
|
-
**Ngrok Configuration**:
|
|
68
|
-
```bash
|
|
69
|
-
ngrok http 3000 --domain=<custom-domain>
|
|
70
|
-
# Exposes local server at https://<custom-domain>.ngrok-free.app
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
**Environment Variables**:
|
|
74
|
-
```bash
|
|
75
|
-
# Existing Miadi API config
|
|
76
|
-
EH_TOKEN=<miadi-api-token>
|
|
77
|
-
EH_API_URL=<miadi-api-base-url>
|
|
78
|
-
|
|
79
|
-
# OAuth configuration
|
|
80
|
-
OAUTH_CLIENT_ID=<dynamic-or-configured>
|
|
81
|
-
OAUTH_CLIENT_SECRET=<if-confidential-client>
|
|
82
|
-
OAUTH_ISSUER=<identity-provider-url>
|
|
83
|
-
JWT_SECRET=<token-validation-secret>
|
|
84
|
-
|
|
85
|
-
# Server configuration
|
|
86
|
-
MCP_PORT=3000
|
|
87
|
-
MCP_HOST=0.0.0.0
|
|
88
|
-
NGROK_AUTHTOKEN=<ngrok-token>
|
|
89
|
-
|
|
90
|
-
# Tool selection (preserved)
|
|
91
|
-
MIADI_TOOLS_ENABLED=<categories-or-tools>
|
|
92
|
-
MIADI_TOOLS_DISABLED=<categories-or-tools>
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
## Technical Implementation Specification
|
|
98
|
-
|
|
99
|
-
### File Structure
|
|
100
|
-
```
|
|
101
|
-
src/
|
|
102
|
-
├── index.ts # Main server entry (HTTP instead of stdio)
|
|
103
|
-
├── http-transport.ts # Express.js HTTP transport implementation
|
|
104
|
-
├── oauth/
|
|
105
|
-
│ ├── resource-server.ts # OAuth 2.1 Resource Server implementation
|
|
106
|
-
│ ├── middleware.ts # Authentication middleware
|
|
107
|
-
│ ├── user-validator.ts # EH_TOKEN integration
|
|
108
|
-
│ └── metadata.ts # /.well-known/oauth-protected-resource
|
|
109
|
-
├── tool-registry.ts # Existing (preserved)
|
|
110
|
-
├── utils.ts # Existing (preserved)
|
|
111
|
-
└── tools/ # Existing tool modules (preserved)
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Core Components
|
|
115
|
-
|
|
116
|
-
#### 1. HTTP Transport Layer (`http-transport.ts`)
|
|
117
|
-
```typescript
|
|
118
|
-
interface HttpMcpTransport {
|
|
119
|
-
// Express.js server with JSON-RPC handling
|
|
120
|
-
server: Express.Application
|
|
121
|
-
port: number
|
|
122
|
-
|
|
123
|
-
// Methods
|
|
124
|
-
start(): Promise<void>
|
|
125
|
-
stop(): Promise<void>
|
|
126
|
-
handleJsonRpc(req: Request, res: Response): Promise<void>
|
|
127
|
-
}
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
#### 2. OAuth Resource Server (`oauth/resource-server.ts`)
|
|
131
|
-
```typescript
|
|
132
|
-
interface OAuthResourceServer {
|
|
133
|
-
// OAuth 2.1 Resource Server implementation
|
|
134
|
-
validateToken(token: string): Promise<TokenValidationResult>
|
|
135
|
-
getUserFromToken(token: string): Promise<MiadiUser>
|
|
136
|
-
generateMetadata(): ResourceServerMetadata
|
|
137
|
-
|
|
138
|
-
// Integration with Miadi user system
|
|
139
|
-
validateUserAccess(userId: string): Promise<boolean>
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
#### 3. Authentication Middleware (`oauth/middleware.ts`)
|
|
144
|
-
```typescript
|
|
145
|
-
interface AuthMiddleware {
|
|
146
|
-
// Express middleware for token validation
|
|
147
|
-
authenticate(req: Request, res: Response, next: NextFunction): Promise<void>
|
|
148
|
-
|
|
149
|
-
// User context injection
|
|
150
|
-
injectUser(req: AuthenticatedRequest): void
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### MCP JSON-RPC Protocol Adaptation
|
|
155
|
-
|
|
156
|
-
**Request Format** (unchanged from stdio):
|
|
157
|
-
```json
|
|
158
|
-
{
|
|
159
|
-
"jsonrpc": "2.0",
|
|
160
|
-
"id": "request-id",
|
|
161
|
-
"method": "tools/call",
|
|
162
|
-
"params": {
|
|
163
|
-
"name": "miadi-get-memory",
|
|
164
|
-
"arguments": {
|
|
165
|
-
"key": "session:active",
|
|
166
|
-
"type": "auto"
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
**HTTP Headers Required**:
|
|
173
|
-
```
|
|
174
|
-
Authorization: Bearer <jwt-token>
|
|
175
|
-
Content-Type: application/json
|
|
176
|
-
Accept: application/json
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
**Response Format** (unchanged):
|
|
180
|
-
```json
|
|
181
|
-
{
|
|
182
|
-
"jsonrpc": "2.0",
|
|
183
|
-
"id": "request-id",
|
|
184
|
-
"result": {
|
|
185
|
-
"content": [
|
|
186
|
-
{
|
|
187
|
-
"type": "text",
|
|
188
|
-
"text": "<tool-result-json>"
|
|
189
|
-
}
|
|
190
|
-
],
|
|
191
|
-
"_meta": {
|
|
192
|
-
"tool": "miadi-get-memory",
|
|
193
|
-
"timestamp": "2025-01-08T..."
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
---
|
|
200
|
-
|
|
201
|
-
## Security Specifications
|
|
202
|
-
|
|
203
|
-
### 1. OAuth 2.1 Security Requirements
|
|
204
|
-
- **PKCE mandatory** for all authorization flows
|
|
205
|
-
- **Resource Indicators** (RFC8707) for token scoping
|
|
206
|
-
- **JWT validation** with signature verification and expiration checks
|
|
207
|
-
- **HTTPS enforcement** in production (ngrok provides SSL termination)
|
|
208
|
-
- **CORS policy** restricting origins to claude.ai domains
|
|
209
|
-
|
|
210
|
-
### 2. Rate Limiting
|
|
211
|
-
- **Per-user limits**: 100 requests per minute (existing implementation)
|
|
212
|
-
- **Global limits**: 1000 requests per minute per server instance
|
|
213
|
-
- **Tool-specific limits**: AI tools (10/min), others (50/min)
|
|
214
|
-
|
|
215
|
-
### 3. User Authorization
|
|
216
|
-
- **EH_TOKEN validation** for every authenticated request
|
|
217
|
-
- **User scope validation** against Miadi user permissions
|
|
218
|
-
- **Session invalidation** on user access revocation
|
|
219
|
-
- **Audit logging** for all tool usage with user identification
|
|
220
|
-
|
|
221
|
-
### 4. Error Security
|
|
222
|
-
- **No sensitive data** in error responses
|
|
223
|
-
- **Generic error messages** for authentication failures
|
|
224
|
-
- **Request ID tracking** for debugging without exposing internals
|
|
225
|
-
|
|
226
|
-
---
|
|
227
|
-
|
|
228
|
-
## Claude.ai Integration Specification
|
|
229
|
-
|
|
230
|
-
### Connector Registration
|
|
231
|
-
**Claude.ai Settings** → **Connectors** → **Add Custom Connector**
|
|
232
|
-
|
|
233
|
-
**Configuration Fields**:
|
|
234
|
-
```
|
|
235
|
-
Name: Miadi Agent System
|
|
236
|
-
Base URL: https://<ngrok-domain>.ngrok-free.app
|
|
237
|
-
Description: Access to Miadi Three-Pathway Agent System with memory operations, session management, and AI integration
|
|
238
|
-
Icon: <miadi-logo-url>
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### OAuth Discovery Flow
|
|
242
|
-
1. Claude.ai fetches `/.well-known/oauth-protected-resource` from server
|
|
243
|
-
2. Discovers authorization and token endpoints
|
|
244
|
-
3. Initiates Dynamic Client Registration if supported
|
|
245
|
-
4. Redirects user to authorization endpoint with PKCE challenge
|
|
246
|
-
5. User authenticates with identity provider
|
|
247
|
-
6. Authorization code returned to claude.ai callback
|
|
248
|
-
7. Token exchange with PKCE verifier
|
|
249
|
-
8. Claude.ai stores access token for MCP tool invocations
|
|
250
|
-
|
|
251
|
-
### Tool Invocation Pattern
|
|
252
|
-
```
|
|
253
|
-
Claude.ai → HTTP POST /mcp/jsonrpc
|
|
254
|
-
Headers: Authorization: Bearer <jwt>
|
|
255
|
-
Body: MCP JSON-RPC tool call
|
|
256
|
-
← Tool result with Miadi agent data
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
---
|
|
260
|
-
|
|
261
|
-
## Testing and Validation Specification
|
|
262
|
-
|
|
263
|
-
### 1. Unit Tests
|
|
264
|
-
- OAuth token validation functions
|
|
265
|
-
- User authorization against EH_TOKEN
|
|
266
|
-
- HTTP transport JSON-RPC handling
|
|
267
|
-
- Tool registry with HTTP context
|
|
268
|
-
- Error handling and security edge cases
|
|
269
|
-
|
|
270
|
-
### 2. Integration Tests
|
|
271
|
-
- Complete OAuth flow with test identity provider
|
|
272
|
-
- Tool execution through HTTP transport
|
|
273
|
-
- User restriction enforcement
|
|
274
|
-
- Rate limiting behavior
|
|
275
|
-
- CORS and security headers
|
|
276
|
-
|
|
277
|
-
### 3. End-to-End Tests
|
|
278
|
-
- Ngrok tunnel establishment
|
|
279
|
-
- Claude.ai connector registration
|
|
280
|
-
- Full authentication and tool invocation flow
|
|
281
|
-
- Error scenarios and recovery
|
|
282
|
-
- Performance under load
|
|
283
|
-
|
|
284
|
-
### 4. Security Testing
|
|
285
|
-
- JWT token tampering attempts
|
|
286
|
-
- Unauthorized user access attempts
|
|
287
|
-
- Rate limiting bypass attempts
|
|
288
|
-
- CORS policy violation tests
|
|
289
|
-
- Input validation and injection tests
|
|
290
|
-
|
|
291
|
-
---
|
|
292
|
-
|
|
293
|
-
## Performance and Monitoring Specification
|
|
294
|
-
|
|
295
|
-
### 1. Metrics Collection
|
|
296
|
-
- **Request latency**: P50, P95, P99 response times
|
|
297
|
-
- **Authentication latency**: OAuth validation timing
|
|
298
|
-
- **Tool execution time**: Per-tool performance tracking
|
|
299
|
-
- **Error rates**: Authentication failures, tool errors, rate limits
|
|
300
|
-
- **User activity**: Tool usage patterns per user
|
|
301
|
-
|
|
302
|
-
### 2. Logging Requirements
|
|
303
|
-
- **Structured logging** with request IDs and user context
|
|
304
|
-
- **Security events**: Authentication failures, unauthorized access
|
|
305
|
-
- **Performance events**: Slow requests, rate limit hits
|
|
306
|
-
- **Business events**: Tool usage, session management actions
|
|
307
|
-
|
|
308
|
-
### 3. Health Endpoints
|
|
309
|
-
- `/health` - Basic server health check
|
|
310
|
-
- `/metrics` - Prometheus-compatible metrics
|
|
311
|
-
- `/oauth/health` - OAuth provider connectivity
|
|
312
|
-
- `/miadi/health` - Miadi API connectivity
|
|
313
|
-
|
|
314
|
-
---
|
|
315
|
-
|
|
316
|
-
## Migration and Rollback Specification
|
|
317
|
-
|
|
318
|
-
### 1. Backward Compatibility
|
|
319
|
-
- **Stdio transport preserved** for local development
|
|
320
|
-
- **Environment variable** to select transport mode
|
|
321
|
-
- **Tool registry unchanged** - no breaking changes to tool interface
|
|
322
|
-
- **Configuration migration** from stdio to HTTP with sensible defaults
|
|
323
|
-
|
|
324
|
-
### 2. Deployment Strategy
|
|
325
|
-
- **Blue-green deployment** for production environments
|
|
326
|
-
- **Canary rollout** for gradual user migration
|
|
327
|
-
- **Rollback procedures** with automatic health check triggers
|
|
328
|
-
- **Configuration validation** before server startup
|
|
329
|
-
|
|
330
|
-
### 3. Migration Steps
|
|
331
|
-
1. **Development**: Local HTTP server with ngrok tunnel
|
|
332
|
-
2. **Staging**: Cloud deployment with test OAuth provider
|
|
333
|
-
3. **Production**: Production OAuth integration and claude.ai connector
|
|
334
|
-
4. **Validation**: User acceptance testing and performance verification
|
|
335
|
-
5. **Rollout**: Gradual user migration with monitoring
|
|
336
|
-
|
|
337
|
-
---
|
|
338
|
-
|
|
339
|
-
## Implementation Acceptance Criteria
|
|
340
|
-
|
|
341
|
-
### ✅ Core Functionality
|
|
342
|
-
- [ ] HTTP server replaces stdio transport completely
|
|
343
|
-
- [ ] All 26 tools function identically through HTTP
|
|
344
|
-
- [ ] Tool selection system works with HTTP transport
|
|
345
|
-
- [ ] Error handling and logging preserved
|
|
346
|
-
|
|
347
|
-
### ✅ OAuth Integration
|
|
348
|
-
- [ ] OAuth 2.1 Resource Server fully compliant
|
|
349
|
-
- [ ] Dynamic Client Registration working
|
|
350
|
-
- [ ] JWT token validation secure and performant
|
|
351
|
-
- [ ] EH_TOKEN user validation integrated
|
|
352
|
-
|
|
353
|
-
### ✅ Security Requirements
|
|
354
|
-
- [ ] All requests require valid authentication
|
|
355
|
-
- [ ] User authorization enforced for all tools
|
|
356
|
-
- [ ] Rate limiting and CORS protection active
|
|
357
|
-
- [ ] Security headers properly configured
|
|
358
|
-
|
|
359
|
-
### ✅ Claude.ai Compatibility
|
|
360
|
-
- [ ] Connector registration successful
|
|
361
|
-
- [ ] OAuth flow completes without errors
|
|
362
|
-
- [ ] All tools accessible through claude.ai interface
|
|
363
|
-
- [ ] Performance acceptable for interactive use
|
|
364
|
-
|
|
365
|
-
### ✅ Production Readiness
|
|
366
|
-
- [ ] Ngrok tunnel stable and performant
|
|
367
|
-
- [ ] Health checks and monitoring operational
|
|
368
|
-
- [ ] Error handling graceful and informative
|
|
369
|
-
- [ ] Documentation complete and accurate
|
|
370
|
-
|
|
371
|
-
---
|
|
372
|
-
|
|
373
|
-
This specification provides the complete natural language-driven blueprint for transforming the Miadi MCP server into a production-ready remote server with OAuth authentication and claude.ai integration while preserving all existing functionality and security requirements.
|