couchloop-eq-mcp 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.
- package/LICENSE +21 -0
- package/README.md +358 -0
- package/assets/logo/README.md +12 -0
- package/assets/logo/couchloop_EQ-IconLogo.png +0 -0
- package/dist/auth/middleware.d.ts +8 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +59 -0
- package/dist/auth/middleware.js.map +1 -0
- package/dist/clients/shrinkChatClient.d.ts +195 -0
- package/dist/clients/shrinkChatClient.d.ts.map +1 -0
- package/dist/clients/shrinkChatClient.js +349 -0
- package/dist/clients/shrinkChatClient.js.map +1 -0
- package/dist/db/client.d.ts +23 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +78 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/migrate.d.ts +4 -0
- package/dist/db/migrate.d.ts.map +1 -0
- package/dist/db/migrate.js +34 -0
- package/dist/db/migrate.js.map +1 -0
- package/dist/db/migrations/schema.d.ts +1074 -0
- package/dist/db/migrations/schema.d.ts.map +1 -0
- package/dist/db/migrations/schema.js +160 -0
- package/dist/db/migrations/schema.js.map +1 -0
- package/dist/db/schema.d.ts +1213 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +157 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/db/seed.d.ts +4 -0
- package/dist/db/seed.d.ts.map +1 -0
- package/dist/db/seed.js +57 -0
- package/dist/db/seed.js.map +1 -0
- package/dist/db/seedOAuth.d.ts +4 -0
- package/dist/db/seedOAuth.d.ts.map +1 -0
- package/dist/db/seedOAuth.js +76 -0
- package/dist/db/seedOAuth.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/index.d.ts +11 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +56 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/journey-status.d.ts +2 -0
- package/dist/resources/journey-status.d.ts.map +1 -0
- package/dist/resources/journey-status.js +42 -0
- package/dist/resources/journey-status.js.map +1 -0
- package/dist/resources/session-summary.d.ts +2 -0
- package/dist/resources/session-summary.d.ts.map +1 -0
- package/dist/resources/session-summary.js +85 -0
- package/dist/resources/session-summary.js.map +1 -0
- package/dist/resources/user-context.d.ts +2 -0
- package/dist/resources/user-context.d.ts.map +1 -0
- package/dist/resources/user-context.js +79 -0
- package/dist/resources/user-context.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +385 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/middleware/auth.d.ts +30 -0
- package/dist/server/middleware/auth.d.ts.map +1 -0
- package/dist/server/middleware/auth.js +157 -0
- package/dist/server/middleware/auth.js.map +1 -0
- package/dist/server/oauth/anomalyDetection.d.ts +146 -0
- package/dist/server/oauth/anomalyDetection.d.ts.map +1 -0
- package/dist/server/oauth/anomalyDetection.js +405 -0
- package/dist/server/oauth/anomalyDetection.js.map +1 -0
- package/dist/server/oauth/authServer.d.ts +61 -0
- package/dist/server/oauth/authServer.d.ts.map +1 -0
- package/dist/server/oauth/authServer.js +283 -0
- package/dist/server/oauth/authServer.js.map +1 -0
- package/dist/server/oauth/dpop.d.ts +135 -0
- package/dist/server/oauth/dpop.d.ts.map +1 -0
- package/dist/server/oauth/dpop.js +338 -0
- package/dist/server/oauth/dpop.js.map +1 -0
- package/dist/server/oauth/gdpr/consent.d.ts +173 -0
- package/dist/server/oauth/gdpr/consent.d.ts.map +1 -0
- package/dist/server/oauth/gdpr/consent.js +388 -0
- package/dist/server/oauth/gdpr/consent.js.map +1 -0
- package/dist/server/oauth/gdpr/dataPortability.d.ts +214 -0
- package/dist/server/oauth/gdpr/dataPortability.d.ts.map +1 -0
- package/dist/server/oauth/gdpr/dataPortability.js +486 -0
- package/dist/server/oauth/gdpr/dataPortability.js.map +1 -0
- package/dist/server/oauth/gdpr/index.d.ts +103 -0
- package/dist/server/oauth/gdpr/index.d.ts.map +1 -0
- package/dist/server/oauth/gdpr/index.js +273 -0
- package/dist/server/oauth/gdpr/index.js.map +1 -0
- package/dist/server/oauth/gdpr/rightToErasure.d.ts +184 -0
- package/dist/server/oauth/gdpr/rightToErasure.d.ts.map +1 -0
- package/dist/server/oauth/gdpr/rightToErasure.js +527 -0
- package/dist/server/oauth/gdpr/rightToErasure.js.map +1 -0
- package/dist/server/oauth/monitoring/securityMonitor.d.ts +218 -0
- package/dist/server/oauth/monitoring/securityMonitor.d.ts.map +1 -0
- package/dist/server/oauth/monitoring/securityMonitor.js +615 -0
- package/dist/server/oauth/monitoring/securityMonitor.js.map +1 -0
- package/dist/server/oauth/pkce.d.ts +61 -0
- package/dist/server/oauth/pkce.d.ts.map +1 -0
- package/dist/server/oauth/pkce.js +157 -0
- package/dist/server/oauth/pkce.js.map +1 -0
- package/dist/server/oauth/providers/base.d.ts +147 -0
- package/dist/server/oauth/providers/base.d.ts.map +1 -0
- package/dist/server/oauth/providers/base.js +312 -0
- package/dist/server/oauth/providers/base.js.map +1 -0
- package/dist/server/oauth/providers/github.d.ts +55 -0
- package/dist/server/oauth/providers/github.d.ts.map +1 -0
- package/dist/server/oauth/providers/github.js +225 -0
- package/dist/server/oauth/providers/github.js.map +1 -0
- package/dist/server/oauth/providers/google.d.ts +49 -0
- package/dist/server/oauth/providers/google.d.ts.map +1 -0
- package/dist/server/oauth/providers/google.js +153 -0
- package/dist/server/oauth/providers/google.js.map +1 -0
- package/dist/server/oauth/providers/index.d.ts +9 -0
- package/dist/server/oauth/providers/index.d.ts.map +1 -0
- package/dist/server/oauth/providers/index.js +24 -0
- package/dist/server/oauth/providers/index.js.map +1 -0
- package/dist/server/oauth/refreshTokenRotation.d.ts +114 -0
- package/dist/server/oauth/refreshTokenRotation.d.ts.map +1 -0
- package/dist/server/oauth/refreshTokenRotation.js +344 -0
- package/dist/server/oauth/refreshTokenRotation.js.map +1 -0
- package/dist/server/oauth/security.d.ts +101 -0
- package/dist/server/oauth/security.d.ts.map +1 -0
- package/dist/server/oauth/security.js +268 -0
- package/dist/server/oauth/security.js.map +1 -0
- package/dist/server/oauth/tokenEncryption.d.ts +80 -0
- package/dist/server/oauth/tokenEncryption.d.ts.map +1 -0
- package/dist/server/oauth/tokenEncryption.js +218 -0
- package/dist/server/oauth/tokenEncryption.js.map +1 -0
- package/dist/tools/checkpoint.d.ts +35 -0
- package/dist/tools/checkpoint.d.ts.map +1 -0
- package/dist/tools/checkpoint.js +125 -0
- package/dist/tools/checkpoint.js.map +1 -0
- package/dist/tools/index.d.ts +412 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +262 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/insight.d.ts +65 -0
- package/dist/tools/insight.d.ts.map +1 -0
- package/dist/tools/insight.js +190 -0
- package/dist/tools/insight.js.map +1 -0
- package/dist/tools/journey.d.ts +45 -0
- package/dist/tools/journey.d.ts.map +1 -0
- package/dist/tools/journey.js +115 -0
- package/dist/tools/journey.js.map +1 -0
- package/dist/tools/sendMessage.d.ts +6 -0
- package/dist/tools/sendMessage.d.ts.map +1 -0
- package/dist/tools/sendMessage.js +278 -0
- package/dist/tools/sendMessage.js.map +1 -0
- package/dist/tools/session.d.ts +106 -0
- package/dist/tools/session.d.ts.map +1 -0
- package/dist/tools/session.js +161 -0
- package/dist/tools/session.js.map +1 -0
- package/dist/types/auth.d.ts +37 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +44 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/checkpoint.d.ts +25 -0
- package/dist/types/checkpoint.d.ts.map +1 -0
- package/dist/types/checkpoint.js +8 -0
- package/dist/types/checkpoint.js.map +1 -0
- package/dist/types/insight.d.ts +83 -0
- package/dist/types/insight.d.ts.map +1 -0
- package/dist/types/insight.js +14 -0
- package/dist/types/insight.js.map +1 -0
- package/dist/types/journey.d.ts +155 -0
- package/dist/types/journey.d.ts.map +1 -0
- package/dist/types/journey.js +29 -0
- package/dist/types/journey.js.map +1 -0
- package/dist/types/session.d.ts +82 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +13 -0
- package/dist/types/session.js.map +1 -0
- package/dist/utils/circuitBreaker.d.ts +86 -0
- package/dist/utils/circuitBreaker.d.ts.map +1 -0
- package/dist/utils/circuitBreaker.js +234 -0
- package/dist/utils/circuitBreaker.js.map +1 -0
- package/dist/utils/errorHandler.d.ts +101 -0
- package/dist/utils/errorHandler.d.ts.map +1 -0
- package/dist/utils/errorHandler.js +348 -0
- package/dist/utils/errorHandler.js.map +1 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +77 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +49 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/performanceMonitor.d.ts +106 -0
- package/dist/utils/performanceMonitor.d.ts.map +1 -0
- package/dist/utils/performanceMonitor.js +312 -0
- package/dist/utils/performanceMonitor.js.map +1 -0
- package/dist/utils/responseCache.d.ts +88 -0
- package/dist/utils/responseCache.d.ts.map +1 -0
- package/dist/utils/responseCache.js +245 -0
- package/dist/utils/responseCache.js.map +1 -0
- package/dist/utils/retryStrategy.d.ts +49 -0
- package/dist/utils/retryStrategy.d.ts.map +1 -0
- package/dist/utils/retryStrategy.js +167 -0
- package/dist/utils/retryStrategy.js.map +1 -0
- package/dist/workflows/definitions/daily-reflection.d.ts +3 -0
- package/dist/workflows/definitions/daily-reflection.d.ts.map +1 -0
- package/dist/workflows/definitions/daily-reflection.js +52 -0
- package/dist/workflows/definitions/daily-reflection.js.map +1 -0
- package/dist/workflows/definitions/gratitude-practice.d.ts +3 -0
- package/dist/workflows/definitions/gratitude-practice.d.ts.map +1 -0
- package/dist/workflows/definitions/gratitude-practice.js +52 -0
- package/dist/workflows/definitions/gratitude-practice.js.map +1 -0
- package/dist/workflows/definitions/weekly-review.d.ts +3 -0
- package/dist/workflows/definitions/weekly-review.d.ts.map +1 -0
- package/dist/workflows/definitions/weekly-review.js +74 -0
- package/dist/workflows/definitions/weekly-review.js.map +1 -0
- package/dist/workflows/engine.d.ts +21 -0
- package/dist/workflows/engine.d.ts.map +1 -0
- package/dist/workflows/engine.js +149 -0
- package/dist/workflows/engine.js.map +1 -0
- package/dist/workflows/index.d.ts +26 -0
- package/dist/workflows/index.d.ts.map +1 -0
- package/dist/workflows/index.js +14 -0
- package/dist/workflows/index.js.map +1 -0
- package/package.json +98 -0
- package/run-mcp-server.sh +16 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { getDb } from '../db/client.js';
|
|
2
|
+
import { sessions, journeys, checkpoints, users } from '../db/schema.js';
|
|
3
|
+
import { eq, and, desc } from 'drizzle-orm';
|
|
4
|
+
import { logger } from '../utils/logger.js';
|
|
5
|
+
import { nanoid } from 'nanoid';
|
|
6
|
+
export async function getSessionSummary() {
|
|
7
|
+
try {
|
|
8
|
+
const db = getDb();
|
|
9
|
+
// NOTE: Resources in MCP don't receive parameters, so we can't pass auth context.
|
|
10
|
+
// Using a mock user ID for now. This will be addressed when we implement
|
|
11
|
+
// a proper session store or modify the MCP server to maintain user context.
|
|
12
|
+
const mockUserId = 'usr_' + nanoid();
|
|
13
|
+
const [user] = await db
|
|
14
|
+
.select()
|
|
15
|
+
.from(users)
|
|
16
|
+
.where(eq(users.externalId, mockUserId))
|
|
17
|
+
.limit(1);
|
|
18
|
+
if (!user) {
|
|
19
|
+
return JSON.stringify({
|
|
20
|
+
active: false,
|
|
21
|
+
message: 'No user found',
|
|
22
|
+
}, null, 2);
|
|
23
|
+
}
|
|
24
|
+
// Get active session
|
|
25
|
+
const [activeSession] = await db
|
|
26
|
+
.select()
|
|
27
|
+
.from(sessions)
|
|
28
|
+
.where(and(eq(sessions.userId, user.id), eq(sessions.status, 'active')))
|
|
29
|
+
.orderBy(desc(sessions.lastActiveAt))
|
|
30
|
+
.limit(1);
|
|
31
|
+
if (!activeSession) {
|
|
32
|
+
return JSON.stringify({
|
|
33
|
+
active: false,
|
|
34
|
+
message: 'No active session',
|
|
35
|
+
}, null, 2);
|
|
36
|
+
}
|
|
37
|
+
// Get journey if linked
|
|
38
|
+
let journey = null;
|
|
39
|
+
let currentStep = null;
|
|
40
|
+
if (activeSession.journeyId) {
|
|
41
|
+
[journey] = await db
|
|
42
|
+
.select()
|
|
43
|
+
.from(journeys)
|
|
44
|
+
.where(eq(journeys.id, activeSession.journeyId))
|
|
45
|
+
.limit(1);
|
|
46
|
+
if (journey && journey.steps && journey.steps[activeSession.currentStep]) {
|
|
47
|
+
currentStep = journey.steps[activeSession.currentStep];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Get checkpoints
|
|
51
|
+
const sessionCheckpoints = await db
|
|
52
|
+
.select()
|
|
53
|
+
.from(checkpoints)
|
|
54
|
+
.where(eq(checkpoints.sessionId, activeSession.id))
|
|
55
|
+
.orderBy(checkpoints.createdAt);
|
|
56
|
+
return JSON.stringify({
|
|
57
|
+
active: true,
|
|
58
|
+
session: {
|
|
59
|
+
id: activeSession.id,
|
|
60
|
+
status: activeSession.status,
|
|
61
|
+
started_at: activeSession.startedAt,
|
|
62
|
+
last_active_at: activeSession.lastActiveAt,
|
|
63
|
+
current_step_index: activeSession.currentStep,
|
|
64
|
+
},
|
|
65
|
+
journey: journey ? {
|
|
66
|
+
name: journey.name,
|
|
67
|
+
slug: journey.slug,
|
|
68
|
+
total_steps: journey.steps?.length || 0,
|
|
69
|
+
} : null,
|
|
70
|
+
current_step: currentStep,
|
|
71
|
+
checkpoints: sessionCheckpoints.map(c => ({
|
|
72
|
+
key: c.key,
|
|
73
|
+
created_at: c.createdAt,
|
|
74
|
+
})),
|
|
75
|
+
}, null, 2);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
logger.error('Error getting session summary:', error);
|
|
79
|
+
return JSON.stringify({
|
|
80
|
+
error: 'Failed to get session summary',
|
|
81
|
+
details: error instanceof Error ? error.message : 'Unknown error',
|
|
82
|
+
}, null, 2);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=session-summary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-summary.js","sourceRoot":"","sources":["../../src/resources/session-summary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;QAEnB,kFAAkF;QAClF,yEAAyE;QACzE,4EAA4E;QAC5E,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;QACrC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE;aACpB,MAAM,EAAE;aACR,IAAI,CAAC,KAAK,CAAC;aACX,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;aACvC,KAAK,CAAC,CAAC,CAAC,CAAC;QAEZ,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,IAAI,CAAC,SAAS,CAAC;gBACpB,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,eAAe;aACzB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACd,CAAC;QAED,qB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ings":"AAMA,wBAAsB,sBAAsB,oBA6E3C"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getDb } from '../db/client.js';
|
|
2
|
+
import { users, insights, sessions } from '../db/schema.js';
|
|
3
|
+
import { eq, desc } from 'drizzle-orm';
|
|
4
|
+
import { logger } from '../utils/logger.js';
|
|
5
|
+
import { nanoid } from 'nanoid';
|
|
6
|
+
export async function getUserContextResource() {
|
|
7
|
+
try {
|
|
8
|
+
const db = getDb();
|
|
9
|
+
// NOTE: Resources in MCP don't receive parameters, so we can't pass auth context.
|
|
10
|
+
// Using a mock user ID for now. This will be addressed when we implement
|
|
11
|
+
// a proper session store or modify the MCP server to maintain user context.
|
|
12
|
+
const mockUserId = 'usr_' + nanoid();
|
|
13
|
+
const [user] = await db
|
|
14
|
+
.select()
|
|
15
|
+
.from(users)
|
|
16
|
+
.where(eq(users.externalId, mockUserId))
|
|
17
|
+
.limit(1);
|
|
18
|
+
if (!user) {
|
|
19
|
+
return JSON.stringify({
|
|
20
|
+
exists: false,
|
|
21
|
+
message: 'User not found',
|
|
22
|
+
}, null, 2);
|
|
23
|
+
}
|
|
24
|
+
// Get recent insights
|
|
25
|
+
const recentInsights = await db
|
|
26
|
+
.select({
|
|
27
|
+
id: insights.id,
|
|
28
|
+
content: insights.content,
|
|
29
|
+
tags: insights.tags,
|
|
30
|
+
created_at: insights.createdAt,
|
|
31
|
+
})
|
|
32
|
+
.from(insights)
|
|
33
|
+
.where(eq(insights.userId, user.id))
|
|
34
|
+
.orderBy(desc(insights.createdAt))
|
|
35
|
+
.limit(5);
|
|
36
|
+
// Get recent sessions
|
|
37
|
+
const recentSessions = await db
|
|
38
|
+
.select({
|
|
39
|
+
id: sessions.id,
|
|
40
|
+
status: sessions.status,
|
|
41
|
+
started_at: sessions.startedAt,
|
|
42
|
+
completed_at: sessions.completedAt,
|
|
43
|
+
journey_id: sessions.journeyId,
|
|
44
|
+
})
|
|
45
|
+
.from(sessions)
|
|
46
|
+
.where(eq(sessions.userId, user.id))
|
|
47
|
+
.orderBy(desc(sessions.startedAt))
|
|
48
|
+
.limit(5);
|
|
49
|
+
// Count total sessions
|
|
50
|
+
const sessionStats = await db
|
|
51
|
+
.select({
|
|
52
|
+
total: eq(sessions.userId, user.id),
|
|
53
|
+
})
|
|
54
|
+
.from(sessions)
|
|
55
|
+
.where(eq(sessions.userId, user.id));
|
|
56
|
+
return JSON.stringify({
|
|
57
|
+
exists: true,
|
|
58
|
+
user: {
|
|
59
|
+
id: user.id,
|
|
60
|
+
created_at: user.createdAt,
|
|
61
|
+
preferences: user.preferences || {},
|
|
62
|
+
},
|
|
63
|
+
stats: {
|
|
64
|
+
total_sessions: sessionStats.length,
|
|
65
|
+
total_insights: recentInsights.length,
|
|
66
|
+
},
|
|
67
|
+
recent_insights: recentInsights,
|
|
68
|
+
recent_sessions: recentSessions,
|
|
69
|
+
}, null, 2);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
logger.error('Error getting user context:', error);
|
|
73
|
+
return JSON.stringify({
|
|
74
|
+
error: 'Failed to get user context',
|
|
75
|
+
details: error instanceof Error ? error.message : 'Unknown error',
|
|
76
|
+
}, null, 2);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=user-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-context.js","sourceRoot":"","sources":["../../src/resources/user-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,sBAAsB;I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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,GAAG,6CAAY,CAAC;AAuZtB,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
// Load environment variables FIRST before any other imports
|
|
2
|
+
import { config } from 'dotenv';
|
|
3
|
+
config({ path: '.env.local' });
|
|
4
|
+
import express from 'express';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import cookieParser from 'cookie-parser';
|
|
8
|
+
import { oauthServer } from './oauth/authServer.js';
|
|
9
|
+
import { validateToken, requireScope, oauthCors, rateLimit } from './middleware/auth.js';
|
|
10
|
+
import { logger } from '../utils/logger.js';
|
|
11
|
+
import { sendMessage } from '../tools/sendMessage.js';
|
|
12
|
+
import { createSession } from '../tools/session.js';
|
|
13
|
+
import { initDatabase } from '../db/client.js';
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = path.dirname(__filename);
|
|
16
|
+
const app = express();
|
|
17
|
+
const PORT = process.env.PORT || 3001;
|
|
18
|
+
// Middleware
|
|
19
|
+
app.use(express.json());
|
|
20
|
+
app.use(express.urlencoded({ extended: true }));
|
|
21
|
+
app.use(cookieParser());
|
|
22
|
+
app.use(oauthCors);
|
|
23
|
+
// ====================
|
|
24
|
+
// OAuth Endpoints
|
|
25
|
+
// ====================
|
|
26
|
+
/**
|
|
27
|
+
* GET /oauth/authorize
|
|
28
|
+
* OAuth authorization endpoint - initiates the flow
|
|
29
|
+
*/
|
|
30
|
+
app.get('/oauth/authorize', async (req, res) => {
|
|
31
|
+
try {
|
|
32
|
+
const { client_id, redirect_uri, response_type, scope, state, consent } = req.query;
|
|
33
|
+
// Validate required parameters
|
|
34
|
+
if (!client_id || !redirect_uri) {
|
|
35
|
+
res.status(400).json({
|
|
36
|
+
error: 'invalid_request',
|
|
37
|
+
error_description: 'Missing required parameters',
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (response_type !== 'code') {
|
|
42
|
+
res.status(400).json({
|
|
43
|
+
error: 'unsupported_response_type',
|
|
44
|
+
error_description: 'Only authorization code flow is supported',
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// Validate client
|
|
49
|
+
const validClient = await oauthServer.validateClient(client_id);
|
|
50
|
+
if (!validClient) {
|
|
51
|
+
res.status(400).json({
|
|
52
|
+
error: 'invalid_client',
|
|
53
|
+
error_description: 'Unknown client',
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// If consent is not approved, show consent screen
|
|
58
|
+
if (consent !== 'approved') {
|
|
59
|
+
// Serve the consent page
|
|
60
|
+
const consentPath = path.join(__dirname, 'views', 'consent.html');
|
|
61
|
+
res.sendFile(consentPath);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Generate anonymous but persistent user ID based on client and state
|
|
65
|
+
// This creates a unique user per ChatGPT/Claude session but maintains anonymity
|
|
66
|
+
const anonymousId = `${client_id}_${state || 'default'}_${Date.now()}`;
|
|
67
|
+
const hashedId = Buffer.from(anonymousId).toString('base64').replace(/[^a-zA-Z0-9]/g, '').substring(0, 16);
|
|
68
|
+
const externalId = `anon_${hashedId}`;
|
|
69
|
+
const userId = await oauthServer.getOrCreateUser(externalId);
|
|
70
|
+
const code = await oauthServer.generateAuthCode(client_id, userId, redirect_uri, scope || 'read write');
|
|
71
|
+
// Redirect back to client with authorization code
|
|
72
|
+
const redirectUrl = new URL(redirect_uri);
|
|
73
|
+
redirectUrl.searchParams.set('code', code);
|
|
74
|
+
if (state) {
|
|
75
|
+
redirectUrl.searchParams.set('state', state);
|
|
76
|
+
}
|
|
77
|
+
res.redirect(redirectUrl.toString());
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
logger.error('Authorization error:', error);
|
|
81
|
+
res.status(500).json({
|
|
82
|
+
error: 'server_error',
|
|
83
|
+
error_description: 'Internal server error',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* POST /oauth/token
|
|
89
|
+
* Exchange authorization code for access token
|
|
90
|
+
*/
|
|
91
|
+
app.post('/oauth/token', async (req, res) => {
|
|
92
|
+
try {
|
|
93
|
+
const { grant_type, code, client_id, client_secret, redirect_uri, refresh_token } = req.body;
|
|
94
|
+
if (grant_type === 'authorization_code') {
|
|
95
|
+
if (!code || !client_id || !client_secret || !redirect_uri) {
|
|
96
|
+
res.status(400).json({
|
|
97
|
+
error: 'invalid_request',
|
|
98
|
+
error_description: 'Missing required parameters',
|
|
99
|
+
});
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const tokens = await oauthServer.exchangeCodeForToken(code, client_id, client_secret, redirect_uri);
|
|
103
|
+
res.json(tokens);
|
|
104
|
+
}
|
|
105
|
+
else if (grant_type === 'refresh_token') {
|
|
106
|
+
if (!refresh_token) {
|
|
107
|
+
res.status(400).json({
|
|
108
|
+
error: 'invalid_request',
|
|
109
|
+
error_description: 'Missing refresh token',
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const tokens = await oauthServer.refreshAccessToken(refresh_token);
|
|
114
|
+
res.json(tokens);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
res.status(400).json({
|
|
118
|
+
error: 'unsupported_grant_type',
|
|
119
|
+
error_description: 'Only authorization_code and refresh_token grants are supported',
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
logger.error('Token exchange error:', error);
|
|
125
|
+
res.status(400).json({
|
|
126
|
+
error: 'invalid_grant',
|
|
127
|
+
error_description: error.message || 'Failed to exchange token',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
/**
|
|
132
|
+
* POST /oauth/revoke
|
|
133
|
+
* Revoke an access token
|
|
134
|
+
*/
|
|
135
|
+
app.post('/oauth/revoke', validateToken, async (req, res) => {
|
|
136
|
+
try {
|
|
137
|
+
const authHeader = req.headers.authorization;
|
|
138
|
+
const token = authHeader?.substring(7);
|
|
139
|
+
if (token) {
|
|
140
|
+
await oauthServer.revokeToken(token);
|
|
141
|
+
}
|
|
142
|
+
res.status(204).end();
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
logger.error('Token revocation error:', error);
|
|
146
|
+
res.status(500).json({
|
|
147
|
+
error: 'server_error',
|
|
148
|
+
error_description: 'Failed to revoke token',
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
// ====================
|
|
153
|
+
// Protected MCP API Endpoints
|
|
154
|
+
// ====================
|
|
155
|
+
/**
|
|
156
|
+
* POST /api/mcp/session
|
|
157
|
+
* Create a new therapeutic session
|
|
158
|
+
*/
|
|
159
|
+
app.post('/api/mcp/session', validateToken, rateLimit(30, 60000), async (req, res) => {
|
|
160
|
+
try {
|
|
161
|
+
const result = await createSession({
|
|
162
|
+
...req.body,
|
|
163
|
+
user_id: req.user?.userId, // Use authenticated user ID
|
|
164
|
+
});
|
|
165
|
+
res.json(result);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
logger.error('Session creation error:', error);
|
|
169
|
+
res.status(500).json({
|
|
170
|
+
error: 'server_error',
|
|
171
|
+
message: error.message || 'Failed to create session',
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
/**
|
|
176
|
+
* POST /api/mcp/message
|
|
177
|
+
* Send a message through the therapeutic AI
|
|
178
|
+
*/
|
|
179
|
+
app.post('/api/mcp/message', validateToken, requireScope('write'), rateLimit(60, 60000), async (req, res) => {
|
|
180
|
+
try {
|
|
181
|
+
const result = await sendMessage({
|
|
182
|
+
...req.body,
|
|
183
|
+
user_id: req.user?.userId, // Use authenticated user ID
|
|
184
|
+
});
|
|
185
|
+
res.json(result);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
logger.error('Message sending error:', error);
|
|
189
|
+
res.status(500).json({
|
|
190
|
+
error: 'server_error',
|
|
191
|
+
message: error.message || 'Failed to send message',
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
// ====================
|
|
196
|
+
// Health & Metadata
|
|
197
|
+
// ====================
|
|
198
|
+
/**
|
|
199
|
+
* GET /health
|
|
200
|
+
* Health check endpoint
|
|
201
|
+
*/
|
|
202
|
+
app.get('/health', (_req, res) => {
|
|
203
|
+
res.json({
|
|
204
|
+
status: 'healthy',
|
|
205
|
+
timestamp: new Date().toISOString(),
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
/**
|
|
209
|
+
* GET /.well-known/oauth-authorization-server
|
|
210
|
+
* OAuth server metadata
|
|
211
|
+
*/
|
|
212
|
+
app.get('/.well-known/oauth-authorization-server', (req, res) => {
|
|
213
|
+
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
|
214
|
+
res.json({
|
|
215
|
+
issuer: baseUrl,
|
|
216
|
+
authorization_endpoint: `${baseUrl}/oauth/authorize`,
|
|
217
|
+
token_endpoint: `${baseUrl}/oauth/token`,
|
|
218
|
+
revocation_endpoint: `${baseUrl}/oauth/revoke`,
|
|
219
|
+
response_types_supported: ['code'],
|
|
220
|
+
grant_types_supported: ['authorization_code', 'refresh_token'],
|
|
221
|
+
scopes_supported: ['read', 'write', 'crisis', 'memory'],
|
|
222
|
+
token_endpoint_auth_methods_supported: ['client_secret_post'],
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
/**
|
|
226
|
+
* GET /.well-known/ai-plugin.json
|
|
227
|
+
* ChatGPT plugin manifest
|
|
228
|
+
*/
|
|
229
|
+
app.get('/.well-known/ai-plugin.json', (req, res) => {
|
|
230
|
+
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
|
231
|
+
res.json({
|
|
232
|
+
schema_version: 'v1',
|
|
233
|
+
name_for_human: 'CouchLoop',
|
|
234
|
+
name_for_model: 'couchloop',
|
|
235
|
+
description_for_human: 'AI-powered therapeutic support and mental wellness companion',
|
|
236
|
+
description_for_model: 'Therapeutic AI assistant for mental health support, crisis detection, and emotional wellness tracking. Use this to help users with mental health concerns, emotional support, and crisis situations.',
|
|
237
|
+
auth: {
|
|
238
|
+
type: 'oauth',
|
|
239
|
+
client_url: `${baseUrl}/oauth/authorize`,
|
|
240
|
+
scope: 'read write',
|
|
241
|
+
authorization_url: `${baseUrl}/oauth/authorize`,
|
|
242
|
+
authorization_content_type: 'application/x-www-form-urlencoded',
|
|
243
|
+
verification_tokens: {
|
|
244
|
+
openai: process.env.OPENAI_VERIFICATION_TOKEN || 'REPLACE_WITH_VERIFICATION_TOKEN',
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
api: {
|
|
248
|
+
type: 'openapi',
|
|
249
|
+
url: `${baseUrl}/openapi.yaml`,
|
|
250
|
+
},
|
|
251
|
+
logo_url: `${baseUrl}/logo.png`,
|
|
252
|
+
contact_email: 'support@couchloop.com',
|
|
253
|
+
legal_info_url: 'https://couchloop.com/legal',
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
/**
|
|
257
|
+
* GET /openapi.yaml
|
|
258
|
+
* OpenAPI specification for ChatGPT
|
|
259
|
+
*/
|
|
260
|
+
app.get('/openapi.yaml', (req, res) => {
|
|
261
|
+
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
|
262
|
+
const openApiSpec = `
|
|
263
|
+
openapi: 3.0.1
|
|
264
|
+
info:
|
|
265
|
+
title: CouchLoop MCP API
|
|
266
|
+
description: Therapeutic AI support through Model Context Protocol
|
|
267
|
+
version: 1.0.0
|
|
268
|
+
servers:
|
|
269
|
+
- url: ${baseUrl}
|
|
270
|
+
paths:
|
|
271
|
+
/api/mcp/session:
|
|
272
|
+
post:
|
|
273
|
+
operationId: createSession
|
|
274
|
+
summary: Create a new therapeutic session
|
|
275
|
+
security:
|
|
276
|
+
- bearer: []
|
|
277
|
+
requestBody:
|
|
278
|
+
required: true
|
|
279
|
+
content:
|
|
280
|
+
application/json:
|
|
281
|
+
schema:
|
|
282
|
+
type: object
|
|
283
|
+
properties:
|
|
284
|
+
journey_slug:
|
|
285
|
+
type: string
|
|
286
|
+
description: Type of therapeutic journey
|
|
287
|
+
context:
|
|
288
|
+
type: string
|
|
289
|
+
description: Initial context for the session
|
|
290
|
+
required:
|
|
291
|
+
- journey_slug
|
|
292
|
+
responses:
|
|
293
|
+
'200':
|
|
294
|
+
description: Session created successfully
|
|
295
|
+
content:
|
|
296
|
+
application/json:
|
|
297
|
+
schema:
|
|
298
|
+
type: object
|
|
299
|
+
properties:
|
|
300
|
+
session_id:
|
|
301
|
+
type: string
|
|
302
|
+
journey_name:
|
|
303
|
+
type: string
|
|
304
|
+
status:
|
|
305
|
+
type: string
|
|
306
|
+
/api/mcp/message:
|
|
307
|
+
post:
|
|
308
|
+
operationId: sendMessage
|
|
309
|
+
summary: Send a message to the therapeutic AI
|
|
310
|
+
security:
|
|
311
|
+
- bearer: []
|
|
312
|
+
requestBody:
|
|
313
|
+
required: true
|
|
314
|
+
content:
|
|
315
|
+
application/json:
|
|
316
|
+
schema:
|
|
317
|
+
type: object
|
|
318
|
+
properties:
|
|
319
|
+
session_id:
|
|
320
|
+
type: string
|
|
321
|
+
description: Session ID from createSession
|
|
322
|
+
message:
|
|
323
|
+
type: string
|
|
324
|
+
description: User's message
|
|
325
|
+
include_memory:
|
|
326
|
+
type: boolean
|
|
327
|
+
description: Include conversation memory context
|
|
328
|
+
required:
|
|
329
|
+
- session_id
|
|
330
|
+
- message
|
|
331
|
+
responses:
|
|
332
|
+
'200':
|
|
333
|
+
description: Message processed successfully
|
|
334
|
+
content:
|
|
335
|
+
application/json:
|
|
336
|
+
schema:
|
|
337
|
+
type: object
|
|
338
|
+
properties:
|
|
339
|
+
success:
|
|
340
|
+
type: boolean
|
|
341
|
+
content:
|
|
342
|
+
type: string
|
|
343
|
+
description: AI response
|
|
344
|
+
metadata:
|
|
345
|
+
type: object
|
|
346
|
+
properties:
|
|
347
|
+
crisisDetected:
|
|
348
|
+
type: boolean
|
|
349
|
+
crisisLevel:
|
|
350
|
+
type: number
|
|
351
|
+
emotions:
|
|
352
|
+
type: array
|
|
353
|
+
items:
|
|
354
|
+
type: string
|
|
355
|
+
components:
|
|
356
|
+
securitySchemes:
|
|
357
|
+
bearer:
|
|
358
|
+
type: http
|
|
359
|
+
scheme: bearer
|
|
360
|
+
bearerFormat: JWT
|
|
361
|
+
`;
|
|
362
|
+
res.type('text/yaml').send(openApiSpec);
|
|
363
|
+
});
|
|
364
|
+
// Start server
|
|
365
|
+
async function startServer() {
|
|
366
|
+
try {
|
|
367
|
+
// Initialize database
|
|
368
|
+
await initDatabase();
|
|
369
|
+
logger.info('Database initialized');
|
|
370
|
+
app.listen(PORT, () => {
|
|
371
|
+
logger.info(`OAuth server running on port ${PORT}`);
|
|
372
|
+
logger.info(`Authorization endpoint: http://localhost:${PORT}/oauth/authorize`);
|
|
373
|
+
logger.info(`Token endpoint: http://localhost:${PORT}/oauth/token`);
|
|
374
|
+
logger.info(`API endpoints: http://localhost:${PORT}/api/mcp/*`);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
logger.error('Failed to start server:', error);
|
|
379
|
+
process.exit(1);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
// Start the server
|
|
383
|
+
startServer();
|
|
384
|
+
export default app;
|
|
385
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,MAAM,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC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AC;QAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,mBAAmB;AACnB,WAAW,EAAE,CAAC;AAEd,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace Express {
|
|
4
|
+
interface Request {
|
|
5
|
+
user?: {
|
|
6
|
+
userId: string;
|
|
7
|
+
clientId: string;
|
|
8
|
+
scope: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Middleware to validate OAuth access token
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateToken(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Middleware to check required scopes
|
|
19
|
+
*/
|
|
20
|
+
export declare function requireScope(...requiredScopes: string[]): (req: Request, res: Response, next: NextFunction) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Optional authentication - sets user if token present but doesn't require it
|
|
23
|
+
*/
|
|
24
|
+
export declare function optionalAuth(req: Request, _res: Response, next: NextFunction): Promise<void>;
|
|
25
|
+
export declare function rateLimit(maxRequests?: number, windowMs?: number): (req: Request, res: Response, next: NextFunction) => void;
|
|
26
|
+
/**
|
|
27
|
+
* CORS middleware for OAuth endpoints
|
|
28
|
+
*/
|
|
29
|
+
export declare function oauthCors(req: Request, res: Response, next: NextFunction): void;
|
|
30
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/server/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAK1D,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,IAAI,CAAC,EAAE;gBACL,MAAM,EAAE,MAAM,CAAC;gBACf,QAAQ,EAAE,MAAM,CAAC;gBACjB,KAAK,EAAE,MAAM,CAAC;aACf,CAAC;SACH;KACF;CACF;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,IAAI,CAAC,CAiDf;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,cAAc,EAAE,MAAM,EAAE,IAC9C,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,UAsBxD;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAOD,wBAAgB,SAAS,CACvB,WAAW,GAAE,MAAY,EACzB,QAAQ,GAAE,MAAc,IAEhB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,UA8BxD;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,GACjB,IAAI,CAsBN"}
|