Skip to main content
Glama

Generation module

Automatically rewrites variable values in files by matching and replacing them with specified options from an array, enabling configuration updates.

Instructions

 遍历工具返回的数组,将数组中每一项有 writeOptions: object、dir: string,两个属性。
 需要将对象writeOptions的属性进行遍历,找到dir文件中对应的变量名。 匹配规则:变量名和writeOptions的属性名称相等。
 匹配到了之后将dir中的变量值自动重写,使用writeOptions属性值覆盖,一定是自动重写。
 For example: 
 writeOptions示例
 ``` javascript
   writeOptions:{subnaem:'用户管理'}
 ```

 dir文件代码示例:
 ``` javascript
   const subnaem = '';
 ```

 经过规则匹配之后,dir文件重写后应该是:
 ``` javascript
   const subnaem = '用户管理';
 ```

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes描述文件地址

Implementation Reference

  • Registers the 'Generation module' tool, including name, description, input schema, and handler function.
    export function registerMyTool({ mcp }: McpToolContext): void {
      mcp.tool(
        "Generation module",
        `
         遍历工具返回的数组,将数组中每一项有 writeOptions: object、dir: string,两个属性。
         需要将对象writeOptions的属性进行遍历,找到dir文件中对应的变量名。 匹配规则:变量名和writeOptions的属性名称相等。
         匹配到了之后将dir中的变量值自动重写,使用writeOptions属性值覆盖,一定是自动重写。
         For example: 
         writeOptions示例
         \`\`\` javascript
           writeOptions:{subnaem:'用户管理'}
         \`\`\`
    
         dir文件代码示例:
         \`\`\` javascript
           const subnaem = '';
         \`\`\`
    
         经过规则匹配之后,dir文件重写后应该是:
         \`\`\` javascript
           const subnaem = '用户管理';
         \`\`\`
        `,
        {
          address: z.string().describe("描述文件地址"),
        },
        async ({ address }) => {
          if (!address)
            return {
              isError: true,
              content: [
                {
                  type: "text" as const,
                  text: "未识别到描述文件地址",
                },
              ],
            };
          const arr = await generration(address);
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({
                  ...arr,
                }),
              },
            ],
          };
        }
      );
    }
  • Tool handler: validates address, calls the generration module, returns array as JSON string in content.
      async ({ address }) => {
        if (!address)
          return {
            isError: true,
            content: [
              {
                type: "text" as const,
                text: "未识别到描述文件地址",
              },
            ],
          };
        const arr = await generration(address);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                ...arr,
              }),
            },
          ],
        };
      }
    );
  • Input schema: requires 'address' as a string, described as '描述文件地址'.
    {
      address: z.string().describe("描述文件地址"),
    },
  • Core 'generration' function (exported as default): reads markdown file at address, parses frontmatter for directoryStructure, fetches and writes templates to dirs, collects items with writeOptions into an array.
    import fs from "fs-extra";
    import matter from "gray-matter";
    async function main(
      address = "/Users/mac/project/mcp/funi-paas-cs-web-cli/src/apps/mcpText/user/readme.md"
    ) {
      const md = await fs.readFile(address, "utf-8");
      const { data } = matter(md);
      const arr: Record<any, any>[] = [];
      const { directoryStructure } = data;
      for (let i = 0; i < directoryStructure.length; i++) {
        const { dir, temeplate, writeOptions } = directoryStructure[i];
        const res = await fetch(temeplate);
        const text = await res.text();
        fs.ensureFileSync(dir);
        fs.writeFileSync(dir, text);
        if (writeOptions) {
          arr.push({
            dir,
            writeOptions,
          });
        }
      }
      return arr;
    }
    
    export default main;
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/CoutinhoTTS/funi-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server