Skip to main content
Glama

Get Recommendation History

get_recommendation_history

Retrieve your past recommendation submissions and received model codes, ordered newest first, to review previous explorations and prevent duplicate recommendations.

Instructions

Fetch the caller's past recommendation calls (problems submitted and the model codes that were returned), newest first. Useful for 'what did we explore last time?' and for avoiding re-recommending the same models.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMax rows to return (default 20, max 100)
offsetNoPagination offset (default 0)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
countYes
limitYes
offsetYes
recommendationsYes

Implementation Reference

  • Registration of the 'get_recommendation_history' tool via server.registerTool(). Defines inputSchema (limit, offset) and outputSchema (count, limit, offset, recommendations array).
    // Tool: Retrieve past recommendations for the authenticated caller
    server.registerTool(
      "get_recommendation_history",
      {
        title: "Get Recommendation History",
        description:
          "Fetch the caller's past recommendation calls (problems submitted and the model codes that were returned), newest first. Useful for 'what did we explore last time?' and for avoiding re-recommending the same models.",
        inputSchema: z.object({
          limit: z
            .number()
            .int()
            .min(1)
            .max(100)
            .optional()
            .describe("Max rows to return (default 20, max 100)"),
          offset: z.number().int().min(0).optional().describe("Pagination offset (default 0)"),
        }),
        outputSchema: z.object({
          count: z.number(),
          limit: z.number(),
          offset: z.number(),
          recommendations: z.array(
            z.object({
              id: z.string(),
              problem: z.string(),
              model_codes: z.array(z.string()),
              top_pattern: z.string().nullable(),
              created_at: z.string(),
            })
          ),
        }),
      },
      async ({ limit, offset }) => {
        if (!API_CONFIG.apiKey) {
          return {
            content: [
              {
                type: "text",
                text: "HUMMBL API key not configured. Set HUMMBL_API_KEY to retrieve recommendation history.",
              },
            ],
            isError: true,
            structuredContent: undefined,
          } as const;
        }
    
        const params = new URLSearchParams();
        if (limit !== undefined) params.set("limit", String(limit));
        if (offset !== undefined) params.set("offset", String(offset));
        const qs = params.toString();
        const url = `${API_CONFIG.baseUrl}/v1/recommendations${qs ? `?${qs}` : ""}`;
    
        try {
          const response = await fetch(url, {
            headers: { Authorization: `Bearer ${API_CONFIG.apiKey}` },
          });
    
          if (!response.ok) {
            const errorText = await response.text();
            return {
              content: [
                {
                  type: "text",
                  text: `API request failed: ${response.status} ${response.statusText}\n${errorText}`,
                },
              ],
              isError: true,
              structuredContent: undefined,
            } as const;
          }
    
          const payload = (await response.json()) as {
            count: number;
            limit: number;
            offset: number;
            recommendations: Array<{
              id: string;
              problem: string;
              model_codes: string[];
              top_pattern: string | null;
              created_at: string;
            }>;
          };
    
          return {
            content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
            structuredContent: payload,
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Failed to fetch recommendation history: ${error instanceof Error ? error.message : "Unknown error"}`,
              },
            ],
            isError: true,
            structuredContent: undefined,
          } as const;
        }
      }
    );
  • Handler function for the tool. Checks API key, then calls the internal REST API at /v1/recommendations with limit/offset params, passing the API key as Bearer token. Returns the JSON response as tool output.
    async ({ limit, offset }) => {
      if (!API_CONFIG.apiKey) {
        return {
          content: [
            {
              type: "text",
              text: "HUMMBL API key not configured. Set HUMMBL_API_KEY to retrieve recommendation history.",
            },
          ],
          isError: true,
          structuredContent: undefined,
        } as const;
      }
    
      const params = new URLSearchParams();
      if (limit !== undefined) params.set("limit", String(limit));
      if (offset !== undefined) params.set("offset", String(offset));
      const qs = params.toString();
      const url = `${API_CONFIG.baseUrl}/v1/recommendations${qs ? `?${qs}` : ""}`;
    
      try {
        const response = await fetch(url, {
          headers: { Authorization: `Bearer ${API_CONFIG.apiKey}` },
        });
    
        if (!response.ok) {
          const errorText = await response.text();
          return {
            content: [
              {
                type: "text",
                text: `API request failed: ${response.status} ${response.statusText}\n${errorText}`,
              },
            ],
            isError: true,
            structuredContent: undefined,
          } as const;
        }
    
        const payload = (await response.json()) as {
          count: number;
          limit: number;
          offset: number;
          recommendations: Array<{
            id: string;
            problem: string;
            model_codes: string[];
            top_pattern: string | null;
            created_at: string;
          }>;
        };
    
        return {
          content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
          structuredContent: payload,
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Failed to fetch recommendation history: ${error instanceof Error ? error.message : "Unknown error"}`,
            },
          ],
          isError: true,
          structuredContent: undefined,
        } as const;
      }
    }
  • Input/output schemas for the tool. Input: optional limit (1-100) and offset (0+). Output: count, limit, offset, and array of recommendations with id, problem, model_codes, top_pattern, created_at.
    inputSchema: z.object({
      limit: z
        .number()
        .int()
        .min(1)
        .max(100)
        .optional()
        .describe("Max rows to return (default 20, max 100)"),
      offset: z.number().int().min(0).optional().describe("Pagination offset (default 0)"),
    }),
    outputSchema: z.object({
      count: z.number(),
      limit: z.number(),
      offset: z.number(),
      recommendations: z.array(
        z.object({
          id: z.string(),
          problem: z.string(),
          model_codes: z.array(z.string()),
          top_pattern: z.string().nullable(),
          created_at: z.string(),
        })
      ),
    }),
  • D1 database helper getRecommendationHistory(). Queries the recommendations table for a given apiKeyId, ordered by created_at DESC with LIMIT/OFFSET. Deserializes model_codes from JSON string to string array.
    async getRecommendationHistory(
      apiKeyId: string,
      limit = 20,
      offset = 0
    ): Promise<
      Array<{
        id: string;
        problem: string;
        modelCodes: string[];
        topPattern: string | null;
        createdAt: string;
      }>
    > {
      const rows = await this.query<{
        id: string;
        problem: string;
        model_codes: string;
        top_pattern: string | null;
        created_at: string;
      }>(
        `SELECT id, problem, model_codes, top_pattern, created_at
         FROM recommendations
         WHERE api_key_id = ?
         ORDER BY created_at DESC
         LIMIT ? OFFSET ?`,
        apiKeyId,
        limit,
        offset
      );
    
      return rows.map((r) => {
        let modelCodes: string[] = [];
        try {
          const parsed = JSON.parse(r.model_codes);
          if (Array.isArray(parsed)) modelCodes = parsed.filter((v) => typeof v === "string");
        } catch {
          // Malformed row — surface an empty list rather than throwing.
        }
        return {
          id: r.id,
          problem: r.problem,
          modelCodes,
          topPattern: r.top_pattern,
          createdAt: r.created_at,
        };
      });
    }
  • REST API endpoint GET /v1/recommendations that the tool handler calls. Authenticates the user, calls db.getRecommendationHistory(), and returns the paginated recommendation rows as JSON.
    // List recent recommendation history for the authenticated caller
    app.get("/v1/recommendations", authenticate, async (c: AppContext) => {
      const user = c.get("user");
      if (!user) {
        return c.json({ error: "Unauthenticated" }, 401);
      }
    
      const limitParam = c.req.query("limit");
      const offsetParam = c.req.query("offset");
      const limit = Math.min(Math.max(parseInt(limitParam ?? "20", 10) || 20, 1), 100);
      const offset = Math.max(parseInt(offsetParam ?? "0", 10) || 0, 0);
    
      const db = createD1Client(c.env.DB);
      try {
        const rows = await db.getRecommendationHistory(user.id, limit, offset);
        return c.json({
          count: rows.length,
          limit,
          offset,
          recommendations: rows.map((r) => ({
            id: r.id,
            problem: r.problem,
            model_codes: r.modelCodes,
            top_pattern: r.topPattern,
            created_at: r.createdAt,
          })),
        });
      } catch {
        return c.json({ error: "Failed to load recommendation history" }, 500);
      }
    });
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description indicates this is a read operation (fetch) and specifies ordering ('newest first'). However, without annotations, it omits other behavioral aspects such as whether authentication is required, rate limits, or fallback behavior for empty history. The bar is higher due to no annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences: one for function, one for use case. Every word adds value with no redundancy or irrelevant detail.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the output schema exists, the description does not need to detail return format. It covers purpose, content, ordering, and use cases. The two parameters are fully documented in the schema, and the description completes the picture.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with clear descriptions for 'limit' and 'offset'. The description adds no parameter-specific details beyond the schema and a note on ordering. Per guidelines, high coverage allows a baseline of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Fetch'), names the resource ('past recommendation calls'), and details the content ('problems submitted and the model codes that were returned'). This clearly distinguishes it from siblings like 'recommend_models' and 'list_all_models'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states two use cases: 'what did we explore last time?' and avoiding re-recommending the same models. While it does not list when not to use or alternative tools, the context is clear and actionable.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/hummbl-dev/mcp-server'

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