@goonnguyen/human-mcp 1.3.0 → 2.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 (128) hide show
  1. package/README.md +261 -19
  2. package/bin/human-mcp.js +2 -0
  3. package/dist/index.js +65180 -1698
  4. package/package.json +19 -2
  5. package/.claude/agents/code-reviewer.md +0 -140
  6. package/.claude/agents/database-admin.md +0 -86
  7. package/.claude/agents/debugger.md +0 -119
  8. package/.claude/agents/docs-manager.md +0 -113
  9. package/.claude/agents/git-manager.md +0 -59
  10. package/.claude/agents/planner-researcher.md +0 -97
  11. package/.claude/agents/project-manager.md +0 -113
  12. package/.claude/agents/tester.md +0 -95
  13. package/.claude/commands/cook.md +0 -7
  14. package/.claude/commands/debug.md +0 -10
  15. package/.claude/commands/docs/init.md +0 -11
  16. package/.claude/commands/docs/update.md +0 -11
  17. package/.claude/commands/fix/ci.md +0 -8
  18. package/.claude/commands/fix/fast.md +0 -5
  19. package/.claude/commands/fix/hard.md +0 -7
  20. package/.claude/commands/fix/test.md +0 -16
  21. package/.claude/commands/git/cm.md +0 -5
  22. package/.claude/commands/git/cp.md +0 -4
  23. package/.claude/commands/plan/ci.md +0 -12
  24. package/.claude/commands/plan/two.md +0 -13
  25. package/.claude/commands/plan.md +0 -10
  26. package/.claude/commands/test.md +0 -7
  27. package/.claude/commands/watzup.md +0 -8
  28. package/.claude/hooks/telegram_notify.sh +0 -136
  29. package/.claude/send-discord.sh +0 -64
  30. package/.claude/settings.json +0 -7
  31. package/.claude/statusline.sh +0 -143
  32. package/.dockerignore +0 -81
  33. package/.env.example +0 -44
  34. package/.github/workflows/publish.yml +0 -88
  35. package/.opencode/agent/code-reviewer.md +0 -142
  36. package/.opencode/agent/debugger.md +0 -74
  37. package/.opencode/agent/docs-manager.md +0 -119
  38. package/.opencode/agent/git-manager.md +0 -60
  39. package/.opencode/agent/planner-researcher.md +0 -100
  40. package/.opencode/agent/project-manager.md +0 -113
  41. package/.opencode/agent/system-architecture.md +0 -200
  42. package/.opencode/agent/tester.md +0 -96
  43. package/.opencode/agent/ui-ux-developer.md +0 -97
  44. package/.opencode/command/cook.md +0 -7
  45. package/.opencode/command/debug.md +0 -10
  46. package/.opencode/command/fix/ci.md +0 -8
  47. package/.opencode/command/fix/fast.md +0 -5
  48. package/.opencode/command/fix/hard.md +0 -7
  49. package/.opencode/command/fix/test.md +0 -16
  50. package/.opencode/command/git/cm.md +0 -5
  51. package/.opencode/command/git/cp.md +0 -4
  52. package/.opencode/command/plan/ci.md +0 -12
  53. package/.opencode/command/plan/two.md +0 -13
  54. package/.opencode/command/plan.md +0 -10
  55. package/.opencode/command/test.md +0 -7
  56. package/.opencode/command/watzup.md +0 -8
  57. package/.releaserc.json +0 -26
  58. package/.serena/project.yml +0 -68
  59. package/CHANGELOG.md +0 -62
  60. package/CLAUDE.md +0 -141
  61. package/DEPLOYMENT.md +0 -329
  62. package/Dockerfile +0 -52
  63. package/QUICKSTART.md +0 -97
  64. package/bun.lock +0 -1872
  65. package/bunfig.toml +0 -15
  66. package/docker-compose.yaml +0 -128
  67. package/docs/README.md +0 -51
  68. package/docs/codebase-structure-architecture-code-standards.md +0 -428
  69. package/docs/codebase-summary.md +0 -321
  70. package/docs/project-overview-pdr.md +0 -286
  71. package/docs/project-roadmap.md +0 -494
  72. package/examples/debugging-session.ts +0 -96
  73. package/human-mcp.png +0 -0
  74. package/inspector-wrapper.mjs +0 -33
  75. package/plans/001-streamable-http-transport-plan.md +0 -905
  76. package/plans/002-sse-fallback-http-transport-plan.md +0 -161
  77. package/plans/003-fix-test-infrastructure-and-ci-plan.md +0 -699
  78. package/plans/003-http-transport-local-file-access-plan.md +0 -880
  79. package/plans/004-fix-typescript-compilation-errors-plan.md +0 -388
  80. package/plans/005-comprehensive-test-infrastructure-fix-plan.md +0 -854
  81. package/plans/templates/bug-fix-template.md +0 -69
  82. package/plans/templates/feature-implementation-template.md +0 -84
  83. package/plans/templates/refactor-template.md +0 -82
  84. package/plans/templates/template-usage-guide.md +0 -58
  85. package/src/index.ts +0 -49
  86. package/src/prompts/debugging-prompts.ts +0 -149
  87. package/src/prompts/index.ts +0 -55
  88. package/src/resources/documentation.ts +0 -316
  89. package/src/resources/index.ts +0 -49
  90. package/src/server.ts +0 -36
  91. package/src/tools/eyes/index.ts +0 -225
  92. package/src/tools/eyes/processors/gif.ts +0 -137
  93. package/src/tools/eyes/processors/image.ts +0 -213
  94. package/src/tools/eyes/processors/video.ts +0 -135
  95. package/src/tools/eyes/schemas.ts +0 -51
  96. package/src/tools/eyes/utils/formatters.ts +0 -126
  97. package/src/tools/eyes/utils/gemini-client.ts +0 -73
  98. package/src/transports/http/file-interceptor.ts +0 -134
  99. package/src/transports/http/middleware.ts +0 -46
  100. package/src/transports/http/routes.ts +0 -297
  101. package/src/transports/http/server.ts +0 -116
  102. package/src/transports/http/session.ts +0 -93
  103. package/src/transports/http/sse-routes.ts +0 -210
  104. package/src/transports/index.ts +0 -36
  105. package/src/transports/stdio.ts +0 -7
  106. package/src/transports/types.ts +0 -50
  107. package/src/types/index.ts +0 -41
  108. package/src/utils/cloudflare-r2.ts +0 -107
  109. package/src/utils/config.ts +0 -123
  110. package/src/utils/errors.ts +0 -40
  111. package/src/utils/logger.ts +0 -49
  112. package/tests/integration/http-transport-files.test.ts +0 -190
  113. package/tests/integration/server.test.ts +0 -27
  114. package/tests/integration/sse-transport.test.ts +0 -142
  115. package/tests/setup.ts +0 -55
  116. package/tests/types/api-responses.ts +0 -35
  117. package/tests/types/test-types.ts +0 -105
  118. package/tests/unit/cloudflare-r2.test.ts +0 -118
  119. package/tests/unit/config.test.ts +0 -40
  120. package/tests/unit/eyes-analyze.test.ts +0 -150
  121. package/tests/unit/formatters.test.ts +0 -85
  122. package/tests/unit/sse-routes.test.ts +0 -92
  123. package/tests/utils/error-scenarios.ts +0 -198
  124. package/tests/utils/index.ts +0 -3
  125. package/tests/utils/mock-helpers.ts +0 -99
  126. package/tests/utils/test-data-generators.ts +0 -217
  127. package/tests/utils/test-server-manager.ts +0 -172
  128. package/tsconfig.json +0 -26
package/bunfig.toml DELETED
@@ -1,15 +0,0 @@
1
- [install]
2
- auto = "fallback"
3
- peer = false
4
- exact = false
5
-
6
- [install.cache]
7
- dir = "~/.bun/install/cache"
8
- disable = false
9
- disableManifest = false
10
-
11
- [test]
12
- preload = ["./tests/setup.ts"]
13
-
14
- [run]
15
- bun = true
@@ -1,128 +0,0 @@
1
- version: '3.8'
2
-
3
- services:
4
- human-mcp:
5
- build:
6
- context: .
7
- dockerfile: Dockerfile
8
- image: human-mcp:latest
9
- container_name: human-mcp-server
10
- restart: unless-stopped
11
- ports:
12
- - "3000:3000"
13
- environment:
14
- # Core Configuration
15
- - NODE_ENV=production
16
- - GOOGLE_GEMINI_API_KEY=${GOOGLE_GEMINI_API_KEY}
17
- - GOOGLE_GEMINI_MODEL=${GOOGLE_GEMINI_MODEL:-gemini-2.5-flash}
18
-
19
- # Transport Configuration
20
- - TRANSPORT_TYPE=http
21
- - HTTP_PORT=3000
22
- - HTTP_HOST=0.0.0.0
23
- - HTTP_SESSION_MODE=${HTTP_SESSION_MODE:-stateful}
24
- - HTTP_ENABLE_SSE=${HTTP_ENABLE_SSE:-true}
25
- - HTTP_ENABLE_JSON_RESPONSE=${HTTP_ENABLE_JSON_RESPONSE:-true}
26
-
27
- # Security Configuration
28
- - HTTP_CORS_ENABLED=${HTTP_CORS_ENABLED:-true}
29
- - HTTP_CORS_ORIGINS=${HTTP_CORS_ORIGINS:-*}
30
- - HTTP_DNS_REBINDING_ENABLED=${HTTP_DNS_REBINDING_ENABLED:-true}
31
- - HTTP_ALLOWED_HOSTS=${HTTP_ALLOWED_HOSTS:-127.0.0.1,localhost}
32
- - HTTP_ENABLE_RATE_LIMITING=${HTTP_ENABLE_RATE_LIMITING:-false}
33
- - HTTP_SECRET=${HTTP_SECRET:-}
34
-
35
- # Server Configuration
36
- - MAX_REQUEST_SIZE=${MAX_REQUEST_SIZE:-100MB}
37
- - ENABLE_CACHING=${ENABLE_CACHING:-true}
38
- - CACHE_TTL=${CACHE_TTL:-3600}
39
- - REQUEST_TIMEOUT=${REQUEST_TIMEOUT:-300000}
40
- - FETCH_TIMEOUT=${FETCH_TIMEOUT:-60000}
41
-
42
- # Rate Limiting
43
- - RATE_LIMIT_REQUESTS=${RATE_LIMIT_REQUESTS:-100}
44
- - RATE_LIMIT_WINDOW=${RATE_LIMIT_WINDOW:-60000}
45
-
46
- # Logging
47
- - LOG_LEVEL=${LOG_LEVEL:-info}
48
-
49
- volumes:
50
- # Optional: Mount a volume for persistent data if needed
51
- - ./data:/app/data
52
-
53
- labels:
54
- - "traefik.enable=true"
55
- - "traefik.http.routers.human-mcp.rule=Host(`${DOMAIN:-localhost}`)"
56
- - "traefik.http.routers.human-mcp.entrypoints=websecure"
57
- - "traefik.http.routers.human-mcp.tls.certresolver=letsencrypt"
58
- - "traefik.http.services.human-mcp.loadbalancer.server.port=3000"
59
-
60
- networks:
61
- - human-mcp-network
62
-
63
- # Resource limits for production
64
- deploy:
65
- resources:
66
- limits:
67
- cpus: '1.0'
68
- memory: 1G
69
- reservations:
70
- cpus: '0.5'
71
- memory: 512M
72
-
73
- # Health check
74
- healthcheck:
75
- test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"]
76
- interval: 30s
77
- timeout: 10s
78
- retries: 3
79
- start_period: 15s
80
-
81
- # Optional: Traefik reverse proxy for production deployment
82
- traefik:
83
- image: traefik:v3.1
84
- container_name: traefik
85
- restart: unless-stopped
86
- profiles:
87
- - proxy
88
- ports:
89
- - "80:80"
90
- - "443:443"
91
- - "8080:8080" # Traefik dashboard (disable in production)
92
- environment:
93
- - TRAEFIK_API_DASHBOARD=true
94
- - TRAEFIK_API_INSECURE=true
95
- - TRAEFIK_ENTRYPOINTS_WEB_ADDRESS=:80
96
- - TRAEFIK_ENTRYPOINTS_WEBSECURE_ADDRESS=:443
97
- - TRAEFIK_PROVIDERS_DOCKER=true
98
- - TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT=false
99
- - TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_EMAIL=${ACME_EMAIL:-admin@example.com}
100
- - TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_STORAGE=/letsencrypt/acme.json
101
- - TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_HTTPCHALLENGE_ENTRYPOINT=web
102
- volumes:
103
- - /var/run/docker.sock:/var/run/docker.sock:ro
104
- - ./letsencrypt:/letsencrypt
105
- networks:
106
- - human-mcp-network
107
-
108
- # Optional: Redis for session storage (if needed for scaling)
109
- redis:
110
- image: redis:7-alpine
111
- container_name: human-mcp-redis
112
- restart: unless-stopped
113
- profiles:
114
- - redis
115
- ports:
116
- - "6379:6379"
117
- volumes:
118
- - redis-data:/data
119
- networks:
120
- - human-mcp-network
121
- command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
122
-
123
- volumes:
124
- redis-data:
125
-
126
- networks:
127
- human-mcp-network:
128
- driver: bridge
package/docs/README.md DELETED
@@ -1,51 +0,0 @@
1
- # Human MCP Documentation
2
-
3
- This directory contains comprehensive documentation for the Human MCP project. Navigate through the documentation using the links below for the most current information about the project's architecture, roadmap, and implementation details.
4
-
5
- ## Documentation Index
6
-
7
- ### 📋 Project Overview
8
- - **[Project Roadmap](project-roadmap.md)** - Complete development roadmap, phases, and vision through 2025
9
- - **[Project Overview & PDR](project-overview-pdr.md)** - Project overview and product development requirements
10
- - **[Codebase Summary](codebase-summary.md)** - Comprehensive overview of the current codebase
11
-
12
- ### 🏗️ Architecture & Development
13
- - **[Architecture & Code Standards](codebase-structure-architecture-code-standards.md)** - Technical architecture, code organization, and development standards
14
-
15
- ## Quick Navigation
16
-
17
- ### For Developers
18
- If you're looking to contribute to or understand the Human MCP codebase:
19
- 1. Start with **[Codebase Summary](codebase-summary.md)** for a high-level overview
20
- 2. Review **[Architecture & Code Standards](codebase-structure-architecture-code-standards.md)** for technical details
21
- 3. Check the **[Project Roadmap](project-roadmap.md)** to understand future development plans
22
-
23
- ### For Product Managers
24
- If you're interested in the product vision and requirements:
25
- 1. Begin with **[Project Overview & PDR](project-overview-pdr.md)** for product requirements
26
- 2. Review **[Project Roadmap](project-roadmap.md)** for development phases and timeline
27
- 3. Reference **[Architecture & Code Standards](codebase-structure-architecture-code-standards.md)** for technical constraints
28
-
29
- ### For Users & Integrators
30
- If you're using Human MCP in your projects:
31
- 1. Start with the main **[README.md](../README.md)** for setup instructions
32
- 2. Check **[Project Overview & PDR](project-overview-pdr.md)** for capability details
33
- 3. Refer to **[Project Roadmap](project-roadmap.md)** for upcoming features
34
-
35
- ## Documentation Standards
36
-
37
- All documentation follows these principles:
38
- - **Accuracy**: Documentation reflects the current state of the codebase
39
- - **Completeness**: Comprehensive coverage of features and architecture
40
- - **Clarity**: Written for both technical and non-technical audiences
41
- - **Currency**: Regularly updated to match code changes
42
- - **Cross-referencing**: Linked navigation between related documents
43
-
44
- ## Last Updated
45
-
46
- This documentation structure was established to support the project roadmap and ensure comprehensive coverage of the Human MCP development vision through 2025.
47
-
48
- ---
49
-
50
- **Quick Links:**
51
- - [Main README](../README.md) | [Project Roadmap](project-roadmap.md) | [Architecture](codebase-structure-architecture-code-standards.md) | [Overview](project-overview-pdr.md)
@@ -1,428 +0,0 @@
1
- # Human MCP - Codebase Structure, Architecture & Code Standards
2
-
3
- ## Project Architecture
4
-
5
- ### High-Level Architecture
6
-
7
- Human MCP follows a modular, event-driven architecture built around the Model Context Protocol (MCP). The system is designed as a server that exposes multimodal analysis capabilities through standardized MCP tools.
8
-
9
- #### Current Architecture (Phase 1 - v1.2.1)
10
- ```
11
- ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
12
- │ MCP Client │◄──►│ Human MCP │◄──►│ Google Gemini │
13
- │ (AI Agent) │ │ Server │ │ Vision API │
14
- └─────────────────┘ └──────────────────┘ └─────────────────┘
15
-
16
-
17
- ┌──────────────────┐
18
- │ Media Processors │
19
- │ (Image/Video/GIF) │
20
- └──────────────────┘
21
-
22
-
23
- ┌──────────────────┐
24
- │ System Tools │
25
- │ (ffmpeg/sharp) │
26
- └──────────────────┘
27
- ```
28
-
29
- #### Target Architecture (Full Roadmap - v2.0.0 by End 2025)
30
-
31
- For complete architectural evolution and development phases, see **[Project Roadmap](project-roadmap.md)** - Target Architecture section.
32
-
33
- The roadmap extends the current visual analysis foundation to include:
34
- - **Phase 2**: Document Understanding (Eyes extension for PDFs, Word docs, Excel)
35
- - **Phase 3**: Audio Processing (Ears - speech-to-text, audio analysis)
36
- - **Phase 4**: Speech Generation (Mouth - text-to-speech, narration)
37
- - **Phase 5**: Content Generation (Hands - image/video creation)
38
-
39
- ### Core Components
40
-
41
- 1. **MCP Server Layer**: Protocol implementation and tool registration
42
- 2. **Tool Layer**: Visual analysis and comparison tools (`eyes.analyze`, `eyes.compare`)
43
- 3. **Processing Layer**: Media-specific processors for different content types
44
- 4. **Integration Layer**: External service integration (Gemini API)
45
- 5. **Utility Layer**: Configuration, logging, error handling, and validation
46
-
47
- ## Directory Structure
48
-
49
- ```
50
- human-mcp/
51
- ├── .claude/ # Claude Code agent configurations
52
- │ ├── agents/ # Specialized agent definitions
53
- │ ├── commands/ # Custom commands and workflows
54
- │ └── hooks/ # Git hooks and automation scripts
55
- ├── .github/
56
- │ └── workflows/ # GitHub Actions for CI/CD
57
- ├── .serena/ # Serena MCP tool configuration
58
- ├── docs/ # Project documentation
59
- │ ├── project-roadmap.md # Development roadmap and future vision
60
- │ ├── project-overview-pdr.md # Project overview and requirements
61
- │ ├── codebase-summary.md # Generated codebase overview
62
- │ └── codebase-structure-architecture-code-standards.md # This file
63
- ├── examples/ # Usage examples and demonstrations
64
- │ └── debugging-session.ts
65
- ├── src/ # Source code
66
- │ ├── index.ts # Entry point - starts stdio server
67
- │ ├── server.ts # MCP server setup and initialization
68
- │ ├── tools/ # MCP tools implementation
69
- │ │ └── eyes/ # Vision analysis tools
70
- │ │ ├── index.ts # Tool registration and orchestration
71
- │ │ ├── schemas.ts # Zod validation schemas
72
- │ │ ├── processors/ # Media type processors
73
- │ │ │ ├── image.ts # Image processing logic
74
- │ │ │ ├── video.ts # Video processing with ffmpeg
75
- │ │ │ └── gif.ts # GIF frame extraction
76
- │ │ └── utils/ # Tool-specific utilities
77
- │ │ ├── gemini-client.ts # Google Gemini API client
78
- │ │ └── formatters.ts # Output formatting utilities
79
- │ ├── prompts/ # Pre-built debugging prompts
80
- │ │ ├── index.ts # Prompt registration
81
- │ │ └── debugging-prompts.ts # Debugging workflow templates
82
- │ ├── resources/ # MCP resources (documentation)
83
- │ │ ├── index.ts # Resource registration
84
- │ │ └── documentation.ts # Tool documentation and examples
85
- │ ├── types/ # TypeScript type definitions
86
- │ │ └── index.ts # Shared type definitions
87
- │ └── utils/ # Core utilities
88
- │ ├── config.ts # Environment-based configuration
89
- │ ├── logger.ts # Structured logging
90
- │ └── errors.ts # Error handling and formatting
91
- ├── tests/ # Test suites
92
- │ ├── setup.ts # Test environment setup
93
- │ ├── unit/ # Unit tests
94
- │ │ ├── config.test.ts # Configuration validation tests
95
- │ │ └── formatters.test.ts # Output formatting tests
96
- │ └── integration/ # Integration tests
97
- │ └── server.test.ts # MCP server functionality tests
98
- ├── dist/ # Built output (generated)
99
- ├── package.json # Project dependencies and scripts
100
- ├── tsconfig.json # TypeScript configuration
101
- ├── CLAUDE.md # Claude Code project instructions
102
- ├── QUICKSTART.md # Quick setup guide
103
- └── README.md # Project overview and setup
104
- ```
105
-
106
- ## Architectural Patterns
107
-
108
- ### 1. Model Context Protocol (MCP) Architecture
109
-
110
- **Pattern**: Server-Client Protocol Implementation
111
- - **Server Component**: Human MCP implements MCP server specification
112
- - **Transport Layer**: Stdio transport for command-line integration
113
- - **Tool Registration**: Dynamic tool registration with schema validation
114
- - **Resource Exposure**: Documentation and examples exposed as MCP resources
115
-
116
- ```typescript
117
- // MCP Server Setup Pattern
118
- export async function createServer() {
119
- const config = loadConfig();
120
- const server = new McpServer({
121
- name: "human-mcp",
122
- version: "1.0.0",
123
- });
124
-
125
- await registerEyesTool(server, config);
126
- await registerPrompts(server);
127
- await registerResources(server);
128
-
129
- return server;
130
- }
131
- ```
132
-
133
- ### 2. Plugin-based Tool Architecture
134
-
135
- **Pattern**: Modular Tool Registration
136
- - **Tool Interface**: Standardized tool registration with schema validation
137
- - **Processor Strategy**: Different processors for different media types
138
- - **Configuration Injection**: Environment-based configuration passed to tools
139
-
140
- ```typescript
141
- // Tool Registration Pattern
142
- server.registerTool(
143
- "eyes.analyze",
144
- {
145
- title: "Vision Analysis Tool",
146
- description: "Analyze images, videos, and GIFs using AI vision capabilities",
147
- inputSchema: EyesInputSchema
148
- },
149
- async (args) => {
150
- return await handleAnalyze(geminiClient, args, config);
151
- }
152
- );
153
- ```
154
-
155
- ### 3. Strategy Pattern for Media Processing
156
-
157
- **Pattern**: Media Type Specific Processing
158
- - **Image Processor**: Direct processing with Gemini Vision API
159
- - **Video Processor**: Frame extraction using ffmpeg, then batch analysis
160
- - **GIF Processor**: Frame extraction using Sharp, animation sequence analysis
161
-
162
- ```typescript
163
- // Strategy Pattern Implementation
164
- switch (type) {
165
- case "image":
166
- result = await processImage(model, source, options);
167
- break;
168
- case "video":
169
- result = await processVideo(model, source, options);
170
- break;
171
- case "gif":
172
- result = await processGif(model, source, options);
173
- break;
174
- default:
175
- throw new Error(`Unsupported media type: ${type}`);
176
- }
177
- ```
178
-
179
- ### 4. Configuration-driven Architecture
180
-
181
- **Pattern**: Environment-based Configuration with Validation
182
- - **Schema Validation**: Zod schemas for runtime configuration validation
183
- - **Environment Variables**: All configuration via environment variables
184
- - **Default Values**: Sensible defaults with override capability
185
- - **Type Safety**: Full TypeScript typing for configuration objects
186
-
187
- ## Code Standards & Best Practices
188
-
189
- ### 1. TypeScript Standards
190
-
191
- #### Type Safety
192
- - **Strict Mode**: All TypeScript strict checks enabled
193
- - **No Implicit Any**: Explicit typing required for all parameters
194
- - **Runtime Validation**: Zod schemas for external input validation
195
- - **Path Mapping**: `@/*` aliases for clean imports
196
-
197
- ```typescript
198
- // Type-safe configuration pattern
199
- const ConfigSchema = z.object({
200
- gemini: z.object({
201
- apiKey: z.string().min(1, "Google Gemini API key is required"),
202
- model: z.string().default("gemini-2.5-flash"),
203
- }),
204
- // ... other config
205
- });
206
-
207
- export type Config = z.infer<typeof ConfigSchema>;
208
- ```
209
-
210
- #### Module Organization
211
- - **ESNext Modules**: Modern ES module syntax throughout
212
- - **Explicit Extensions**: `.js` extensions for all imports
213
- - **Barrel Exports**: Index files for clean public APIs
214
- - **Single Responsibility**: One primary export per file
215
-
216
- ### 2. Error Handling Patterns
217
-
218
- #### Centralized Error Management
219
- - **Error Utility**: Centralized error handling in `utils/errors.ts`
220
- - **Structured Errors**: Consistent error format across all tools
221
- - **MCP Compliance**: Error responses conform to MCP specification
222
- - **Logging Integration**: All errors logged with context
223
-
224
- ```typescript
225
- // Centralized error handling pattern
226
- export function handleError(error: unknown): McpError {
227
- if (error instanceof Error) {
228
- return {
229
- code: ErrorCode.InternalError,
230
- message: error.message
231
- };
232
- }
233
- return {
234
- code: ErrorCode.InternalError,
235
- message: "An unknown error occurred"
236
- };
237
- }
238
- ```
239
-
240
- #### Graceful Degradation
241
- - **Try-Catch Blocks**: Comprehensive error catching
242
- - **Fallback Behaviors**: Graceful handling of missing dependencies
243
- - **User-Friendly Messages**: Clear error messages for end users
244
- - **Recovery Mechanisms**: Retry logic for transient failures
245
-
246
- ### 3. Logging Standards
247
-
248
- #### Structured Logging
249
- - **Log Levels**: debug, info, warn, error with configuration
250
- - **Contextual Information**: Request IDs, tool names, processing steps
251
- - **Performance Metrics**: Timing information for operations
252
- - **Privacy Awareness**: No sensitive data in logs
253
-
254
- ```typescript
255
- // Structured logging pattern
256
- logger.info(`Analyzing ${type} with detail level: ${detail_level}`, {
257
- toolName: 'eyes.analyze',
258
- mediaType: type,
259
- detailLevel: detail_level,
260
- processingTime: Date.now() - startTime
261
- });
262
- ```
263
-
264
- ### 4. Input Validation Standards
265
-
266
- #### Schema-driven Validation
267
- - **Zod Schemas**: Runtime validation for all external inputs
268
- - **Type Inference**: TypeScript types derived from schemas
269
- - **Descriptive Errors**: Clear validation error messages
270
- - **Optional Parameters**: Proper handling of optional inputs
271
-
272
- ```typescript
273
- // Schema validation pattern
274
- export const EyesInputSchema = z.object({
275
- source: z.string().describe("URL, file path, or base64 encoded content"),
276
- type: z.enum(["image", "video", "gif"]).describe("Type of visual content"),
277
- detail_level: z.enum(["quick", "detailed"]).default("detailed"),
278
- // ... other fields
279
- });
280
-
281
- export type EyesInput = z.infer<typeof EyesInputSchema>;
282
- ```
283
-
284
- ### 5. Security Standards
285
-
286
- #### API Key Management
287
- - **Environment Variables**: API keys only via environment variables
288
- - **No Hardcoding**: Never commit API keys or secrets
289
- - **Configuration Validation**: Required secrets validated at startup
290
- - **Secure Defaults**: Security-first configuration defaults
291
-
292
- #### Input Sanitization
293
- - **Path Validation**: Safe file path handling
294
- - **URL Validation**: Proper URL parsing and validation
295
- - **Content Limits**: Size limits for uploaded content
296
- - **Rate Limiting**: Protection against abuse
297
-
298
- ### 6. Performance Standards
299
-
300
- #### Memory Management
301
- - **Stream Processing**: Large files processed in streams where possible
302
- - **Cleanup**: Proper cleanup of temporary files and resources
303
- - **Memory Limits**: Awareness of memory constraints for media processing
304
- - **Garbage Collection**: Minimal object retention
305
-
306
- #### Async/Await Patterns
307
- - **Promise-based**: All async operations use Promise patterns
308
- - **Error Propagation**: Proper async error handling
309
- - **Concurrent Processing**: Parallel processing where beneficial
310
- - **Timeout Handling**: Configurable timeouts for operations
311
-
312
- ```typescript
313
- // Async processing pattern with timeout
314
- async function processWithTimeout<T>(
315
- operation: () => Promise<T>,
316
- timeout: number
317
- ): Promise<T> {
318
- const timeoutPromise = new Promise<never>((_, reject) => {
319
- setTimeout(() => reject(new Error('Operation timeout')), timeout);
320
- });
321
-
322
- return Promise.race([operation(), timeoutPromise]);
323
- }
324
- ```
325
-
326
- ### 7. Testing Standards
327
-
328
- #### Test Organization
329
- - **Unit Tests**: Individual function and class testing
330
- - **Integration Tests**: End-to-end MCP server testing
331
- - **Test Setup**: Centralized test environment configuration
332
- - **Mock Usage**: Appropriate mocking of external services
333
-
334
- #### Test Coverage
335
- - **Core Functions**: 100% coverage for utility functions
336
- - **Error Paths**: Testing of error handling scenarios
337
- - **Configuration**: Testing of configuration validation
338
- - **Edge Cases**: Testing of boundary conditions
339
-
340
- ### 8. Documentation Standards
341
-
342
- #### Code Documentation
343
- - **JSDoc Comments**: Comprehensive function documentation
344
- - **Type Annotations**: Clear type information
345
- - **Usage Examples**: Example code in documentation
346
- - **Architecture Notes**: High-level design documentation
347
-
348
- #### API Documentation
349
- - **Schema Documentation**: Clear description of input/output schemas
350
- - **Tool Descriptions**: Comprehensive tool functionality descriptions
351
- - **Integration Guides**: How to use the MCP server
352
- - **Configuration Reference**: Complete configuration option documentation
353
-
354
- ## Development Workflow
355
-
356
- ### 1. Development Commands
357
-
358
- ```bash
359
- # Development with hot reload
360
- bun run dev
361
-
362
- # Production build
363
- bun run build
364
-
365
- # Run production build
366
- bun run start
367
-
368
- # Run tests
369
- bun test
370
-
371
- # Type checking
372
- bun run typecheck
373
-
374
- # Interactive tool testing
375
- bun run inspector
376
- ```
377
-
378
- ### 2. Code Quality Checks
379
-
380
- - **TypeScript Compilation**: No compilation errors allowed
381
- - **Test Passing**: All tests must pass before commits
382
- - **Linting**: Code style consistency (relaxed for productivity)
383
- - **Security Scanning**: Basic security checks on dependencies
384
-
385
- ### 3. Release Process
386
-
387
- - **Semantic Versioning**: Automated version management
388
- - **GitHub Actions**: Automated testing and release
389
- - **Changelog**: Automated changelog generation
390
- - **npm Publishing**: Automated package publishing
391
-
392
- ## Integration Patterns
393
-
394
- ### 1. MCP Client Integration
395
-
396
- ```javascript
397
- // Example MCP client integration
398
- const client = new McpClient();
399
- await client.connect(stdio('bun', ['run', 'src/index.ts']));
400
-
401
- const result = await client.callTool('eyes.analyze', {
402
- source: '/path/to/screenshot.png',
403
- type: 'image',
404
- analysis_type: 'ui_debug'
405
- });
406
- ```
407
-
408
- ### 2. External Service Integration
409
-
410
- ```typescript
411
- // Gemini API integration pattern
412
- export class GeminiClient {
413
- constructor(private config: Config) {
414
- this.genAI = new GoogleGenerativeAI(config.gemini.apiKey);
415
- }
416
-
417
- getModel(detailLevel: 'quick' | 'detailed'): GenerativeModel {
418
- const modelName = detailLevel === 'quick'
419
- ? 'gemini-2.5-flash'
420
- : this.config.gemini.model;
421
- return this.genAI.getGenerativeModel({ model: modelName });
422
- }
423
- }
424
- ```
425
-
426
- ## Conclusion
427
-
428
- The Human MCP codebase follows modern TypeScript best practices with a focus on modularity, type safety, and robust error handling. The architecture enables easy extension with new tools and processors while maintaining clean separation of concerns. The comprehensive configuration system and error handling patterns ensure reliable operation across different environments and use cases.