@portel/photon 1.0.0

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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +952 -0
  3. package/dist/base.d.ts +58 -0
  4. package/dist/base.d.ts.map +1 -0
  5. package/dist/base.js +92 -0
  6. package/dist/base.js.map +1 -0
  7. package/dist/cli.d.ts +8 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +1441 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/dependency-manager.d.ts +49 -0
  12. package/dist/dependency-manager.d.ts.map +1 -0
  13. package/dist/dependency-manager.js +165 -0
  14. package/dist/dependency-manager.js.map +1 -0
  15. package/dist/loader.d.ts +86 -0
  16. package/dist/loader.d.ts.map +1 -0
  17. package/dist/loader.js +612 -0
  18. package/dist/loader.js.map +1 -0
  19. package/dist/marketplace-manager.d.ts +261 -0
  20. package/dist/marketplace-manager.d.ts.map +1 -0
  21. package/dist/marketplace-manager.js +767 -0
  22. package/dist/marketplace-manager.js.map +1 -0
  23. package/dist/path-resolver.d.ts +21 -0
  24. package/dist/path-resolver.d.ts.map +1 -0
  25. package/dist/path-resolver.js +71 -0
  26. package/dist/path-resolver.js.map +1 -0
  27. package/dist/photon-doc-extractor.d.ts +89 -0
  28. package/dist/photon-doc-extractor.d.ts.map +1 -0
  29. package/dist/photon-doc-extractor.js +228 -0
  30. package/dist/photon-doc-extractor.js.map +1 -0
  31. package/dist/readme-syncer.d.ts +33 -0
  32. package/dist/readme-syncer.d.ts.map +1 -0
  33. package/dist/readme-syncer.js +93 -0
  34. package/dist/readme-syncer.js.map +1 -0
  35. package/dist/registry-manager.d.ts +76 -0
  36. package/dist/registry-manager.d.ts.map +1 -0
  37. package/dist/registry-manager.js +220 -0
  38. package/dist/registry-manager.js.map +1 -0
  39. package/dist/schema-extractor.d.ts +83 -0
  40. package/dist/schema-extractor.d.ts.map +1 -0
  41. package/dist/schema-extractor.js +396 -0
  42. package/dist/schema-extractor.js.map +1 -0
  43. package/dist/security-scanner.d.ts +52 -0
  44. package/dist/security-scanner.d.ts.map +1 -0
  45. package/dist/security-scanner.js +172 -0
  46. package/dist/security-scanner.js.map +1 -0
  47. package/dist/server.d.ts +73 -0
  48. package/dist/server.d.ts.map +1 -0
  49. package/dist/server.js +474 -0
  50. package/dist/server.js.map +1 -0
  51. package/dist/template-manager.d.ts +56 -0
  52. package/dist/template-manager.d.ts.map +1 -0
  53. package/dist/template-manager.js +509 -0
  54. package/dist/template-manager.js.map +1 -0
  55. package/dist/test-client.d.ts +52 -0
  56. package/dist/test-client.d.ts.map +1 -0
  57. package/dist/test-client.js +168 -0
  58. package/dist/test-client.js.map +1 -0
  59. package/dist/test-marketplace-sources.d.ts +5 -0
  60. package/dist/test-marketplace-sources.d.ts.map +1 -0
  61. package/dist/test-marketplace-sources.js +53 -0
  62. package/dist/test-marketplace-sources.js.map +1 -0
  63. package/dist/types.d.ts +108 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +12 -0
  66. package/dist/types.js.map +1 -0
  67. package/dist/version-checker.d.ts +48 -0
  68. package/dist/version-checker.d.ts.map +1 -0
  69. package/dist/version-checker.js +128 -0
  70. package/dist/version-checker.js.map +1 -0
  71. package/dist/watcher.d.ts +26 -0
  72. package/dist/watcher.d.ts.map +1 -0
  73. package/dist/watcher.js +72 -0
  74. package/dist/watcher.js.map +1 -0
  75. package/package.json +79 -0
  76. package/templates/photon.template.ts +55 -0
package/README.md ADDED
@@ -0,0 +1,952 @@
1
+
2
+ ![Photon Logo](https://raw.githubusercontent.com/portel-dev/photon/refs/heads/main/assets/photon-logo.png)
3
+
4
+ [![npm version](https://img.shields.io/npm/v/@portel/photon.svg)](https://www.npmjs.com/package/@portel/photon)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@portel/photon.svg)](https://www.npmjs.com/package/@portel/photon)
6
+ [![MCP](https://img.shields.io/badge/MCP-Compatible-blue)](https://modelcontextprotocol.io)
7
+
8
+ # Photon
9
+
10
+ **Runtime that turns single-file TypeScript classes into production-ready MCP servers.**
11
+
12
+ Photon TS files are Single file. Zero boilerplate. Pure business logic.
13
+
14
+ ---
15
+
16
+ ## The Problem
17
+
18
+ Traditional MCP servers scatter your logic across 4-6 files:
19
+
20
+ ```
21
+ traditional-mcp/
22
+ ├── server.ts (50 lines of boilerplate)
23
+ ├── transport.ts (40 lines of setup)
24
+ ├── schemas.ts (40 lines of type definitions)
25
+ ├── types.ts (30 lines more types)
26
+ ├── package.json (dependencies)
27
+ └── business.ts (20 lines of YOUR CODE)
28
+ ```
29
+
30
+ **This creates real problems:**
31
+
32
+ - ❌ **For AI agents**: Scattered context across files makes understanding difficult
33
+ - ❌ **For humans**: Jump between files to understand one feature
34
+ - ❌ **For teams**: 200+ lines before you write business logic
35
+ - ❌ **For maintenance**: Changes require updating multiple files and configs
36
+
37
+ ---
38
+
39
+ ## The Solution
40
+
41
+ Photon puts everything in **one file**:
42
+
43
+ ```typescript
44
+ /**
45
+ * Analytics - Query company analytics database
46
+ * @dependencies pg@^8.11.0
47
+ */
48
+ import { Client } from 'pg';
49
+
50
+ export default class Analytics {
51
+ private db: Client;
52
+
53
+ constructor(
54
+ private host: string,
55
+ private database: string,
56
+ private password: string
57
+ ) {}
58
+
59
+ async onInitialize() {
60
+ this.db = new Client({
61
+ host: this.host,
62
+ database: this.database,
63
+ password: this.password
64
+ });
65
+ await this.db.connect();
66
+ }
67
+
68
+ /**
69
+ * Get revenue by date range
70
+ * @param startDate Start date (YYYY-MM-DD)
71
+ * @param endDate End date (YYYY-MM-DD)
72
+ */
73
+ async revenue(params: { startDate: string; endDate: string }) {
74
+ const result = await this.db.query(
75
+ 'SELECT date, SUM(amount) FROM orders WHERE date BETWEEN $1 AND $2 GROUP BY date',
76
+ [params.startDate, params.endDate]
77
+ );
78
+ return result.rows;
79
+ }
80
+ }
81
+ ```
82
+
83
+ **40 lines. One file. Production-ready.**
84
+
85
+ ---
86
+
87
+ ## Why One File Changes Everything
88
+
89
+ ### 🤖 AI-Native Design
90
+
91
+ AI agents can now understand your entire MCP in one context:
92
+
93
+ ```bash
94
+ # AI can read, understand, and suggest improvements
95
+ "Read my analytics.photon.ts and explain how it works"
96
+ "Review this photon for security issues"
97
+ "Add error handling to this photon"
98
+ ```
99
+
100
+ Traditional MCPs require AI to piece together scattered files — Photons give complete context.
101
+
102
+ ### 👤 Human-Friendly
103
+
104
+ - **Understand**: Read one file, understand the whole system
105
+ - **Review**: Code reviews are one file, one story
106
+ - **Debug**: All logic in one place, no jumping around
107
+ - **Learn**: New team members read one file
108
+
109
+ ### 🔧 Fork-First Philosophy
110
+
111
+ Every photon is designed to be customized:
112
+
113
+ ```bash
114
+ # Copy, modify, done — no build configs to update
115
+ cp ~/.photon/jira.photon.ts ~/.photon/my-jira.photon.ts
116
+ # Edit my-jira.photon.ts however you want
117
+ photon mcp my-jira # Works immediately
118
+ ```
119
+
120
+ **Use cases:**
121
+ - Add company-specific authentication
122
+ - Customize business logic
123
+ - Merge multiple photons
124
+ - Experiment without breaking originals
125
+
126
+ ### 📦 Zero-Friction Dependencies
127
+
128
+ Dependencies are auto-installed via JSDoc (like `npx` or `uv`):
129
+
130
+ ```typescript
131
+ /**
132
+ * @dependencies axios@^1.6.0, lodash@^4.17.21
133
+ */
134
+ ```
135
+
136
+ No manual `npm install`. No `package.json`. Photon handles it.
137
+
138
+ ---
139
+
140
+ ## Quick Start
141
+
142
+ ### Install
143
+
144
+ ```bash
145
+ npm install -g @portel/photon
146
+ ```
147
+
148
+ ### Use Ready-Made Photons
149
+
150
+ The [**official Photon marketplace**](https://github.com/portel-dev/photons) comes pre-configured with 16+ production-ready photons:
151
+
152
+ ```bash
153
+ # Browse all photons
154
+ photon get
155
+
156
+ # Install any photon (filesystem, git, postgres, mongodb, slack, etc.)
157
+ photon add filesystem
158
+
159
+ # Run as MCP server
160
+ photon mcp filesystem
161
+ ```
162
+
163
+ ### Build Photons with AI
164
+
165
+ Use the [**photon-skill**](https://github.com/portel-dev/photon-skill) for Claude Desktop or Claude Code to generate `.photon.ts` files:
166
+ - Single TypeScript files with metadata
167
+ - AI understands complete context in one file
168
+ - Zero boilerplate, just business logic
169
+
170
+ ### Add Your Own Marketplace
171
+
172
+ ```bash
173
+ # Add custom marketplace from GitHub
174
+ photon marketplace add your-org/your-photons
175
+
176
+ # Install from your marketplace
177
+ photon add your-custom-tool
178
+ ```
179
+
180
+ ### Integrate with Your MCP Client
181
+
182
+ ```bash
183
+ # Get configuration for any MCP client
184
+ photon get filesystem --mcp
185
+ ```
186
+
187
+ Add the output to your MCP client's config file. **Consult your client's documentation** for setup instructions.
188
+
189
+ **MCP clients include:** Claude Desktop, Cursor, Zed, Continue, Cline, and more.
190
+
191
+ ---
192
+
193
+ ## The Value Proposition
194
+
195
+ | Metric | Traditional MCP | Photon |
196
+ |--------|-----------------|--------|
197
+ | **Setup Time** | 40 minutes | 5 minutes |
198
+ | **Lines of Code** | 200+ | ~40 |
199
+ | **Files Needed** | 4-6 files | 1 file |
200
+ | **Boilerplate** | Manual | Auto-handled |
201
+ | **Schema Generation** | Manual | Automatic from TypeScript |
202
+ | **Dependencies** | Manual npm install | Auto-installed from @dependencies |
203
+ | **Hot Reload** | Configure yourself | Built-in with --dev |
204
+ | **AI Context** | Scattered | Single file |
205
+
206
+ [See detailed comparison →](COMPARISON.md)
207
+
208
+ ---
209
+
210
+ ## How Photon Works
211
+
212
+ ### Convention = Automation
213
+
214
+ **File Name → MCP Name**
215
+ ```typescript
216
+ // analytics.photon.ts → "analytics" MCP
217
+ ```
218
+
219
+ **Class Methods → Tools**
220
+ ```typescript
221
+ async revenue() {} // → "revenue" tool
222
+ async topCustomers() {} // → "topCustomers" tool
223
+ ```
224
+
225
+ **TypeScript Types → JSON Schemas**
226
+ ```typescript
227
+ async create(params: { title: string; priority: number }) {}
228
+ // Photon auto-generates JSON schema from TypeScript types
229
+ ```
230
+
231
+ **JSDoc → Tool Descriptions**
232
+ ```typescript
233
+ /**
234
+ * Get revenue by date range
235
+ * @param startDate Start date (YYYY-MM-DD)
236
+ */
237
+ // Photon extracts descriptions automatically
238
+ ```
239
+
240
+ **Constructor Parameters → Environment Variables**
241
+ ```typescript
242
+ constructor(private host: string, private database: string) {}
243
+ // Maps to: ANALYTICS_HOST, ANALYTICS_DATABASE
244
+ ```
245
+
246
+ **JSDoc @dependencies → Auto-Install**
247
+ ```typescript
248
+ /**
249
+ * @dependencies pg@^8.11.0, lodash@^4.17.21
250
+ */
251
+ // Photon auto-installs on first run (like npx or uv)
252
+ ```
253
+
254
+ ---
255
+
256
+ ## Available Photons
257
+
258
+ Production-ready photons from **[portel-dev/photons](https://github.com/portel-dev/photons)**:
259
+
260
+ | Category | Photons | Total Tools |
261
+ |----------|---------|-------------|
262
+ | **Databases** | PostgreSQL (7), MongoDB (13), Redis (18), SQLite (9) | 47 |
263
+ | **Infrastructure** | AWS S3 (11), Docker (10), Filesystem (13) | 34 |
264
+ | **Development** | Git (11), GitHub Issues (7) | 18 |
265
+ | **Communication** | Email (8), Slack (7) | 15 |
266
+ | **Productivity** | Google Calendar (9), Jira (10) | 19 |
267
+ | **Utilities** | Fetch (2), Time (3), Memory (10) | 15 |
268
+
269
+ **Total: 16 photons, 148 focused tools**
270
+
271
+ Browse and install:
272
+ ```bash
273
+ photon get # See all available photons
274
+ photon add postgres # Install any photon
275
+ photon search git # Search by keyword
276
+ ```
277
+
278
+ ---
279
+
280
+ ## Create Your Own Photon
281
+
282
+ ### 1. Initialize
283
+
284
+ ```bash
285
+ photon init analytics
286
+ ```
287
+
288
+ Creates `analytics.photon.ts` in `~/.photon/` (accessible from anywhere).
289
+
290
+ **Custom directory:**
291
+ ```bash
292
+ photon --working-dir ./my-photons init analytics
293
+ ```
294
+
295
+ ### 2. Write Business Logic
296
+
297
+ ```typescript
298
+ /**
299
+ * Analytics - Query company analytics database
300
+ * @dependencies pg@^8.11.0
301
+ */
302
+ import { Client } from 'pg';
303
+
304
+ export default class Analytics {
305
+ private db: Client;
306
+
307
+ constructor(
308
+ private host: string,
309
+ private database: string,
310
+ private password: string
311
+ ) {}
312
+
313
+ async onInitialize() {
314
+ this.db = new Client({
315
+ host: this.host,
316
+ database: this.database,
317
+ password: this.password
318
+ });
319
+ await this.db.connect();
320
+ }
321
+
322
+ /**
323
+ * Get revenue by date range
324
+ * @param startDate Start date (YYYY-MM-DD)
325
+ * @param endDate End date (YYYY-MM-DD)
326
+ */
327
+ async revenue(params: { startDate: string; endDate: string }) {
328
+ const result = await this.db.query(
329
+ 'SELECT date, SUM(amount) FROM orders WHERE date BETWEEN $1 AND $2 GROUP BY date',
330
+ [params.startDate, params.endDate]
331
+ );
332
+ return result.rows;
333
+ }
334
+
335
+ async onShutdown() {
336
+ await this.db.end();
337
+ }
338
+ }
339
+ ```
340
+
341
+ ### 3. Run
342
+
343
+ ```bash
344
+ # Development mode (hot reload)
345
+ photon mcp analytics --dev
346
+
347
+ # Production mode
348
+ photon mcp analytics
349
+ ```
350
+
351
+ **That's it!** Photon handles:
352
+ - ✅ TypeScript compilation (via esbuild)
353
+ - ✅ Schema generation from types
354
+ - ✅ MCP protocol implementation
355
+ - ✅ Environment variable mapping
356
+ - ✅ Dependency installation (@dependencies)
357
+ - ✅ Hot reload in dev mode
358
+
359
+ **You focus on:** Your business logic
360
+ **Photon handles:** Everything else
361
+
362
+ ---
363
+
364
+ ## Commands Reference
365
+
366
+ ### Global Options
367
+
368
+ ```bash
369
+ --working-dir <dir> # Use custom directory instead of ~/.photon
370
+ -V, --version # Show version number
371
+ -h, --help # Show help
372
+ ```
373
+
374
+ ### Development Commands
375
+
376
+ #### `photon init <name>`
377
+ Create a new `.photon.ts` file from template.
378
+
379
+ ```bash
380
+ # Create in default directory (~/.photon)
381
+ photon init calculator
382
+
383
+ # Create in custom directory
384
+ photon --working-dir ./my-photons init calculator
385
+ ```
386
+
387
+ #### `photon validate <name>`
388
+ Validate syntax and extract schemas without running.
389
+
390
+ ```bash
391
+ photon validate calculator
392
+ ```
393
+
394
+ Useful for:
395
+ - Checking syntax errors
396
+ - Testing schema generation
397
+ - CI/CD validation
398
+
399
+ ### Running Photons
400
+
401
+ #### `photon mcp <name>`
402
+ Run a photon as an MCP server.
403
+
404
+ ```bash
405
+ # Production mode
406
+ photon mcp calculator
407
+
408
+ # Development mode (hot reload on file changes)
409
+ photon mcp calculator --dev
410
+
411
+ # Validate configuration without running
412
+ photon mcp calculator --validate
413
+
414
+ # Show MCP configuration template
415
+ photon mcp calculator --config
416
+ ```
417
+
418
+ **Options:**
419
+ - `--dev` - Enable hot reload for development
420
+ - `--validate` - Validate configuration without running server
421
+ - `--config` - Show configuration template and exit
422
+
423
+ ### Inspect & Configure
424
+
425
+ #### `photon get [name]`
426
+ List all photons or show details for a specific one.
427
+
428
+ ```bash
429
+ # List all installed photons
430
+ photon get
431
+
432
+ # Show details for one photon
433
+ photon get calculator
434
+
435
+ # Get MCP client configuration
436
+ photon get calculator --mcp
437
+ ```
438
+
439
+ **Options:**
440
+ - `--mcp` - Output MCP server configuration for your client
441
+
442
+ ### Marketplace Commands
443
+
444
+ #### `photon add <name>`
445
+ Install a photon from a marketplace.
446
+
447
+ ```bash
448
+ # Install from any enabled marketplace
449
+ photon add filesystem
450
+
451
+ # Install from specific marketplace
452
+ photon add filesystem --marketplace portel-dev/photons
453
+ ```
454
+
455
+ **Options:**
456
+ - `--marketplace <name>` - Specify which marketplace to use
457
+
458
+ #### `photon search <query>`
459
+ Search for photons across all enabled marketplaces.
460
+
461
+ ```bash
462
+ photon search database
463
+ photon search git
464
+ ```
465
+
466
+ #### `photon info <name>`
467
+ Show detailed information about a photon from marketplaces.
468
+
469
+ ```bash
470
+ photon info postgres
471
+ ```
472
+
473
+ Shows:
474
+ - Description
475
+ - Available tools
476
+ - Configuration requirements
477
+ - Marketplace source
478
+
479
+ #### `photon upgrade [name]`
480
+ Upgrade photons from marketplaces.
481
+
482
+ ```bash
483
+ # Upgrade all photons
484
+ photon upgrade
485
+
486
+ # Upgrade specific photon
487
+ photon upgrade filesystem
488
+
489
+ # Check for updates without upgrading
490
+ photon upgrade --check
491
+ ```
492
+
493
+ **Options:**
494
+ - `--check` - Only check for updates, don't install
495
+
496
+ #### `photon conflicts`
497
+ Show photons available in multiple marketplaces.
498
+
499
+ ```bash
500
+ photon conflicts
501
+ ```
502
+
503
+ Useful when same photon name exists in different marketplaces.
504
+
505
+ ### Marketplace Management
506
+
507
+ #### `photon marketplace list`
508
+ List all configured marketplaces.
509
+
510
+ ```bash
511
+ photon marketplace list
512
+ ```
513
+
514
+ #### `photon marketplace add <repo>`
515
+ Add a new marketplace.
516
+
517
+ ```bash
518
+ # GitHub shorthand
519
+ photon marketplace add username/repo
520
+
521
+ # Full HTTPS URL
522
+ photon marketplace add https://github.com/username/repo
523
+
524
+ # SSH URL
525
+ photon marketplace add git@github.com:username/repo.git
526
+
527
+ # Direct URL
528
+ photon marketplace add https://example.com/marketplace
529
+
530
+ # Local path
531
+ photon marketplace add ./my-local-marketplace
532
+ ```
533
+
534
+ #### `photon marketplace remove <name>`
535
+ Remove a marketplace.
536
+
537
+ ```bash
538
+ photon marketplace remove my-marketplace
539
+ ```
540
+
541
+ #### `photon marketplace enable <name>`
542
+ Enable a previously disabled marketplace.
543
+
544
+ ```bash
545
+ photon marketplace enable my-marketplace
546
+ ```
547
+
548
+ #### `photon marketplace disable <name>`
549
+ Disable a marketplace without removing it.
550
+
551
+ ```bash
552
+ photon marketplace disable my-marketplace
553
+ ```
554
+
555
+ #### `photon marketplace update [name]`
556
+ Update marketplace metadata from remote.
557
+
558
+ ```bash
559
+ # Update all marketplaces
560
+ photon marketplace update
561
+
562
+ # Update specific marketplace
563
+ photon marketplace update portel-dev/photons
564
+ ```
565
+
566
+ ### Advanced Commands
567
+
568
+ #### `photon sync marketplace [path]`
569
+ Generate marketplace manifest and documentation.
570
+
571
+ ```bash
572
+ # Sync current directory
573
+ photon sync marketplace
574
+
575
+ # Sync specific directory
576
+ photon sync marketplace ./my-marketplace
577
+ ```
578
+
579
+ Used when creating your own marketplace. See [Marketplace System](#marketplace-system).
580
+
581
+ #### `photon audit [name]`
582
+ Security audit of photon dependencies.
583
+
584
+ ```bash
585
+ # Audit all photons
586
+ photon audit
587
+
588
+ # Audit specific photon
589
+ photon audit postgres
590
+ ```
591
+
592
+ Checks for:
593
+ - Vulnerable dependencies
594
+ - Outdated packages
595
+ - Security advisories
596
+
597
+ ---
598
+
599
+ ## Marketplace System
600
+
601
+ ### For Users: Install from Marketplace
602
+
603
+ ```bash
604
+ # Install from official marketplace (portel-dev/photons)
605
+ photon add github-issues
606
+ photon add sqlite
607
+ photon add memory
608
+
609
+ # Search for photons
610
+ photon search slack
611
+ ```
612
+
613
+ ### For Teams: Create Your Marketplace
614
+
615
+ **Build an internal marketplace for your organization:**
616
+
617
+ ```bash
618
+ # 1. Organize your photons
619
+ mkdir company-photons && cd company-photons
620
+ cp ~/.photon/*.photon.ts .
621
+
622
+ # 2. Generate marketplace manifest
623
+ photon sync marketplace
624
+
625
+ # 3. Push to GitHub/Git
626
+ git init
627
+ git add .
628
+ git commit -m "Initial marketplace"
629
+ git push origin main
630
+
631
+ # 4. Team members install
632
+ photon marketplace add company/photons
633
+ photon add internal-crm
634
+ photon add analytics-db
635
+ ```
636
+
637
+ **Benefits:**
638
+
639
+ - 🔒 **Secure**: Your code, your infrastructure, your control
640
+ - 📦 **Easy**: Single-file photons are trivial to maintain
641
+ - 🎯 **Focused**: Build exact tools for your workflows
642
+ - 📊 **Traceable**: Git-based versioning and attribution
643
+
644
+ ### Manage Marketplaces
645
+
646
+ ```bash
647
+ # List all marketplaces
648
+ photon marketplace list
649
+
650
+ # Add marketplace (multiple formats supported)
651
+ photon marketplace add username/repo # GitHub shorthand
652
+ photon marketplace add https://github.com/u/repo # HTTPS
653
+ photon marketplace add git@github.com:u/repo.git # SSH
654
+ photon marketplace add https://example.com/mkt # Direct URL
655
+ photon marketplace add ./local-photons # Local path
656
+
657
+ # Remove marketplace
658
+ photon marketplace remove <name>
659
+
660
+ # Search across all marketplaces
661
+ photon search <keyword>
662
+ ```
663
+
664
+ ---
665
+
666
+ ## Advanced Features
667
+
668
+ ### Lifecycle Hooks
669
+
670
+ ```typescript
671
+ export default class MyPhoton {
672
+ async onInitialize() {
673
+ // Called when photon loads
674
+ console.error('Photon initialized');
675
+ }
676
+
677
+ async onShutdown() {
678
+ // Called on shutdown
679
+ console.error('Photon shutting down');
680
+ }
681
+
682
+ async myTool(params: { input: string }) {
683
+ return `Processed: ${params.input}`;
684
+ }
685
+ }
686
+ ```
687
+
688
+ ### Templates (MCP Prompts)
689
+
690
+ ```typescript
691
+ import { Template, asTemplate } from '@portel/photon';
692
+
693
+ export default class MyPhoton {
694
+ /**
695
+ * Generate a code review prompt
696
+ * @Template
697
+ * @param language Programming language
698
+ * @param code Code to review
699
+ */
700
+ async codeReview(params: { language: string; code: string }): Promise<Template> {
701
+ const prompt = `Review this ${params.language} code:\n\`\`\`\n${params.code}\n\`\`\``;
702
+ return asTemplate(prompt);
703
+ }
704
+ }
705
+ ```
706
+
707
+ ### Static Resources (MCP Resources)
708
+
709
+ ```typescript
710
+ import { Static, asStatic } from '@portel/photon';
711
+
712
+ export default class MyPhoton {
713
+ /**
714
+ * Get API documentation
715
+ * @Static api://docs
716
+ * @mimeType text/markdown
717
+ */
718
+ async apiDocs(params: {}): Promise<Static> {
719
+ const docs = `# API Documentation\n\n...`;
720
+ return asStatic(docs);
721
+ }
722
+ }
723
+ ```
724
+
725
+ ### Private Methods
726
+
727
+ Methods starting with `_` are private (not exposed as tools):
728
+
729
+ ```typescript
730
+ export default class MyPhoton {
731
+ // Public tool
732
+ async publicTool(params: {}) {
733
+ return this._helperMethod();
734
+ }
735
+
736
+ // Private helper (NOT exposed)
737
+ async _helperMethod() {
738
+ return "Internal logic only";
739
+ }
740
+ }
741
+ ```
742
+
743
+ ---
744
+
745
+ ## Integration with MCP Clients
746
+
747
+ Photon works with **any MCP client**:
748
+
749
+ - **Claude Desktop** (Anthropic)
750
+ - **Cursor** (IDE)
751
+ - **Zed** (IDE)
752
+ - **Continue** (VS Code extension)
753
+ - **Cline** (VS Code extension)
754
+ - ... and more
755
+
756
+ ### Setup
757
+
758
+ ```bash
759
+ # Get configuration for your MCP client
760
+ photon get <photon-name> --mcp
761
+ ```
762
+
763
+ **Consult your MCP client's documentation** for:
764
+ - Config file location
765
+ - Configuration format
766
+ - Setup instructions
767
+
768
+ Example output:
769
+ ```json
770
+ {
771
+ "analytics": {
772
+ "command": "photon",
773
+ "args": ["mcp", "analytics"],
774
+ "env": {
775
+ "ANALYTICS_HOST": "localhost",
776
+ "ANALYTICS_DATABASE": "company",
777
+ "ANALYTICS_PASSWORD": "secret"
778
+ }
779
+ }
780
+ }
781
+ ```
782
+
783
+ ---
784
+
785
+ ## Examples
786
+
787
+ The repository includes example photons in `examples/`:
788
+
789
+ ### Content (Templates & Static Resources)
790
+ ```bash
791
+ npx photon --working-dir examples mcp content --dev
792
+ ```
793
+ Demonstrates Templates (MCP Prompts) and Static resources.
794
+
795
+ ### Calculator
796
+ ```bash
797
+ npx photon --working-dir examples mcp math --dev
798
+ ```
799
+ Basic arithmetic operations.
800
+
801
+ ### String Utilities
802
+ ```bash
803
+ npx photon --working-dir examples mcp text --dev
804
+ ```
805
+ Text manipulation tools.
806
+
807
+ ### Workflow
808
+ ```bash
809
+ npx photon --working-dir examples mcp workflow --dev
810
+ ```
811
+ Task management system.
812
+
813
+ ---
814
+
815
+ ## Architecture
816
+
817
+ ```
818
+ ┌─────────────────────┐
819
+ │ .photon.ts file │ ← Your single TypeScript file
820
+ └──────────┬──────────┘
821
+
822
+
823
+ ┌───────────────┐
824
+ │ Auto-Install │ ← Reads @dependencies, installs packages
825
+ └───────┬───────┘
826
+
827
+
828
+ ┌───────────────┐
829
+ │ Loader │ ← Compiles TypeScript with esbuild
830
+ └───────┬───────┘ Loads class dynamically
831
+
832
+
833
+ ┌─────────────────────┐
834
+ │ Schema Extractor │ ← Parses JSDoc + TypeScript types
835
+ └──────────┬──────────┘ Generates JSON schemas
836
+
837
+
838
+ ┌──────────────┐
839
+ │ MCP Server │ ← Implements MCP protocol
840
+ └──────┬───────┘ Using @modelcontextprotocol/sdk
841
+
842
+
843
+ ┌─────────────-─┐
844
+ │ stdio/JSON-RPC│ ← Communicates with MCP clients
845
+ └─────────────-─┘ (Claude Desktop, Cursor, Zed, etc.)
846
+ ```
847
+
848
+ ---
849
+
850
+ ## Philosophy
851
+
852
+ > **"Singular focus. Precise target."**
853
+
854
+ A **photon** is the smallest unit of light, delivering **singular focus** to a **precise target**.
855
+
856
+ Each Photon module embodies this principle:
857
+
858
+ - **Singular focus** - One responsibility, executed flawlessly
859
+ - **Precise target** - Clear purpose, clean API
860
+ - **Universal design** - Pure TypeScript, ready for future possibilities
861
+
862
+ ---
863
+
864
+ ## FAQ
865
+
866
+ ### Do I need to extend a base class?
867
+
868
+ No! Just export any class with async methods. Photon handles the rest.
869
+
870
+ ### How are parameters validated?
871
+
872
+ Photon extracts JSON schemas from your TypeScript types. MCP clients validate parameters before calling your tools.
873
+
874
+ ### Can I use external packages?
875
+
876
+ Yes! Dependencies are **auto-installed** from JSDoc `@dependencies` tags (like `npx` or `uv`).
877
+
878
+ ### How does hot reload work?
879
+
880
+ In `--dev` mode, Photon watches your `.photon.ts` file and recompiles on save.
881
+
882
+ ### Where are compiled files cached?
883
+
884
+ `~/.cache/photon-mcp/compiled/`
885
+
886
+ ### Where are my photons stored?
887
+
888
+ **Default:** `~/.photon/`
889
+ **Custom:** Use `--working-dir` flag
890
+
891
+ ### Can I fork and customize photons?
892
+
893
+ Absolutely! That's the design. Copy any `.photon.ts` file, edit it, run it. No build config changes needed.
894
+
895
+ ### How do I update photons?
896
+
897
+ ```bash
898
+ photon upgrade # Update all
899
+ photon upgrade <name> # Update specific photon
900
+ ```
901
+
902
+ ---
903
+
904
+ ## Roadmap
905
+
906
+ ### ✅ Version 1.0 - MCP Servers (Available Now)
907
+
908
+ Build and run photons as MCP servers for AI assistants. Works with Claude Desktop, Cursor, Zed, Continue, Cline, and any MCP-compatible client.
909
+
910
+ ### 🔮 Future Versions
911
+
912
+ Photon's framework-agnostic design enables future deployment targets:
913
+
914
+ - **CLI tools** - Run photons as terminal commands
915
+ - **More targets** - Additional deployment options as the ecosystem grows
916
+
917
+ **The vision:** Write focused business logic once. As Photon evolves, deploy it to multiple targets.
918
+
919
+ ---
920
+
921
+ ## Documentation
922
+
923
+ - **[GUIDE.md](GUIDE.md)** - Complete tutorial for creating photons
924
+ - **[ADVANCED.md](ADVANCED.md)** - Lifecycle hooks, performance, production deployment
925
+ - **[COMPARISON.md](COMPARISON.md)** - Detailed comparison vs traditional MCP
926
+ - **[TROUBLESHOOTING.md](TROUBLESHOOTING.md)** - Common issues and solutions
927
+ - **[CHANGELOG.md](CHANGELOG.md)** - Version history
928
+
929
+ ---
930
+
931
+ ## Contributing
932
+
933
+ Contributions welcome! Please open issues and PRs at [github.com/portel-dev/photon-mcp](https://github.com/portel-dev/photon-mcp).
934
+
935
+ ---
936
+
937
+ ## Related Projects
938
+
939
+ - **[photons](https://github.com/portel-dev/photons)** - Official marketplace with 16+ production-ready photons
940
+ - **@modelcontextprotocol/sdk** - Official MCP TypeScript SDK
941
+
942
+ ---
943
+
944
+ ## License
945
+
946
+ MIT © Portel
947
+
948
+ ---
949
+
950
+ **Built with singular focus. Deployed with precise targeting.**
951
+
952
+ Made with ⚛️ by [Portel](https://github.com/portel-dev)