@elliotding/ai-agent-mcp 0.1.21 → 0.1.23

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/README.md ADDED
@@ -0,0 +1,450 @@
1
+ # CSP AI Agent MCP Server
2
+
3
+ Centralized AI tools distribution and management system powered by Model Context Protocol (MCP).
4
+
5
+ ## Overview
6
+
7
+ CSP AI Agent is an MCP server that enables seamless synchronization of AI resources (commands, skills, rules, and MCP servers) between a centralized repository and Cursor IDE. It provides automatic resource discovery, subscription management, and intelligent caching.
8
+
9
+ ## Key Features
10
+
11
+ - **AI Resource Management**: Subscribe, sync, search, and upload AI resources
12
+ - **Multi-source Git Support**: Aggregate resources from multiple Git repositories with priority-based conflict resolution
13
+ - **Intelligent Caching**: Skip redundant downloads and file writes using content-based comparison
14
+ - **MCP Prompt Mode**: Commands and Skills are registered as MCP Prompts (no local file writes)
15
+ - **Auto-configuration**: MCP servers are automatically registered in `~/.cursor/mcp.json`
16
+ - **Telemetry & Analytics**: Track resource usage and sync health
17
+
18
+ ## Quick Start
19
+
20
+ ### Installation
21
+
22
+ ```bash
23
+ npm install -g @elliotding/ai-agent-mcp
24
+ ```
25
+
26
+ ### Configuration
27
+
28
+ Create a `~/.cursor/mcp.json` (or let Cursor create it) and add:
29
+
30
+ ```json
31
+ {
32
+ "mcpServers": {
33
+ "csp-ai-agent": {
34
+ "url": "https://your-server.example.com/sse",
35
+ "transport": {
36
+ "type": "sse"
37
+ },
38
+ "env": {
39
+ "CSP_USER_TOKEN": "your-token-here"
40
+ }
41
+ }
42
+ }
43
+ }
44
+ ```
45
+
46
+ ### Starting the Server
47
+
48
+ **Development:**
49
+ ```bash
50
+ cd SourceCode
51
+ npm install
52
+ npm run dev
53
+ ```
54
+
55
+ **Production (SSE mode):**
56
+ ```bash
57
+ CSP_API_BASE_URL=https://api.example.com \
58
+ CSP_USER_TOKEN=your-token \
59
+ AI_RESOURCES_PATH=/path/to/AI-Resources \
60
+ csp-ai-agent-mcp --transport sse --port 3000
61
+ ```
62
+
63
+ **Production (stdio mode):**
64
+ ```bash
65
+ csp-ai-agent-mcp --transport stdio
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ ### Available Tools
71
+
72
+ #### 1. `sync_resources`
73
+
74
+ Synchronize subscribed AI resources.
75
+
76
+ ```typescript
77
+ // In Cursor AI Agent context
78
+ const mcpJson = JSON.parse(fs.readFileSync('~/.cursor/mcp.json', 'utf8'));
79
+ const configured = Object.keys(mcpJson.mcpServers || {});
80
+
81
+ await callMcpTool('sync_resources', {
82
+ mode: 'incremental', // or 'full', 'check'
83
+ configured_mcp_servers: configured, // Optimization: skip already configured MCPs
84
+ });
85
+ ```
86
+
87
+ **Modes:**
88
+ - `incremental` (default): Update only changed resources
89
+ - `full`: Download all resources (file recovery mode)
90
+ - `check`: Status check only (no downloads)
91
+
92
+ **Optimization:** Pass `configured_mcp_servers` to skip downloading MCP resources that are already in `~/.cursor/mcp.json`. This can save **70-90% of API calls and network traffic** in typical scenarios.
93
+
94
+ #### 2. `manage_subscription`
95
+
96
+ Manage resource subscriptions.
97
+
98
+ ```typescript
99
+ // Subscribe to a resource
100
+ await callMcpTool('manage_subscription', {
101
+ action: 'subscribe',
102
+ resource_ids: ['resource-id-1', 'resource-id-2'],
103
+ auto_sync: true, // Trigger sync after subscribing
104
+ });
105
+
106
+ // List subscriptions
107
+ await callMcpTool('manage_subscription', {
108
+ action: 'list',
109
+ });
110
+
111
+ // Unsubscribe
112
+ await callMcpTool('manage_subscription', {
113
+ action: 'unsubscribe',
114
+ resource_ids: ['resource-id-1'],
115
+ });
116
+ ```
117
+
118
+ #### 3. `search_resources`
119
+
120
+ Search available AI resources.
121
+
122
+ ```typescript
123
+ await callMcpTool('search_resources', {
124
+ keyword: 'code review',
125
+ type: 'skill', // Optional: 'command', 'skill', 'rule', 'mcp'
126
+ });
127
+ ```
128
+
129
+ #### 4. `upload_resource`
130
+
131
+ Upload a new AI resource to the repository.
132
+
133
+ ```typescript
134
+ await callMcpTool('upload_resource', {
135
+ resource_id: 'my-custom-skill',
136
+ type: 'skill',
137
+ message: 'Add custom code review skill',
138
+ files: [
139
+ { path: 'SKILL.md', content: '# My Skill...' },
140
+ { path: 'examples.md', content: '# Examples...' },
141
+ ],
142
+ });
143
+ ```
144
+
145
+ #### 5. `uninstall_resource`
146
+
147
+ Remove a resource from local installation.
148
+
149
+ ```typescript
150
+ await callMcpTool('uninstall_resource', {
151
+ resource_id_or_name: 'my-skill',
152
+ remove_from_account: false, // Keep subscription, only remove local files
153
+ });
154
+ ```
155
+
156
+ #### 6. `track_usage`
157
+
158
+ Record resource invocation telemetry.
159
+
160
+ ```typescript
161
+ await callMcpTool('track_usage', {
162
+ resource_id: 'resource-id',
163
+ resource_type: 'command',
164
+ resource_name: 'my-command',
165
+ });
166
+ ```
167
+
168
+ ### MCP Prompts
169
+
170
+ The server provides several built-in prompts:
171
+
172
+ - **`csp-ai-agent-setup`**: Interactive setup wizard for new users
173
+ - **AI resource prompts**: All subscribed commands/skills are automatically available as prompts
174
+
175
+ ## Configuration
176
+
177
+ ### Environment Variables
178
+
179
+ **Required:**
180
+ - `CSP_API_BASE_URL`: Base URL of the CSP API server (e.g., `https://api.example.com`)
181
+ - `CSP_USER_TOKEN`: Authentication token for API access
182
+
183
+ **Optional:**
184
+ - `AI_RESOURCES_PATH`: Path to local AI-Resources directory (default: auto-detected)
185
+ - `PORT`: Server port (default: `3000`)
186
+ - `LOG_LEVEL`: Logging level (default: `info`)
187
+ - `LOG_DIR`: Log directory (default: `./Logs`)
188
+
189
+ ### AI-Resources Configuration
190
+
191
+ The server reads `AI-Resources/ai-resources-config.json` to discover available Git sources:
192
+
193
+ ```json
194
+ {
195
+ "default_source": "csp",
196
+ "sources": [
197
+ {
198
+ "name": "csp",
199
+ "path": "csp/ai-resources",
200
+ "repo": "https://git.zoom.us/main/csp.git",
201
+ "branch": "main",
202
+ "priority": 100,
203
+ "resources": {
204
+ "commands": "commands",
205
+ "skills": "skills",
206
+ "rules": "rules",
207
+ "mcp": "mcp"
208
+ }
209
+ }
210
+ ]
211
+ }
212
+ ```
213
+
214
+ ## Resource Types
215
+
216
+ ### 1. Command
217
+ - Single-use AI instructions
218
+ - Registered as MCP Prompts (no local files)
219
+ - Example: `/ask-expert`, `/review-code`
220
+
221
+ ### 2. Skill
222
+ - Reusable workflows with multiple steps
223
+ - Registered as MCP Prompts
224
+ - Must have `SKILL.md` as entry point
225
+
226
+ ### 3. Rule
227
+ - Always-applied Cursor rules
228
+ - Written to `~/.cursor/rules/`
229
+ - Auto-loaded by Cursor on startup
230
+
231
+ ### 4. MCP
232
+ - Full MCP servers (local or remote)
233
+ - **Local executable**: Downloaded to `~/.cursor/mcp-servers/`, auto-registered
234
+ - **Remote SSE/stdio**: Only registration, no file download
235
+
236
+ ## Architecture
237
+
238
+ ### Resource Delivery Strategy
239
+
240
+ ```
241
+ ┌─────────────────┬──────────────────┬─────────────────────┐
242
+ │ Resource Type │ Storage │ Delivery Method │
243
+ ├─────────────────┼──────────────────┼─────────────────────┤
244
+ │ Command │ MCP Prompt │ In-memory cache │
245
+ │ Skill │ MCP Prompt │ In-memory cache │
246
+ │ Rule │ ~/.cursor/rules/ │ write_file action │
247
+ │ MCP (local) │ ~/.cursor/mcp-*/ │ write_file actions │
248
+ │ MCP (remote) │ ~/.cursor/mcp.* │ merge_mcp_json only │
249
+ └─────────────────┴──────────────────┴─────────────────────┘
250
+ ```
251
+
252
+ ### Sync Flow
253
+
254
+ ```
255
+ User: "csp 同步资源"
256
+
257
+ AI Agent: Read ~/.cursor/mcp.json → extract configured MCP servers
258
+
259
+ AI Agent: Call sync_resources(mode: 'incremental', configured_mcp_servers: [...])
260
+
261
+ MCP Server:
262
+ 1. Fetch subscription list from CSP API
263
+ 2. For each subscription:
264
+ - Skip if MCP already in configured_mcp_servers (optimization)
265
+ - Download resource files (API or Git fallback)
266
+ - Generate local_actions_required
267
+ 3. Return result + actions
268
+
269
+ AI Agent: Execute local_actions_required
270
+ - write_file: Compare content, skip if identical
271
+ - merge_mcp_json: Check skip_if_exists, preserve user env
272
+
273
+ User: Resources synced ✅
274
+ ```
275
+
276
+ ## Performance Optimizations
277
+
278
+ ### 1. Content-based File Comparison (v0.1.23)
279
+
280
+ **Before:** Used SHA-256 hash comparison (error-prone, platform-dependent)
281
+ **After:** Direct string equality check (`existing === action.content`)
282
+
283
+ **Benefits:**
284
+ - ✅ Infinitely faster (0ms vs 6ms per file)
285
+ - ✅ 100% reliable (no platform issues)
286
+ - ✅ Simpler implementation (6 lines vs 15+ lines)
287
+
288
+ ### 2. MCP Skip Optimization (v0.1.23)
289
+
290
+ **Before:** Always downloaded all MCP resources, generated all write_file actions
291
+ **After:** Skip downloading MCPs that are already in `configured_mcp_servers`
292
+
293
+ **Benefits:**
294
+ - ✅ Saves 70-90% of API calls (typical: 8/11 resources skipped)
295
+ - ✅ Reduces network traffic by ~95% (skip ~750KB downloads)
296
+ - ✅ Reduces AI Agent overhead (skip ~77 file operations)
297
+ - ✅ Sync time: 8-12s → 1-2s (**80-85% faster**)
298
+
299
+ ### 3. Server-side Download Cache
300
+
301
+ Avoids redundant API calls for unchanged resources within the same server session.
302
+
303
+ ## Testing
304
+
305
+ ### Run All Tests
306
+
307
+ ```bash
308
+ # Content comparison test
309
+ node Test/test-bug-BUG-2026-03-27-001.js
310
+
311
+ # MCP optimization test
312
+ node Test/test-mcp-skip-optimization.js
313
+ ```
314
+
315
+ ### Mock Server for Development
316
+
317
+ ```bash
318
+ # Start mock CSP API server
319
+ node Test/mock-csp-resource-server.js
320
+
321
+ # Run integration tests
322
+ node Test/test-runner.js
323
+ ```
324
+
325
+ ## Troubleshooting
326
+
327
+ ### Git Pull Failures
328
+
329
+ If you see `SSL certificate problem: self-signed certificate in certificate chain`:
330
+
331
+ ```bash
332
+ # Option 1: Trust the certificate (recommended)
333
+ git config --global http.sslCAInfo /path/to/certificate.pem
334
+
335
+ # Option 2: Disable SSL verification (development only)
336
+ export GIT_SSL_NO_VERIFY=true
337
+ ```
338
+
339
+ The server automatically falls back to reading from local Git checkout when pull fails.
340
+
341
+ ### MCP Server Not Syncing
342
+
343
+ Check logs in `Logs/app.YYYY-MM-DD.N.log`:
344
+
345
+ ```bash
346
+ # Search for sync operations
347
+ grep "sync_resources" Logs/app.*.log | tail -20
348
+
349
+ # Check for errors
350
+ grep '"level":50' Logs/app.*.log | tail -10
351
+ ```
352
+
353
+ ### Files Keep Being Rewritten
354
+
355
+ If files are rewritten on every sync (timestamps change):
356
+ 1. Ensure AI Agent uses `fs.readFileSync()` for content comparison
357
+ 2. Avoid shell commands like `cat file | sha256sum`
358
+ 3. Check that `configured_mcp_servers` parameter is passed
359
+
360
+ ## Contributing
361
+
362
+ ### Bug Reports
363
+
364
+ Follow the bug management workflow:
365
+ 1. Create `Bug/BUG-YYYY-MM-DD-NNN-title/` folder
366
+ 2. Write `bug-description.md` (description + reproduction)
367
+ 3. Fix the bug
368
+ 4. Write `fix-solution.md` (root cause + solution)
369
+ 5. Create test case in `Test/test-bug-BUG-*.js`
370
+ 6. Write `test-result.md` (test output + verification)
371
+ 7. Archive to `Bug/Fixed Bugs/` when complete
372
+
373
+ ### Development Rules
374
+
375
+ See `AGENTS.md` for complete development guidelines including:
376
+ - OpenSpec-driven development workflow
377
+ - Design document requirements
378
+ - Testing standards
379
+ - Git commit rules
380
+
381
+ ## Project Structure
382
+
383
+ ```
384
+ SourceCode/
385
+ ├── src/
386
+ │ ├── tools/ # MCP tool implementations
387
+ │ ├── api/ # CSP API client
388
+ │ ├── git/ # Multi-source Git manager
389
+ │ ├── prompts/ # MCP Prompt manager
390
+ │ ├── server/ # HTTP + SSE server
391
+ │ └── types/ # TypeScript definitions
392
+ ├── dist/ # Compiled JavaScript (gitignored)
393
+ └── package.json
394
+
395
+ Test/ # Test cases and mock servers
396
+ Logs/ # Runtime logs (gitignored)
397
+ Bug/ # Bug tracking
398
+ ├── BUG-*/ # Active bugs
399
+ └── Fixed Bugs/ # Archived bugs
400
+ Docs/
401
+ ├── Design/ # Architecture documents
402
+ └── FeatureDocs/ # Feature specifications
403
+ ```
404
+
405
+ ## API Endpoints (HTTP Server)
406
+
407
+ **Health Check:**
408
+ ```bash
409
+ GET /health
410
+ ```
411
+
412
+ **Trigger Sync (webhook):**
413
+ ```bash
414
+ POST /sync
415
+ Authorization: Bearer <CSP_USER_TOKEN>
416
+ ```
417
+
418
+ **SSE Connection:**
419
+ ```bash
420
+ GET /sse
421
+ ```
422
+
423
+ ## Version History
424
+
425
+ ### v0.1.23 (2026-03-27)
426
+
427
+ **Performance Optimizations:**
428
+ - Removed hash-based file comparison, use direct content equality
429
+ - Added `configured_mcp_servers` parameter to skip downloading already-configured MCPs
430
+ - Typical sync time reduced by 80-85% (8-12s → 1-2s)
431
+ - Removed `crypto` dependency from sync operations
432
+
433
+ **Bug Fixes:**
434
+ - Fixed hash calculation mismatch between MCP Server and AI Agent (BUG-2026-03-27-001)
435
+ - Eliminated platform-dependent `cat | sha256sum` issues
436
+
437
+ ### v0.1.22 and earlier
438
+
439
+ See Git commit history for details.
440
+
441
+ ## License
442
+
443
+ MIT
444
+
445
+ ## Support
446
+
447
+ For issues and questions, please refer to:
448
+ - Bug tracking: `Bug/` directory
449
+ - Design docs: `Docs/Design/`
450
+ - Development rules: `AGENTS.md`
@@ -2,7 +2,7 @@
2
2
  "client_version": "0.1.5",
3
3
  "users": {
4
4
  "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJDU1BfTUNQX0FVVEgiLCJpc3MiOiJjbGllbnQtc2VydmljZS1wbGF0Zm9ybSIsImlhdCI6MTc3MjA3NjIxNSwiZW1haWwiOiJlbGxpb3QuZGluZ0B6b29tLnVzIn0.xw7Np0MynXqhL4ay_vN1v5Ac332aga0tgybPQsC7WMc": {
5
- "last_reported_at": "2026-03-25T12:39:38.570Z",
5
+ "last_reported_at": "2026-03-27T05:44:49.394Z",
6
6
  "pending_events": [],
7
7
  "subscribed_rules": [],
8
8
  "configured_mcps": [
@@ -1 +1 @@
1
- {"version":3,"file":"multi-source-manager.d.ts","sourceRoot":"","sources":["../../src/git/multi-source-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA8BH,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,cAAM,qBAAqB;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,MAAM;IAK3B;;OAEG;YACW,UAAU;IASxB;;OAEG;YACW,iBAAiB;IAe/B;;OAEG;YACW,gBAAgB;IAU9B;;OAEG;YACW,UAAU;IAWxB;;OAEG;YACW,eAAe;IAwB7B;;;;;OAKG;YACW,cAAc;IA+C5B;;OAEG;YACW,UAAU;IAgExB;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAyC7C;;;;;;;;;;;OAWG;IACG,iBAAiB,CACrB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GACjD,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAoIpD;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,KAAK,CAAC;QACrC,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,OAAO,CAAC;QAChB,SAAS,EAAE,OAAO,CAAC;QACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,CAAC,CAAC;CAuBJ;AAqDD,eAAO,MAAM,qBAAqB,uBAA+C,CAAC"}
1
+ {"version":3,"file":"multi-source-manager.d.ts","sourceRoot":"","sources":["../../src/git/multi-source-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA8BH,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,cAAM,qBAAqB;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,MAAM;IAK3B;;OAEG;YACW,UAAU;IASxB;;OAEG;YACW,iBAAiB;IAe/B;;OAEG;YACW,gBAAgB;IAU9B;;OAEG;YACW,UAAU;IAWxB;;OAEG;YACW,eAAe;IAwB7B;;;;;OAKG;YACW,cAAc;IAgI5B;;OAEG;YACW,UAAU;IA4GxB;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAyC7C;;;;;;;;;;;OAWG;IACG,iBAAiB,CACrB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GACjD,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAoIpD;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,KAAK,CAAC;QACrC,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,OAAO,CAAC;QAChB,SAAS,EAAE,OAAO,CAAC;QACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,CAAC,CAAC;CAuBJ;AAqDD,eAAO,MAAM,qBAAqB,uBAA+C,CAAC"}