@qverisai/sdk 0.1.2 → 0.2.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/dist/index.js CHANGED
@@ -1,268 +1,20 @@
1
- #!/usr/bin/env node
2
1
  /**
3
- * Qveris MCP Server
2
+ * QVeris TypeScript SDK.
4
3
  *
5
- * A Model Context Protocol (MCP) server that provides access to the Qveris
6
- * tool discovery and execution API. Enables LLMs to dynamically search for
7
- * and execute third-party tools via natural language.
8
- *
9
- * @module @qverisai/sdk
10
- * @version 0.1.0
4
+ * Typed client for the QVeris Agent External Data & Tool Harness:
5
+ * discover, inspect, call, plus usage and credits-ledger audit.
11
6
  *
12
7
  * @example
13
- * Configure in Claude Desktop or Cursor:
14
- * ```json
15
- * {
16
- * "mcpServers": {
17
- * "qveris": {
18
- * "command": "npx",
19
- * "args": ["@qverisai/sdk"],
20
- * "env": { "QVERIS_API_KEY": "your-api-key" }
21
- * }
22
- * }
23
- * }
8
+ * ```typescript
9
+ * import { Qveris } from '@qverisai/sdk';
10
+ *
11
+ * const qveris = Qveris.fromEnv();
12
+ * const found = await qveris.discover('weather forecast API');
24
13
  * ```
25
- */
26
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
27
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
28
- import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
29
- import { v4 as uuidv4 } from 'uuid';
30
- import { createClientFromEnv } from './api/client.js';
31
- import { searchToolsSchema, executeSearchTools, } from './tools/search.js';
32
- import { executeToolSchema, executeExecuteTool, } from './tools/execute.js';
33
- import { getToolsByIdsSchema, executeGetToolsByIds, } from './tools/get-by-ids.js';
34
- // ============================================================================
35
- // Server Configuration
36
- // ============================================================================
37
- const SERVER_NAME = 'qveris';
38
- const SERVER_VERSION = '0.1.0';
39
- /**
40
- * Main entry point for the Qveris MCP Server.
41
14
  *
42
- * Sets up the MCP server with stdio transport, registers the search_tools
43
- * and execute_tool handlers, and starts listening for requests.
44
- */
45
- async function main() {
46
- // Initialize API client (validates QVERIS_API_KEY)
47
- let client;
48
- try {
49
- client = createClientFromEnv();
50
- }
51
- catch (error) {
52
- console.error(error instanceof Error ? error.message : 'Failed to initialize Qveris client');
53
- process.exit(1);
54
- }
55
- // Generate a default session ID for this server instance
56
- const defaultSessionId = uuidv4();
57
- // Create MCP server
58
- const server = new Server({
59
- name: SERVER_NAME,
60
- version: SERVER_VERSION,
61
- }, {
62
- capabilities: {
63
- tools: {},
64
- },
65
- });
66
- // =========================================================================
67
- // Tool Handlers
68
- // =========================================================================
69
- /**
70
- * Lists available tools.
71
- * Returns the search_tools, get_tools_by_ids, and execute_tool definitions.
72
- */
73
- server.setRequestHandler(ListToolsRequestSchema, async () => {
74
- return {
75
- tools: [
76
- {
77
- name: 'search_tools',
78
- description: 'Search for available tools based on natural language queries. ' +
79
- 'Returns relevant tools that can help accomplish tasks. ' +
80
- 'Use this to discover tools before executing them.',
81
- inputSchema: searchToolsSchema,
82
- },
83
- {
84
- name: 'get_tools_by_ids',
85
- description: 'Get descriptions of tools based on their tool IDs. ' +
86
- 'Useful for retrieving detailed information about specific tools ' +
87
- 'when you already know their tool_ids from previous searches.',
88
- inputSchema: getToolsByIdsSchema,
89
- },
90
- {
91
- name: 'execute_tool',
92
- description: 'Execute a specific remote tool with provided parameters. ' +
93
- 'The tool_id and search_id must come from a previous search_tools call. ' +
94
- 'Pass parameters to the tool through params_to_tool as a JSON string.',
95
- inputSchema: executeToolSchema,
96
- },
97
- ],
98
- };
99
- });
100
- /**
101
- * Handles tool execution requests.
102
- * Routes to the appropriate handler based on tool name.
103
- */
104
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
105
- const { name, arguments: args } = request.params;
106
- try {
107
- if (name === 'search_tools') {
108
- const input = args;
109
- // Validate required fields
110
- if (!input.query || typeof input.query !== 'string') {
111
- return {
112
- content: [
113
- {
114
- type: 'text',
115
- text: JSON.stringify({
116
- error: 'Missing required parameter: query',
117
- hint: 'Provide a natural language query describing the tool capability you need',
118
- }),
119
- },
120
- ],
121
- isError: true,
122
- };
123
- }
124
- const result = await executeSearchTools(client, input, defaultSessionId);
125
- return {
126
- content: [
127
- {
128
- type: 'text',
129
- text: JSON.stringify(result, null, 2),
130
- },
131
- ],
132
- };
133
- }
134
- if (name === 'get_tools_by_ids') {
135
- const input = args;
136
- // Validate required fields
137
- if (!input.tool_ids || !Array.isArray(input.tool_ids) || input.tool_ids.length === 0) {
138
- return {
139
- content: [
140
- {
141
- type: 'text',
142
- text: JSON.stringify({
143
- error: 'Missing or invalid required parameter: tool_ids',
144
- hint: 'Provide an array of tool IDs (at least one) to retrieve tool information',
145
- }),
146
- },
147
- ],
148
- isError: true,
149
- };
150
- }
151
- const result = await executeGetToolsByIds(client, input, defaultSessionId);
152
- return {
153
- content: [
154
- {
155
- type: 'text',
156
- text: JSON.stringify(result, null, 2),
157
- },
158
- ],
159
- };
160
- }
161
- if (name === 'execute_tool') {
162
- const input = args;
163
- // Validate required fields
164
- const missingFields = [];
165
- if (!input.tool_id)
166
- missingFields.push('tool_id');
167
- if (!input.search_id)
168
- missingFields.push('search_id');
169
- if (!input.params_to_tool)
170
- missingFields.push('params_to_tool');
171
- if (missingFields.length > 0) {
172
- return {
173
- content: [
174
- {
175
- type: 'text',
176
- text: JSON.stringify({
177
- error: `Missing required parameters: ${missingFields.join(', ')}`,
178
- hint: 'tool_id and search_id must come from a previous search_tools call',
179
- }),
180
- },
181
- ],
182
- isError: true,
183
- };
184
- }
185
- const result = await executeExecuteTool(client, input, defaultSessionId);
186
- return {
187
- content: [
188
- {
189
- type: 'text',
190
- text: JSON.stringify(result, null, 2),
191
- },
192
- ],
193
- };
194
- }
195
- // Unknown tool
196
- return {
197
- content: [
198
- {
199
- type: 'text',
200
- text: JSON.stringify({
201
- error: `Unknown tool: ${name}`,
202
- available_tools: ['search_tools', 'get_tools_by_ids', 'execute_tool'],
203
- }),
204
- },
205
- ],
206
- isError: true,
207
- };
208
- }
209
- catch (error) {
210
- // Handle API errors
211
- if (isApiError(error)) {
212
- return {
213
- content: [
214
- {
215
- type: 'text',
216
- text: JSON.stringify({
217
- error: error.message,
218
- status: error.status,
219
- details: error.details,
220
- }),
221
- },
222
- ],
223
- isError: true,
224
- };
225
- }
226
- // Handle other errors (including fetch network errors)
227
- const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
228
- const errorCause = error instanceof Error && error.cause instanceof Error
229
- ? error.cause.message
230
- : undefined;
231
- return {
232
- content: [
233
- {
234
- type: 'text',
235
- text: JSON.stringify({
236
- error: errorMessage,
237
- ...(errorCause && { cause: errorCause }),
238
- }),
239
- },
240
- ],
241
- isError: true,
242
- };
243
- }
244
- });
245
- // =========================================================================
246
- // Start Server
247
- // =========================================================================
248
- const transport = new StdioServerTransport();
249
- await server.connect(transport);
250
- // Log startup to stderr (stdout is reserved for MCP protocol)
251
- console.error(`Qveris MCP Server v${SERVER_VERSION} started`);
252
- console.error(`Session ID: ${defaultSessionId}`);
253
- }
254
- /**
255
- * Type guard for API errors.
15
+ * @module @qverisai/sdk
256
16
  */
257
- function isApiError(error) {
258
- return (typeof error === 'object' &&
259
- error !== null &&
260
- 'status' in error &&
261
- 'message' in error);
262
- }
263
- // Run the server
264
- main().catch((error) => {
265
- console.error('Fatal error:', error);
266
- process.exit(1);
267
- });
17
+ export { Qveris } from './client.js';
18
+ export { QverisApiError } from './errors.js';
19
+ export * from './types.js';
268
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAEvB,MAAM,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