Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion .mise-tasks/seed.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { projectsRead } from "@gram/client/funcs/projectsRead.js";
import { toolsList } from "@gram/client/funcs/toolsList.js";
import { toolsetsCreate } from "@gram/client/funcs/toolsetsCreate.js";
import { toolsetsUpdateBySlug } from "@gram/client/funcs/toolsetsUpdateBySlug.js";
import { mcpMetadataSet } from "@gram/client/funcs/mcpMetadataSet.js";
import { ServiceError } from "@gram/client/models/errors";
import { $ } from "zx";

Expand All @@ -27,6 +28,8 @@ type Asset = {
slug: string;
filename: string;
storybookDefault?: boolean;
docsUrl?: string;
docsBtnText?: string;
};

const SEED_PROJECTS: {
Expand All @@ -47,6 +50,8 @@ const SEED_PROJECTS: {
slug: "kitchen-sink",
filename: path.join("local", "openapi", "kitchen-sink.json"),
storybookDefault: true,
docsUrl: "https://docs.getgram.ai",
docsBtnText: "Gram Docs",
},
{
type: "openapi",
Expand Down Expand Up @@ -149,6 +154,8 @@ async function seed() {
projectSlug,
assetSlug: asset.slug,
mcpPublic,
docsUrl: asset.docsUrl,
docsBtnText: asset.docsBtnText,
});
verb = toolset.created ? "Created" : "Updated";
log.info(
Expand Down Expand Up @@ -340,8 +347,10 @@ async function upsertToolset(init: {
projectSlug: string;
assetSlug: string;
mcpPublic: boolean;
docsUrl?: string;
docsBtnText?: string;
}): Promise<Toolset> {
const { gram, serverURL, sessionId, projectSlug, assetSlug, mcpPublic } =
const { gram, serverURL, sessionId, projectSlug, assetSlug, mcpPublic, docsUrl, docsBtnText } =
init;

// Fetch tools filtered by URN prefix
Expand Down Expand Up @@ -465,6 +474,29 @@ async function upsertToolset(init: {

log.info(`${toolset.mcpURL} visibility was changed to public`);

// Set MCP metadata if docs URL is provided
if (docsUrl) {
const metadataRes = await mcpMetadataSet(
gram,
{
setMcpMetadataRequestBody: {
toolsetSlug: toolset.slug,
externalDocumentationUrl: docsUrl,
externalDocumentationText: docsBtnText,
},
},
{
sessionHeaderGramSession: sessionId,
projectSlugHeaderGramProject: projectSlug,
},
);
if (!metadataRes.ok) {
log.warn(`Failed to set MCP metadata for toolset '${toolset.slug}': ${metadataRes.error}`);
} else {
log.info(`Set MCP metadata for toolset '${toolset.slug}' (docs: ${docsUrl})`);
}
}

return toolset;
}

Expand Down
Loading
Loading