Skip to main content
Glama
damonxue

OSSInsight MCP Server

get_repo_analysis

Analyze GitHub repository metrics including activity, stars, and issues to gain insights into project performance and trends.

Instructions

Get detailed analysis of a GitHub repository, including activity, stars, issues, and other metrics.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
owner_repoYesRepository name in the format 'owner/repo'
time_periodNoTime range for analysis (optional)

Implementation Reference

  • Core handler function that performs the repository analysis by querying the OSSInsight API or falling back to web scraping.
    async function getRepoAnalysis(ownerRepo: string, timePeriod?: string): Promise<any> {
      const [owner, repo] = ownerRepo.split('/');
      if (!owner || !repo) {
        throw new Error('Invalid repository format. Use "owner/repo"');
      }
    
      try {
        // Get repository basic info from API
        const repoResponse = await apiRequest(`/repo/${owner}/${repo}`) as ApiResponse;
        
        // Extract data from response structure (which matches repo.json)
        const repoData = (repoResponse['data'] || repoResponse) as RepositoryData;
        
        // Create a structured response with the available data
        const analysis = {
          basic_info: {
            name: repoData.name,
            full_name: repoData.full_name,
            description: repoData.description,
            html_url: repoData.html_url,
            homepage: repoData.homepage,
            created_at: repoData.created_at,
            updated_at: repoData.updated_at,
            language: repoData.language,
            license: repoData.license,
            topics: repoData.topics
          },
          statistics: {
            stars: repoData.stargazers_count,
            watchers: repoData.watchers_count,
            forks: repoData.forks_count,
            open_issues: repoData.open_issues_count,
            size: repoData.size
          },
          owner: {
            login: repoData.owner?.login,
            type: repoData.owner?.type,
            html_url: repoData.owner?.html_url,
            avatar_url: repoData.owner?.avatar_url
          },
          web_url: `${OSSINSIGHT_WEB_URL}/analyze/${owner}/${repo}`
        };
        
        return analysis;
      } catch (error) {
        // If API fails, try to extract data from the web page
        console.error(`API request failed, falling back to web scraping: ${error}`);
        const webUrl = `${OSSINSIGHT_WEB_URL}/analyze/${owner}/${repo}`;
        
        return {
          message: "API request failed. Falling back to web scraping.",
          web_data: await scrapeOSSInsightPage(webUrl, {
            title: 'h1',
            stars: '.stars-count',
            forks: '.forks-count',
            open_issues: '.issues-count',
            // Add more selectors as needed
          }),
          web_url: webUrl
        };
      }
    }
  • Zod schema defining the input parameters for the get_repo_analysis tool.
    export const GetRepoAnalysisParamsSchema = z.object({
      owner_repo: z.string().describe("Repository name in the format 'owner/repo'"),
      time_period: z.enum(['last_28_days', 'last_90_days', 'last_year', 'all_time']).optional()
        .describe("Time range for analysis (optional)")
    });
  • index.ts:288-291 (registration)
    Registration of the tool in the list of available tools returned by ListToolsRequest.
      name: "get_repo_analysis",
      description: "Get detailed analysis of a GitHub repository, including activity, stars, issues, and other metrics.",
      inputSchema: zodToJsonSchema(GetRepoAnalysisParamsSchema)
    },
  • Dispatch handler in CallToolRequestSchema that parses arguments and invokes the getRepoAnalysis function.
    case "get_repo_analysis": {
      const args = GetRepoAnalysisParamsSchema.parse(request.params.arguments);
      const analysis = await getRepoAnalysis(args.owner_repo, args.time_period);
      return { content: [{ type: "text", text: JSON.stringify(analysis, null, 2) }] };
    }
  • Helper function for making API requests to OSSInsight, used by the getRepoAnalysis handler.
    async function apiRequest(endpoint: string, params: Record<string, any> = {}, useRepoApi: boolean = true) {
      // Build URL and query parameters
      const baseUrl = useRepoApi ? OSSINSIGHT_REPO_API_URL : OSSINSIGHT_API_URL;
      const url = new URL(`${baseUrl}${endpoint}`);
      
      // Add query parameters
      Object.entries(params).forEach(([key, value]) => {
        if (value !== undefined) {
          url.searchParams.append(key, String(value));
        }
      });
    
      // Send request
      const response = await fetch(url.toString(), {
        headers: {
          "Accept": "application/json"
        }
      });
    
      if (!response.ok) {
        const errorText = await response.text();
        throw new Error(`OSSInsight API error: ${response.status} ${response.statusText}\n${errorText}`);
      }
    
      return response.json();
    }

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/damonxue/mcp-ossinsight'

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