motionmcp 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.
@@ -0,0 +1,15 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npm init:*)",
5
+ "Bash(npm install:*)",
6
+ "Bash(mkdir:*)",
7
+ "Bash(git init:*)",
8
+ "Bash(git add:*)",
9
+ "WebFetch(domain:modelcontextprotocol.io)",
10
+ "WebFetch(domain:github.com)",
11
+ "Bash(chmod:*)"
12
+ ],
13
+ "deny": []
14
+ }
15
+ }
package/.env.example ADDED
@@ -0,0 +1,3 @@
1
+ MOTION_API_KEY=your_motion_api_key_here
2
+ PORT=3000
3
+ NODE_ENV=development
package/README.md ADDED
@@ -0,0 +1,510 @@
1
+ # Motion MCP Server
2
+
3
+ A Model Context Protocol (MCP) server that provides LLMs with direct access to the Motion API for task and project management. This server implements the MCP protocol to enable seamless integration between AI assistants and Motion's productivity platform.
4
+
5
+ ## Preview
6
+
7
+ <a href="sample.png"><img src="sample.png" alt="Motion MCP Server Preview" width="400" /></a>
8
+
9
+ *Click the image above to view full size*
10
+
11
+ ## Features
12
+
13
+ - **MCP Protocol Implementation**: Full Model Context Protocol support for LLM integration
14
+ - **Motion API Integration**: Complete CRUD operations for projects, tasks, workspaces, and users
15
+ - **18 Built-in Tools**: Comprehensive set of tools for Motion management with AI-powered intelligence
16
+ - **Context Awareness**: Real-time workspace context, recent activity, and intelligent suggestions
17
+ - **Smart Workspace Management**: Automatic workspace detection and selection
18
+ - **Intelligent Search**: Semantic search across tasks and projects with relevance scoring
19
+ - **Workload Analytics**: Comprehensive workload analysis with overdue tasks and deadline tracking
20
+ - **Workflow Intelligence**: Smart scheduling, bulk operations, and next action suggestions
21
+ - **Project Templates**: Pre-built project templates with intelligent task creation
22
+ - **Enhanced Task Creation**: Supports all Motion API parameters with intelligent defaults
23
+ - **MCP-Compliant Logging**: Structured JSON logging to stderr for debugging
24
+ - **JSON Schema Validation**: Proper input validation and type safety
25
+ - **Robust Error Handling**: Detailed error messages and fallback mechanisms
26
+ - **API Key Authentication**: Secure Motion API integration
27
+
28
+ ## Prerequisites
29
+
30
+ - Node.js 18 or higher
31
+ - Motion API key (get from https://app.usemotion.com/settings/api)
32
+
33
+ ## Installation
34
+
35
+ 1. Clone the repository
36
+ 2. Install dependencies:
37
+ ```bash
38
+ npm install
39
+ ```
40
+
41
+ 3. Create a `.env` file based on `.env.example`:
42
+ ```bash
43
+ cp .env.example .env
44
+ ```
45
+
46
+ 4. Update the `.env` file with your Motion API key:
47
+ ```
48
+ MOTION_API_KEY=your_motion_api_key_here
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ The Motion MCP Server runs as a Model Context Protocol server for direct LLM integration:
54
+
55
+ ```bash
56
+ # Run the MCP server
57
+ npm run mcp
58
+
59
+ # Or run directly
60
+ node src/mcp-server.js
61
+ ```
62
+
63
+ ## MCP Tools
64
+
65
+ The MCP server provides 18 intelligent tools for Motion integration with enhanced AI capabilities:
66
+
67
+ ### Context & Intelligence
68
+ - `get_motion_context` - Get comprehensive workspace context, recent activity, and smart suggestions
69
+ - `search_motion_content` - Intelligent search across tasks and projects with semantic relevance
70
+ - `analyze_motion_workload` - Analyze workload distribution, overdue tasks, and productivity insights
71
+ - `suggest_next_actions` - AI-powered suggestions for next actions based on current state
72
+
73
+ ### Project Management
74
+ - `create_motion_project` - Create a new project with workspace auto-detection
75
+ - `create_project_template` - Create projects from intelligent templates (software dev, marketing, etc.)
76
+ - `list_motion_projects` - List projects with workspace filtering support
77
+ - `get_motion_project` - Get project details by ID
78
+ - `update_motion_project` - Update project properties
79
+ - `delete_motion_project` - Delete a project
80
+
81
+ ### Task Management
82
+ - `create_motion_task` - Create a new task with intelligent workspace/project resolution
83
+ - `list_motion_tasks` - List tasks with workspace and project filtering
84
+ - `get_motion_task` - Get task details by ID
85
+ - `update_motion_task` - Update task properties
86
+ - `delete_motion_task` - Delete a task
87
+ - `bulk_update_tasks` - Update multiple tasks simultaneously
88
+ - `smart_schedule_tasks` - AI-powered intelligent task scheduling
89
+
90
+ ### Workspace & User Info
91
+ - `list_motion_workspaces` - List all workspaces with enhanced details
92
+ - `list_motion_users` - List all users
93
+
94
+ ## Enhanced Tool Features
95
+
96
+ ### Smart Workspace Management
97
+ - **Auto-detection**: Automatically uses default workspace when none specified
98
+ - **Name resolution**: Find workspaces by name instead of requiring IDs
99
+ - **Intelligent defaults**: Prefers "Personal" workspaces as default
100
+ - **Fallback handling**: Graceful handling when workspace resolution fails
101
+
102
+ ### Advanced Task Creation
103
+ The `create_motion_task` tool now supports all Motion API parameters:
104
+
105
+ **Basic Parameters:**
106
+ - `name` (required) - Task title
107
+ - `description` - Markdown-supported task description
108
+ - `workspaceId` / `workspaceName` - Workspace specification (auto-detects if omitted)
109
+ - `projectId` / `projectName` - Project assignment (optional)
110
+
111
+ **Advanced Parameters:**
112
+ - `status` - Task status (uses workspace default if omitted)
113
+ - `priority` - ASAP, HIGH, MEDIUM, or LOW
114
+ - `dueDate` - ISO 8601 date (required for scheduled tasks)
115
+ - `duration` - Minutes (number), "NONE", or "REMINDER"
116
+ - `assigneeId` - User ID for task assignment
117
+ - `labels` - Array of label names
118
+ - `autoScheduled` - Auto-scheduling configuration (object or null)
119
+
120
+ ### Intelligent Project Resolution
121
+ - **Name lookup**: Find projects by partial or exact name match
122
+ - **Workspace scoping**: Project searches are scoped to specific workspaces
123
+ - **Fuzzy matching**: Supports partial name matching for easier use
124
+ - **Error feedback**: Clear messages when projects aren't found
125
+
126
+ ## AI-Powered Intelligence Features
127
+
128
+ ### Context Awareness
129
+ The `get_motion_context` tool provides LLMs with comprehensive situational awareness:
130
+
131
+ **Real-time Context:**
132
+ - Current default workspace and available workspaces
133
+ - User information and permissions
134
+ - Recent activity across tasks and projects
135
+ - Current workload distribution and status
136
+
137
+ **Intelligent Suggestions:**
138
+ - Overdue tasks requiring immediate attention
139
+ - High-priority items to focus on next
140
+ - Upcoming deadlines and time-sensitive work
141
+ - Project status insights and recommendations
142
+
143
+ **Example Usage:**
144
+ ```
145
+ LLM: Let me get your current Motion context to understand your situation.
146
+ Tool: get_motion_context
147
+ Result: You're in "Development" workspace with 15 active tasks. You have 3 overdue tasks and 5 high-priority items. Recent activity shows focus on "API Integration" project.
148
+ Suggestions:
149
+ - Address 3 overdue tasks (Task A, B, C)
150
+ - Continue work on high-priority "Security Review"
151
+ - Upcoming deadline: "Release Planning" due tomorrow
152
+ ```
153
+
154
+ ### Intelligent Search
155
+ The `search_motion_content` tool provides semantic search capabilities:
156
+
157
+ **Advanced Search Features:**
158
+ - Content-aware search across task descriptions and project details
159
+ - Relevance scoring based on exact matches, partial matches, and priority
160
+ - Scoped search (tasks only, projects only, or both)
161
+ - Priority boosting for urgent items
162
+
163
+ **Example Usage:**
164
+ ```
165
+ LLM: Let me search for anything related to "API security"
166
+ Tool: search_motion_content
167
+ Args: {"query": "API security", "searchScope": "both"}
168
+ Result: Found 4 relevant items:
169
+ - [task] API Security Review (ID: task_789) - Relevance: 95
170
+ - [project] Security Audit (ID: proj_456) - Relevance: 70
171
+ - [task] Update API documentation (ID: task_012) - Relevance: 45
172
+ ```
173
+
174
+ ### Workload Analytics
175
+ The `analyze_motion_workload` tool provides comprehensive productivity insights:
176
+
177
+ **Analytics Capabilities:**
178
+ - Task distribution by status, priority, and project
179
+ - Overdue task identification and counting
180
+ - Upcoming deadline tracking and alerts
181
+ - Project health and progress monitoring
182
+ - Time-based analysis (today, this week, this month)
183
+
184
+ **Example Usage:**
185
+ ```
186
+ LLM: Let me analyze your current workload.
187
+ Tool: analyze_motion_workload
188
+ Args: {"timeframe": "this_week", "includeProjects": true}
189
+ Result: Workload Analysis (this_week):
190
+ - Total Tasks: 23
191
+ - Overdue Tasks: 3
192
+ - Upcoming Deadlines: 7
193
+ - Task Distribution:
194
+ - In Progress: 8 tasks
195
+ - Todo: 12 tasks
196
+ - Completed: 3 tasks
197
+ - Project Insights:
198
+ - 4 active projects
199
+ - 2 projects behind schedule
200
+ ```
201
+
202
+ ### Smart Scheduling
203
+ The `smart_schedule_tasks` tool provides AI-powered task optimization:
204
+
205
+ **Intelligent Scheduling Features:**
206
+ - Priority-based task ordering (ASAP → HIGH → MEDIUM → LOW)
207
+ - Deadline-aware scheduling with urgency detection
208
+ - Workload balancing and buffer time inclusion
209
+ - Conflict detection and resolution suggestions
210
+ - Automatic unscheduled task discovery
211
+
212
+ **Example Usage:**
213
+ ```
214
+ LLM: Let me intelligently schedule your unscheduled tasks.
215
+ Tool: smart_schedule_tasks
216
+ Args: {"schedulingPreferences": {"prioritizeDeadlines": true}}
217
+ Result: Scheduled 8 tasks optimally:
218
+ - Task ID: task_456 -> 9:00 AM (ASAP priority)
219
+ - Task ID: task_789 -> 10:30 AM (Due today)
220
+ - Task ID: task_012 -> 2:00 PM (HIGH priority)
221
+ ```
222
+
223
+ ### Workflow Intelligence
224
+ The `suggest_next_actions` tool provides proactive assistance:
225
+
226
+ **Smart Suggestions Based On:**
227
+ - Current task priorities and deadlines
228
+ - Project status and momentum
229
+ - Historical patterns and preferences
230
+ - Workload balance and capacity
231
+ - Context-aware recommendations (daily planning, project review, etc.)
232
+
233
+ **Example Usage:**
234
+ ```
235
+ LLM: What should I focus on next?
236
+ Tool: suggest_next_actions
237
+ Args: {"context": "daily planning", "maxSuggestions": 3}
238
+ Result: Suggested Next Actions:
239
+ ✅ Complete "Security Review" (task_789) - ASAP priority, due today
240
+ ⏰ Start "Database Migration" (task_456) - Due in 2 days
241
+ 🔄 Review stalled project: "Mobile App" - No recent activity
242
+ ```
243
+
244
+ ## Quick Start for LLM Context
245
+
246
+ **For optimal LLM assistance, start with these tools:**
247
+
248
+ 1. **`get_motion_context`** - Get comprehensive workspace overview and current state
249
+ 2. **`analyze_motion_workload`** - Understand current workload and priorities
250
+ 3. **`suggest_next_actions`** - Get AI-powered recommendations for what to focus on next
251
+
252
+ **Example Intelligent Workflow:**
253
+ ```
254
+ User: "Help me plan my day"
255
+
256
+ LLM: I'll help you plan your day efficiently. Let me first understand your current situation.
257
+
258
+ 1. Getting your Motion context...
259
+ Tool: get_motion_context
260
+ Result: You're in "Work" workspace with 12 active tasks, 2 overdue items, and 4 high-priority tasks.
261
+
262
+ 2. Analyzing your current workload...
263
+ Tool: analyze_motion_workload
264
+ Args: {"timeframe": "today"}
265
+ Result: Today you have 6 tasks, 2 are overdue, 3 due by end of day.
266
+
267
+ 3. Generating smart suggestions...
268
+ Tool: suggest_next_actions
269
+ Args: {"context": "daily planning"}
270
+ Result: Recommended focus:
271
+ - ✅ Complete overdue "Security Review" (ASAP priority)
272
+ - ⏰ Finish "Database Migration" (due today)
273
+ - 🚀 Start "Feature Testing" (high priority, good momentum)
274
+
275
+ Based on this analysis, I recommend starting with the overdue Security Review task since it's marked ASAP priority, then moving to the Database Migration that's due today. This will clear your urgent items and give you momentum for the day.
276
+
277
+ Would you like me to help schedule these tasks or create any new tasks for your day?
278
+ ```
279
+
280
+ ## MCP Integration Examples
281
+
282
+ ### Using with Claude Desktop
283
+ Add to your `claude_desktop_config.json`:
284
+
285
+ ```json
286
+ {
287
+ "mcpServers": {
288
+ "motion": {
289
+ "command": "node",
290
+ "args": ["/path/to/MotionMCP/src/mcp-server.js"],
291
+ "env": {
292
+ "MOTION_API_KEY": "your_motion_api_key_here"
293
+ }
294
+ }
295
+ }
296
+ }
297
+ ```
298
+
299
+ ### LLM Tool Usage Examples
300
+
301
+ **Create a simple task:**
302
+ ```
303
+ LLM: I'll create a new task for you.
304
+ Tool: create_motion_task
305
+ Args: {"name": "Review quarterly reports"}
306
+ Result: Successfully created task "Review quarterly reports" with ID: task_123 in workspace ws_456
307
+ ```
308
+
309
+ **Create an advanced task with project assignment:**
310
+ ```
311
+ LLM: I'll create a detailed task in your development project.
312
+ Tool: create_motion_task
313
+ Args: {
314
+ "name": "Complete API integration",
315
+ "description": "Integrate with Motion API and test all endpoints",
316
+ "workspaceName": "Development",
317
+ "projectName": "Feature Release",
318
+ "priority": "HIGH",
319
+ "dueDate": "2025-05-30T17:00:00.000Z",
320
+ "duration": 120,
321
+ "labels": ["api", "integration", "urgent"]
322
+ }
323
+ Result: Successfully created task "Complete API integration" with ID: task_789 in project proj_456 in workspace ws_123
324
+ ```
325
+
326
+ **List projects with workspace filtering:**
327
+ ```
328
+ LLM: Let me check your development projects.
329
+ Tool: list_motion_projects
330
+ Args: {"workspaceName": "Development"}
331
+ Result: Found 3 projects in Development workspace:
332
+ - Feature Release (ID: proj_456) - Status: In Progress
333
+ - Bug Fixes (ID: proj_789) - Status: Todo
334
+ - Documentation (ID: proj_012) - Status: Backlog
335
+ ```
336
+
337
+ **List tasks with intelligent filtering:**
338
+ ```
339
+ LLM: Let me check your current tasks.
340
+ Tool: list_motion_tasks
341
+ Args: {"workspaceName": "Personal", "projectName": "Website Redesign"}
342
+ Result: Found 5 tasks in Website Redesign project:
343
+ - Fix responsive layout (ID: task_456) - Status: In Progress
344
+ - Update color scheme (ID: task_789) - Status: Todo
345
+ - Optimize images (ID: task_012) - Status: Done
346
+ - Test on mobile (ID: task_345) - Status: Todo
347
+ - Deploy to staging (ID: task_678) - Status: Backlog
348
+ ```
349
+
350
+ ## Configuration
351
+
352
+ ### Environment Variables
353
+
354
+ | Variable | Description | Default |
355
+ | ---------------- | ------------------------------ | ------- |
356
+ | `MOTION_API_KEY` | Your Motion API key (required) | - |
357
+
358
+ ## Motion API Documentation
359
+
360
+ For detailed information about Motion's API, visit: https://docs.usemotion.com/
361
+
362
+ ## Error Handling & Logging
363
+
364
+ The server includes comprehensive error handling and MCP-compliant logging:
365
+
366
+ ### MCP-Compliant Logging
367
+ - **Structured JSON logs** to stderr for MCP compliance
368
+ - **Detailed context** including method names, IDs, and API responses
369
+ - **Error tracking** with API status codes and messages
370
+ - **Performance monitoring** with request/response timing
371
+
372
+ ### Enhanced Error Handling
373
+ - **Smart workspace resolution** with fallback to defaults
374
+ - **Project lookup validation** with helpful error messages
375
+ - **API response structure handling** for wrapped/unwrapped responses
376
+ - **Input validation** with detailed parameter requirements
377
+ - **Graceful degradation** when optional features fail
378
+
379
+ ### Error Response Examples
380
+ ```json
381
+ // Missing workspace error
382
+ {"error": "workspaceId is required and no default workspace could be found"}
383
+
384
+ // Project not found error
385
+ {"error": "Project 'Marketing Campaign' not found in workspace"}
386
+
387
+ // Invalid parameter error
388
+ {"error": "Task priority must be one of: ASAP, HIGH, MEDIUM, LOW"}
389
+ ```
390
+
391
+ ## Security
392
+
393
+ - API keys are never logged or exposed
394
+ - All sensitive information is kept out of logs
395
+ - Input validation on all endpoints
396
+ - MCP-compliant structured logging to stderr
397
+ - Workspace-scoped operations for data isolation
398
+
399
+ ## Architecture
400
+
401
+ The Motion MCP Server is designed as a focused MCP implementation:
402
+
403
+ ```
404
+ src/
405
+ ├── mcp-server.js # MCP protocol server implementation
406
+ ├── services/
407
+ │ └── motionApi.js # Enhanced Motion API service layer
408
+ └── utils/ # Utility functions
409
+ ```
410
+
411
+ ### Key Components
412
+
413
+ **MotionApiService (`motionApi.js`):**
414
+ - **Smart workspace detection** with default workspace resolution
415
+ - **Project lookup by name** with fuzzy matching capabilities
416
+ - **Enhanced error handling** with detailed context and fallbacks
417
+ - **MCP-compliant logging** with structured JSON output
418
+ - **API response handling** for Motion's wrapped response formats
419
+
420
+ **MCP Server (`mcp-server.js`):**
421
+ - **Intelligent parameter resolution** for workspace and project names
422
+ - **Enhanced tool definitions** with comprehensive parameter documentation
423
+ - **Robust error handling** with user-friendly error messages
424
+ - **Workspace-aware operations** for all project and task management
425
+
426
+ ## Recent Improvements
427
+
428
+ ### Version 2.0 Enhancements
429
+ - ✅ **MCP-Compliant Logging**: Replaced Winston with structured JSON logging to stderr
430
+ - ✅ **Smart Workspace Management**: Auto-detection and intelligent defaults for workspaces
431
+ - ✅ **Enhanced Task Creation**: Support for all Motion API parameters with intelligent resolution
432
+ - ✅ **Project Name Resolution**: Find projects by name with fuzzy matching
433
+ - ✅ **Robust Error Handling**: Detailed error messages with context and fallback mechanisms
434
+ - ✅ **API Response Handling**: Fixed handling of Motion's wrapped response formats (`{projects: [...]}`, `{workspaces: [...]}`)
435
+ - ✅ **Workspace-Aware Operations**: All tools now support workspace filtering and auto-detection
436
+ - ✅ **Improved Documentation**: Comprehensive parameter descriptions and usage examples
437
+
438
+ ### Version 2.1 Intelligence Enhancements
439
+ - ✅ **Context Awareness**: Real-time workspace context with activity tracking and intelligent suggestions
440
+ - ✅ **Intelligent Search**: Semantic search across tasks and projects with relevance scoring
441
+ - ✅ **Workload Analytics**: Comprehensive workload analysis with overdue tasks and deadline tracking
442
+ - ✅ **Smart Scheduling**: AI-powered task scheduling with priority and deadline optimization
443
+ - ✅ **Workflow Intelligence**: Proactive next action suggestions based on current state
444
+ - ✅ **Project Templates**: Pre-built intelligent templates for common project types
445
+ - ✅ **Bulk Operations**: Efficient batch updates for multiple tasks simultaneously
446
+ - ✅ **Enhanced Tool Count**: Expanded from 12 to 18 tools with AI-powered capabilities
447
+
448
+ ### Breaking Changes
449
+ - **Logging Format**: Changed from Winston file logging to MCP-compliant JSON stderr logging
450
+ - **Task Creation**: `workspaceId` is now auto-resolved if not provided (was previously required)
451
+ - **Response Handling**: Fixed array method errors by properly handling wrapped API responses
452
+
453
+ ## Debugging & Troubleshooting
454
+
455
+ ### MCP Logging
456
+ The server outputs structured JSON logs to stderr for debugging:
457
+ ```json
458
+ {"level":"info","msg":"Successfully fetched projects","method":"getProjects","count":3,"workspaceId":"ws_123","time":"2025-05-26T22:30:45.123Z"}
459
+ {"level":"error","msg":"Failed to create task","method":"createTask","error":"workspaceId is required","time":"2025-05-26T22:30:46.456Z"}
460
+ ```
461
+
462
+ ### Common Issues
463
+
464
+ **Task Creation Fails:**
465
+ - Ensure your Motion API key has task creation permissions
466
+ - Check that the workspace exists and is accessible
467
+ - Verify project names are spelled correctly (uses fuzzy matching)
468
+
469
+ **Workspace Not Found:**
470
+ - List workspaces first with `list_motion_workspaces`
471
+ - Use exact workspace names or IDs
472
+ - Check API key permissions for workspace access
473
+
474
+ **Project Resolution Issues:**
475
+ - Projects are searched within the specified workspace only
476
+ - Use partial names for fuzzy matching: "Marketing" will find "Marketing Campaign"
477
+ - Ensure the project exists in the target workspace
478
+
479
+ ### Debugging Tips
480
+ 1. **Check stderr output** for detailed MCP logs
481
+ 2. **Use `list_motion_workspaces`** to see available workspaces
482
+ 3. **Test with simple task creation** before using advanced parameters
483
+ 4. **Verify API key permissions** in Motion settings
484
+
485
+ ## How MCP Communication Works
486
+
487
+ 1. **LLM Discovery**: LLM calls `tools/list` to discover available tools
488
+ 2. **Tool Schema**: Server returns JSON schemas for each tool
489
+ 3. **Tool Execution**: LLM calls `tools/call` with tool name and arguments
490
+ 4. **Response**: Server executes Motion API call and returns structured result
491
+
492
+ **Example Protocol Flow:**
493
+ ```json
494
+ // LLM requests available tools
495
+ {"jsonrpc": "2.0", "id": 1, "method": "tools/list"}
496
+
497
+ // Server responds with tool definitions
498
+ {"jsonrpc": "2.0", "id": 1, "result": {"tools": [...]}}
499
+
500
+ // LLM calls a tool
501
+ {"jsonrpc": "2.0", "id": 2, "method": "tools/call",
502
+ "params": {"name": "create_motion_task", "arguments": {...}}}
503
+
504
+ // Server executes and responds
505
+ {"jsonrpc": "2.0", "id": 2, "result": {"content": [...]}}
506
+ ```
507
+
508
+ ## License
509
+
510
+ ISC
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "motionmcp",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node src/index.js",
8
+ "dev": "node src/index.js",
9
+ "mcp": "node src/mcp-server.js",
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "worker:dev": "wrangler dev",
12
+ "worker:deploy": "wrangler deploy"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "ISC",
17
+ "type": "commonjs",
18
+ "dependencies": {
19
+ "@modelcontextprotocol/sdk": "^1.12.0",
20
+ "axios": "^1.9.0",
21
+ "cors": "^2.8.5",
22
+ "dotenv": "^16.5.0",
23
+ "express": "^5.1.0",
24
+ "winston": "^3.17.0"
25
+ }
26
+ }
package/sample.png ADDED
Binary file
package/src/index.js ADDED
@@ -0,0 +1,47 @@
1
+ const express = require('express');
2
+ const cors = require('cors');
3
+ const winston = require('winston');
4
+ require('dotenv').config();
5
+
6
+ const motionRoutes = require('./routes/motion');
7
+
8
+ const logger = winston.createLogger({
9
+ level: 'info',
10
+ format: winston.format.combine(
11
+ winston.format.timestamp(),
12
+ winston.format.json()
13
+ ),
14
+ transports: [
15
+ new winston.transports.Console({
16
+ format: winston.format.simple()
17
+ })
18
+ ]
19
+ });
20
+
21
+ const app = express();
22
+ const PORT = process.env.PORT || 3000;
23
+
24
+ app.use(cors());
25
+ app.use(express.json());
26
+
27
+ app.use((req, res, next) => {
28
+ logger.info(`${req.method} ${req.path}`, { ip: req.ip });
29
+ next();
30
+ });
31
+
32
+ app.get('/health', (req, res) => {
33
+ res.json({ status: 'ok', timestamp: new Date().toISOString() });
34
+ });
35
+
36
+ app.use('/api/motion', motionRoutes);
37
+
38
+ app.use((err, req, res, next) => {
39
+ logger.error('Unhandled error:', err);
40
+ res.status(500).json({ error: 'Internal server error' });
41
+ });
42
+
43
+ app.listen(PORT, () => {
44
+ logger.info(`Motion MCP Server running on port ${PORT}`);
45
+ });
46
+
47
+ module.exports = app;