Skip to main content
Glama

m9k_similar_work

Find similar past work to inform your current complex task. Use this tool at project start to discover previous approaches with rich metadata like multiple tools and files.

Instructions

Find past work similar to what you're about to do. Use at the start of a complex task to see previous approaches. Unlike m9k_search, this prioritizes chunks with rich metadata (multiple tools used, multiple files touched).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYesDescription of the current task
limitNo
sourceNoFilter by source type. Default: all sources.

Implementation Reference

  • The handler logic for 'm9k_similar_work' tool, which performs a search and applies a bonus score based on metadata (tool calls and touched files).
      async ({ description, limit }) => {
        // Use the same search pipeline as m9k_search
        const results = await search(
          ctx.db,
          { query: description, limit: limit * 3 },
          ctx.searchContext,
        );
    
        // Apply metadata bonus scoring
        const enriched = results.map((r) => {
          const chunk = ctx.db
            .prepare('SELECT metadata_json FROM conv_chunks WHERE id = ?')
            .get(r.chunkId) as { metadata_json: string } | undefined;
    
          let metadataBonus = 0;
          if (chunk?.metadata_json) {
            try {
              const meta = JSON.parse(chunk.metadata_json) as {
                toolCalls?: string[];
                filePaths?: string[];
              };
              if (meta.toolCalls && meta.toolCalls.length >= 3) metadataBonus += 0.2;
              if (meta.filePaths && meta.filePaths.length >= 2) metadataBonus += 0.1;
            } catch {
              // ignore parse error
            }
          }
    
          return {
            chunkId: r.chunkId,
            snippet: r.snippet,
            score: r.score + metadataBonus,
            metadataBonus,
            project: r.project,
            timestamp: r.timestamp,
            matchType: r.matchType,
            sessionId: r.sessionId,
          };
        });
    
        // Re-sort by adjusted score, take top limit
        enriched.sort((a, b) => b.score - a.score);
        return {
          content: [{ type: 'text' as const, text: JSON.stringify(enriched.slice(0, limit)) }],
        };
      },
    );
  • Schema definition for the inputs to the 'm9k_similar_work' tool.
    inputSchema: {
      description: z.string().describe('Description of the current task'),
      limit: z.number().int().min(1).max(20).default(5),
      source: z
        .enum(['conversations', 'git', 'files'])
        .optional()
        .describe('Filter by source type. Default: all sources.'),
    },
  • Registration block for the 'm9k_similar_work' tool within the server.
    server.registerTool(
      'm9k_similar_work',
      {
        description:
          "Find past work similar to what you're about to do. Use at the start of a complex task to see previous approaches. Unlike m9k_search, this prioritizes chunks with rich metadata (multiple tools used, multiple files touched).",
        inputSchema: {
          description: z.string().describe('Description of the current task'),
          limit: z.number().int().min(1).max(20).default(5),
          source: z
            .enum(['conversations', 'git', 'files'])
            .optional()
            .describe('Filter by source type. Default: all sources.'),
        },
        annotations: {
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
      async ({ description, limit }) => {
        // Use the same search pipeline as m9k_search
        const results = await search(
          ctx.db,
          { query: description, limit: limit * 3 },
          ctx.searchContext,
        );
    
        // Apply metadata bonus scoring
        const enriched = results.map((r) => {
          const chunk = ctx.db
            .prepare('SELECT metadata_json FROM conv_chunks WHERE id = ?')
            .get(r.chunkId) as { metadata_json: string } | undefined;
    
          let metadataBonus = 0;
          if (chunk?.metadata_json) {
            try {
              const meta = JSON.parse(chunk.metadata_json) as {
                toolCalls?: string[];
                filePaths?: string[];
              };
              if (meta.toolCalls && meta.toolCalls.length >= 3) metadataBonus += 0.2;
              if (meta.filePaths && meta.filePaths.length >= 2) metadataBonus += 0.1;
            } catch {
              // ignore parse error
            }
          }
    
          return {
            chunkId: r.chunkId,
            snippet: r.snippet,
            score: r.score + metadataBonus,
            metadataBonus,
            project: r.project,
            timestamp: r.timestamp,
            matchType: r.matchType,
            sessionId: r.sessionId,
          };
        });
    
        // Re-sort by adjusted score, take top limit
        enriched.sort((a, b) => b.score - a.score);
        return {
          content: [{ type: 'text' as const, text: JSON.stringify(enriched.slice(0, limit)) }],
        };
      },
    );

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/louis49/melchizedek'

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