search_mcp_servers
Search the Glama MCP directory for servers using free text queries, retrieve results with pagination, and explore detailed server attributes efficiently.
Instructions
Search for MCP servers in the Glama directory using free text queries
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| after | No | Cursor for pagination to get results after this point | |
| first | No | Number of results to return (1-100, default: 10) | |
| query | No | Free text search query (e.g., 'hacker news', 'database', 'weather') |
Implementation Reference
- src/server.ts:46-66 (handler)The execute handler for the 'search_mcp_servers' tool. It builds query parameters from input args and calls the makeGlamaRequest helper to fetch search results from the Glama MCP API, returning formatted JSON or an error message.execute: async (args) => { try { const params: Record<string, string> = {}; if (args.query) { params.query = args.query; } if (args.first) { params.first = args.first.toString(); } if (args.after) { params.after = args.after; } const result = await makeGlamaRequest("/v1/servers", params); return JSON.stringify(result, null, 2); } catch (error) { return `Error searching MCP servers: ${error instanceof Error ? error.message : String(error)}`; } },
- src/server.ts:68-86 (schema)Zod schema defining the input parameters for the 'search_mcp_servers' tool: query (optional free-text search string), first (optional number of results, 1-100, default 10), after (optional pagination cursor).parameters: z.object({ after: z .string() .optional() .describe("Cursor for pagination to get results after this point"), first: z .number() .min(1) .max(100) .default(10) .optional() .describe("Number of results to return (1-100, default: 10)"), query: z .string() .optional() .describe( "Free text search query (e.g., 'hacker news', 'database', 'weather')", ), }),
- src/server.ts:38-87 (registration)Full registration of the 'search_mcp_servers' tool using server.addTool(), including annotations, description, name, input schema, and execute handler.server.addTool({ annotations: { openWorldHint: true, // This tool interacts with external API readOnlyHint: true, // This tool only reads data title: "Search MCP Servers", }, description: "Search for MCP servers in the Glama directory using free text queries", execute: async (args) => { try { const params: Record<string, string> = {}; if (args.query) { params.query = args.query; } if (args.first) { params.first = args.first.toString(); } if (args.after) { params.after = args.after; } const result = await makeGlamaRequest("/v1/servers", params); return JSON.stringify(result, null, 2); } catch (error) { return `Error searching MCP servers: ${error instanceof Error ? error.message : String(error)}`; } }, name: "search_mcp_servers", parameters: z.object({ after: z .string() .optional() .describe("Cursor for pagination to get results after this point"), first: z .number() .min(1) .max(100) .default(10) .optional() .describe("Number of results to return (1-100, default: 10)"), query: z .string() .optional() .describe( "Free text search query (e.g., 'hacker news', 'database', 'weather')", ), }), });
- src/server.ts:13-36 (helper)Helper utility function to construct and make HTTP GET requests to the Glama MCP API endpoints, handling query parameters and error checking. Used by the search_mcp_servers handler.async function makeGlamaRequest( endpoint: string, params?: Record<string, string>, ) { const url = new URL(`${GLAMA_API_BASE}${endpoint}`); if (params) { Object.entries(params).forEach(([key, value]) => { if (value) { url.searchParams.append(key, value); } }); } const response = await fetch(url.toString()); if (!response.ok) { throw new Error( `API request failed: ${response.status} ${response.statusText}`, ); } return response.json(); }