@stage-labs/metro 0.1.0-beta.30 → 0.1.0-beta.32
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/api.js +12 -12
- package/dist/bedrock.js +5 -3
- package/dist/cli.js +23 -11
- package/dist/runtime.js +4 -1
- package/dist/serve.js +57 -0
- package/dist/store.js +26 -3
- package/package.json +1 -1
- package/runtime/node_modules/@metro-labs/mcp/package.json +1 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/account-api.ts +5 -5
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-api.ts +24 -28
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-connector-api.ts +150 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-pair.ts +20 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/api-http.ts +34 -10
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-serve.ts +5 -3
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-session.ts +2 -2
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/boot.ts +119 -72
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair-api.ts +31 -20
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-api.ts +17 -43
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-oauth-routes.ts +8 -8
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-oauth.ts +3 -3
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/http.ts +12 -2
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/identity.ts +11 -4
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/local-mode.ts +158 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/local-secret.ts +21 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/mode-api.ts +31 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/oauth-pending.ts +1 -1
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/paths.ts +10 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/project-api.ts +17 -17
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/relay.ts +13 -12
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-api.ts +15 -6
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-api.ts +1 -1
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-apis.ts +12 -3
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-config.ts +27 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/session.ts +21 -21
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/siwe-auth.ts +82 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/siwe-nonces.ts +43 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/siwe-routes.ts +89 -0
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/supervisor.ts +2 -5
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-admin.ts +15 -16
- package/runtime/node_modules/@metro-labs/mcp/src/db/agent-connectors.ts +143 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/connector-relay.ts +8 -8
- package/runtime/node_modules/@metro-labs/mcp/src/db/connectors.ts +32 -32
- package/runtime/node_modules/@metro-labs/mcp/src/db/file-admin.ts +250 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/file-source.ts +152 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/ids.ts +2 -0
- package/runtime/node_modules/@metro-labs/mcp/src/db/materialize.ts +16 -7
- package/runtime/node_modules/@metro-labs/mcp/src/db/projects.ts +49 -40
- package/runtime/node_modules/@metro-labs/mcp/src/db/runtime-admin.ts +13 -20
- package/runtime/node_modules/@metro-labs/mcp/src/db/schema.ts +8 -21
- package/runtime/node_modules/@metro-labs/mcp/src/db/users.ts +32 -17
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/request-identity.ts +4 -4
- package/runtime/node_modules/@metro-labs/mcp/src/mcp/session-route.ts +1 -1
- package/runtime/runtime.json +1 -1
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair.ts +0 -20
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/collection-api.ts +0 -202
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-auth.ts +0 -164
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/google-oauth.ts +0 -208
- package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-pair.ts +0 -18
- package/runtime/node_modules/@metro-labs/mcp/src/db/connector-collections.ts +0 -218
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { isUniqueViolation } from './users.js';
|
|
2
|
-
import { projectIdOrThrow } from './projects.js';
|
|
3
|
-
import { and, asc, eq, inArray, ne } from 'drizzle-orm';
|
|
4
|
-
import { getDb } from './client.js';
|
|
5
|
-
import { newId } from './ids.js';
|
|
6
|
-
import { ConnectorError, connectorName } from './connector-config.js';
|
|
7
|
-
import { collectionItems, collections, connectors } from './schema.js';
|
|
8
|
-
|
|
9
|
-
export interface ConnectorCollectionRow {
|
|
10
|
-
id: string;
|
|
11
|
-
name: string;
|
|
12
|
-
connectorIds: string[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface CollectionRow {
|
|
16
|
-
id: string;
|
|
17
|
-
projectId: string;
|
|
18
|
-
name: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const missing = (): ConnectorError =>
|
|
22
|
-
new ConnectorError('no such collection', 404);
|
|
23
|
-
|
|
24
|
-
const duplicate = (name: string): ConnectorError =>
|
|
25
|
-
new ConnectorError(`you already have a collection named '${name}'`, 409);
|
|
26
|
-
|
|
27
|
-
const nameClash = (name: string, collection: string): ConnectorError =>
|
|
28
|
-
new ConnectorError(
|
|
29
|
-
`the collection '${collection}' already has a connector named '${name}'`,
|
|
30
|
-
409,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
async function collidingCollection(
|
|
34
|
-
collectionIds: string[],
|
|
35
|
-
name: string,
|
|
36
|
-
exceptConnectorId: string,
|
|
37
|
-
): Promise<string | null> {
|
|
38
|
-
if (collectionIds.length === 0) return null;
|
|
39
|
-
const rows = await getDb()
|
|
40
|
-
.select({ collection: collections.name })
|
|
41
|
-
.from(collectionItems)
|
|
42
|
-
.innerJoin(connectors, eq(connectors.id, collectionItems.connectorId))
|
|
43
|
-
.innerJoin(collections, eq(collections.id, collectionItems.collectionId))
|
|
44
|
-
.where(
|
|
45
|
-
and(
|
|
46
|
-
inArray(collectionItems.collectionId, collectionIds),
|
|
47
|
-
eq(connectors.name, name),
|
|
48
|
-
ne(connectors.id, exceptConnectorId),
|
|
49
|
-
),
|
|
50
|
-
)
|
|
51
|
-
.limit(1);
|
|
52
|
-
return rows[0]?.collection ?? null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function assertRenameFreeOfClash(
|
|
56
|
-
connectorId: string,
|
|
57
|
-
name: string,
|
|
58
|
-
): Promise<void> {
|
|
59
|
-
const rows = await getDb()
|
|
60
|
-
.select({ collectionId: collectionItems.collectionId })
|
|
61
|
-
.from(collectionItems)
|
|
62
|
-
.where(eq(collectionItems.connectorId, connectorId));
|
|
63
|
-
const clash = await collidingCollection(
|
|
64
|
-
rows.map((r) => r.collectionId),
|
|
65
|
-
name,
|
|
66
|
-
connectorId,
|
|
67
|
-
);
|
|
68
|
-
if (clash !== null) throw nameClash(name, clash);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function ownedCollectionOrThrow(
|
|
72
|
-
email: string,
|
|
73
|
-
id: string,
|
|
74
|
-
): Promise<CollectionRow> {
|
|
75
|
-
const rows = await getDb()
|
|
76
|
-
.select()
|
|
77
|
-
.from(collections)
|
|
78
|
-
.where(eq(collections.id, id));
|
|
79
|
-
const row = rows[0];
|
|
80
|
-
if (row === undefined) throw missing();
|
|
81
|
-
try {
|
|
82
|
-
await projectIdOrThrow(email, row.projectId);
|
|
83
|
-
} catch {
|
|
84
|
-
throw missing();
|
|
85
|
-
}
|
|
86
|
-
return row;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async function itemsOf(collectionId: string): Promise<string[]> {
|
|
90
|
-
const rows = await getDb()
|
|
91
|
-
.select({ connectorId: collectionItems.connectorId })
|
|
92
|
-
.from(collectionItems)
|
|
93
|
-
.where(eq(collectionItems.collectionId, collectionId))
|
|
94
|
-
.orderBy(asc(collectionItems.id));
|
|
95
|
-
return rows.map((r) => r.connectorId);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async function withItems(row: CollectionRow): Promise<ConnectorCollectionRow> {
|
|
99
|
-
return { id: row.id, name: row.name, connectorIds: await itemsOf(row.id) };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export async function listCollectionsForEmail(
|
|
103
|
-
email: string,
|
|
104
|
-
project: string,
|
|
105
|
-
): Promise<ConnectorCollectionRow[]> {
|
|
106
|
-
const projectId = await projectIdOrThrow(email, project);
|
|
107
|
-
const rows = await getDb()
|
|
108
|
-
.select()
|
|
109
|
-
.from(collections)
|
|
110
|
-
.where(eq(collections.projectId, projectId))
|
|
111
|
-
.orderBy(asc(collections.id));
|
|
112
|
-
return Promise.all(rows.map(withItems));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export async function getCollectionForEmail(
|
|
116
|
-
email: string,
|
|
117
|
-
id: string,
|
|
118
|
-
): Promise<ConnectorCollectionRow> {
|
|
119
|
-
return withItems(await ownedCollectionOrThrow(email, id));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export async function createCollectionForEmail(
|
|
123
|
-
email: string,
|
|
124
|
-
project: string,
|
|
125
|
-
raw: string,
|
|
126
|
-
): Promise<ConnectorCollectionRow> {
|
|
127
|
-
const name = connectorName(raw);
|
|
128
|
-
const projectId = await projectIdOrThrow(email, project);
|
|
129
|
-
try {
|
|
130
|
-
const rows = await getDb()
|
|
131
|
-
.insert(collections)
|
|
132
|
-
.values({ id: newId(), projectId, name })
|
|
133
|
-
.returning();
|
|
134
|
-
const row = rows[0];
|
|
135
|
-
if (row === undefined)
|
|
136
|
-
throw new ConnectorError('collection insert returned no row', 500);
|
|
137
|
-
return { id: row.id, name: row.name, connectorIds: [] };
|
|
138
|
-
} catch (err) {
|
|
139
|
-
if (!isUniqueViolation(err)) throw err;
|
|
140
|
-
throw duplicate(name);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export async function renameCollectionForEmail(
|
|
145
|
-
email: string,
|
|
146
|
-
id: string,
|
|
147
|
-
raw: string,
|
|
148
|
-
): Promise<ConnectorCollectionRow> {
|
|
149
|
-
const name = connectorName(raw);
|
|
150
|
-
const row = await ownedCollectionOrThrow(email, id);
|
|
151
|
-
try {
|
|
152
|
-
await getDb()
|
|
153
|
-
.update(collections)
|
|
154
|
-
.set({ name })
|
|
155
|
-
.where(eq(collections.id, row.id));
|
|
156
|
-
} catch (err) {
|
|
157
|
-
if (!isUniqueViolation(err)) throw err;
|
|
158
|
-
throw duplicate(name);
|
|
159
|
-
}
|
|
160
|
-
return withItems({ ...row, name });
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export async function deleteCollectionForEmail(
|
|
164
|
-
email: string,
|
|
165
|
-
id: string,
|
|
166
|
-
): Promise<{ id: string; name: string }> {
|
|
167
|
-
const row = await ownedCollectionOrThrow(email, id);
|
|
168
|
-
await getDb().delete(collections).where(eq(collections.id, row.id));
|
|
169
|
-
return { id: row.id, name: row.name };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
async function connectorNameIn(
|
|
173
|
-
projectId: string,
|
|
174
|
-
connectorId: string,
|
|
175
|
-
): Promise<string | null> {
|
|
176
|
-
const rows = await getDb()
|
|
177
|
-
.select({ name: connectors.name })
|
|
178
|
-
.from(connectors)
|
|
179
|
-
.where(and(eq(connectors.id, connectorId), eq(connectors.projectId, projectId)));
|
|
180
|
-
return rows[0]?.name ?? null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export async function addToCollectionForEmail(
|
|
184
|
-
email: string,
|
|
185
|
-
id: string,
|
|
186
|
-
connectorId: string,
|
|
187
|
-
): Promise<ConnectorCollectionRow> {
|
|
188
|
-
const row = await ownedCollectionOrThrow(email, id);
|
|
189
|
-
const name = await connectorNameIn(row.projectId, connectorId);
|
|
190
|
-
if (name === null) throw new ConnectorError('no such connector', 404);
|
|
191
|
-
const clash = await collidingCollection([row.id], name, connectorId);
|
|
192
|
-
if (clash !== null) throw nameClash(name, clash);
|
|
193
|
-
try {
|
|
194
|
-
await getDb()
|
|
195
|
-
.insert(collectionItems)
|
|
196
|
-
.values({ id: newId(), collectionId: row.id, connectorId });
|
|
197
|
-
} catch (err) {
|
|
198
|
-
if (!isUniqueViolation(err)) throw err;
|
|
199
|
-
}
|
|
200
|
-
return withItems(row);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export async function removeFromCollectionForEmail(
|
|
204
|
-
email: string,
|
|
205
|
-
id: string,
|
|
206
|
-
connectorId: string,
|
|
207
|
-
): Promise<ConnectorCollectionRow> {
|
|
208
|
-
const row = await ownedCollectionOrThrow(email, id);
|
|
209
|
-
await getDb()
|
|
210
|
-
.delete(collectionItems)
|
|
211
|
-
.where(
|
|
212
|
-
and(
|
|
213
|
-
eq(collectionItems.collectionId, row.id),
|
|
214
|
-
eq(collectionItems.connectorId, connectorId),
|
|
215
|
-
),
|
|
216
|
-
);
|
|
217
|
-
return withItems(row);
|
|
218
|
-
}
|