generate-tools-docs.jsā¢4.49 kB
#!/usr/bin/env node
/**
* Generate markdown documentation for MCP tools from tools-config.json
*/
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Load tools configuration
const toolsConfigPath = path.join(__dirname, "..", "tools-config.json");
const tools = JSON.parse(fs.readFileSync(toolsConfigPath, "utf-8"));
// Group tools by category
const toolCategories = {
"Collection Management": ["uranium_list_collections", "uranium_create_collection"],
"Asset Management": ["uranium_list_assets", "uranium_create_asset"],
};
/**
* Format a single parameter for documentation
*/
function formatParameter(name, param, required = false) {
const parts = [];
// Parameter name
parts.push(` - \`${name}\``);
// Type and optionality
const meta = [];
if (param.type) {
meta.push(param.type);
}
if (param.enum) {
meta.push(`enum: ${param.enum.join(", ")}`);
}
if (!required) {
meta.push("optional");
} else {
meta.push("required");
}
if (meta.length > 0) {
parts.push(` (${meta.join(", ")})`);
}
// Description
parts.push(`: ${param.description || "No description"}`);
// Additional constraints
const constraints = [];
if (param.minLength !== undefined) {
constraints.push(`min length: ${param.minLength}`);
}
if (param.maxLength !== undefined) {
constraints.push(`max length: ${param.maxLength}`);
}
if (param.minimum !== undefined) {
constraints.push(`min: ${param.minimum}`);
}
if (param.maximum !== undefined) {
constraints.push(`max: ${param.maximum}`);
}
if (param.default !== undefined) {
constraints.push(`default: ${JSON.stringify(param.default)}`);
}
if (constraints.length > 0) {
parts.push(` [${constraints.join(", ")}]`);
}
return parts.join("");
}
/**
* Generate example usage for a tool
*/
function generateExample(tool) {
const examples = {
uranium_list_collections: `uranium_list_collections()`,
uranium_list_assets: `uranium_list_assets({
contractId: "collection_id_here",
quickFilter: "search text",
page: 1,
pageSize: 20
})`,
uranium_create_collection: `uranium_create_collection({
name: "My NFT Collection",
symbol: "MNC",
type: "ERC721"
})`,
uranium_create_asset: `uranium_create_asset({
contractId: "collection_id_here",
title: "My NFT Title",
filePath: "/absolute/path/to/image.jpg",
description: "Beautiful digital art",
shareWithCommunity: true
})`,
};
return examples[tool.name] || "";
}
/**
* Format a single tool for documentation
*/
function formatTool(tool) {
const lines = [];
lines.push(`#### ${tool.name}`);
lines.push(`- **Description**: ${tool.description}`);
// Parameters
const params = tool.inputSchema.properties || {};
const required = tool.inputSchema.required || [];
if (Object.keys(params).length === 0) {
lines.push("- **Parameters**: None");
} else {
lines.push("- **Parameters**:");
for (const [name, param] of Object.entries(params)) {
lines.push(formatParameter(name, param, required.includes(name)));
}
}
// Add example if available
const example = generateExample(tool);
if (example) {
lines.push("- **Example**:");
lines.push("```typescript");
lines.push(example);
lines.push("```");
}
return lines.join("\n");
}
/**
* Generate the complete tools documentation
*/
function generateToolsDocs() {
const lines = [];
lines.push("<!--- Tools generated by utils/generate-tools-docs.js -->");
lines.push("");
lines.push("This MCP server provides 4 main tools for NFT management:");
lines.push("");
// Generate documentation for each category
for (const [category, toolNames] of Object.entries(toolCategories)) {
lines.push("<details>");
lines.push(`<summary><b>${category}</b></summary>`);
lines.push("");
for (const toolName of toolNames) {
const tool = tools.find((t) => t.name === toolName);
if (tool) {
lines.push(formatTool(tool));
lines.push("");
}
}
lines.push("</details>");
lines.push("");
}
lines.push("<!--- End of tools generated section -->");
return lines.join("\n");
}
// If run directly, output the documentation
if (import.meta.url === `file://${process.argv[1]}`) {
console.log(generateToolsDocs());
}
export { generateToolsDocs };