Skip to main content
Glama
connection-annotations.ts1.49 kB
import * as _ from "lodash-es"; export type ConnectionAnnotation = { tokens: string[]; }; export function parseConnectionAnnotation(annotation: string): string[] { let token = annotation; const typeArray = []; do { const [_, newAnnotation, tail] = token.match(/^([\w ]+)(?:<(.+)>)?$/) ?? []; if (!newAnnotation) { throw new Error(`Couldn't parse connection annotation "${annotation}"`); } typeArray.push(newAnnotation.toLowerCase().trim()); if (!tail) break; token = tail; } while (token != null); return typeArray; } export function connectionAnnotationFitsReference( { tokens: targetCa }: ConnectionAnnotation, { tokens: referenceCa }: ConnectionAnnotation, ) { // If the length is longer than 1, we assume you have already parsed the // connection annotations. Otherwise, we need to parse them. if (targetCa.length === 1) { // @ts-ignore ignoring targetCa = parseConnectionAnnotation(targetCa[0]); } if (referenceCa.length === 1) { // @ts-ignore ignoring referenceCa = parseConnectionAnnotation(referenceCa[0]); } // a fitting target annotation is either the same as the reference one or a supertype thereof const lowerTargetCa = _.map(targetCa, (a: string) => a.toLowerCase()); const lowerReferenceCa = _.map(referenceCa, (a: string) => a.toLowerCase()); return lowerTargetCa.length >= lowerReferenceCa.length && _.isEqual(lowerTargetCa.slice(-lowerReferenceCa.length), lowerReferenceCa); }

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/systeminit/si'

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