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

Function createArtifact

packages/hosts/mcp/src/tool-server.ts:1787–1827  ·  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

1785 * what is stored, so a pure code tweak doesn't have to restate them.
1786 */
1787 const createArtifact = (input: {
1788 readonly code: string;
1789 readonly title?: string;
1790 readonly description?: string;
1791 readonly connections?: Readonly<Record<string, string>>;
1792 readonly artifactId?: string;
1793 }): Effect.Effect<McpToolResult, unknown> =>
1794 Effect.gen(function* () {
1795 // An update reads the existing row FIRST, both to carry its title and
1796 // description forward and to refuse a foreign id before any work. The
1797 // refusal is `artifact_unavailable` — the same answer `execute-action`
1798 // gives — so create-artifact cannot be used to probe which ids exist.
1799 const existing =
1800 input.artifactId === undefined ? null : yield* loadArtifact(input.artifactId);
1801 if (input.artifactId !== undefined && !existing) return actionArtifactUnavailableResult();
1802
1803 const title = input.title ?? existing?.title;
1804 if (title === undefined) {
1805 return renderRejectedResult(
1806 "title is required when creating an artifact. Give it a short human-readable name.",
1807 );
1808 }
1809 // Only an update inherits; a create with no description stores none.
1810 const description = input.description ?? existing?.description ?? undefined;
1811
1812 return yield* validateRenderAndSave({
1813 code: input.code,
1814 title,
1815 description,
1816 connections: input.connections,
1817 existing,
1818 });
1819 }).pipe(
1820 Effect.withSpan("mcp.host.tool.create_artifact", {
1821 attributes: {
1822 "mcp.tool.name": "create-artifact",
1823 "mcp.artifact.update": input.artifactId !== undefined,
1824 "mcp.execute.code_length": input.code.length,
1825 },
1826 }),
1827 );
1828
1829 /**
1830 * `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