@llmindset/hf-mcp 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs-search/docs-semantic-search.d.ts.map +1 -1
- package/dist/docs-search/docs-semantic-search.js +7 -1
- package/dist/docs-search/docs-semantic-search.js.map +1 -1
- package/dist/hub-inspect.d.ts +2 -2
- package/dist/hub-inspect.d.ts.map +1 -1
- package/dist/hub-inspect.js +1 -1
- package/dist/hub-inspect.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/repo-search.d.ts +46 -0
- package/dist/repo-search.d.ts.map +1 -0
- package/dist/repo-search.js +310 -0
- package/dist/repo-search.js.map +1 -0
- package/dist/repo-search.test.d.ts +2 -0
- package/dist/repo-search.test.d.ts.map +1 -0
- package/dist/repo-search.test.js +130 -0
- package/dist/repo-search.test.js.map +1 -0
- package/dist/tool-ids.d.ts +6 -5
- package/dist/tool-ids.d.ts.map +1 -1
- package/dist/tool-ids.js +9 -14
- package/dist/tool-ids.js.map +1 -1
- package/package.json +2 -2
- package/src/docs-search/docs-semantic-search.ts +8 -1
- package/src/hub-inspect.ts +2 -2
- package/src/index.ts +1 -0
- package/src/repo-search.test.ts +155 -0
- package/src/repo-search.ts +414 -0
- package/src/tool-ids.ts +10 -14
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { RepoSearchTool } from './repo-search.js';
|
|
3
|
+
describe('RepoSearchTool', () => {
|
|
4
|
+
const originalFetch = globalThis.fetch;
|
|
5
|
+
let calls = [];
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
calls = [];
|
|
8
|
+
vi.stubGlobal('fetch', (input, init) => {
|
|
9
|
+
const inputString = stringifyRequestInput(input);
|
|
10
|
+
calls.push({ input: inputString, init });
|
|
11
|
+
if (inputString.includes('/api/models')) {
|
|
12
|
+
return Promise.resolve(jsonResponse([
|
|
13
|
+
{
|
|
14
|
+
id: 'meta-llama/Llama-3.1-8B-Instruct',
|
|
15
|
+
pipeline_tag: 'text-generation',
|
|
16
|
+
library_name: 'transformers',
|
|
17
|
+
downloads: 123,
|
|
18
|
+
likes: 10,
|
|
19
|
+
tags: ['text-generation'],
|
|
20
|
+
},
|
|
21
|
+
]));
|
|
22
|
+
}
|
|
23
|
+
if (inputString.includes('/api/datasets')) {
|
|
24
|
+
return Promise.resolve(jsonResponse([
|
|
25
|
+
{
|
|
26
|
+
id: 'openbmb/UltraData-Math',
|
|
27
|
+
description: 'Large-scale mathematical dataset',
|
|
28
|
+
downloads: 50,
|
|
29
|
+
likes: 3,
|
|
30
|
+
tags: ['math'],
|
|
31
|
+
},
|
|
32
|
+
]));
|
|
33
|
+
}
|
|
34
|
+
if (inputString.includes('/api/spaces')) {
|
|
35
|
+
return Promise.resolve(jsonResponse([
|
|
36
|
+
{
|
|
37
|
+
id: 'mrfakename/Z-Image-Turbo',
|
|
38
|
+
title: 'Z Image Turbo',
|
|
39
|
+
sdk: 'gradio',
|
|
40
|
+
likes: 20,
|
|
41
|
+
},
|
|
42
|
+
]));
|
|
43
|
+
}
|
|
44
|
+
return Promise.resolve(jsonResponse([]));
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
vi.unstubAllGlobals();
|
|
49
|
+
globalThis.fetch = originalFetch;
|
|
50
|
+
});
|
|
51
|
+
it('aggregates model and dataset results in one response', async () => {
|
|
52
|
+
const tool = new RepoSearchTool('token');
|
|
53
|
+
const result = await tool.searchWithParams({
|
|
54
|
+
query: 'llama',
|
|
55
|
+
repo_types: ['model', 'dataset'],
|
|
56
|
+
limit: 5,
|
|
57
|
+
});
|
|
58
|
+
expect(calls).toHaveLength(2);
|
|
59
|
+
expect(calls[0]?.input).toContain('/api/models');
|
|
60
|
+
expect(calls[1]?.input).toContain('/api/datasets');
|
|
61
|
+
expect(result.totalResults).toBe(2);
|
|
62
|
+
expect(result.formatted).toContain('## Models (1)');
|
|
63
|
+
expect(result.formatted).toContain('## Datasets (1)');
|
|
64
|
+
expect(result.formatted).toContain('[https://hf.co/meta-llama/Llama-3.1-8B-Instruct]');
|
|
65
|
+
expect(result.formatted).toContain('[https://hf.co/datasets/openbmb/UltraData-Math]');
|
|
66
|
+
});
|
|
67
|
+
it('supports searching spaces through the same interface', async () => {
|
|
68
|
+
const tool = new RepoSearchTool('token');
|
|
69
|
+
const result = await tool.searchWithParams({
|
|
70
|
+
query: 'image generation',
|
|
71
|
+
repo_types: ['space'],
|
|
72
|
+
limit: 3,
|
|
73
|
+
});
|
|
74
|
+
expect(calls).toHaveLength(1);
|
|
75
|
+
expect(calls[0]?.input).toContain('/api/spaces');
|
|
76
|
+
expect(result.totalResults).toBe(1);
|
|
77
|
+
expect(result.formatted).toContain('## Spaces (1)');
|
|
78
|
+
expect(result.formatted).toContain('[https://hf.co/spaces/mrfakename/Z-Image-Turbo]');
|
|
79
|
+
});
|
|
80
|
+
it('applies an overall output length guard with truncation notice', async () => {
|
|
81
|
+
vi.stubGlobal('fetch', (input, init) => {
|
|
82
|
+
const inputString = stringifyRequestInput(input);
|
|
83
|
+
calls.push({ input: inputString, init });
|
|
84
|
+
if (inputString.includes('/api/models')) {
|
|
85
|
+
const longTag = 'very-long-tag-name-for-output-growth';
|
|
86
|
+
const models = Array.from({ length: 100 }, (_, index) => ({
|
|
87
|
+
id: `org/super-long-model-name-${index.toString().padStart(3, '0')}-with-extra-context`,
|
|
88
|
+
pipeline_tag: 'text-generation',
|
|
89
|
+
library_name: 'transformers',
|
|
90
|
+
downloads: 100000 - index,
|
|
91
|
+
likes: 1000 - index,
|
|
92
|
+
tags: Array.from({ length: 30 }, (_unused, tagIndex) => `${longTag}-${tagIndex.toString()}`),
|
|
93
|
+
}));
|
|
94
|
+
return Promise.resolve(jsonResponse(models));
|
|
95
|
+
}
|
|
96
|
+
return Promise.resolve(jsonResponse([]));
|
|
97
|
+
});
|
|
98
|
+
const tool = new RepoSearchTool('token');
|
|
99
|
+
const result = await tool.searchWithParams({
|
|
100
|
+
repo_types: ['model'],
|
|
101
|
+
limit: 100,
|
|
102
|
+
});
|
|
103
|
+
expect(result.totalResults).toBe(100);
|
|
104
|
+
expect(result.resultsShared).toBeLessThan(result.totalResults);
|
|
105
|
+
expect(result.formatted.length).toBeLessThanOrEqual(12_500 * 3);
|
|
106
|
+
expect(result.formatted).toContain('Results truncated at approximately 12,500 tokens');
|
|
107
|
+
expect(result.formatted).toContain('Included');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
function jsonResponse(payload) {
|
|
111
|
+
return new Response(JSON.stringify(payload), {
|
|
112
|
+
status: 200,
|
|
113
|
+
headers: {
|
|
114
|
+
'content-type': 'application/json',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function stringifyRequestInput(input) {
|
|
119
|
+
if (typeof input === 'string') {
|
|
120
|
+
return input;
|
|
121
|
+
}
|
|
122
|
+
if (input instanceof URL) {
|
|
123
|
+
return input.toString();
|
|
124
|
+
}
|
|
125
|
+
if (input instanceof Request) {
|
|
126
|
+
return input.url;
|
|
127
|
+
}
|
|
128
|
+
return input;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=repo-search.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-search.test.js","sourceRoot":"","sources":["../src/repo-search.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOlD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC/B,MAAM,aAAa,GAAG,UAAU,CAAC,KAAK,CAAC;IACvC,IAAI,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H,SAAS,YAAY,CAAC,OAAgB;IACrC,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;QAC5C,MAAM,EAAE,GAAG;QACX,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;SAClC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAwB;IACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
|
package/dist/tool-ids.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export declare const SPACE_SEARCH_TOOL_ID: "space_search";
|
|
2
2
|
export declare const MODEL_SEARCH_TOOL_ID: "model_search";
|
|
3
|
+
export declare const REPO_SEARCH_TOOL_ID: "hub_repo_search";
|
|
3
4
|
export declare const MODEL_DETAIL_TOOL_ID: "model_details";
|
|
4
5
|
export declare const PAPER_SEARCH_TOOL_ID: "paper_search";
|
|
5
6
|
export declare const DATASET_SEARCH_TOOL_ID: "dataset_search";
|
|
6
7
|
export declare const DATASET_DETAIL_TOOL_ID: "dataset_details";
|
|
7
|
-
export declare const
|
|
8
|
+
export declare const HUB_REPO_DETAILS_TOOL_ID: "hub_repo_details";
|
|
8
9
|
export declare const DUPLICATE_SPACE_TOOL_ID: "duplicate_space";
|
|
9
10
|
export declare const SPACE_INFO_TOOL_ID: "space_info";
|
|
10
11
|
export declare const SPACE_FILES_TOOL_ID: "space_files";
|
|
@@ -17,15 +18,15 @@ export declare const MODEL_DETAIL_PROMPT_ID: string;
|
|
|
17
18
|
export declare const DATASET_DETAIL_PROMPT_ID: string;
|
|
18
19
|
export declare const HF_JOBS_TOOL_ID: "hf_jobs";
|
|
19
20
|
export declare const DYNAMIC_SPACE_TOOL_ID: "dynamic_space";
|
|
20
|
-
export declare const ALL_BUILTIN_TOOL_IDS: readonly ["space_search", "model_search", "model_details", "paper_search", "dataset_search", "dataset_details", "hub_repo_details", "duplicate_space", "space_info", "space_files", "hf_doc_search", "hf_doc_fetch", "use_space", "hf_jobs", "dynamic_space"];
|
|
21
|
+
export declare const ALL_BUILTIN_TOOL_IDS: readonly ["space_search", "model_search", "hub_repo_search", "model_details", "paper_search", "dataset_search", "dataset_details", "hub_repo_details", "duplicate_space", "space_info", "space_files", "hf_doc_search", "hf_doc_fetch", "use_space", "hf_jobs", "dynamic_space"];
|
|
21
22
|
export declare const TOOL_ID_GROUPS: {
|
|
22
|
-
readonly search: readonly ["space_search", "
|
|
23
|
+
readonly search: readonly ["space_search", "hub_repo_search", "paper_search", "hf_doc_search"];
|
|
23
24
|
readonly spaces: readonly ["space_search", "duplicate_space", "space_info", "space_files", "use_space"];
|
|
24
25
|
readonly detail: readonly ["model_details", "dataset_details", "hub_repo_details"];
|
|
25
26
|
readonly docs: readonly ["hf_doc_search", "hf_doc_fetch"];
|
|
26
|
-
readonly hf_api: readonly ["space_search", "
|
|
27
|
+
readonly hf_api: readonly ["space_search", "hub_repo_search", "paper_search", "hub_repo_details", "hf_doc_search"];
|
|
27
28
|
readonly dynamic_space: readonly ["dynamic_space"];
|
|
28
|
-
readonly all: readonly ["space_search", "model_search", "model_details", "paper_search", "dataset_search", "dataset_details", "hub_repo_details", "duplicate_space", "space_info", "space_files", "hf_doc_search", "hf_doc_fetch", "use_space", "hf_jobs", "dynamic_space"];
|
|
29
|
+
readonly all: readonly ["space_search", "model_search", "hub_repo_search", "model_details", "paper_search", "dataset_search", "dataset_details", "hub_repo_details", "duplicate_space", "space_info", "space_files", "hf_doc_search", "hf_doc_fetch", "use_space", "hf_jobs", "dynamic_space"];
|
|
29
30
|
};
|
|
30
31
|
export type BuiltinToolId = (typeof ALL_BUILTIN_TOOL_IDS)[number];
|
|
31
32
|
export declare function isValidBuiltinToolId(toolId: string): toolId is BuiltinToolId;
|
package/dist/tool-ids.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-ids.d.ts","sourceRoot":"","sources":["../src/tool-ids.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool-ids.d.ts","sourceRoot":"","sources":["../src/tool-ids.ts"],"names":[],"mappings":"AA6BA,eAAO,MAAM,oBAAoB,gBAAmC,CAAC;AACrE,eAAO,MAAM,oBAAoB,gBAAgC,CAAC;AAClE,eAAO,MAAM,mBAAmB,mBAA+B,CAAC;AAChE,eAAO,MAAM,oBAAoB,iBAAgC,CAAC;AAClE,eAAO,MAAM,oBAAoB,gBAAgC,CAAC;AAClE,eAAO,MAAM,sBAAsB,kBAAkC,CAAC;AACtE,eAAO,MAAM,sBAAsB,mBAAkC,CAAC;AACtE,eAAO,MAAM,wBAAwB,oBAAoC,CAAC;AAC1E,eAAO,MAAM,uBAAuB,mBAAmC,CAAC;AACxE,eAAO,MAAM,kBAAkB,cAA8B,CAAC;AAC9D,eAAO,MAAM,mBAAmB,eAA+B,CAAC;AAChE,eAAO,MAAM,iBAAiB,aAA6B,CAAC;AAC5D,eAAO,MAAM,4BAA4B,iBAAmC,CAAC;AAC7E,eAAO,MAAM,iBAAiB,gBAAwB,CAAC;AACvD,eAAO,MAAM,sBAAsB,gBAAkC,CAAC;AACtE,eAAO,MAAM,uBAAuB,iBAAmC,CAAC;AACxE,eAAO,MAAM,sBAAsB,QAAkC,CAAC;AACtE,eAAO,MAAM,wBAAwB,QAAoC,CAAC;AAC1E,eAAO,MAAM,eAAe,WAA2B,CAAC;AACxD,eAAO,MAAM,qBAAqB,iBAAiC,CAAC;AAGpE,eAAO,MAAM,oBAAoB,kRAiBvB,CAAC;AAEX,eAAO,MAAM,cAAc;;;;;;;;CAqBjB,CAAC;AAGX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAGlE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,aAAa,CAE5E"}
|
package/dist/tool-ids.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { SEMANTIC_SEARCH_TOOL_CONFIG, MODEL_SEARCH_TOOL_CONFIG, MODEL_DETAIL_TOOL_CONFIG, MODEL_DETAIL_PROMPT_CONFIG, PAPER_SEARCH_TOOL_CONFIG, DATASET_SEARCH_TOOL_CONFIG, DATASET_DETAIL_TOOL_CONFIG, DATASET_DETAIL_PROMPT_CONFIG,
|
|
1
|
+
import { SEMANTIC_SEARCH_TOOL_CONFIG, MODEL_SEARCH_TOOL_CONFIG, MODEL_DETAIL_TOOL_CONFIG, MODEL_DETAIL_PROMPT_CONFIG, PAPER_SEARCH_TOOL_CONFIG, REPO_SEARCH_TOOL_CONFIG, DATASET_SEARCH_TOOL_CONFIG, DATASET_DETAIL_TOOL_CONFIG, DATASET_DETAIL_PROMPT_CONFIG, HUB_REPO_DETAILS_TOOL_CONFIG, DUPLICATE_SPACE_TOOL_CONFIG, SPACE_INFO_TOOL_CONFIG, SPACE_FILES_TOOL_CONFIG, USER_SUMMARY_PROMPT_CONFIG, PAPER_SUMMARY_PROMPT_CONFIG, DOCS_SEMANTIC_SEARCH_CONFIG, DOC_FETCH_CONFIG, USE_SPACE_TOOL_CONFIG, HF_JOBS_TOOL_CONFIG, DYNAMIC_SPACE_TOOL_CONFIG, } from './index.js';
|
|
2
2
|
export const SPACE_SEARCH_TOOL_ID = SEMANTIC_SEARCH_TOOL_CONFIG.name;
|
|
3
3
|
export const MODEL_SEARCH_TOOL_ID = MODEL_SEARCH_TOOL_CONFIG.name;
|
|
4
|
+
export const REPO_SEARCH_TOOL_ID = REPO_SEARCH_TOOL_CONFIG.name;
|
|
4
5
|
export const MODEL_DETAIL_TOOL_ID = MODEL_DETAIL_TOOL_CONFIG.name;
|
|
5
6
|
export const PAPER_SEARCH_TOOL_ID = PAPER_SEARCH_TOOL_CONFIG.name;
|
|
6
7
|
export const DATASET_SEARCH_TOOL_ID = DATASET_SEARCH_TOOL_CONFIG.name;
|
|
7
8
|
export const DATASET_DETAIL_TOOL_ID = DATASET_DETAIL_TOOL_CONFIG.name;
|
|
8
|
-
export const
|
|
9
|
+
export const HUB_REPO_DETAILS_TOOL_ID = HUB_REPO_DETAILS_TOOL_CONFIG.name;
|
|
9
10
|
export const DUPLICATE_SPACE_TOOL_ID = DUPLICATE_SPACE_TOOL_CONFIG.name;
|
|
10
11
|
export const SPACE_INFO_TOOL_ID = SPACE_INFO_TOOL_CONFIG.name;
|
|
11
12
|
export const SPACE_FILES_TOOL_ID = SPACE_FILES_TOOL_CONFIG.name;
|
|
@@ -21,11 +22,12 @@ export const DYNAMIC_SPACE_TOOL_ID = DYNAMIC_SPACE_TOOL_CONFIG.name;
|
|
|
21
22
|
export const ALL_BUILTIN_TOOL_IDS = [
|
|
22
23
|
SPACE_SEARCH_TOOL_ID,
|
|
23
24
|
MODEL_SEARCH_TOOL_ID,
|
|
25
|
+
REPO_SEARCH_TOOL_ID,
|
|
24
26
|
MODEL_DETAIL_TOOL_ID,
|
|
25
27
|
PAPER_SEARCH_TOOL_ID,
|
|
26
28
|
DATASET_SEARCH_TOOL_ID,
|
|
27
29
|
DATASET_DETAIL_TOOL_ID,
|
|
28
|
-
|
|
30
|
+
HUB_REPO_DETAILS_TOOL_ID,
|
|
29
31
|
DUPLICATE_SPACE_TOOL_ID,
|
|
30
32
|
SPACE_INFO_TOOL_ID,
|
|
31
33
|
SPACE_FILES_TOOL_ID,
|
|
@@ -36,13 +38,7 @@ export const ALL_BUILTIN_TOOL_IDS = [
|
|
|
36
38
|
DYNAMIC_SPACE_TOOL_ID,
|
|
37
39
|
];
|
|
38
40
|
export const TOOL_ID_GROUPS = {
|
|
39
|
-
search: [
|
|
40
|
-
SPACE_SEARCH_TOOL_ID,
|
|
41
|
-
MODEL_SEARCH_TOOL_ID,
|
|
42
|
-
DATASET_SEARCH_TOOL_ID,
|
|
43
|
-
PAPER_SEARCH_TOOL_ID,
|
|
44
|
-
DOCS_SEMANTIC_SEARCH_TOOL_ID,
|
|
45
|
-
],
|
|
41
|
+
search: [SPACE_SEARCH_TOOL_ID, REPO_SEARCH_TOOL_ID, PAPER_SEARCH_TOOL_ID, DOCS_SEMANTIC_SEARCH_TOOL_ID],
|
|
46
42
|
spaces: [
|
|
47
43
|
SPACE_SEARCH_TOOL_ID,
|
|
48
44
|
DUPLICATE_SPACE_TOOL_ID,
|
|
@@ -50,14 +46,13 @@ export const TOOL_ID_GROUPS = {
|
|
|
50
46
|
SPACE_FILES_TOOL_ID,
|
|
51
47
|
USE_SPACE_TOOL_ID,
|
|
52
48
|
],
|
|
53
|
-
detail: [MODEL_DETAIL_TOOL_ID, DATASET_DETAIL_TOOL_ID,
|
|
49
|
+
detail: [MODEL_DETAIL_TOOL_ID, DATASET_DETAIL_TOOL_ID, HUB_REPO_DETAILS_TOOL_ID],
|
|
54
50
|
docs: [DOCS_SEMANTIC_SEARCH_TOOL_ID, DOC_FETCH_TOOL_ID],
|
|
55
51
|
hf_api: [
|
|
56
52
|
SPACE_SEARCH_TOOL_ID,
|
|
57
|
-
|
|
58
|
-
DATASET_SEARCH_TOOL_ID,
|
|
53
|
+
REPO_SEARCH_TOOL_ID,
|
|
59
54
|
PAPER_SEARCH_TOOL_ID,
|
|
60
|
-
|
|
55
|
+
HUB_REPO_DETAILS_TOOL_ID,
|
|
61
56
|
DOCS_SEMANTIC_SEARCH_TOOL_ID,
|
|
62
57
|
],
|
|
63
58
|
dynamic_space: [DYNAMIC_SPACE_TOOL_ID],
|
package/dist/tool-ids.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-ids.js","sourceRoot":"","sources":["../src/tool-ids.ts"],"names":[],"mappings":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,CAAU;IAChE,MAAM,EAAE;QACP,oBAAoB;QACpB,mBAAmB;QACnB,oBAAoB;QACpB,wBAAwB;QACxB,4BAA4B;KAEnB;IACV,aAAa,EAAE,CAAC,qBAAqB,CAAU;IAC/C,GAAG,EAAE,CAAC,GAAG,oBAAoB,CAAU;CAC9B,CAAC;AAMX,MAAM,UAAU,oBAAoB,CAAC,MAAc;IAClD,OAAQ,oBAA0C,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmindset/hf-mcp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@huggingface/hub": "^2.6.12",
|
|
27
27
|
"@mcp-ui/server": "^5.12.0",
|
|
28
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
28
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
29
29
|
"shell-quote": "^1.8.3",
|
|
30
30
|
"turndown": "^7.2.0",
|
|
31
31
|
"zod": "^3.24.4"
|
|
@@ -7,11 +7,18 @@ import type { ToolResult } from '../types/tool-result.js';
|
|
|
7
7
|
/** token estimation. initial results for "how to load a image to image model in transformers" returned
|
|
8
8
|
* 121973 characters (36711 anthropic tokens) */
|
|
9
9
|
|
|
10
|
+
const KNOWLEDGE_DATE = new Intl.DateTimeFormat('en-GB', {
|
|
11
|
+
day: 'numeric',
|
|
12
|
+
month: 'long',
|
|
13
|
+
year: 'numeric',
|
|
14
|
+
timeZone: 'UTC',
|
|
15
|
+
}).format(new Date());
|
|
16
|
+
|
|
10
17
|
export const DOCS_SEMANTIC_SEARCH_CONFIG = {
|
|
11
18
|
name: 'hf_doc_search',
|
|
12
19
|
description:
|
|
13
20
|
'Search and Discover Hugging Face Product and Library documentation. Send an empty query to discover structure and navigation instructions. ' +
|
|
14
|
-
|
|
21
|
+
`Knowledge up-to-date as at ${KNOWLEDGE_DATE}. Combine with the Product filter to focus results.`,
|
|
15
22
|
schema: z.object({
|
|
16
23
|
query: z
|
|
17
24
|
.string()
|
package/src/hub-inspect.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { DatasetDetailTool } from './dataset-detail.js';
|
|
|
5
5
|
import { spaceInfo } from '@huggingface/hub';
|
|
6
6
|
import { formatDate } from './utilities.js';
|
|
7
7
|
|
|
8
|
-
export const
|
|
8
|
+
export const HUB_REPO_DETAILS_TOOL_CONFIG = {
|
|
9
9
|
name: 'hub_repo_details',
|
|
10
10
|
description:
|
|
11
11
|
'Get details for one or more Hugging Face repos (model, dataset, or space). ' +
|
|
@@ -27,7 +27,7 @@ export const HUB_INSPECT_TOOL_CONFIG = {
|
|
|
27
27
|
},
|
|
28
28
|
} as const;
|
|
29
29
|
|
|
30
|
-
export type HubInspectParams = z.infer<typeof
|
|
30
|
+
export type HubInspectParams = z.infer<typeof HUB_REPO_DETAILS_TOOL_CONFIG.schema>;
|
|
31
31
|
|
|
32
32
|
export class HubInspectTool {
|
|
33
33
|
private readonly modelDetail: ModelDetailTool;
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './model-detail.js';
|
|
|
7
7
|
export * from './utilities.js';
|
|
8
8
|
export * from './paper-search.js';
|
|
9
9
|
export * from './dataset-search.js';
|
|
10
|
+
export * from './repo-search.js';
|
|
10
11
|
export * from './dataset-detail.js';
|
|
11
12
|
export * from './hub-inspect.js';
|
|
12
13
|
export * from './duplicate-space.js';
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { RepoSearchTool } from './repo-search.js';
|
|
3
|
+
|
|
4
|
+
interface MockFetchCall {
|
|
5
|
+
input: string;
|
|
6
|
+
init?: RequestInit;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('RepoSearchTool', () => {
|
|
10
|
+
const originalFetch = globalThis.fetch;
|
|
11
|
+
let calls: MockFetchCall[] = [];
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
calls = [];
|
|
15
|
+
vi.stubGlobal('fetch', (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
|
16
|
+
const inputString = stringifyRequestInput(input);
|
|
17
|
+
calls.push({ input: inputString, init });
|
|
18
|
+
|
|
19
|
+
if (inputString.includes('/api/models')) {
|
|
20
|
+
return Promise.resolve(jsonResponse([
|
|
21
|
+
{
|
|
22
|
+
id: 'meta-llama/Llama-3.1-8B-Instruct',
|
|
23
|
+
pipeline_tag: 'text-generation',
|
|
24
|
+
library_name: 'transformers',
|
|
25
|
+
downloads: 123,
|
|
26
|
+
likes: 10,
|
|
27
|
+
tags: ['text-generation'],
|
|
28
|
+
},
|
|
29
|
+
]));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (inputString.includes('/api/datasets')) {
|
|
33
|
+
return Promise.resolve(jsonResponse([
|
|
34
|
+
{
|
|
35
|
+
id: 'openbmb/UltraData-Math',
|
|
36
|
+
description: 'Large-scale mathematical dataset',
|
|
37
|
+
downloads: 50,
|
|
38
|
+
likes: 3,
|
|
39
|
+
tags: ['math'],
|
|
40
|
+
},
|
|
41
|
+
]));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (inputString.includes('/api/spaces')) {
|
|
45
|
+
return Promise.resolve(jsonResponse([
|
|
46
|
+
{
|
|
47
|
+
id: 'mrfakename/Z-Image-Turbo',
|
|
48
|
+
title: 'Z Image Turbo',
|
|
49
|
+
sdk: 'gradio',
|
|
50
|
+
likes: 20,
|
|
51
|
+
},
|
|
52
|
+
]));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return Promise.resolve(jsonResponse([]));
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
vi.unstubAllGlobals();
|
|
61
|
+
globalThis.fetch = originalFetch;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('aggregates model and dataset results in one response', async () => {
|
|
65
|
+
const tool = new RepoSearchTool('token');
|
|
66
|
+
const result = await tool.searchWithParams({
|
|
67
|
+
query: 'llama',
|
|
68
|
+
repo_types: ['model', 'dataset'],
|
|
69
|
+
limit: 5,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(calls).toHaveLength(2);
|
|
73
|
+
expect(calls[0]?.input).toContain('/api/models');
|
|
74
|
+
expect(calls[1]?.input).toContain('/api/datasets');
|
|
75
|
+
expect(result.totalResults).toBe(2);
|
|
76
|
+
expect(result.formatted).toContain('## Models (1)');
|
|
77
|
+
expect(result.formatted).toContain('## Datasets (1)');
|
|
78
|
+
expect(result.formatted).toContain('[https://hf.co/meta-llama/Llama-3.1-8B-Instruct]');
|
|
79
|
+
expect(result.formatted).toContain('[https://hf.co/datasets/openbmb/UltraData-Math]');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('supports searching spaces through the same interface', async () => {
|
|
83
|
+
const tool = new RepoSearchTool('token');
|
|
84
|
+
const result = await tool.searchWithParams({
|
|
85
|
+
query: 'image generation',
|
|
86
|
+
repo_types: ['space'],
|
|
87
|
+
limit: 3,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(calls).toHaveLength(1);
|
|
91
|
+
expect(calls[0]?.input).toContain('/api/spaces');
|
|
92
|
+
expect(result.totalResults).toBe(1);
|
|
93
|
+
expect(result.formatted).toContain('## Spaces (1)');
|
|
94
|
+
expect(result.formatted).toContain('[https://hf.co/spaces/mrfakename/Z-Image-Turbo]');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('applies an overall output length guard with truncation notice', async () => {
|
|
98
|
+
vi.stubGlobal('fetch', (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
|
99
|
+
const inputString = stringifyRequestInput(input);
|
|
100
|
+
calls.push({ input: inputString, init });
|
|
101
|
+
|
|
102
|
+
if (inputString.includes('/api/models')) {
|
|
103
|
+
const longTag = 'very-long-tag-name-for-output-growth';
|
|
104
|
+
const models = Array.from({ length: 100 }, (_, index) => ({
|
|
105
|
+
id: `org/super-long-model-name-${index.toString().padStart(3, '0')}-with-extra-context`,
|
|
106
|
+
pipeline_tag: 'text-generation',
|
|
107
|
+
library_name: 'transformers',
|
|
108
|
+
downloads: 100000 - index,
|
|
109
|
+
likes: 1000 - index,
|
|
110
|
+
tags: Array.from({ length: 30 }, (_unused, tagIndex) => `${longTag}-${tagIndex.toString()}`),
|
|
111
|
+
}));
|
|
112
|
+
return Promise.resolve(jsonResponse(models));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return Promise.resolve(jsonResponse([]));
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const tool = new RepoSearchTool('token');
|
|
119
|
+
const result = await tool.searchWithParams({
|
|
120
|
+
repo_types: ['model'],
|
|
121
|
+
limit: 100,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
expect(result.totalResults).toBe(100);
|
|
125
|
+
expect(result.resultsShared).toBeLessThan(result.totalResults);
|
|
126
|
+
expect(result.formatted.length).toBeLessThanOrEqual(12_500 * 3);
|
|
127
|
+
expect(result.formatted).toContain('Results truncated at approximately 12,500 tokens');
|
|
128
|
+
expect(result.formatted).toContain('Included');
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
function jsonResponse(payload: unknown): Response {
|
|
133
|
+
return new Response(JSON.stringify(payload), {
|
|
134
|
+
status: 200,
|
|
135
|
+
headers: {
|
|
136
|
+
'content-type': 'application/json',
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function stringifyRequestInput(input: RequestInfo | URL): string {
|
|
142
|
+
if (typeof input === 'string') {
|
|
143
|
+
return input;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (input instanceof URL) {
|
|
147
|
+
return input.toString();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (input instanceof Request) {
|
|
151
|
+
return input.url;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return input;
|
|
155
|
+
}
|