@catamorphic/fastify-plugin 0.1.0-alpha.39 → 0.1.0-alpha.42
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/NOTICE.txt +7 -0
- package/dist/app.d.ts +2 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/chunk-jytcc42y.js +592 -0
- package/dist/chunk-jytcc42y.js.map +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1673 -411
- package/dist/index.js.map +29 -25
- package/dist/mcp-scopes.d.ts +12 -0
- package/dist/mcp-scopes.d.ts.map +1 -0
- package/dist/mcp-server.d.ts +158 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-shared.d.ts +3 -50
- package/dist/mcp-shared.d.ts.map +1 -1
- package/dist/mcp.d.ts +4 -2
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +6 -4
- package/dist/mcp.js.map +1 -1
- package/dist/plugin.d.ts +26 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/project-capabilities.d.ts.map +1 -1
- package/dist/project-mcp-surface.d.ts +3 -4
- package/dist/project-mcp-surface.d.ts.map +1 -1
- package/dist/routes/agent.d.ts.map +1 -1
- package/dist/routes/apps-mcp.d.ts.map +1 -1
- package/dist/routes/client-runners.d.ts.map +1 -1
- package/dist/routes/connection-mcp.d.ts.map +1 -1
- package/dist/routes/documents.d.ts.map +1 -1
- package/dist/routes/environments.d.ts.map +1 -1
- package/dist/routes/project-mcp.d.ts.map +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/publications.d.ts.map +1 -1
- package/dist/routes/run-errors.d.ts.map +1 -1
- package/dist/routes/runs.d.ts.map +1 -1
- package/dist/routes/server-mcp.d.ts +17 -0
- package/dist/routes/server-mcp.d.ts.map +1 -0
- package/dist/routes/session-mailboxes.d.ts.map +1 -1
- package/dist/routes/triggers.d.ts.map +1 -1
- package/dist/routes/watchers.d.ts.map +1 -1
- package/dist/routes/workflow-enablements.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/schemas.d.ts +3684 -28
- package/dist/schemas.d.ts.map +1 -1
- package/dist/session-mcp.d.ts +54 -0
- package/dist/session-mcp.d.ts.map +1 -0
- package/dist/session-tools.d.ts +49 -0
- package/dist/session-tools.d.ts.map +1 -0
- package/package.json +12 -12
- package/src/app.ts +3 -0
- package/src/index.ts +1 -0
- package/src/mcp-scopes.ts +69 -0
- package/src/mcp-server.ts +827 -0
- package/src/mcp-shared.ts +3 -151
- package/src/mcp.ts +6 -5
- package/src/plugin.ts +73 -2
- package/src/project-capabilities.ts +5 -3
- package/src/project-mcp-program.ts +2 -2
- package/src/project-mcp-surface.ts +18 -239
- package/src/routes/agent.ts +384 -41
- package/src/routes/apps-mcp.ts +84 -82
- package/src/routes/client-runners.ts +3 -1
- package/src/routes/connection-mcp.ts +6 -13
- package/src/routes/documents.ts +4 -0
- package/src/routes/environments.ts +49 -1
- package/src/routes/project-mcp.ts +176 -154
- package/src/routes/projects.ts +6 -0
- package/src/routes/publications.ts +2 -0
- package/src/routes/run-errors.ts +5 -1
- package/src/routes/runs.ts +4 -0
- package/src/routes/server-mcp.ts +151 -0
- package/src/routes/session-mailboxes.ts +1 -0
- package/src/routes/triggers.ts +6 -1
- package/src/routes/watchers.ts +1 -0
- package/src/routes/workflow-enablements.ts +132 -1
- package/src/routes/workflows.ts +4 -0
- package/src/schemas.ts +347 -5
- package/src/session-mcp.ts +696 -0
- package/src/session-tools.ts +169 -0
- package/dist/chunk-baagvvm3.js +0 -164
- package/dist/chunk-baagvvm3.js.map +0 -10
package/src/routes/apps-mcp.ts
CHANGED
|
@@ -2,11 +2,10 @@ import { buildAppGuestDocument } from "@catamorphic/app";
|
|
|
2
2
|
import type { FastifyInstance } from "fastify";
|
|
3
3
|
import type { RouteContext } from "../app.js";
|
|
4
4
|
import { resolveIdentity } from "../http-identity.js";
|
|
5
|
+
import { mayCallTool, withheldTools } from "../mcp-scopes.js";
|
|
6
|
+
import { MCP_ERROR, McpError, type McpTool, serveMcp } from "../mcp-server.js";
|
|
5
7
|
import {
|
|
6
8
|
callPollRunTool,
|
|
7
|
-
handleMcpPost,
|
|
8
|
-
McpRequestError,
|
|
9
|
-
negotiateProtocolVersion,
|
|
10
9
|
POLL_RUN_TOOL,
|
|
11
10
|
POLL_RUN_TOOL_DEFINITION,
|
|
12
11
|
toolError,
|
|
@@ -30,10 +29,10 @@ import {
|
|
|
30
29
|
* app, so the frozen-workflow-set authorization applies to MCP callers
|
|
31
30
|
* exactly as it does to the in-product iframe.
|
|
32
31
|
*
|
|
33
|
-
* The endpoint is
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
32
|
+
* The endpoint is stateless Streamable HTTP on the dispatcher every MCP
|
|
33
|
+
* endpoint shares (`mcp-server.ts`, ADR 0347): the current revision and
|
|
34
|
+
* the handshake revisions on one URL. Requests are independent; no
|
|
35
|
+
* sessions.
|
|
37
36
|
*/
|
|
38
37
|
|
|
39
38
|
const RUN_CALL_BUDGET_MS = 120_000;
|
|
@@ -52,86 +51,89 @@ interface PublishedApp {
|
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
export function registerAppsMcpRoutes(app: FastifyInstance, ctx: RouteContext) {
|
|
55
|
-
app.post(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
app.post(
|
|
55
|
+
"/projects/:projectId/apps-mcp",
|
|
56
|
+
{ config: { tokenScope: "work:read" } },
|
|
57
|
+
async (request, reply) => {
|
|
58
|
+
const core = ctx.core;
|
|
59
|
+
if (!core?.apps || !core.runs) {
|
|
60
|
+
return reply.status(503).send({ error: "Apps not configured" });
|
|
61
|
+
}
|
|
62
|
+
const { projectId } = request.params as { projectId: string };
|
|
61
63
|
|
|
62
|
-
return handleMcpPost(reply, request.body, async (method, params) => {
|
|
63
64
|
const identity = resolveIdentity(request);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
contents: [
|
|
106
|
-
{
|
|
107
|
-
uri,
|
|
65
|
+
let loaded: Promise<PublishedApp[]> | undefined;
|
|
66
|
+
const apps = () => {
|
|
67
|
+
loaded ??= loadPublishedApps(core, identity, projectId);
|
|
68
|
+
return loaded;
|
|
69
|
+
};
|
|
70
|
+
const tools = async () =>
|
|
71
|
+
buildTools(await apps()).map(
|
|
72
|
+
(definition): McpTool => ({
|
|
73
|
+
definition,
|
|
74
|
+
scope:
|
|
75
|
+
definition.name === POLL_RUN_TOOL ? "work:read" : "sessions:run",
|
|
76
|
+
call: (args) =>
|
|
77
|
+
callTool(
|
|
78
|
+
core,
|
|
79
|
+
identity,
|
|
80
|
+
projectId,
|
|
81
|
+
String(definition.name),
|
|
82
|
+
args,
|
|
83
|
+
),
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
return serveMcp({
|
|
87
|
+
request,
|
|
88
|
+
reply,
|
|
89
|
+
resourceMetadataUrl: ctx.mcp?.resourceMetadataUrl,
|
|
90
|
+
endpoint: {
|
|
91
|
+
serverInfo: {
|
|
92
|
+
name: "catamorphic-apps",
|
|
93
|
+
title: "Catamorphic apps",
|
|
94
|
+
version: "1.0.0",
|
|
95
|
+
},
|
|
96
|
+
tools: async () =>
|
|
97
|
+
(await tools()).filter((tool) => mayCallTool(identity, tool)),
|
|
98
|
+
withheld: async () => withheldTools(identity, await tools()),
|
|
99
|
+
resources: {
|
|
100
|
+
list: async () =>
|
|
101
|
+
(await apps()).map((published) => ({
|
|
102
|
+
uri: appResourceUri(published.name),
|
|
103
|
+
name: `${published.name} app`,
|
|
108
104
|
mimeType: MCP_APP_MIME_TYPE,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
105
|
+
})),
|
|
106
|
+
templates: async () => [],
|
|
107
|
+
read: async (uri) => {
|
|
108
|
+
const published = (await apps()).find(
|
|
109
|
+
(candidate) => appResourceUri(candidate.name) === uri,
|
|
110
|
+
);
|
|
111
|
+
if (!published)
|
|
112
|
+
throw new McpError(
|
|
113
|
+
MCP_ERROR.invalidParams,
|
|
114
|
+
`Unknown resource ${uri}`,
|
|
115
|
+
);
|
|
116
|
+
return [
|
|
117
|
+
{
|
|
118
|
+
uri,
|
|
119
|
+
mimeType: MCP_APP_MIME_TYPE,
|
|
120
|
+
text: buildAppDocument(published),
|
|
121
|
+
_meta: {
|
|
122
|
+
ui: {
|
|
123
|
+
// Catamorphic apps have no network of their own:
|
|
124
|
+
// every effect is a workflow call through the host.
|
|
125
|
+
csp: { connectDomains: [], resourceDomains: [] },
|
|
126
|
+
prefersBorder: true,
|
|
127
|
+
},
|
|
116
128
|
},
|
|
117
129
|
},
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
typeof params.arguments === "object" && params.arguments !== null
|
|
126
|
-
? (params.arguments as Record<string, unknown>)
|
|
127
|
-
: {};
|
|
128
|
-
return callTool(core, identity, projectId, name, args);
|
|
129
|
-
}
|
|
130
|
-
default:
|
|
131
|
-
throw new McpRequestError(-32601, `Method not found: ${method}`);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
130
|
+
];
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
);
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app";
|
|
@@ -44,7 +44,7 @@ export function registerClientRunnerRoutes(
|
|
|
44
44
|
isolation: z.enum(["none", "process", "sandbox"]).optional(),
|
|
45
45
|
/** The runner's provider runs background processes (ADR 0174). */
|
|
46
46
|
processes: z.boolean().optional(),
|
|
47
|
-
/** What its sandboxes can be given (ADRs 0176, 0208). */
|
|
47
|
+
/** What its sandboxes can be given (ADRs 0176, 0208, 0332, 0334). */
|
|
48
48
|
capabilities: z
|
|
49
49
|
.array(
|
|
50
50
|
z.enum([
|
|
@@ -54,6 +54,8 @@ export function registerClientRunnerRoutes(
|
|
|
54
54
|
"network.policy",
|
|
55
55
|
"network.setup",
|
|
56
56
|
"volumes",
|
|
57
|
+
"caches",
|
|
58
|
+
"commands.separate",
|
|
57
59
|
]),
|
|
58
60
|
)
|
|
59
61
|
.optional(),
|
|
@@ -5,12 +5,8 @@ import {
|
|
|
5
5
|
import type { Json } from "@catamorphic/db";
|
|
6
6
|
import type { FastifyInstance } from "fastify";
|
|
7
7
|
import type { RouteContext } from "../app.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
serveForwardedTools,
|
|
11
|
-
toolError,
|
|
12
|
-
toolValue,
|
|
13
|
-
} from "../mcp-shared.js";
|
|
8
|
+
import { McpError, serveForwardedTools } from "../mcp-server.js";
|
|
9
|
+
import { toolError, toolValue } from "../mcp-shared.js";
|
|
14
10
|
|
|
15
11
|
/**
|
|
16
12
|
* One brokered connection as an agent's MCP server (`connection_<alias>`).
|
|
@@ -65,8 +61,8 @@ export function registerConnectionMcpRoutes(
|
|
|
65
61
|
}
|
|
66
62
|
const mcp = broker.servesMcp(binding.providerKind);
|
|
67
63
|
return serveForwardedTools({
|
|
64
|
+
request,
|
|
68
65
|
reply,
|
|
69
|
-
body: request.body,
|
|
70
66
|
serverName: "catamorphic-connection-broker",
|
|
71
67
|
listTools: async () => {
|
|
72
68
|
try {
|
|
@@ -86,15 +82,12 @@ export function registerConnectionMcpRoutes(
|
|
|
86
82
|
outputSchema: undefined,
|
|
87
83
|
}));
|
|
88
84
|
} catch {
|
|
89
|
-
throw new
|
|
85
|
+
throw new McpError(-32_000, "Connection action failed");
|
|
90
86
|
}
|
|
91
87
|
},
|
|
92
88
|
callTool: async (call) => {
|
|
93
89
|
if (!binding.capabilities.includes(call.name)) {
|
|
94
|
-
throw new
|
|
95
|
-
-32602,
|
|
96
|
-
"Tool is outside the connection grant",
|
|
97
|
-
);
|
|
90
|
+
throw new McpError(-32602, "Tool is outside the connection grant");
|
|
98
91
|
}
|
|
99
92
|
try {
|
|
100
93
|
const output = await broker.invoke({
|
|
@@ -118,7 +111,7 @@ export function registerConnectionMcpRoutes(
|
|
|
118
111
|
) {
|
|
119
112
|
return toolError(error.message);
|
|
120
113
|
}
|
|
121
|
-
throw new
|
|
114
|
+
throw new McpError(-32_000, "Connection action failed");
|
|
122
115
|
}
|
|
123
116
|
},
|
|
124
117
|
});
|
package/src/routes/documents.ts
CHANGED
|
@@ -210,6 +210,7 @@ export function registerDocumentRoutes(
|
|
|
210
210
|
typed.route({
|
|
211
211
|
method: "PUT",
|
|
212
212
|
url: "/projects/:projectId/documents/content",
|
|
213
|
+
config: { tokenScope: "documents:write" },
|
|
213
214
|
// The body must fit the largest allowed document base64-inflated (4/3)
|
|
214
215
|
// plus the JSON envelope; the handler's storeUploadMaxBytes check owns
|
|
215
216
|
// the accurate 413 for decoded content.
|
|
@@ -262,6 +263,7 @@ export function registerDocumentRoutes(
|
|
|
262
263
|
typed.route({
|
|
263
264
|
method: "DELETE",
|
|
264
265
|
url: "/projects/:projectId/documents/content",
|
|
266
|
+
config: { tokenScope: "documents:write" },
|
|
265
267
|
schema: {
|
|
266
268
|
params: ProjectIdParamsSchema,
|
|
267
269
|
querystring: z.object({
|
|
@@ -360,6 +362,7 @@ export function registerDocumentRoutes(
|
|
|
360
362
|
typed.route({
|
|
361
363
|
method: "POST",
|
|
362
364
|
url: "/projects/:projectId/proposals",
|
|
365
|
+
config: { tokenScope: "program:write" },
|
|
363
366
|
schema: {
|
|
364
367
|
params: ProjectIdParamsSchema,
|
|
365
368
|
body: ProposeChangeSchema,
|
|
@@ -507,6 +510,7 @@ export function registerDocumentRoutes(
|
|
|
507
510
|
typed.route({
|
|
508
511
|
method: "POST",
|
|
509
512
|
url: "/projects/:projectId/proposals/:number/comments",
|
|
513
|
+
config: { tokenScope: "program:write" },
|
|
510
514
|
schema: {
|
|
511
515
|
params: ProjectIdParamsSchema.extend({
|
|
512
516
|
number: z.coerce.number().int().positive(),
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AccessDeniedError,
|
|
3
|
+
AgentNotConfiguredError,
|
|
4
|
+
hasProjectPermission,
|
|
5
|
+
} from "@catamorphic/core";
|
|
2
6
|
import type { FastifyInstance } from "fastify";
|
|
3
7
|
import type { ZodTypeProvider } from "fastify-type-provider-zod";
|
|
4
8
|
import type { RouteContext } from "../app.js";
|
|
5
9
|
import { resolveIdentity } from "../http-identity.js";
|
|
6
10
|
import {
|
|
11
|
+
EnvironmentCacheListSchema,
|
|
7
12
|
EnvironmentListQuerySchema,
|
|
8
13
|
EnvironmentListSchema,
|
|
9
14
|
ErrorSchema,
|
|
@@ -69,4 +74,47 @@ export function registerEnvironmentRoutes(
|
|
|
69
74
|
}
|
|
70
75
|
},
|
|
71
76
|
});
|
|
77
|
+
// Operators see each cache's copies on machines, sizes, last use and
|
|
78
|
+
// the last fills' errors (ADR 0334).
|
|
79
|
+
typed.route({
|
|
80
|
+
method: "GET",
|
|
81
|
+
url: "/projects/:projectId/environment-caches",
|
|
82
|
+
schema: {
|
|
83
|
+
params: ProjectIdParamsSchema,
|
|
84
|
+
response: {
|
|
85
|
+
200: EnvironmentCacheListSchema,
|
|
86
|
+
403: ErrorSchema,
|
|
87
|
+
503: ErrorSchema,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
handler: async (request, reply) => {
|
|
91
|
+
const service = ctx.core?.cacheFills;
|
|
92
|
+
if (!service)
|
|
93
|
+
return reply
|
|
94
|
+
.status(503)
|
|
95
|
+
.send({ error: "Environment provider not configured" });
|
|
96
|
+
const identity = resolveIdentity(request);
|
|
97
|
+
if (
|
|
98
|
+
!hasProjectPermission(
|
|
99
|
+
identity,
|
|
100
|
+
request.params.projectId,
|
|
101
|
+
"automations:read",
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
return reply
|
|
105
|
+
.status(403)
|
|
106
|
+
.send({ error: "Seeing caches needs automations:read" });
|
|
107
|
+
try {
|
|
108
|
+
const items = await service.list({
|
|
109
|
+
identity,
|
|
110
|
+
projectId: request.params.projectId,
|
|
111
|
+
});
|
|
112
|
+
return reply.send(EnvironmentCacheListSchema.parse({ items }));
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (error instanceof AccessDeniedError)
|
|
115
|
+
return reply.status(403).send({ error: error.message });
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
});
|
|
72
120
|
}
|