@daylight-labs/sharedb-mcp 0.1.6 → 0.1.7
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/dist/tools/auth.js +97 -3
- package/package.json +1 -1
package/dist/tools/auth.js
CHANGED
|
@@ -20,6 +20,22 @@ async function getEmailIntegrationInfo(appId) {
|
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
async function getOpenAIIntegrationInfo(appId) {
|
|
24
|
+
try {
|
|
25
|
+
const response = await fetch(`${config.adminApiUrl}/admin/apps/${appId}/integrations/openai`, {
|
|
26
|
+
headers: {
|
|
27
|
+
'Content-Type': 'application/json',
|
|
28
|
+
Authorization: `Bearer ${config.token}`,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok)
|
|
32
|
+
return null;
|
|
33
|
+
return response.json();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
23
39
|
export const authTools = [
|
|
24
40
|
{
|
|
25
41
|
name: 'get_api_endpoints',
|
|
@@ -93,6 +109,7 @@ export async function handleAuthTool(name, args) {
|
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
111
|
let emailSection;
|
|
112
|
+
let openaiSection;
|
|
96
113
|
if (appId && appName) {
|
|
97
114
|
const emailInfo = await getEmailIntegrationInfo(appId);
|
|
98
115
|
if (emailInfo) {
|
|
@@ -101,7 +118,7 @@ export async function handleAuthTool(name, args) {
|
|
|
101
118
|
description: 'Send transactional emails via AWS SES',
|
|
102
119
|
status: enabled ? 'enabled' : 'disabled',
|
|
103
120
|
endpoint: `POST <API_BASE_URL>/admin/apps/<app_id>/integrations/email/send`,
|
|
104
|
-
authentication: 'Include
|
|
121
|
+
authentication: 'Include access token from login: Authorization: Bearer <accessToken>',
|
|
105
122
|
fromAddress: emailInfo.fromAddress,
|
|
106
123
|
rateLimit: `1 email per ${emailInfo.rateLimitSeconds} seconds per app`,
|
|
107
124
|
currentAppId: appId,
|
|
@@ -115,7 +132,7 @@ export async function handleAuthTool(name, args) {
|
|
|
115
132
|
method: 'POST',
|
|
116
133
|
headers: {
|
|
117
134
|
'Content-Type': 'application/json',
|
|
118
|
-
'Authorization': \`Bearer \${
|
|
135
|
+
'Authorization': \`Bearer \${accessToken}\`
|
|
119
136
|
},
|
|
120
137
|
body: JSON.stringify({
|
|
121
138
|
to: 'user@example.com',
|
|
@@ -125,7 +142,8 @@ export async function handleAuthTool(name, args) {
|
|
|
125
142
|
})
|
|
126
143
|
})`,
|
|
127
144
|
importantNotes: [
|
|
128
|
-
'Store API_BASE_URL
|
|
145
|
+
'Store API_BASE_URL and APP_ID in environment variables or config - never hardcode',
|
|
146
|
+
'Use the accessToken from user login for authentication',
|
|
129
147
|
enabled
|
|
130
148
|
? 'Email integration is ENABLED for this app'
|
|
131
149
|
: 'Email integration is DISABLED - enable it in the Admin UI before sending',
|
|
@@ -136,6 +154,79 @@ export async function handleAuthTool(name, args) {
|
|
|
136
154
|
],
|
|
137
155
|
};
|
|
138
156
|
}
|
|
157
|
+
const openaiInfo = await getOpenAIIntegrationInfo(appId);
|
|
158
|
+
if (openaiInfo) {
|
|
159
|
+
const enabled = openaiInfo.integration?.enabled ?? false;
|
|
160
|
+
const hasApiKey = openaiInfo.hasApiKey ?? false;
|
|
161
|
+
openaiSection = {
|
|
162
|
+
description: 'Send chat requests via OpenAI API (Chat Completions or Assistants)',
|
|
163
|
+
status: enabled && hasApiKey ? 'enabled' : 'disabled',
|
|
164
|
+
endpoint: `POST <API_BASE_URL>/admin/apps/<app_id>/integrations/openai/chat`,
|
|
165
|
+
authentication: 'Include access token from login: Authorization: Bearer <accessToken>',
|
|
166
|
+
defaultModel: openaiInfo.defaultModel,
|
|
167
|
+
defaultAssistantId: openaiInfo.defaultAssistantId,
|
|
168
|
+
currentAppId: appId,
|
|
169
|
+
requestBody: {
|
|
170
|
+
messages: 'array (required) - Array of message objects with role and content',
|
|
171
|
+
model: 'string (optional) - Override default model (gpt-4o, gpt-4o-mini, gpt-4-turbo, gpt-3.5-turbo)',
|
|
172
|
+
assistant_id: 'string (optional) - Use OpenAI Assistant instead of Chat Completions',
|
|
173
|
+
thread_id: 'string (optional) - Continue existing Assistant thread',
|
|
174
|
+
},
|
|
175
|
+
responseBody: {
|
|
176
|
+
id: 'string - Response ID (or thread_id when using Assistants)',
|
|
177
|
+
model: 'string - Model used for the response',
|
|
178
|
+
content: 'string - The assistant\'s response text',
|
|
179
|
+
usage: {
|
|
180
|
+
prompt_tokens: 'number',
|
|
181
|
+
completion_tokens: 'number',
|
|
182
|
+
total_tokens: 'number',
|
|
183
|
+
},
|
|
184
|
+
thread_id: 'string (optional) - Returned when using Assistants API for conversation continuity',
|
|
185
|
+
},
|
|
186
|
+
example: `// Chat Completions API (stateless)
|
|
187
|
+
fetch(\`\${API_BASE_URL}/admin/apps/\${APP_ID}/integrations/openai/chat\`, {
|
|
188
|
+
method: 'POST',
|
|
189
|
+
headers: {
|
|
190
|
+
'Content-Type': 'application/json',
|
|
191
|
+
'Authorization': \`Bearer \${accessToken}\`
|
|
192
|
+
},
|
|
193
|
+
body: JSON.stringify({
|
|
194
|
+
messages: [
|
|
195
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
196
|
+
{ role: 'user', content: 'Hello, how are you?' }
|
|
197
|
+
]
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
// Assistants API (stateful with threads)
|
|
202
|
+
fetch(\`\${API_BASE_URL}/admin/apps/\${APP_ID}/integrations/openai/chat\`, {
|
|
203
|
+
method: 'POST',
|
|
204
|
+
headers: {
|
|
205
|
+
'Content-Type': 'application/json',
|
|
206
|
+
'Authorization': \`Bearer \${accessToken}\`
|
|
207
|
+
},
|
|
208
|
+
body: JSON.stringify({
|
|
209
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
210
|
+
assistant_id: 'asst_xxx',
|
|
211
|
+
thread_id: 'thread_xxx' // omit for new conversation
|
|
212
|
+
})
|
|
213
|
+
})`,
|
|
214
|
+
importantNotes: [
|
|
215
|
+
'Store API_BASE_URL and APP_ID in environment variables or config - never hardcode',
|
|
216
|
+
'Use the accessToken from user login for authentication',
|
|
217
|
+
enabled && hasApiKey
|
|
218
|
+
? 'OpenAI integration is ENABLED for this app'
|
|
219
|
+
: hasApiKey
|
|
220
|
+
? 'OpenAI integration is DISABLED - enable it in the Admin UI'
|
|
221
|
+
: 'OpenAI API key not configured - add it in the Admin UI',
|
|
222
|
+
'For Chat Completions API: include full message history in each request (stateless)',
|
|
223
|
+
'For Assistants API: use thread_id from response to continue conversation (stateful)',
|
|
224
|
+
'When using Assistants API, only the last user message is sent to the thread',
|
|
225
|
+
'No rate limiting applied - relies on OpenAI\'s own rate limits',
|
|
226
|
+
'Returns HTTP 403 if OpenAI integration is not enabled',
|
|
227
|
+
],
|
|
228
|
+
};
|
|
229
|
+
}
|
|
139
230
|
}
|
|
140
231
|
const endpoints = {
|
|
141
232
|
auth: {
|
|
@@ -202,6 +293,9 @@ export async function handleAuthTool(name, args) {
|
|
|
202
293
|
if (emailSection) {
|
|
203
294
|
endpoints.email = emailSection;
|
|
204
295
|
}
|
|
296
|
+
if (openaiSection) {
|
|
297
|
+
endpoints.openai = openaiSection;
|
|
298
|
+
}
|
|
205
299
|
return {
|
|
206
300
|
content: [
|
|
207
301
|
{
|