Skip to main content
Glama
0xjcf
by 0xjcf

project-info

Analyzes code projects to extract key information for development workflows, including syntax structure and dependencies.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'project-info' tool that executes the logic to retrieve project metadata including package information, git status, and file statistics.
    server.tool("project-info", {}, async () => {
      try {
        const packageJsonPath = join(process.cwd(), "package.json");
        let packageInfo = {};
    
        if (existsSync(packageJsonPath)) {
          const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
          packageInfo = {
            name: packageJson.name,
            version: packageJson.version,
            description: packageJson.description,
            dependencies: Object.keys(packageJson.dependencies || {}),
            devDependencies: Object.keys(packageJson.devDependencies || {}),
          };
        }
    
        // Get git info
        let gitInfo = {};
        try {
          const branch = execSync("git branch --show-current", {
            encoding: "utf-8",
          }).trim();
          const lastCommit = execSync(
            'git log -1 --pretty=format:"%h - %s (%cr)"',
            { encoding: "utf-8" }
          ).trim();
          gitInfo = { branch, lastCommit };
        } catch (e) {
          gitInfo = { error: "Git information not available" };
        }
    
        // Count files by type
        let fileStats = {};
        try {
          const tsFiles = execSync('find src -name "*.ts" | wc -l', {
            encoding: "utf-8",
          }).trim();
          const jsFiles = execSync('find src -name "*.js" | wc -l', {
            encoding: "utf-8",
          }).trim();
          const testFiles = execSync('find src -name "*.test.ts" | wc -l', {
            encoding: "utf-8",
          }).trim();
          fileStats = {
            tsFiles: parseInt(tsFiles, 10),
            jsFiles: parseInt(jsFiles, 10),
            testFiles: parseInt(testFiles, 10),
          };
        } catch (e) {
          fileStats = { error: "File statistics not available" };
        }
    
        const result = createSuccessResponse(
          {
            packageInfo,
            gitInfo,
            fileStats,
            timestamp: new Date().toISOString(),
          },
          "project-info"
        );
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                createErrorResponse(
                  error instanceof Error ? error.message : String(error),
                  "project-info"
                ),
                null,
                2
              ),
            },
          ],
          isError: true,
        };
      }
    });
  • Registration of the 'project-info' tool using server.tool() within the dev-tools feature module.
    server.tool("project-info", {}, async () => {
      try {
        const packageJsonPath = join(process.cwd(), "package.json");
        let packageInfo = {};
    
        if (existsSync(packageJsonPath)) {
          const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
          packageInfo = {
            name: packageJson.name,
            version: packageJson.version,
            description: packageJson.description,
            dependencies: Object.keys(packageJson.dependencies || {}),
            devDependencies: Object.keys(packageJson.devDependencies || {}),
          };
        }
    
        // Get git info
        let gitInfo = {};
        try {
          const branch = execSync("git branch --show-current", {
            encoding: "utf-8",
          }).trim();
          const lastCommit = execSync(
            'git log -1 --pretty=format:"%h - %s (%cr)"',
            { encoding: "utf-8" }
          ).trim();
          gitInfo = { branch, lastCommit };
        } catch (e) {
          gitInfo = { error: "Git information not available" };
        }
    
        // Count files by type
        let fileStats = {};
        try {
          const tsFiles = execSync('find src -name "*.ts" | wc -l', {
            encoding: "utf-8",
          }).trim();
          const jsFiles = execSync('find src -name "*.js" | wc -l', {
            encoding: "utf-8",
          }).trim();
          const testFiles = execSync('find src -name "*.test.ts" | wc -l', {
            encoding: "utf-8",
          }).trim();
          fileStats = {
            tsFiles: parseInt(tsFiles, 10),
            jsFiles: parseInt(jsFiles, 10),
            testFiles: parseInt(testFiles, 10),
          };
        } catch (e) {
          fileStats = { error: "File statistics not available" };
        }
    
        const result = createSuccessResponse(
          {
            packageInfo,
            gitInfo,
            fileStats,
            timestamp: new Date().toISOString(),
          },
          "project-info"
        );
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                createErrorResponse(
                  error instanceof Error ? error.message : String(error),
                  "project-info"
                ),
                null,
                2
              ),
            },
          ],
          isError: true,
        };
      }
    });
  • Helper function createSuccessResponse used by the project-info handler to format successful responses in standard format.
    export function createSuccessResponse<T>(
      data: T,
      tool: string,
      options?: {
        version?: string;
        sessionId?: string;
        relatedResults?: string[];
        executionTime?: number;
      }
    ): ToolResponse<T> {
      const startTime =
        options?.executionTime !== undefined
          ? Date.now() - options.executionTime
          : undefined;
    
      const response: ToolResponse<T> = {
        data,
        metadata: {
          tool,
          version: options?.version || "1.0.0",
          executionTime: options?.executionTime || 0,
          timestamp: new Date().toISOString(),
        },
        status: {
          success: true,
          code: 200,
        },
      };
    
      // Add context if we have session information
      if (options?.sessionId || options?.relatedResults) {
        response.context = {
          sessionId: options?.sessionId,
          relatedResults: options?.relatedResults,
        };
      }
    
      // If we need to calculate execution time
      if (startTime) {
        response.metadata.executionTime = Date.now() - startTime;
      }
    
      // Validate the response structure
      try {
        ToolResponseSchema.parse(response);
      } catch (error) {
        console.error("Invalid response structure:", error);
        // Still return the response even if validation fails
      }
    
      return response;
    }
  • Helper function createErrorResponse used by the project-info handler for error responses.
    export function createErrorResponse<T = null>(
      message: string,
      tool: string,
      options?: {
        code?: number;
        data?: T;
        version?: string;
        sessionId?: string;
        executionTime?: number;
      }
    ): ToolResponse<T | null> {
      const startTime =
        options?.executionTime !== undefined
          ? Date.now() - options.executionTime
          : undefined;
    
      const response: ToolResponse<T | null> = {
        data: options?.data || null,
        metadata: {
          tool,
          version: options?.version || "1.0.0",
          executionTime: options?.executionTime || 0,
          timestamp: new Date().toISOString(),
        },
        status: {
          success: false,
          code: options?.code || 400,
          message,
        },
      };
    
      // Add context if we have session information
      if (options?.sessionId) {
        response.context = {
          sessionId: options?.sessionId,
        };
      }
    
      // If we need to calculate execution time
      if (startTime) {
        response.metadata.executionTime = Date.now() - startTime;
      }
    
      // Validate the response structure
      try {
        ToolResponseSchema.parse(response);
      } catch (error) {
        console.error("Invalid error response structure:", error);
        // Still return the response even if validation fails
      }
    
      return response;
    }

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/0xjcf/MCP_CodeAnalysis'

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