MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / createArtifact

Function createArtifact

packages/hosts/mcp/src/tool-server.ts:2460–2500  ·  view source on GitHub ↗
(input: {
      readonly code: string;
      readonly title?: string;
      readonly description?: string;
      readonly connections?: Readonly<Record<string, string>>;
      readonly artifactId?: string;
    })

Source from the content-addressed store, hash-verified

2458 * what is stored, so a pure code tweak doesn't have to restate them.
2459 */
2460 const createArtifact = (input: {
2461 readonly code: string;
2462 readonly title?: string;
2463 readonly description?: string;
2464 readonly connections?: Readonly<Record<string, string>>;
2465 readonly artifactId?: string;
2466 }): Effect.Effect<McpToolResult, unknown> =>
2467 Effect.gen(function* () {
2468 // An update reads the existing row FIRST, both to carry its title and
2469 // description forward and to refuse a foreign id before any work. The
2470 // refusal is `artifact_unavailable` — the same answer `execute-action`
2471 // gives — so create-artifact cannot be used to probe which ids exist.
2472 const existing =
2473 input.artifactId === undefined ? null : yield* loadArtifact(input.artifactId);
2474 if (input.artifactId !== undefined && !existing) return actionArtifactUnavailableResult();
2475
2476 const title = input.title ?? existing?.title;
2477 if (title === undefined) {
2478 return renderRejectedResult(
2479 "title is required when creating an artifact. Give it a short human-readable name.",
2480 );
2481 }
2482 // Only an update inherits; a create with no description stores none.
2483 const description = input.description ?? existing?.description ?? undefined;
2484
2485 return yield* validateRenderAndSave({
2486 code: input.code,
2487 title,
2488 description,
2489 connections: input.connections,
2490 existing,
2491 });
2492 }).pipe(
2493 Effect.withSpan("mcp.host.tool.create_artifact", {
2494 attributes: {
2495 "mcp.tool.name": "create-artifact",
2496 "mcp.artifact.update": input.artifactId !== undefined,
2497 "mcp.execute.code_length": input.code.length,
2498 },
2499 }),
2500 );
2501
2502 /**
2503 * `edit-artifact`: the update path for tweaks, patching the stored source

Callers 1

createExecutorMcpServerFunction · 0.85

Calls 4

loadArtifactFunction · 0.85
renderRejectedResultFunction · 0.85
validateRenderAndSaveFunction · 0.85

Tested by

no test coverage detected