Skip to main content
Glama

getUsers

Retrieve a list of users using the MCP YAML API tool, enabling easy integration of user data into the MCP ecosystem without requiring custom coding.

Instructions

Retrieve a list of users.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The MCP call tool handler that matches the tool name 'getUsers', retrieves the corresponding API config, and calls the ApiClient to execute the tool.
    private registerCallToolHandler() { const apiClient = new ApiClient(); this.server.setRequestHandler(CallToolRequestSchema, async (request: any) => { const tool = this.tools.find(t => t.name === request.params.name) if (!tool) { throw new Error(`Tool ${request.params.name} not found`) } const apiConfig = this.apis.find((api: ApiConfig) => api.name === tool.name) if (!apiConfig) { throw new Error(`API configuration for tool ${tool.name} not found`)} const response = await apiClient.callApi(apiConfig, request.params.arguments); console.error("Response:", response); return { content: [ { type: 'text', text: typeof response === 'string' ? response : JSON.stringify(response, null, 2), }, ], }; });
  • Executes the HTTP request for the getUsers tool based on its API configuration, handling parameters, headers, body, and response parsing.
    async callApi(apiConfig: ApiConfig, args?: Record<string, any>): Promise<any> { const { url, method, options } = apiConfig; let endpoint = url; let headers: Record<string, string> = {}; let body: Record<string, any> = {}; // Interpolación de path & query params if (endpoint && args) { endpoint = endpoint.replace(/\{(\w+)\}/g, (_: string, key: string) => args[key] ?? `{${key}}`); } // Headers if (options?.headers) { for (const [k, v] of Object.entries(options.headers)) { headers[k] = String(v); } } // API Token if ('api-token' in apiConfig && apiConfig['api-token']) { headers['Authorization'] = `Bearer ${process.env.API_TOKEN || ''}`; } // Body if (options?.body) { for (const b of options.body) { if (args && args[b.name] !== undefined) { body[b.name] = args[b.name]; } else if (b.default !== undefined) { body[b.name] = b.default; } } } const fetchOptions: RequestInit = { method: method, headers, }; if (["POST", "PUT", "PATCH"].includes((method || '').toUpperCase())) { fetchOptions.body = JSON.stringify(body); } try { const response = await fetch(endpoint, fetchOptions); const contentType = response.headers.get('content-type') || ''; if (contentType.includes('application/json')) { return await response.json(); } else { return await response.text(); } } catch (error: any) { return { error: error.message }; } }
  • Builds the MCP tool definitions including inputSchema from API config. Contains specific debug logging for the 'getUsers' tool.
    export const buildToolsFromApiConfigArray = (apiConfigArray: any[]): any[] => apiConfigArray.map((apiConfig: any) => { // Get parameters and query from a url like http://localhost:3000/users/{id}?page={page}&limit={limit} const parametersAndQuerys = getUrlParametersAndQuerys(apiConfig.url); const method = apiConfig.method?.toUpperCase(); const body: ApiBodyProperty[] | undefined = apiConfig.options?.body; const schema = getBodyProperties(body); const properties = { ...parametersAndQuerys, ...schema } if(apiConfig.name === 'getUsers' ) { // console.error('parametersAndQuerys', parametersAndQuerys) // console.error('schema', getPropertiesFromSchema(schema)) console.error('parametersAndQuerys', parametersAndQuerys) console.error('body', body) console.error('properties', properties) } return { name: apiConfig.name, description: apiConfig.description, inputSchema: { type: "object", properties: properties, required: (body || []).filter((p: ApiBodyProperty) => p.required).map((p: ApiBodyProperty) => p.name), }, annotations: { title: apiConfig.description, readOnlyHint: method === "GET", destructiveHint: method === "DELETE", idempotentHint: method === "GET" || method === "DELETE", openWorldHint: true, }, }; });
  • src/lib/mcp.ts:35-39 (registration)
    Registers the listTools handler which returns the list of tools including 'getUsers'.
    private registerListToolsHandler() { this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: this.tools }; }); }
  • src/lib/mcp.ts:21-33 (registration)
    Initializes the MCP server, builds tools list from API configs (including getUsers), declares tools capability, and registers tool handlers.
    this.tools = buildToolsFromApiConfigArray(this.apis); this.server = new Server({ name: this.metadata.name || 'mcp-yaml-api', description: this.metadata.description || 'MCP Yaml API', version: this.metadata.version || '1.0.0' }, { capabilities: { tools: {} } }); this.registerListToolsHandler(); this.registerCallToolHandler(); }

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/molavec/mcp-yaml-api'

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