@llmindset/hf-mcp 0.3.2 → 0.3.3

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.
Files changed (137) hide show
  1. package/dist/docs-search/doc-fetch.d.ts +1 -0
  2. package/dist/docs-search/doc-fetch.d.ts.map +1 -1
  3. package/dist/docs-search/doc-fetch.js +9 -12
  4. package/dist/docs-search/doc-fetch.js.map +1 -1
  5. package/dist/docs-search/doc-fetch.test.js +56 -11
  6. package/dist/docs-search/doc-fetch.test.js.map +1 -1
  7. package/dist/file-icons.d.ts +3 -0
  8. package/dist/file-icons.d.ts.map +1 -0
  9. package/dist/file-icons.js +38 -0
  10. package/dist/file-icons.js.map +1 -0
  11. package/dist/gradio-files.d.ts +0 -1
  12. package/dist/gradio-files.d.ts.map +1 -1
  13. package/dist/gradio-files.js +2 -35
  14. package/dist/gradio-files.js.map +1 -1
  15. package/dist/hf-api-call.d.ts.map +1 -1
  16. package/dist/hf-api-call.js +7 -7
  17. package/dist/hf-api-call.js.map +1 -1
  18. package/dist/index.browser.d.ts +48 -0
  19. package/dist/index.browser.d.ts.map +1 -0
  20. package/dist/index.browser.js +153 -0
  21. package/dist/index.browser.js.map +1 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/jobs/commands/uv-utils.d.ts +0 -3
  27. package/dist/jobs/commands/uv-utils.d.ts.map +1 -1
  28. package/dist/jobs/commands/uv-utils.js +2 -2
  29. package/dist/jobs/commands/uv-utils.js.map +1 -1
  30. package/dist/jobs/jobs-tool.d.ts.map +1 -1
  31. package/dist/jobs/jobs-tool.js +11 -12
  32. package/dist/jobs/jobs-tool.js.map +1 -1
  33. package/dist/jobs/schema-help.d.ts +2 -9
  34. package/dist/jobs/schema-help.d.ts.map +1 -1
  35. package/dist/jobs/schema-help.js +3 -3
  36. package/dist/jobs/schema-help.js.map +1 -1
  37. package/dist/jobs/sse-handler.d.ts +3 -2
  38. package/dist/jobs/sse-handler.d.ts.map +1 -1
  39. package/dist/jobs/sse-handler.js +8 -4
  40. package/dist/jobs/sse-handler.js.map +1 -1
  41. package/dist/jobs/types.d.ts +1 -1
  42. package/dist/logger.d.ts +2 -2
  43. package/dist/logger.d.ts.map +1 -1
  44. package/dist/network/fetch-profile.d.ts +24 -0
  45. package/dist/network/fetch-profile.d.ts.map +1 -0
  46. package/dist/network/fetch-profile.js +80 -0
  47. package/dist/network/fetch-profile.js.map +1 -0
  48. package/dist/network/index.d.ts +5 -0
  49. package/dist/network/index.d.ts.map +1 -0
  50. package/dist/network/index.js +5 -0
  51. package/dist/network/index.js.map +1 -0
  52. package/dist/network/ip-policy.d.ts +6 -0
  53. package/dist/network/ip-policy.d.ts.map +1 -0
  54. package/dist/network/ip-policy.js +166 -0
  55. package/dist/network/ip-policy.js.map +1 -0
  56. package/dist/network/ip-policy.test.d.ts +2 -0
  57. package/dist/network/ip-policy.test.d.ts.map +1 -0
  58. package/dist/network/ip-policy.test.js +26 -0
  59. package/dist/network/ip-policy.test.js.map +1 -0
  60. package/dist/network/safe-fetch.d.ts +16 -0
  61. package/dist/network/safe-fetch.d.ts.map +1 -0
  62. package/dist/network/safe-fetch.js +124 -0
  63. package/dist/network/safe-fetch.js.map +1 -0
  64. package/dist/network/safe-fetch.test.d.ts +2 -0
  65. package/dist/network/safe-fetch.test.d.ts.map +1 -0
  66. package/dist/network/safe-fetch.test.js +136 -0
  67. package/dist/network/safe-fetch.test.js.map +1 -0
  68. package/dist/network/url-policy.d.ts +32 -0
  69. package/dist/network/url-policy.d.ts.map +1 -0
  70. package/dist/network/url-policy.js +230 -0
  71. package/dist/network/url-policy.js.map +1 -0
  72. package/dist/network/url-policy.test.d.ts +2 -0
  73. package/dist/network/url-policy.test.d.ts.map +1 -0
  74. package/dist/network/url-policy.test.js +57 -0
  75. package/dist/network/url-policy.test.js.map +1 -0
  76. package/dist/readme-utils.d.ts.map +1 -1
  77. package/dist/readme-utils.js +3 -4
  78. package/dist/readme-utils.js.map +1 -1
  79. package/dist/space/commands/discover.d.ts +0 -5
  80. package/dist/space/commands/discover.d.ts.map +1 -1
  81. package/dist/space/commands/discover.js +9 -2
  82. package/dist/space/commands/discover.js.map +1 -1
  83. package/dist/space/commands/invoke.js +1 -59
  84. package/dist/space/commands/invoke.js.map +1 -1
  85. package/dist/space/commands/view-parameters.d.ts.map +1 -1
  86. package/dist/space/commands/view-parameters.js +3 -98
  87. package/dist/space/commands/view-parameters.js.map +1 -1
  88. package/dist/space/dynamic-space-tool.d.ts.map +1 -1
  89. package/dist/space/dynamic-space-tool.js +5 -2
  90. package/dist/space/dynamic-space-tool.js.map +1 -1
  91. package/dist/space/utils/gradio-caller.d.ts.map +1 -1
  92. package/dist/space/utils/gradio-caller.js +13 -6
  93. package/dist/space/utils/gradio-caller.js.map +1 -1
  94. package/dist/space/utils/space-http.d.ts +8 -0
  95. package/dist/space/utils/space-http.d.ts.map +1 -0
  96. package/dist/space/utils/space-http.js +49 -0
  97. package/dist/space/utils/space-http.js.map +1 -0
  98. package/dist/space-files.d.ts +0 -1
  99. package/dist/space-files.d.ts.map +1 -1
  100. package/dist/space-files.js +3 -36
  101. package/dist/space-files.js.map +1 -1
  102. package/package.json +6 -2
  103. package/src/docs-search/doc-fetch.test.ts +98 -28
  104. package/src/docs-search/doc-fetch.ts +9 -16
  105. package/src/file-icons.ts +39 -0
  106. package/src/gradio-files.ts +2 -40
  107. package/src/hf-api-call.ts +8 -10
  108. package/src/index.browser.ts +183 -0
  109. package/src/index.ts +1 -0
  110. package/src/jobs/commands/uv-utils.ts +2 -2
  111. package/src/jobs/jobs-tool.ts +13 -12
  112. package/src/jobs/schema-help.ts +4 -4
  113. package/src/jobs/sse-handler.ts +12 -7
  114. package/src/logger.ts +2 -2
  115. package/src/network/fetch-profile.ts +112 -0
  116. package/src/network/index.ts +4 -0
  117. package/src/network/ip-policy.test.ts +29 -0
  118. package/src/network/ip-policy.ts +206 -0
  119. package/src/network/safe-fetch.test.ts +181 -0
  120. package/src/network/safe-fetch.ts +174 -0
  121. package/src/network/url-policy.test.ts +100 -0
  122. package/src/network/url-policy.ts +304 -0
  123. package/src/readme-utils.ts +11 -10
  124. package/src/space/commands/discover.ts +10 -2
  125. package/src/space/commands/invoke.ts +1 -88
  126. package/src/space/commands/view-parameters.ts +3 -136
  127. package/src/space/dynamic-space-tool.ts +6 -2
  128. package/src/space/utils/gradio-caller.ts +25 -12
  129. package/src/space/utils/space-http.ts +75 -0
  130. package/src/space-files.ts +3 -41
  131. package/test/fetch-guard.spec.ts +70 -0
  132. package/test/jobs/sse-handler.spec.ts +60 -0
  133. package/dist/space/utils/result-formatter.d.ts +0 -4
  134. package/dist/space/utils/result-formatter.d.ts.map +0 -1
  135. package/dist/space/utils/result-formatter.js +0 -146
  136. package/dist/space/utils/result-formatter.js.map +0 -1
  137. package/src/space/utils/result-formatter.ts +0 -226
@@ -1,146 +0,0 @@
1
- export function formatToolResult(result) {
2
- if (result.isError) {
3
- return formatErrorResult(result);
4
- }
5
- if (Array.isArray(result.content) && result.content.length > 0) {
6
- return formatContentArray(result.content);
7
- }
8
- return 'Tool executed successfully (no content returned).';
9
- }
10
- function formatErrorResult(result) {
11
- if (!Array.isArray(result.content) || result.content.length === 0) {
12
- return 'Error: Tool execution failed (no error details provided).';
13
- }
14
- const errorMessages = [];
15
- for (const item of result.content) {
16
- if (typeof item === 'string') {
17
- errorMessages.push(item);
18
- }
19
- else if (item && typeof item === 'object') {
20
- const obj = item;
21
- if (typeof obj.text === 'string') {
22
- errorMessages.push(obj.text);
23
- }
24
- else if (typeof obj.message === 'string') {
25
- errorMessages.push(obj.message);
26
- }
27
- else if (typeof obj.error === 'string') {
28
- errorMessages.push(obj.error);
29
- }
30
- }
31
- }
32
- if (errorMessages.length > 0) {
33
- return `Error: ${errorMessages.join('\n')}`;
34
- }
35
- return 'Error: Tool execution failed.';
36
- }
37
- function formatContentArray(content) {
38
- const formattedItems = [];
39
- for (const item of content) {
40
- const formatted = formatContentItem(item);
41
- if (formatted) {
42
- formattedItems.push(formatted);
43
- }
44
- }
45
- if (formattedItems.length === 0) {
46
- return 'Tool executed successfully (no displayable content).';
47
- }
48
- return formattedItems.join('\n\n');
49
- }
50
- function formatContentItem(item) {
51
- if (!item) {
52
- return null;
53
- }
54
- if (typeof item === 'string') {
55
- return item;
56
- }
57
- if (typeof item !== 'object') {
58
- if (typeof item === 'number' || typeof item === 'boolean') {
59
- return String(item);
60
- }
61
- return JSON.stringify(item);
62
- }
63
- const obj = item;
64
- const type = typeof obj.type === 'string' ? obj.type.toLowerCase() : undefined;
65
- switch (type) {
66
- case 'text':
67
- return formatTextContent(obj);
68
- case 'image':
69
- return formatImageContent(obj);
70
- case 'resource':
71
- return formatResourceContent(obj);
72
- case 'embedded_resource':
73
- return formatEmbeddedResourceContent(obj);
74
- default:
75
- if (typeof obj.text === 'string') {
76
- return obj.text;
77
- }
78
- try {
79
- return JSON.stringify(item, null, 2);
80
- }
81
- catch {
82
- return '[complex object]';
83
- }
84
- }
85
- }
86
- function formatTextContent(obj) {
87
- if (typeof obj.text === 'string') {
88
- return obj.text;
89
- }
90
- return null;
91
- }
92
- function formatImageContent(obj) {
93
- const parts = ['[Image Content]'];
94
- if (typeof obj.mimeType === 'string') {
95
- parts.push(`Type: ${obj.mimeType}`);
96
- }
97
- if (typeof obj.url === 'string') {
98
- parts.push(`URL: ${obj.url}`);
99
- }
100
- if (typeof obj.data === 'string') {
101
- const dataLength = obj.data.length;
102
- parts.push(`Data: ${dataLength} characters (base64)`);
103
- }
104
- return parts.join('\n');
105
- }
106
- function formatResourceContent(obj) {
107
- const parts = ['[Resource]'];
108
- const resource = obj.resource;
109
- if (resource) {
110
- if (typeof resource.uri === 'string') {
111
- parts.push(`URI: ${resource.uri}`);
112
- }
113
- if (typeof resource.name === 'string') {
114
- parts.push(`Name: ${resource.name}`);
115
- }
116
- if (typeof resource.mimeType === 'string') {
117
- parts.push(`Type: ${resource.mimeType}`);
118
- }
119
- if (typeof resource.description === 'string') {
120
- parts.push(`Description: ${resource.description}`);
121
- }
122
- }
123
- return parts.join('\n');
124
- }
125
- function formatEmbeddedResourceContent(obj) {
126
- const parts = ['[Embedded Resource]'];
127
- if (typeof obj.uri === 'string') {
128
- parts.push(`URI: ${obj.uri}`);
129
- }
130
- if (typeof obj.mimeType === 'string') {
131
- parts.push(`Type: ${obj.mimeType}`);
132
- }
133
- if (typeof obj.blob === 'string') {
134
- const blobLength = obj.blob.length;
135
- parts.push(`Data: ${blobLength} characters`);
136
- }
137
- return parts.join('\n');
138
- }
139
- export function formatWarnings(warnings) {
140
- if (warnings.length === 0) {
141
- return '';
142
- }
143
- const header = warnings.length === 1 ? 'Warning:' : 'Warnings:';
144
- return `${header}\n${warnings.map((w) => `- ${w}`).join('\n')}\n\n`;
145
- }
146
- //# sourceMappingURL=result-formatter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"result-formatter.js","sourceRoot":"","sources":["../../../src/space/utils/result-formatter.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,gBAAgB,CAAC,MAAsB;IAEtD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAGD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChE,OAAO,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAGD,OAAO,mDAAmD,CAAC;AAC5D,CAAC;AAKD,SAAS,iBAAiB,CAAC,MAAsB;IAChD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnE,OAAO,2DAA2D,CAAC;IACpE,CAAC;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KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;IAChE,OAAO,GAAG,MAAM,KAAK,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;AACrE,CAAC"}
@@ -1,226 +0,0 @@
1
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
-
3
- /**
4
- * Formats tool result for user-friendly display
5
- * Handles different content types:
6
- * - Text content (primary)
7
- * - Image content (with descriptions)
8
- * - Resource content (with URIs)
9
- * - Error results
10
- */
11
- export function formatToolResult(result: CallToolResult): string {
12
- // Handle error results
13
- if (result.isError) {
14
- return formatErrorResult(result);
15
- }
16
-
17
- // Handle successful results with content
18
- if (Array.isArray(result.content) && result.content.length > 0) {
19
- return formatContentArray(result.content);
20
- }
21
-
22
- // Fallback for empty results
23
- return 'Tool executed successfully (no content returned).';
24
- }
25
-
26
- /**
27
- * Formats error results
28
- */
29
- function formatErrorResult(result: CallToolResult): string {
30
- if (!Array.isArray(result.content) || result.content.length === 0) {
31
- return 'Error: Tool execution failed (no error details provided).';
32
- }
33
-
34
- const errorMessages: string[] = [];
35
-
36
- for (const item of result.content) {
37
- if (typeof item === 'string') {
38
- errorMessages.push(item);
39
- } else if (item && typeof item === 'object') {
40
- const obj = item as Record<string, unknown>;
41
- if (typeof obj.text === 'string') {
42
- errorMessages.push(obj.text);
43
- } else if (typeof obj.message === 'string') {
44
- errorMessages.push(obj.message);
45
- } else if (typeof obj.error === 'string') {
46
- errorMessages.push(obj.error);
47
- }
48
- }
49
- }
50
-
51
- if (errorMessages.length > 0) {
52
- return `Error: ${errorMessages.join('\n')}`;
53
- }
54
-
55
- return 'Error: Tool execution failed.';
56
- }
57
-
58
- /**
59
- * Formats an array of content items
60
- */
61
- function formatContentArray(content: unknown[]): string {
62
- const formattedItems: string[] = [];
63
-
64
- for (const item of content) {
65
- const formatted = formatContentItem(item);
66
- if (formatted) {
67
- formattedItems.push(formatted);
68
- }
69
- }
70
-
71
- if (formattedItems.length === 0) {
72
- return 'Tool executed successfully (no displayable content).';
73
- }
74
-
75
- return formattedItems.join('\n\n');
76
- }
77
-
78
- /**
79
- * Formats a single content item
80
- */
81
- function formatContentItem(item: unknown): string | null {
82
- if (!item) {
83
- return null;
84
- }
85
-
86
- // Handle string content
87
- if (typeof item === 'string') {
88
- return item;
89
- }
90
-
91
- // Handle non-object content
92
- if (typeof item !== 'object') {
93
- if (typeof item === 'number' || typeof item === 'boolean') {
94
- return String(item);
95
- }
96
- return JSON.stringify(item);
97
- }
98
-
99
- const obj = item as Record<string, unknown>;
100
- const type = typeof obj.type === 'string' ? obj.type.toLowerCase() : undefined;
101
-
102
- switch (type) {
103
- case 'text':
104
- return formatTextContent(obj);
105
-
106
- case 'image':
107
- return formatImageContent(obj);
108
-
109
- case 'resource':
110
- return formatResourceContent(obj);
111
-
112
- case 'embedded_resource':
113
- return formatEmbeddedResourceContent(obj);
114
-
115
- default:
116
- // Try to extract text from unknown types
117
- if (typeof obj.text === 'string') {
118
- return obj.text;
119
- }
120
- // Fallback to JSON representation
121
- try {
122
- return JSON.stringify(item, null, 2);
123
- } catch {
124
- return '[complex object]';
125
- }
126
- }
127
- }
128
-
129
- /**
130
- * Formats text content
131
- */
132
- function formatTextContent(obj: Record<string, unknown>): string | null {
133
- if (typeof obj.text === 'string') {
134
- return obj.text;
135
- }
136
- return null;
137
- }
138
-
139
- /**
140
- * Formats image content
141
- */
142
- function formatImageContent(obj: Record<string, unknown>): string {
143
- const parts: string[] = ['[Image Content]'];
144
-
145
- // Add MIME type if available
146
- if (typeof obj.mimeType === 'string') {
147
- parts.push(`Type: ${obj.mimeType}`);
148
- }
149
-
150
- // Add URL if available
151
- if (typeof obj.url === 'string') {
152
- parts.push(`URL: ${obj.url}`);
153
- }
154
-
155
- // Add data indicator if present
156
- if (typeof obj.data === 'string') {
157
- const dataLength = obj.data.length;
158
- parts.push(`Data: ${dataLength} characters (base64)`);
159
- }
160
-
161
- return parts.join('\n');
162
- }
163
-
164
- /**
165
- * Formats resource content
166
- */
167
- function formatResourceContent(obj: Record<string, unknown>): string {
168
- const parts: string[] = ['[Resource]'];
169
-
170
- // Extract resource details
171
- const resource = obj.resource as Record<string, unknown> | undefined;
172
- if (resource) {
173
- if (typeof resource.uri === 'string') {
174
- parts.push(`URI: ${resource.uri}`);
175
- }
176
-
177
- if (typeof resource.name === 'string') {
178
- parts.push(`Name: ${resource.name}`);
179
- }
180
-
181
- if (typeof resource.mimeType === 'string') {
182
- parts.push(`Type: ${resource.mimeType}`);
183
- }
184
-
185
- if (typeof resource.description === 'string') {
186
- parts.push(`Description: ${resource.description}`);
187
- }
188
- }
189
-
190
- return parts.join('\n');
191
- }
192
-
193
- /**
194
- * Formats embedded resource content
195
- */
196
- function formatEmbeddedResourceContent(obj: Record<string, unknown>): string {
197
- const parts: string[] = ['[Embedded Resource]'];
198
-
199
- if (typeof obj.uri === 'string') {
200
- parts.push(`URI: ${obj.uri}`);
201
- }
202
-
203
- if (typeof obj.mimeType === 'string') {
204
- parts.push(`Type: ${obj.mimeType}`);
205
- }
206
-
207
- // Add blob indicator if present
208
- if (typeof obj.blob === 'string') {
209
- const blobLength = obj.blob.length;
210
- parts.push(`Data: ${blobLength} characters`);
211
- }
212
-
213
- return parts.join('\n');
214
- }
215
-
216
- /**
217
- * Formats a list of warnings
218
- */
219
- export function formatWarnings(warnings: string[]): string {
220
- if (warnings.length === 0) {
221
- return '';
222
- }
223
-
224
- const header = warnings.length === 1 ? 'Warning:' : 'Warnings:';
225
- return `${header}\n${warnings.map((w) => `- ${w}`).join('\n')}\n\n`;
226
- }