Skip to main content
Glama

search_pypi

Search the Python Package Index (PyPI) for Python packages to retrieve relevant packages based on a specified query, aiding in code research and development.

Instructions

Search PyPI for Python packages

Input Schema

NameRequiredDescriptionDefault
queryYesSearch query

Input Schema (JSON Schema)

{ "properties": { "query": { "description": "Search query", "type": "string" } }, "required": [ "query" ], "type": "object" }

Implementation Reference

  • The core handler function implementing the search_pypi tool logic: queries PyPI JSON API for the exact package matching the query, formats key info with caching and 404 handling.
    private async searchPyPI(query: string, limit: number = 5): Promise<string> { const cacheKey = `pypi:${query}:${limit}`; const cached = cache.get<string>(cacheKey); if (cached) return cached; try { const response = await this.axiosInstance.get( `https://pypi.org/pypi/${encodeURIComponent(query)}/json` ); const pkg = response.data.info; const result = `Package: ${pkg.name} (v${pkg.version})\n` + `Description: ${pkg.summary || 'No description'}\n` + `Author: ${pkg.author || 'Unknown'}\n` + `Homepage: ${pkg.home_page || pkg.project_url || 'N/A'}\n` + `PyPI: https://pypi.org/project/${pkg.name}/\n`; cache.set(cacheKey, result); return result; } catch (error) { if (axios.isAxiosError(error) && error.response?.status === 404) { return `No package found for "${query}"`; } throw new McpError( ErrorCode.InternalError, `PyPI API error: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
  • Input schema and metadata for the search_pypi tool as registered in ListToolsRequestHandler.
    name: 'search_pypi', description: 'Search PyPI for Python packages', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query' } }, required: ['query'] }
  • src/index.ts:493-504 (registration)
    Registration of the search_pypi tool call handler in the switch statement of CallToolRequestSchema handler.
    case 'search_pypi': { const { query } = request.params.arguments as { query: string }; const results = await this.searchPyPI(query); return { content: [ { type: 'text', text: results } ] }; }

Other Tools

Related 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/nahmanmate/code-research-mcp-server'

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