Skip to main content
Glama

analyze_tag_cooccurrence

Identify which tags frequently appear together in journal entries to reveal patterns and relationships between topics.

Instructions

Analyze which tags frequently appear together

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tagsYesTags to analyze for co-occurrence
journalNoJournal name (uses current/default if not specified)

Implementation Reference

  • Core implementation of the analyze_tag_cooccurrence tool: computes pairwise co-occurrences of tags by searching for entries containing both tags and counting matches, sorts by frequency.
    export async function analyzeTagCooccurrence( tags: string[], journal: string | undefined, executor: JrnlExecutor, ): Promise<{ cooccurrences: TagCooccurrence[] }> { if (tags.length < 2) { return { cooccurrences: [] }; } // For each pair of tags, find entries that contain both const cooccurrences: TagCooccurrence[] = []; for (let i = 0; i < tags.length - 1; i++) { for (let j = i + 1; j < tags.length; j++) { const tag1 = tags[i]; const tag2 = tags[j]; // Search for entries with both tags const command = buildSearchCommand({ tags: [tag1, tag2] }, journal); const result = await executor.execute(command); try { const data = JSON.parse(result); const count = data.entries ? data.entries.length : 0; if (count > 0) { cooccurrences.push({ tag1: tag1.startsWith("@") ? tag1 : `@${tag1}`, tag2: tag2.startsWith("@") ? tag2 : `@${tag2}`, count, }); } } catch (error) { // Skip this pair if there's an error // console.error(`Error analyzing cooccurrence for ${tag1} and ${tag2}: ${error}`); } } } // Sort by count descending cooccurrences.sort((a, b) => b.count - a.count); return { cooccurrences }; }
  • src/index.ts:78-97 (registration)
    Tool registration in the listTools response, including name, description, and input schema.
    { name: "analyze_tag_cooccurrence", description: "Analyze which tags frequently appear together", inputSchema: { type: "object", properties: { tags: { type: "array", items: { type: "string" }, description: "Tags to analyze for co-occurrence", minItems: 2, }, journal: { type: "string", description: "Journal name (uses current/default if not specified)", }, }, required: ["tags"], }, },
  • src/index.ts:178-194 (registration)
    Dispatch logic in CallToolRequest handler that extracts arguments, determines journal, calls analyzeTagCooccurrence, and formats response.
    case "analyze_tag_cooccurrence": return { content: [ { type: "text", text: JSON.stringify( await analyzeTagCooccurrence( Array.isArray(args?.tags) ? args.tags : [], journal, executor, ), null, 2, ), }, ], };
  • TypeScript interface defining the output structure for tag co-occurrences.
    export interface TagCooccurrence { tag1: string; tag2: string; count: number; }

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/yostos/jrnl-mcp'

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