Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ jobs:
bun add --ignore-scripts "$artifact"
bun -e 'import { providers } from "@checkfu/integrations/providers"; if (!providers.openai) process.exit(1)'
bun -e 'import { connectors } from "@checkfu/integrations/connectors"; if (!connectors.linear) process.exit(1)'
node --input-type=module -e 'import { searchToolCatalog } from "@checkfu/integrations/tool-catalog"; if (searchToolCatalog([{ name: "listIssues" }], "list issues").items[0]?.name !== "listIssues") process.exit(1)'
node --input-type=module -e 'import { catalogByKind } from "@checkfu/integrations/catalog"; if (!catalogByKind.channel.some(entry => entry.id === "discord")) process.exit(1)'
node --input-type=module -e 'import { discordReplyRequest } from "@checkfu/integrations/channels"; if (discordReplyRequest("123", "fixture", "reply").redirect !== "manual") process.exit(1)'
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ const { url, transport, auth } = connectors.linear.mcp

Use the URL with a Streamable HTTP MCP client. The catalog lists the supported authentication methods and suggested OAuth scopes, where available. Your application handles OAuth discovery or attaches a separately stored bearer token to requests to the connector URL. See the [Linear MCP documentation](https://linear.app/docs/mcp) for supported credentials and scopes.

## Tool catalogs

Use `@checkfu/integrations/tool-catalog` to present the tools your application has discovered. Supply definitions from an MCP client's `tools/list` response or any source with tool names. Each result keeps the original definition and exact callable name.

```ts
import { searchToolCatalog } from "@checkfu/integrations/tool-catalog"

const tools = [
{ name: "listIssues", description: "Show issues in the repository." },
{ name: "createIssue", description: "Open a new issue." },
]
const page = searchToolCatalog(tools, "list issues", { limit: 20 })
const next = page.nextOffset === null
? null
: searchToolCatalog(tools, "list issues", { limit: 20, offset: page.nextOffset })
```

Search prefers a name match over a title or description match and accepts camel case, underscores, hyphens, and spaces. An empty query lists the available tools in input order. Queries have a 256-character limit and pages have a 100-entry limit. Keep the input catalog stable when paging. The results contain only tools the caller supplied. The host supplies the connection and decides what each user or agent may access.

## Incoming events and channels

The [generic signed webhook](catalog/triggers/webhook.yaml) uses Standard Webhooks. The verifier returns the exact authenticated delivery ID. IDs are opaque, nonempty strings that exclude the signing delimiter (`.`). Apply the host's transport and storage limits when using them as idempotency keys. The `@checkfu/integrations/webhooks` export verifies native GitHub, Linear, and Notion deliveries and returns a verified event, account, and deduplication ID. The [Discord channel](catalog/services/discord.yaml) uses signed interactions. Its reply builder returns a standard Fetch request with redirects disabled through manual handling. The host sends the request and handles the response.
Expand Down
19 changes: 19 additions & 0 deletions dist/tool-catalog.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface ToolCatalogEntry {
readonly name: string;
readonly title?: string;
readonly description?: string;
}
export interface ToolCatalogPageOptions {
readonly offset?: number;
readonly limit?: number;
}
export interface ToolCatalogPage<T extends ToolCatalogEntry> {
readonly items: readonly T[];
readonly total: number;
readonly nextOffset: number | null;
}
/**
* Searches entries supplied by the caller and returns one page of the original entries.
* An empty query lists the catalog in input order. Ties retain that same order.
*/
export declare function searchToolCatalog<T extends ToolCatalogEntry>(tools: readonly T[], query: string, { offset, limit }?: ToolCatalogPageOptions): ToolCatalogPage<T>;
50 changes: 50 additions & 0 deletions dist/tool-catalog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const maxQueryChars = 256;
const maxSearchableChars = 4096;
const maxPageSize = 100;
function words(text) {
return text.slice(0, maxSearchableChars)
.normalize("NFKC")
.replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu, "$1 $2")
.replace(/([\p{Ll}\p{N}])(\p{Lu})/gu, "$1 $2")
.toLowerCase()
.match(/[\p{L}\p{N}]+/gu) ?? [];
}
function matches(query, available) {
return query.every(term => available.some(word => word.startsWith(term)));
}
function rank(tool, exactName, query) {
if (tool.name.toLowerCase() === exactName)
return 4;
if (query.length === 0)
return 0;
const name = words(tool.name);
if (matches(query, name))
return 3;
const headings = [...name, ...words(tool.title ?? "")];
if (matches(query, headings))
return 2;
return matches(query, [...headings, ...words(tool.description ?? "")]) ? 1 : 0;
}
/**
* Searches entries supplied by the caller and returns one page of the original entries.
* An empty query lists the catalog in input order. Ties retain that same order.
*/
export function searchToolCatalog(tools, query, { offset = 0, limit = 20 } = {}) {
if (query.length > maxQueryChars)
throw new RangeError("Tool search accepts up to 256 characters.");
if (!Number.isSafeInteger(offset) || offset < 0)
throw new RangeError("Tool search offset must be a nonnegative safe integer.");
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxPageSize) {
throw new RangeError("Tool search limit must be an integer from 1 to 100.");
}
const exactName = query.trim().toLowerCase();
const terms = words(query);
const found = exactName === "" ? tools : tools
.map(tool => ({ tool, rank: rank(tool, exactName, terms) }))
.filter(entry => entry.rank > 0)
.sort((left, right) => right.rank - left.rank)
.map(entry => entry.tool);
const items = found.slice(offset, offset + limit);
const next = offset + items.length;
return { items, total: found.length, nextOffset: next < found.length ? next : null };
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"./channels": { "types": "./dist/channels.d.ts", "default": "./dist/channels.js" },
"./connectors": { "types": "./dist/connectors.d.ts", "default": "./dist/connectors.js" },
"./providers": { "types": "./dist/providers.d.ts", "default": "./dist/providers.js" },
"./tool-catalog": { "types": "./dist/tool-catalog.d.ts", "default": "./dist/tool-catalog.js" },
"./triggers": { "types": "./dist/triggers.d.ts", "default": "./dist/triggers.js" },
"./webhooks": { "types": "./dist/webhooks.d.ts", "default": "./dist/webhooks.js" }
},
Expand Down
70 changes: 70 additions & 0 deletions src/tool-catalog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
export interface ToolCatalogEntry {
readonly name: string
readonly title?: string
readonly description?: string
}

export interface ToolCatalogPageOptions {
readonly offset?: number
readonly limit?: number
}

export interface ToolCatalogPage<T extends ToolCatalogEntry> {
readonly items: readonly T[]
readonly total: number
readonly nextOffset: number | null
}

const maxQueryChars = 256
const maxSearchableChars = 4096
const maxPageSize = 100

function words(text: string): readonly string[] {
return text.slice(0, maxSearchableChars)
.normalize("NFKC")
.replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu, "$1 $2")
.replace(/([\p{Ll}\p{N}])(\p{Lu})/gu, "$1 $2")
.toLowerCase()
.match(/[\p{L}\p{N}]+/gu) ?? []
}

function matches(query: readonly string[], available: readonly string[]): boolean {
return query.every(term => available.some(word => word.startsWith(term)))
}

function rank(tool: ToolCatalogEntry, exactName: string, query: readonly string[]): number {
if (tool.name.toLowerCase() === exactName) return 4
if (query.length === 0) return 0
const name = words(tool.name)
if (matches(query, name)) return 3
const headings = [...name, ...words(tool.title ?? "")]
if (matches(query, headings)) return 2
return matches(query, [...headings, ...words(tool.description ?? "")]) ? 1 : 0
}

/**
* Searches entries supplied by the caller and returns one page of the original entries.
* An empty query lists the catalog in input order. Ties retain that same order.
*/
export function searchToolCatalog<T extends ToolCatalogEntry>(
tools: readonly T[],
query: string,
{ offset = 0, limit = 20 }: ToolCatalogPageOptions = {},
): ToolCatalogPage<T> {
if (query.length > maxQueryChars) throw new RangeError("Tool search accepts up to 256 characters.")
if (!Number.isSafeInteger(offset) || offset < 0) throw new RangeError("Tool search offset must be a nonnegative safe integer.")
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxPageSize) {
throw new RangeError("Tool search limit must be an integer from 1 to 100.")
}

const exactName = query.trim().toLowerCase()
const terms = words(query)
const found = exactName === "" ? tools : tools
.map(tool => ({ tool, rank: rank(tool, exactName, terms) }))
.filter(entry => entry.rank > 0)
.sort((left, right) => right.rank - left.rank)
.map(entry => entry.tool)
const items = found.slice(offset, offset + limit)
const next = offset + items.length
return { items, total: found.length, nextOffset: next < found.length ? next : null }
}
56 changes: 56 additions & 0 deletions test/tool-catalog.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import assert from "node:assert/strict"
import { test } from "node:test"
import { searchToolCatalog } from "@checkfu/integrations/tool-catalog"

const entries = [
{ name: "get_item", description: "Look up an issue in the backlog." },
{ name: "find", title: "Look up an issue" },
{ name: "lookupIssue", inputSchema: { type: "object" } },
{ name: "mcp__tracker__lookup_issue" },
{ name: "list_issue" },
]

test("keeps exact callable names first and ranks names above titles and descriptions", () => {
const names = query => searchToolCatalog(entries, query).items.map(({ name }) => name)
assert.deepEqual(names("lookupIssue"), ["lookupIssue", "mcp__tracker__lookup_issue"])
assert.deepEqual(names("lookup_issue"), names("lookup-issue"))
assert.deepEqual(names("look issue"), [
"lookupIssue", "mcp__tracker__lookup_issue", "find", "get_item",
])
assert.equal(searchToolCatalog(entries, "lookupIssue").items[0], entries[2])
})

test("returns stable pages and includes every match once", () => {
assert.deepEqual(searchToolCatalog(entries, "issue", { limit: 2 }), {
items: entries.slice(2, 4), total: 5, nextOffset: 2,
})
assert.deepEqual(searchToolCatalog(entries, "issue", { limit: 2, offset: 2 }), {
items: [entries[4], entries[1]], total: 5, nextOffset: 4,
})
assert.deepEqual(searchToolCatalog(entries, "issue", { limit: 2, offset: 4 }), {
items: [entries[0]], total: 5, nextOffset: null,
})
assert.deepEqual(searchToolCatalog(entries, "issue", { offset: 5 }), {
items: [], total: 5, nextOffset: null,
})
})

test("lists in input order for empty queries and reports empty results explicitly", () => {
assert.deepEqual(searchToolCatalog(entries, " ", { limit: 2 }), {
items: entries.slice(0, 2), total: 5, nextOffset: 2,
})
const empty = { items: [], total: 0, nextOffset: null }
assert.deepEqual(searchToolCatalog([], ""), empty)
assert.deepEqual(searchToolCatalog(entries, "nothing matches"), empty)
assert.deepEqual(searchToolCatalog(entries, "???"), empty)
})

test("bounds page inputs and searchable fields", () => {
assert.throws(() => searchToolCatalog(entries, "x".repeat(257)), RangeError)
assert.throws(() => searchToolCatalog(entries, "issue", { offset: -1 }), RangeError)
assert.throws(() => searchToolCatalog(entries, "issue", { limit: 2.5 }), RangeError)
assert.throws(() => searchToolCatalog(entries, "issue", { limit: 101 }), RangeError)
const entry = { name: "read", description: "x".repeat(4096) + " excluded" }
assert.deepEqual(searchToolCatalog([entry], "excluded").items, [])
assert.deepEqual(searchToolCatalog([entry], "read").items, [entry])
})