@metorial/sdk 1.0.0-rc.4 → 1.0.0-rc.6
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/README.md +280 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# @metorial/sdk
|
|
2
|
+
|
|
3
|
+
Primary SDK package for Metorial. Provides the main SDK functionality, session management, and MCP (Model Context Protocol) integration capabilities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @metorial/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @metorial/sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @metorial/sdk
|
|
13
|
+
# or
|
|
14
|
+
bun add @metorial/sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Basic SDK Initialization
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Metorial } from '@metorial/sdk';
|
|
23
|
+
|
|
24
|
+
// Initialize the SDK
|
|
25
|
+
let metorial = new Metorial({
|
|
26
|
+
apiKey: 'your-metorial-api-key',
|
|
27
|
+
apiHost: 'https://api.metorial.com', // optional
|
|
28
|
+
mcpHost: 'https://mcp.metorial.com' // optional
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Access different SDK components
|
|
32
|
+
let instance = metorial.instance; // Instance management
|
|
33
|
+
let secrets = metorial.secrets; // Secrets management
|
|
34
|
+
let servers = metorial.servers; // Server management
|
|
35
|
+
let sessions = metorial.sessions; // Session management
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### MCP Session Management
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { Metorial } from '@metorial/sdk';
|
|
42
|
+
|
|
43
|
+
let metorial = new Metorial({
|
|
44
|
+
apiKey: 'your-metorial-api-key'
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Create a basic MCP session
|
|
48
|
+
await metorial.mcp.withSession(
|
|
49
|
+
{
|
|
50
|
+
serverDeployments: ['your-server-deployment-id']
|
|
51
|
+
},
|
|
52
|
+
async session => {
|
|
53
|
+
// Get session information
|
|
54
|
+
let sessionInfo = await session.getSession();
|
|
55
|
+
console.log('Session:', sessionInfo);
|
|
56
|
+
|
|
57
|
+
// Get available tools
|
|
58
|
+
let toolManager = await session.getToolManager();
|
|
59
|
+
let tools = toolManager.getTools();
|
|
60
|
+
console.log(
|
|
61
|
+
'Available tools:',
|
|
62
|
+
tools.map(t => t.name)
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// Get server capabilities
|
|
66
|
+
let capabilities = await session.getCapabilities();
|
|
67
|
+
console.log('Capabilities:', capabilities);
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Provider Session Integration
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { Metorial } from '@metorial/sdk';
|
|
76
|
+
import { metorialOpenAI } from '@metorial/openai';
|
|
77
|
+
import OpenAI from 'openai';
|
|
78
|
+
|
|
79
|
+
let metorial = new Metorial({
|
|
80
|
+
apiKey: 'your-metorial-api-key'
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
let openai = new OpenAI({
|
|
84
|
+
apiKey: 'your-openai-api-key'
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Use with AI provider integration
|
|
88
|
+
await metorial.mcp.withProviderSession(
|
|
89
|
+
metorialOpenAI.chatCompletions,
|
|
90
|
+
{
|
|
91
|
+
serverDeployments: ['your-server-deployment-id']
|
|
92
|
+
},
|
|
93
|
+
async session => {
|
|
94
|
+
// session.tools contains the tools formatted for OpenAI
|
|
95
|
+
let response = await openai.chat.completions.create({
|
|
96
|
+
model: 'gpt-4o',
|
|
97
|
+
messages: [
|
|
98
|
+
{
|
|
99
|
+
role: 'user',
|
|
100
|
+
content: 'Search for information about AI developments'
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
tools: session.tools
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
let choice = response.choices[0];
|
|
107
|
+
if (choice.message.tool_calls) {
|
|
108
|
+
// Execute tool calls
|
|
109
|
+
let toolResponses = await session.callTools(choice.message.tool_calls);
|
|
110
|
+
console.log('Tool responses:', toolResponses);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Direct MCP Connection
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { Metorial } from '@metorial/sdk';
|
|
120
|
+
|
|
121
|
+
let metorial = new Metorial({
|
|
122
|
+
apiKey: 'your-metorial-api-key'
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Create a direct MCP connection
|
|
126
|
+
let connection = await metorial.mcp.createConnection('your-server-deployment-id');
|
|
127
|
+
|
|
128
|
+
// Use the connection for direct MCP communication
|
|
129
|
+
let tools = await connection.listTools();
|
|
130
|
+
console.log('Available tools:', tools);
|
|
131
|
+
|
|
132
|
+
let result = await connection.callTool('searchContext', {
|
|
133
|
+
query: 'metorial AI tools',
|
|
134
|
+
maxResults: 5
|
|
135
|
+
});
|
|
136
|
+
console.log('Search result:', result);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Server Management
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { Metorial } from '@metorial/sdk';
|
|
143
|
+
|
|
144
|
+
let metorial = new Metorial({
|
|
145
|
+
apiKey: 'your-metorial-api-key'
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// List all servers
|
|
149
|
+
let servers = await metorial.servers.list();
|
|
150
|
+
console.log('Available servers:', servers);
|
|
151
|
+
|
|
152
|
+
// Get specific server
|
|
153
|
+
let server = await metorial.servers.get('server-id');
|
|
154
|
+
console.log('Server details:', server);
|
|
155
|
+
|
|
156
|
+
// List server deployments
|
|
157
|
+
let deployments = await metorial.servers.deployments.list();
|
|
158
|
+
console.log('Deployments:', deployments);
|
|
159
|
+
|
|
160
|
+
// Create a new deployment
|
|
161
|
+
let newDeployment = await metorial.servers.deployments.create({
|
|
162
|
+
serverId: 'server-id',
|
|
163
|
+
variantId: 'variant-id',
|
|
164
|
+
versionId: 'version-id'
|
|
165
|
+
});
|
|
166
|
+
console.log('New deployment:', newDeployment);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Session Management
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { Metorial } from '@metorial/sdk';
|
|
173
|
+
|
|
174
|
+
let metorial = new Metorial({
|
|
175
|
+
apiKey: 'your-metorial-api-key'
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// List all sessions
|
|
179
|
+
let sessions = await metorial.sessions.list();
|
|
180
|
+
console.log('Active sessions:', sessions);
|
|
181
|
+
|
|
182
|
+
// Get specific session
|
|
183
|
+
let session = await metorial.sessions.get('session-id');
|
|
184
|
+
console.log('Session details:', session);
|
|
185
|
+
|
|
186
|
+
// Create a new session
|
|
187
|
+
let newSession = await metorial.sessions.create({
|
|
188
|
+
serverDeploymentId: 'deployment-id'
|
|
189
|
+
});
|
|
190
|
+
console.log('New session:', newSession);
|
|
191
|
+
|
|
192
|
+
// Get session messages
|
|
193
|
+
let messages = await metorial.sessions.messages.list('session-id');
|
|
194
|
+
console.log('Session messages:', messages);
|
|
195
|
+
|
|
196
|
+
// Get session connections
|
|
197
|
+
let connections = await metorial.sessions.connections.list('session-id');
|
|
198
|
+
console.log('Session connections:', connections);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Secrets Management
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
import { Metorial } from '@metorial/sdk';
|
|
205
|
+
|
|
206
|
+
let metorial = new Metorial({
|
|
207
|
+
apiKey: 'your-metorial-api-key'
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// List all secrets
|
|
211
|
+
let secrets = await metorial.secrets.list();
|
|
212
|
+
console.log('Available secrets:', secrets);
|
|
213
|
+
|
|
214
|
+
// Get specific secret
|
|
215
|
+
let secret = await metorial.secrets.get('secret-id');
|
|
216
|
+
console.log('Secret details:', secret);
|
|
217
|
+
|
|
218
|
+
// Create a new secret
|
|
219
|
+
let newSecret = await metorial.secrets.create({
|
|
220
|
+
name: 'my-api-key',
|
|
221
|
+
value: 'secret-value',
|
|
222
|
+
description: 'API key for external service'
|
|
223
|
+
});
|
|
224
|
+
console.log('New secret:', newSecret);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## API Reference
|
|
228
|
+
|
|
229
|
+
### `Metorial` Class
|
|
230
|
+
|
|
231
|
+
#### Constructor
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
new Metorial(config: {
|
|
235
|
+
apiKey: string;
|
|
236
|
+
apiHost?: string;
|
|
237
|
+
mcpHost?: string;
|
|
238
|
+
apiVersion?: string;
|
|
239
|
+
headers?: Record<string, string>;
|
|
240
|
+
})
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
#### Properties
|
|
244
|
+
|
|
245
|
+
- `instance`: Instance management endpoint
|
|
246
|
+
- `secrets`: Secrets management endpoint
|
|
247
|
+
- `servers`: Server management endpoint
|
|
248
|
+
- `sessions`: Session management endpoint
|
|
249
|
+
- `mcp`: MCP-specific methods
|
|
250
|
+
|
|
251
|
+
#### MCP Methods
|
|
252
|
+
|
|
253
|
+
- `mcp.createSession(init)`: Create a new MCP session
|
|
254
|
+
- `mcp.withSession(init, action)`: Execute action with session lifecycle management
|
|
255
|
+
- `mcp.withProviderSession(provider, init, action)`: Execute action with provider integration
|
|
256
|
+
- `mcp.createConnection(deploymentId)`: Create direct MCP connection
|
|
257
|
+
|
|
258
|
+
### Session Management
|
|
259
|
+
|
|
260
|
+
The SDK provides comprehensive session management with automatic lifecycle handling, tool discovery, and provider integration.
|
|
261
|
+
|
|
262
|
+
### Error Handling
|
|
263
|
+
|
|
264
|
+
All SDK methods throw `MetorialSDKError` for API errors with additional context:
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
try {
|
|
268
|
+
await metorial.servers.get('invalid-id');
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (error instanceof MetorialSDKError) {
|
|
271
|
+
console.log('API Error:', error.message);
|
|
272
|
+
console.log('Status:', error.status);
|
|
273
|
+
console.log('Code:', error.code);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## License
|
|
279
|
+
|
|
280
|
+
MIT License - see [LICENSE](../../LICENSE) file for details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metorial/sdk",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.6",
|
|
4
4
|
"author": "Tobias Herber",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@metorial/core": "^1.0.0-rc.
|
|
29
|
-
"@metorial/mcp-session": "^1.0.0-rc.
|
|
30
|
-
"@metorial/util-endpoint": "^1.0.0-rc.
|
|
28
|
+
"@metorial/core": "^1.0.0-rc.6",
|
|
29
|
+
"@metorial/mcp-session": "^1.0.0-rc.6",
|
|
30
|
+
"@metorial/util-endpoint": "^1.0.0-rc.6"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/isomorphic-fetch": "^0.0.39",
|