Skip to main content
Glama

search_pypi

Search PyPI for Python packages to find code examples and documentation, helping developers locate programming resources.

Instructions

Search PyPI for Python packages

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query

Implementation Reference

  • The core handler function for the 'search_pypi' tool. It queries the PyPI JSON API for the exact package name provided in the query parameter, caches the result, and formats package information. Handles 404 by returning a 'not found' message.
    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'}` ); } }
  • The input schema defining the expected parameters for the search_pypi tool: a required 'query' string.
    inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query' } }, required: ['query'] }
  • src/index.ts:398-411 (registration)
    Registration of the 'search_pypi' tool in the ListToolsRequestSchema handler, including name, description, and input schema.
    { 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)
    The dispatch logic in CallToolRequestSchema handler that routes 'search_pypi' calls to the searchPyPI method and formats the response.
    case 'search_pypi': { const { query } = request.params.arguments as { query: string }; const results = await this.searchPyPI(query); return { content: [ { type: 'text', text: results } ] }; }

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