(input: {
readonly code: string;
readonly title?: string;
readonly description?: string;
readonly connections?: Readonly<Record<string, string>>;
readonly artifactId?: string;
})
| 1901 | * what is stored, so a pure code tweak doesn't have to restate them. |
| 1902 | */ |
| 1903 | const createArtifact = (input: { |
| 1904 | readonly code: string; |
| 1905 | readonly title?: string; |
| 1906 | readonly description?: string; |
| 1907 | readonly connections?: Readonly<Record<string, string>>; |
| 1908 | readonly artifactId?: string; |
| 1909 | }): Effect.Effect<McpToolResult, unknown> => |
| 1910 | Effect.gen(function* () { |
| 1911 | // An update reads the existing row FIRST, both to carry its title and |
| 1912 | // description forward and to refuse a foreign id before any work. The |
| 1913 | // refusal is `artifact_unavailable` — the same answer `execute-action` |
| 1914 | // gives — so create-artifact cannot be used to probe which ids exist. |
| 1915 | const existing = |
| 1916 | input.artifactId === undefined ? null : yield* loadArtifact(input.artifactId); |
| 1917 | if (input.artifactId !== undefined && !existing) return actionArtifactUnavailableResult(); |
| 1918 | |
| 1919 | const title = input.title ?? existing?.title; |
| 1920 | if (title === undefined) { |
| 1921 | return renderRejectedResult( |
| 1922 | "title is required when creating an artifact. Give it a short human-readable name.", |
| 1923 | ); |
| 1924 | } |
| 1925 | // Only an update inherits; a create with no description stores none. |
| 1926 | const description = input.description ?? existing?.description ?? undefined; |
| 1927 | |
| 1928 | return yield* validateRenderAndSave({ |
| 1929 | code: input.code, |
| 1930 | title, |
| 1931 | description, |
| 1932 | connections: input.connections, |
| 1933 | existing, |
| 1934 | }); |
| 1935 | }).pipe( |
| 1936 | Effect.withSpan("mcp.host.tool.create_artifact", { |
| 1937 | attributes: { |
| 1938 | "mcp.tool.name": "create-artifact", |
| 1939 | "mcp.artifact.update": input.artifactId !== undefined, |
| 1940 | "mcp.execute.code_length": input.code.length, |
| 1941 | }, |
| 1942 | }), |
| 1943 | ); |
| 1944 | |
| 1945 | /** |
| 1946 | * `edit-artifact`: the update path for tweaks, patching the stored source |
no test coverage detected