@inference-gateway/sdk 0.6.2 → 0.7.0
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/CHANGELOG.md +6 -0
- package/README.md +26 -0
- package/dist/src/client.d.ts +6 -1
- package/dist/src/client.js +9 -0
- package/dist/src/types/generated/index.d.ts +106 -0
- package/dist/tests/client.test.js +47 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.7.0](https://github.com/inference-gateway/typescript-sdk/compare/v0.6.2...v0.7.0) (2025-05-26)
|
|
6
|
+
|
|
7
|
+
### ✨ Features
|
|
8
|
+
|
|
9
|
+
* Implement MCP List Tools ([#13](https://github.com/inference-gateway/typescript-sdk/issues/13)) ([5c0a38c](https://github.com/inference-gateway/typescript-sdk/commit/5c0a38cbe825161c9d5dc1e15f59b31217aebb23))
|
|
10
|
+
|
|
5
11
|
## [0.6.2](https://github.com/inference-gateway/typescript-sdk/compare/v0.6.1...v0.6.2) (2025-04-30)
|
|
6
12
|
|
|
7
13
|
### ♻️ Improvements
|
package/README.md
CHANGED
|
@@ -58,6 +58,32 @@ try {
|
|
|
58
58
|
}
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
### Listing MCP Tools
|
|
62
|
+
|
|
63
|
+
To list available Model Context Protocol (MCP) tools (only available when EXPOSE_MCP is enabled):
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { InferenceGatewayClient } from '@inference-gateway/sdk';
|
|
67
|
+
|
|
68
|
+
const client = new InferenceGatewayClient({
|
|
69
|
+
baseURL: 'http://localhost:8080/v1',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const tools = await client.listTools();
|
|
74
|
+
console.log('Available MCP tools:', tools.data);
|
|
75
|
+
|
|
76
|
+
// Each tool has: name, description, server, and optional input_schema
|
|
77
|
+
tools.data.forEach((tool) => {
|
|
78
|
+
console.log(`Tool: ${tool.name}`);
|
|
79
|
+
console.log(`Description: ${tool.description}`);
|
|
80
|
+
console.log(`Server: ${tool.server}`);
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('Error:', error);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
61
87
|
### Creating Chat Completions
|
|
62
88
|
|
|
63
89
|
To generate content using a model:
|
package/dist/src/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Provider, SchemaChatCompletionMessageToolCall, SchemaCompletionUsage, SchemaCreateChatCompletionRequest, SchemaCreateChatCompletionResponse, SchemaCreateChatCompletionStreamResponse, SchemaError, SchemaListModelsResponse } from './types/generated';
|
|
1
|
+
import type { Provider, SchemaChatCompletionMessageToolCall, SchemaCompletionUsage, SchemaCreateChatCompletionRequest, SchemaCreateChatCompletionResponse, SchemaCreateChatCompletionStreamResponse, SchemaError, SchemaListModelsResponse, SchemaListToolsResponse } from './types/generated';
|
|
2
2
|
interface ChatCompletionStreamCallbacks {
|
|
3
3
|
onOpen?: () => void;
|
|
4
4
|
onChunk?: (chunk: SchemaCreateChatCompletionStreamResponse) => void;
|
|
@@ -37,6 +37,11 @@ export declare class InferenceGatewayClient {
|
|
|
37
37
|
* Lists the currently available models.
|
|
38
38
|
*/
|
|
39
39
|
listModels(provider?: Provider): Promise<SchemaListModelsResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* Lists the currently available MCP tools.
|
|
42
|
+
* Only accessible when EXPOSE_MCP is enabled.
|
|
43
|
+
*/
|
|
44
|
+
listTools(): Promise<SchemaListToolsResponse>;
|
|
40
45
|
/**
|
|
41
46
|
* Creates a chat completion.
|
|
42
47
|
*/
|
package/dist/src/client.js
CHANGED
|
@@ -77,6 +77,15 @@ class InferenceGatewayClient {
|
|
|
77
77
|
}
|
|
78
78
|
return this.request('/models', { method: 'GET' }, query);
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Lists the currently available MCP tools.
|
|
82
|
+
* Only accessible when EXPOSE_MCP is enabled.
|
|
83
|
+
*/
|
|
84
|
+
async listTools() {
|
|
85
|
+
return this.request('/mcp/tools', {
|
|
86
|
+
method: 'GET',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
80
89
|
/**
|
|
81
90
|
* Creates a chat completion.
|
|
82
91
|
*/
|
|
@@ -47,6 +47,27 @@ export interface paths {
|
|
|
47
47
|
patch?: never;
|
|
48
48
|
trace?: never;
|
|
49
49
|
};
|
|
50
|
+
'/mcp/tools': {
|
|
51
|
+
parameters: {
|
|
52
|
+
query?: never;
|
|
53
|
+
header?: never;
|
|
54
|
+
path?: never;
|
|
55
|
+
cookie?: never;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Lists the currently available MCP tools
|
|
59
|
+
* @description Lists the currently available MCP tools. Only accessible when EXPOSE_MCP is enabled.
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
get: operations['listTools'];
|
|
63
|
+
put?: never;
|
|
64
|
+
post?: never;
|
|
65
|
+
delete?: never;
|
|
66
|
+
options?: never;
|
|
67
|
+
head?: never;
|
|
68
|
+
patch?: never;
|
|
69
|
+
trace?: never;
|
|
70
|
+
};
|
|
50
71
|
'/proxy/{provider}/{path}': {
|
|
51
72
|
parameters: {
|
|
52
73
|
query?: never;
|
|
@@ -218,6 +239,53 @@ export interface components {
|
|
|
218
239
|
/** @default [] */
|
|
219
240
|
data: components['schemas']['Model'][];
|
|
220
241
|
};
|
|
242
|
+
/** @description Response structure for listing MCP tools */
|
|
243
|
+
ListToolsResponse: {
|
|
244
|
+
/**
|
|
245
|
+
* @description Always "list"
|
|
246
|
+
* @example list
|
|
247
|
+
*/
|
|
248
|
+
object: string;
|
|
249
|
+
/**
|
|
250
|
+
* @description Array of available MCP tools
|
|
251
|
+
* @default []
|
|
252
|
+
*/
|
|
253
|
+
data: components['schemas']['MCPTool'][];
|
|
254
|
+
};
|
|
255
|
+
/** @description An MCP tool definition */
|
|
256
|
+
MCPTool: {
|
|
257
|
+
/**
|
|
258
|
+
* @description The name of the tool
|
|
259
|
+
* @example read_file
|
|
260
|
+
*/
|
|
261
|
+
name: string;
|
|
262
|
+
/**
|
|
263
|
+
* @description A description of what the tool does
|
|
264
|
+
* @example Read content from a file
|
|
265
|
+
*/
|
|
266
|
+
description: string;
|
|
267
|
+
/**
|
|
268
|
+
* @description The MCP server that provides this tool
|
|
269
|
+
* @example http://mcp-filesystem-server:8083/mcp
|
|
270
|
+
*/
|
|
271
|
+
server: string;
|
|
272
|
+
/**
|
|
273
|
+
* @description JSON schema for the tool's input parameters
|
|
274
|
+
* @example {
|
|
275
|
+
* "type": "object",
|
|
276
|
+
* "properties": {
|
|
277
|
+
* "file_path": {
|
|
278
|
+
* "type": "string",
|
|
279
|
+
* "description": "Path to the file to read"
|
|
280
|
+
* }
|
|
281
|
+
* },
|
|
282
|
+
* "required": [
|
|
283
|
+
* "file_path"
|
|
284
|
+
* ]
|
|
285
|
+
* }
|
|
286
|
+
*/
|
|
287
|
+
input_schema?: Record<string, never>;
|
|
288
|
+
};
|
|
221
289
|
FunctionObject: {
|
|
222
290
|
/** @description A description of what the function does, used by the model to choose when and how to call the function. */
|
|
223
291
|
description?: string;
|
|
@@ -458,6 +526,18 @@ export interface components {
|
|
|
458
526
|
'application/json': components['schemas']['Error'];
|
|
459
527
|
};
|
|
460
528
|
};
|
|
529
|
+
/** @description MCP tools endpoint is not exposed */
|
|
530
|
+
MCPNotExposed: {
|
|
531
|
+
headers: {
|
|
532
|
+
[name: string]: unknown;
|
|
533
|
+
};
|
|
534
|
+
content: {
|
|
535
|
+
/** @example {
|
|
536
|
+
* "error": "MCP tools endpoint is not exposed. Set EXPOSE_MCP=true to enable."
|
|
537
|
+
* } */
|
|
538
|
+
'application/json': components['schemas']['Error'];
|
|
539
|
+
};
|
|
540
|
+
};
|
|
461
541
|
/** @description ProviderResponse depends on the specific provider and endpoint being called
|
|
462
542
|
* If you decide to use this approach, please follow the provider-specific documentations.
|
|
463
543
|
* */
|
|
@@ -513,6 +593,8 @@ export type SchemaMessageRole = components['schemas']['MessageRole'];
|
|
|
513
593
|
export type SchemaMessage = components['schemas']['Message'];
|
|
514
594
|
export type SchemaModel = components['schemas']['Model'];
|
|
515
595
|
export type SchemaListModelsResponse = components['schemas']['ListModelsResponse'];
|
|
596
|
+
export type SchemaListToolsResponse = components['schemas']['ListToolsResponse'];
|
|
597
|
+
export type SchemaMcpTool = components['schemas']['MCPTool'];
|
|
516
598
|
export type SchemaFunctionObject = components['schemas']['FunctionObject'];
|
|
517
599
|
export type SchemaChatCompletionTool = components['schemas']['ChatCompletionTool'];
|
|
518
600
|
export type SchemaFunctionParameters = components['schemas']['FunctionParameters'];
|
|
@@ -534,6 +616,7 @@ export type SchemaConfig = components['schemas']['Config'];
|
|
|
534
616
|
export type ResponseBadRequest = components['responses']['BadRequest'];
|
|
535
617
|
export type ResponseUnauthorized = components['responses']['Unauthorized'];
|
|
536
618
|
export type ResponseInternalError = components['responses']['InternalError'];
|
|
619
|
+
export type ResponseMcpNotExposed = components['responses']['MCPNotExposed'];
|
|
537
620
|
export type ResponseProviderResponse = components['responses']['ProviderResponse'];
|
|
538
621
|
export type RequestBodyProviderRequest = components['requestBodies']['ProviderRequest'];
|
|
539
622
|
export type RequestBodyCreateChatCompletionRequest = components['requestBodies']['CreateChatCompletionRequest'];
|
|
@@ -591,6 +674,29 @@ export interface operations {
|
|
|
591
674
|
500: components['responses']['InternalError'];
|
|
592
675
|
};
|
|
593
676
|
};
|
|
677
|
+
listTools: {
|
|
678
|
+
parameters: {
|
|
679
|
+
query?: never;
|
|
680
|
+
header?: never;
|
|
681
|
+
path?: never;
|
|
682
|
+
cookie?: never;
|
|
683
|
+
};
|
|
684
|
+
requestBody?: never;
|
|
685
|
+
responses: {
|
|
686
|
+
/** @description Successful response */
|
|
687
|
+
200: {
|
|
688
|
+
headers: {
|
|
689
|
+
[name: string]: unknown;
|
|
690
|
+
};
|
|
691
|
+
content: {
|
|
692
|
+
'application/json': components['schemas']['ListToolsResponse'];
|
|
693
|
+
};
|
|
694
|
+
};
|
|
695
|
+
401: components['responses']['Unauthorized'];
|
|
696
|
+
403: components['responses']['MCPNotExposed'];
|
|
697
|
+
500: components['responses']['InternalError'];
|
|
698
|
+
};
|
|
699
|
+
};
|
|
594
700
|
proxyGet: {
|
|
595
701
|
parameters: {
|
|
596
702
|
query?: never;
|
|
@@ -82,6 +82,53 @@ describe('InferenceGatewayClient', () => {
|
|
|
82
82
|
await expect(client.listModels(generated_1.Provider.openai)).rejects.toThrow(errorMessage);
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
|
+
describe('listTools', () => {
|
|
86
|
+
it('should fetch available MCP tools', async () => {
|
|
87
|
+
const mockResponse = {
|
|
88
|
+
object: 'list',
|
|
89
|
+
data: [
|
|
90
|
+
{
|
|
91
|
+
name: 'read_file',
|
|
92
|
+
description: 'Read content from a file',
|
|
93
|
+
server: 'http://mcp-filesystem-server:8083/mcp',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'write_file',
|
|
97
|
+
description: 'Write content to a file',
|
|
98
|
+
server: 'http://mcp-filesystem-server:8083/mcp',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
mockFetch.mockResolvedValueOnce({
|
|
103
|
+
ok: true,
|
|
104
|
+
json: () => Promise.resolve(mockResponse),
|
|
105
|
+
});
|
|
106
|
+
const result = await client.listTools();
|
|
107
|
+
expect(result).toEqual(mockResponse);
|
|
108
|
+
expect(mockFetch).toHaveBeenCalledWith('http://localhost:8080/v1/mcp/tools', expect.objectContaining({
|
|
109
|
+
method: 'GET',
|
|
110
|
+
headers: expect.any(Headers),
|
|
111
|
+
}));
|
|
112
|
+
});
|
|
113
|
+
it('should throw error when MCP is not exposed', async () => {
|
|
114
|
+
const errorMessage = 'MCP not exposed';
|
|
115
|
+
mockFetch.mockResolvedValueOnce({
|
|
116
|
+
ok: false,
|
|
117
|
+
status: 403,
|
|
118
|
+
json: () => Promise.resolve({ error: errorMessage }),
|
|
119
|
+
});
|
|
120
|
+
await expect(client.listTools()).rejects.toThrow(errorMessage);
|
|
121
|
+
});
|
|
122
|
+
it('should throw error when unauthorized', async () => {
|
|
123
|
+
const errorMessage = 'Unauthorized';
|
|
124
|
+
mockFetch.mockResolvedValueOnce({
|
|
125
|
+
ok: false,
|
|
126
|
+
status: 401,
|
|
127
|
+
json: () => Promise.resolve({ error: errorMessage }),
|
|
128
|
+
});
|
|
129
|
+
await expect(client.listTools()).rejects.toThrow(errorMessage);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
85
132
|
describe('createChatCompletion', () => {
|
|
86
133
|
it('should create a chat completion', async () => {
|
|
87
134
|
const mockRequest = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inference-gateway/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "An SDK written in Typescript for the [Inference Gateway](https://github.com/inference-gateway/inference-gateway).",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|