@qverisai/mcp 0.4.1 → 0.6.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/README.md +105 -29
- package/dist/api/client.d.ts +14 -2
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +31 -5
- package/dist/api/client.js.map +1 -1
- package/dist/index.js +87 -19
- package/dist/index.js.map +1 -1
- package/dist/tools/audit-utils.d.ts +52 -0
- package/dist/tools/audit-utils.d.ts.map +1 -0
- package/dist/tools/audit-utils.js +395 -0
- package/dist/tools/audit-utils.js.map +1 -0
- package/dist/tools/credits-ledger.d.ts +57 -0
- package/dist/tools/credits-ledger.d.ts.map +1 -0
- package/dist/tools/credits-ledger.js +124 -0
- package/dist/tools/credits-ledger.js.map +1 -0
- package/dist/tools/execute.d.ts +5 -5
- package/dist/tools/execute.js +5 -5
- package/dist/tools/execute.js.map +1 -1
- package/dist/tools/get-by-ids.d.ts +4 -4
- package/dist/tools/get-by-ids.js +4 -4
- package/dist/tools/get-by-ids.js.map +1 -1
- package/dist/tools/search.d.ts +2 -2
- package/dist/tools/search.js +1 -1
- package/dist/tools/usage-history.d.ts +72 -0
- package/dist/tools/usage-history.d.ts.map +1 -0
- package/dist/tools/usage-history.js +135 -0
- package/dist/tools/usage-history.js.map +1 -0
- package/dist/types.d.ts +149 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,11 +7,13 @@ Official QVeris MCP Server — Dynamically search and execute tools via natural
|
|
|
7
7
|
|
|
8
8
|
## Overview
|
|
9
9
|
|
|
10
|
-
This SDK provides a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that enables LLMs to discover and execute third-party tools through the QVeris API. With
|
|
11
|
-
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
10
|
+
This SDK provides a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that enables LLMs to discover and execute third-party tools through the QVeris API. With a small set of tools, your AI assistant can:
|
|
11
|
+
|
|
12
|
+
- **Discover** tools using natural language queries
|
|
13
|
+
- **Inspect** detailed information about specific tools by their IDs
|
|
14
|
+
- **Call** any discovered tool with the appropriate parameters
|
|
15
|
+
- **Audit usage** with context-safe summaries or precise filtered records
|
|
16
|
+
- **Review credits ledger** without dumping full account history into context
|
|
15
17
|
|
|
16
18
|
## Quick Start
|
|
17
19
|
|
|
@@ -59,22 +61,23 @@ Add the QVeris server to your MCP client configuration:
|
|
|
59
61
|
|
|
60
62
|
Once configured, You could add this to system prompt:
|
|
61
63
|
|
|
62
|
-
> "You can use qveris MCP Server to dynamically
|
|
64
|
+
> "You can use qveris MCP Server to dynamically discover and call tools to help the user. First think about what kind of tools might be useful to accomplish the user's task. Then use the discover tool with a query describing the capability of the tool, not what params you want to pass to the tool later. Then call a suitable tool using the call tool, passing parameters through params_to_tool. You could reference the examples given if any for each tool. You may make multiple tool calls in a single response."
|
|
63
65
|
|
|
64
|
-
Then your AI assistant can
|
|
66
|
+
Then your AI assistant can discover and call tools:
|
|
65
67
|
|
|
66
68
|
> "Find me a weather tool and get the current weather in Tokyo"
|
|
67
69
|
|
|
68
70
|
The assistant will:
|
|
69
|
-
1. Call `
|
|
70
|
-
2.
|
|
71
|
-
3. Call `
|
|
71
|
+
1. Call `discover` with query "weather"
|
|
72
|
+
2. Optionally call `inspect` to review tool details
|
|
73
|
+
3. Call `call` with the tool_id and parameters
|
|
74
|
+
4. Use `usage_history` or `credits_ledger` only when the user asks about charge status or balance changes
|
|
72
75
|
|
|
73
76
|
## Available Tools
|
|
74
77
|
|
|
75
|
-
### `
|
|
78
|
+
### `discover`
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
Discover available tools based on natural language queries.
|
|
78
81
|
|
|
79
82
|
| Parameter | Type | Required | Description |
|
|
80
83
|
|-----------|------|----------|-------------|
|
|
@@ -91,46 +94,119 @@ Search for available tools based on natural language queries.
|
|
|
91
94
|
}
|
|
92
95
|
```
|
|
93
96
|
|
|
94
|
-
### `
|
|
97
|
+
### `inspect`
|
|
95
98
|
|
|
96
|
-
|
|
99
|
+
Inspect tools by their IDs to get detailed information (parameters, success rate, latency, examples, and billing_rule when available).
|
|
97
100
|
|
|
98
101
|
| Parameter | Type | Required | Description |
|
|
99
102
|
|-----------|------|----------|-------------|
|
|
100
|
-
| `
|
|
101
|
-
| `search_id` | string |
|
|
102
|
-
| `params_to_tool` | object | ✓ | A dictionary of parameters to pass to the tool |
|
|
103
|
+
| `tool_ids` | array | ✓ | Array of tool IDs to retrieve (at least one required) |
|
|
104
|
+
| `search_id` | string | | Search ID from the discover call that returned the tool(s) |
|
|
103
105
|
| `session_id` | string | | Session identifier (auto-generated if omitted) |
|
|
104
|
-
| `max_response_size` | number | | Max response size in bytes (default: 20480) |
|
|
105
106
|
|
|
106
107
|
**Example:**
|
|
107
108
|
|
|
108
109
|
```json
|
|
109
110
|
{
|
|
110
|
-
"
|
|
111
|
-
"search_id": "abcd1234-ab12-ab12-ab12-abcdef123456"
|
|
112
|
-
"params_to_tool": {"city": "London", "units": "metric"}
|
|
111
|
+
"tool_ids": ["openweathermap.weather.execute.v1", "worldbank_refined.search_indicators.v1"],
|
|
112
|
+
"search_id": "abcd1234-ab12-ab12-ab12-abcdef123456"
|
|
113
113
|
}
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
### `
|
|
116
|
+
### `call`
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
Call a discovered tool with specific parameters.
|
|
119
119
|
|
|
120
120
|
| Parameter | Type | Required | Description |
|
|
121
121
|
|-----------|------|----------|-------------|
|
|
122
|
-
| `
|
|
123
|
-
| `search_id` | string | | Search ID from the
|
|
122
|
+
| `tool_id` | string | ✓ | Tool ID from discover results |
|
|
123
|
+
| `search_id` | string | ✓ | Search ID from the discover call that found this tool |
|
|
124
|
+
| `params_to_tool` | object | ✓ | A dictionary of parameters to pass to the tool |
|
|
124
125
|
| `session_id` | string | | Session identifier (auto-generated if omitted) |
|
|
126
|
+
| `max_response_size` | number | | Max response size in bytes (default: 20480) |
|
|
125
127
|
|
|
126
128
|
**Example:**
|
|
127
129
|
|
|
128
130
|
```json
|
|
129
131
|
{
|
|
130
|
-
"
|
|
131
|
-
"search_id": "abcd1234-ab12-ab12-ab12-abcdef123456"
|
|
132
|
-
}
|
|
133
|
-
|
|
132
|
+
"tool_id": "openweathermap.weather.execute.v1",
|
|
133
|
+
"search_id": "abcd1234-ab12-ab12-ab12-abcdef123456",
|
|
134
|
+
"params_to_tool": {"city": "London", "units": "metric"}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The `call` response may include compact pre-settlement `billing`. Final charge status should be checked with `usage_history` or `credits_ledger`.
|
|
139
|
+
|
|
140
|
+
### `usage_history`
|
|
141
|
+
|
|
142
|
+
Context-safe request-level usage audit. Defaults to aggregated `summary` mode.
|
|
143
|
+
Summary mode requests service-side `summary=true` aggregates when available and falls back to bounded client-side aggregation for older deployments.
|
|
144
|
+
|
|
145
|
+
| Parameter | Type | Required | Description |
|
|
146
|
+
|-----------|------|----------|-------------|
|
|
147
|
+
| `mode` | string | | `summary`, `search`, or `export_file` (default: `summary`) |
|
|
148
|
+
| `start_date` | string | | Start date, `YYYY-MM-DD` |
|
|
149
|
+
| `end_date` | string | | End date, `YYYY-MM-DD` |
|
|
150
|
+
| `bucket` | string | | `hour`, `day`, or `week` for summary aggregation |
|
|
151
|
+
| `execution_id` | string | | Precise execution lookup |
|
|
152
|
+
| `search_id` | string | | Precise search lookup |
|
|
153
|
+
| `charge_outcome` | string | | `charged`, `included`, `failed_not_charged`, `failed_charged_review` |
|
|
154
|
+
| `min_credits` | number | | Lower credit amount bound |
|
|
155
|
+
| `max_credits` | number | | Upper credit amount bound |
|
|
156
|
+
| `limit` | number | | Search row cap, default 10, hard max 50 |
|
|
157
|
+
|
|
158
|
+
Examples:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{ "mode": "summary", "bucket": "hour" }
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{ "mode": "search", "execution_id": "exec-123" }
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{ "mode": "search", "min_credits": 30, "max_credits": 100 }
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### `credits_ledger`
|
|
173
|
+
|
|
174
|
+
Context-safe final credit ledger query. Defaults to aggregated `summary` mode.
|
|
175
|
+
Summary mode requests service-side `summary=true` aggregates when available and falls back to bounded client-side aggregation for older deployments.
|
|
176
|
+
|
|
177
|
+
| Parameter | Type | Required | Description |
|
|
178
|
+
|-----------|------|----------|-------------|
|
|
179
|
+
| `mode` | string | | `summary`, `search`, or `export_file` (default: `summary`) |
|
|
180
|
+
| `start_date` | string | | Start date, `YYYY-MM-DD` |
|
|
181
|
+
| `end_date` | string | | End date, `YYYY-MM-DD` |
|
|
182
|
+
| `bucket` | string | | `hour`, `day`, or `week` for summary aggregation |
|
|
183
|
+
| `entry_type` | string | | Ledger entry type, for example `consume_tool_execute` |
|
|
184
|
+
| `direction` | string | | `consume`, `grant`, or `any` |
|
|
185
|
+
| `min_credits` | number | | Lower absolute credit amount bound |
|
|
186
|
+
| `max_credits` | number | | Upper absolute credit amount bound |
|
|
187
|
+
| `limit` | number | | Search row cap, default 10, hard max 50 |
|
|
188
|
+
|
|
189
|
+
Examples:
|
|
190
|
+
|
|
191
|
+
```json
|
|
192
|
+
{ "mode": "summary", "bucket": "day" }
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
```json
|
|
196
|
+
{ "mode": "search", "direction": "consume", "min_credits": 50 }
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Large result sets should use `mode: "export_file"`. The server writes JSONL under `.qveris/exports/` and returns the file path instead of emitting every row into MCP context.
|
|
200
|
+
|
|
201
|
+
### Deprecated tool names
|
|
202
|
+
|
|
203
|
+
For backward compatibility, the old tool names are still supported but emit a deprecation warning:
|
|
204
|
+
|
|
205
|
+
| Old name (deprecated) | New name |
|
|
206
|
+
|----------------------|----------|
|
|
207
|
+
| `search_tools` | `discover` |
|
|
208
|
+
| `get_tools_by_ids` | `inspect` |
|
|
209
|
+
| `execute_tool` | `call` |
|
|
134
210
|
|
|
135
211
|
## Session Management
|
|
136
212
|
|
package/dist/api/client.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module api/client
|
|
8
8
|
*/
|
|
9
|
-
import type { SearchRequest, SearchResponse, GetToolsByIdsRequest, ExecuteRequest, ExecuteResponse, QverisClientConfig } from '../types.js';
|
|
9
|
+
import type { SearchRequest, SearchResponse, GetToolsByIdsRequest, ExecuteRequest, ExecuteResponse, CreditsResponse, UsageHistoryRequest, UsageEventsResponse, CreditsLedgerRequest, CreditsLedgerResponse, ApiEnvelope, QverisClientConfig } from '../types.js';
|
|
10
10
|
/**
|
|
11
11
|
* Qveris API Client
|
|
12
12
|
*
|
|
@@ -49,10 +49,22 @@ export declare class QverisClient {
|
|
|
49
49
|
getToolsByIds(request: GetToolsByIdsRequest): Promise<SearchResponse>;
|
|
50
50
|
/**
|
|
51
51
|
* Execute a tool with the specified parameters.
|
|
52
|
-
* This is the Call action
|
|
52
|
+
* This is the Call action; the response may include pre-settlement billing.
|
|
53
53
|
* Uses a longer timeout (120s) by default.
|
|
54
54
|
*/
|
|
55
55
|
executeTool(toolId: string, request: ExecuteRequest): Promise<ExecuteResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* Get current credit balance and bucket details.
|
|
58
|
+
*/
|
|
59
|
+
getCredits(): Promise<ApiEnvelope<CreditsResponse> | CreditsResponse>;
|
|
60
|
+
/**
|
|
61
|
+
* Query request-level usage audit history.
|
|
62
|
+
*/
|
|
63
|
+
getUsageHistory(request: UsageHistoryRequest): Promise<ApiEnvelope<UsageEventsResponse> | UsageEventsResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Query final credits ledger entries.
|
|
66
|
+
*/
|
|
67
|
+
getCreditsLedger(request: CreditsLedgerRequest): Promise<ApiEnvelope<CreditsLedgerResponse> | CreditsLedgerResponse>;
|
|
56
68
|
}
|
|
57
69
|
/**
|
|
58
70
|
* Creates a Qveris client from environment variables.
|
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,kBAAkB,EAEnB,MAAM,aAAa,CAAC;AAkCrB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;gBAE9B,MAAM,EAAE,kBAAkB;IAUtC;;OAEG;YACW,OAAO;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAEnB,MAAM,aAAa,CAAC;AAkCrB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;gBAE9B,MAAM,EAAE,kBAAkB;IAUtC;;OAEG;YACW,OAAO;IA2FrB;;;OAGG;IACG,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAIlE;;;OAGG;IACG,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC;IAI3E;;;;OAIG;IACG,WAAW,CACf,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC;IAU3B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;IAI3E;;OAEG;IACG,eAAe,CACnB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC;IAUlE;;OAEG;IACG,gBAAgB,CACpB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,WAAW,CAAC,qBAAqB,CAAC,GAAG,qBAAqB,CAAC;CASvE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,YAAY,CAiBlD"}
|
package/dist/api/client.js
CHANGED
|
@@ -73,12 +73,19 @@ export class QverisClient {
|
|
|
73
73
|
/**
|
|
74
74
|
* Makes an authenticated HTTP request to the Qveris API.
|
|
75
75
|
*/
|
|
76
|
-
async request(method, endpoint, body, timeoutMs) {
|
|
77
|
-
const url = `${this.baseUrl}${endpoint}
|
|
76
|
+
async request(method, endpoint, body, timeoutMs, query) {
|
|
77
|
+
const url = new URL(`${this.baseUrl}${endpoint}`);
|
|
78
|
+
if (query) {
|
|
79
|
+
for (const [key, value] of Object.entries(query)) {
|
|
80
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
81
|
+
url.searchParams.set(key, String(value));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
78
85
|
const controller = new AbortController();
|
|
79
86
|
const timeout = setTimeout(() => controller.abort(), timeoutMs ?? this.defaultTimeoutMs);
|
|
80
87
|
try {
|
|
81
|
-
const response = await fetch(url, {
|
|
88
|
+
const response = await fetch(url.toString(), {
|
|
82
89
|
method,
|
|
83
90
|
headers: {
|
|
84
91
|
'Authorization': `Bearer ${this.apiKey}`,
|
|
@@ -105,7 +112,8 @@ export class QverisClient {
|
|
|
105
112
|
}
|
|
106
113
|
// Provide actionable hints for specific status codes
|
|
107
114
|
if (status === 402) {
|
|
108
|
-
|
|
115
|
+
const pricingHost = this.baseUrl.includes('qveris.cn') ? 'https://qveris.cn' : 'https://qveris.ai';
|
|
116
|
+
errorMessage = `Insufficient credits. ${errorMessage}. Purchase credits at ${pricingHost}/pricing`;
|
|
109
117
|
}
|
|
110
118
|
const error = {
|
|
111
119
|
status,
|
|
@@ -159,13 +167,31 @@ export class QverisClient {
|
|
|
159
167
|
}
|
|
160
168
|
/**
|
|
161
169
|
* Execute a tool with the specified parameters.
|
|
162
|
-
* This is the Call action
|
|
170
|
+
* This is the Call action; the response may include pre-settlement billing.
|
|
163
171
|
* Uses a longer timeout (120s) by default.
|
|
164
172
|
*/
|
|
165
173
|
async executeTool(toolId, request) {
|
|
166
174
|
const endpoint = `/tools/execute?tool_id=${encodeURIComponent(toolId)}`;
|
|
167
175
|
return this.request('POST', endpoint, request, EXECUTE_TIMEOUT_MS);
|
|
168
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Get current credit balance and bucket details.
|
|
179
|
+
*/
|
|
180
|
+
async getCredits() {
|
|
181
|
+
return this.request('GET', '/auth/credits');
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Query request-level usage audit history.
|
|
185
|
+
*/
|
|
186
|
+
async getUsageHistory(request) {
|
|
187
|
+
return this.request('GET', '/auth/usage/history/v2', undefined, this.defaultTimeoutMs, request);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Query final credits ledger entries.
|
|
191
|
+
*/
|
|
192
|
+
async getCreditsLedger(request) {
|
|
193
|
+
return this.request('GET', '/auth/credits/ledger', undefined, this.defaultTimeoutMs, request);
|
|
194
|
+
}
|
|
169
195
|
}
|
|
170
196
|
/**
|
|
171
197
|
* Creates a Qveris client from environment variables.
|
package/dist/api/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAkBH,oCAAoC;AACpC,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,0BAA0B;IAClC,EAAE,EAAE,0BAA0B;CAC/B,CAAC;AAEF;;;GAGG;AACH,SAAS,mBAAmB,CAAC,MAAc;IACzC,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,MAAc,EAAE,eAAwB;IAC9D,IAAI,eAAe;QAAE,OAAO,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChE,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe;QAAE,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACxF,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;QACvD,OAAO,WAAW,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC;IACnD,CAAC;IACD,OAAO,WAAW,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,gEAAgE;AAChE,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,YAAY;IACN,MAA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IACH,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,OAAO,CAAiD,KAAK,EAAE,eAAe,CAAC,CAAC;IAC9F,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CACnB,OAA4B;QAE5B,OAAO,IAAI,CAAC,OAAO,CACjB,KAAK,EACL,wBAAwB,EACxB,SAAS,EACT,IAAI,CAAC,gBAAgB,EACrB,OAAkC,CACnC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB,CACpB,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CACjB,KAAK,EACL,sBAAsB,EACtB,SAAS,EACT,IAAI,CAAC,gBAAgB,EACrB,OAAkC,CACnC,CAAC;IACJ,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAE1C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,oDAAoD;YACpD,mDAAmD;YACnD,iDAAiD,CAClD,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,CAAC,KAAK,CAAC,WAAW,MAAM,KAAK,YAAY,GAAG,CAAC,CAAC;IAErD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,8 @@ import { createClientFromEnv } from './api/client.js';
|
|
|
31
31
|
import { searchToolsSchema, executeSearchTools, } from './tools/search.js';
|
|
32
32
|
import { executeToolSchema, executeExecuteTool, } from './tools/execute.js';
|
|
33
33
|
import { getToolsByIdsSchema, executeGetToolsByIds, } from './tools/get-by-ids.js';
|
|
34
|
+
import { usageHistorySchema, executeUsageHistory, } from './tools/usage-history.js';
|
|
35
|
+
import { creditsLedgerSchema, executeCreditsLedger, } from './tools/credits-ledger.js';
|
|
34
36
|
// ============================================================================
|
|
35
37
|
// Server Configuration
|
|
36
38
|
// ============================================================================
|
|
@@ -41,8 +43,8 @@ const { version: SERVER_VERSION } = require('../package.json');
|
|
|
41
43
|
/**
|
|
42
44
|
* Main entry point for the Qveris MCP Server.
|
|
43
45
|
*
|
|
44
|
-
* Sets up the MCP server with stdio transport, registers the
|
|
45
|
-
* and
|
|
46
|
+
* Sets up the MCP server with stdio transport, registers the discover,
|
|
47
|
+
* inspect, and call handlers, and starts listening for requests.
|
|
46
48
|
*/
|
|
47
49
|
async function main() {
|
|
48
50
|
// Initialize API client (validates QVERIS_API_KEY)
|
|
@@ -70,43 +72,85 @@ async function main() {
|
|
|
70
72
|
// =========================================================================
|
|
71
73
|
/**
|
|
72
74
|
* Lists available tools.
|
|
73
|
-
* Returns the
|
|
75
|
+
* Returns the discover, inspect, and call definitions (plus deprecated aliases).
|
|
74
76
|
*/
|
|
75
77
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
76
78
|
return {
|
|
77
79
|
tools: [
|
|
80
|
+
// Primary tools (aligned with CLI naming)
|
|
78
81
|
{
|
|
79
|
-
name: '
|
|
80
|
-
description: '
|
|
82
|
+
name: 'discover',
|
|
83
|
+
description: 'Discover available tools based on natural language queries. ' +
|
|
81
84
|
'Returns relevant tools that can help accomplish tasks. ' +
|
|
82
|
-
'Use this to
|
|
85
|
+
'Use this to find tools before inspecting or calling them. ' +
|
|
86
|
+
'Results may include billing_rule metadata for rule-level pricing.',
|
|
87
|
+
inputSchema: searchToolsSchema,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'inspect',
|
|
91
|
+
description: 'Inspect tools by their IDs to get detailed information. ' +
|
|
92
|
+
'Returns parameters, success rate, latency, examples, and billing_rule when available. ' +
|
|
93
|
+
'Use tool_ids from a previous discover call.',
|
|
94
|
+
inputSchema: getToolsByIdsSchema,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'call',
|
|
98
|
+
description: 'Call a specific remote tool with provided parameters. ' +
|
|
99
|
+
'The tool_id and search_id must come from a previous discover call. ' +
|
|
100
|
+
'Pass parameters to the tool through params_to_tool. ' +
|
|
101
|
+
'The response may include pre-settlement billing; use usage_history or credits_ledger for final charge status.',
|
|
102
|
+
inputSchema: executeToolSchema,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'usage_history',
|
|
106
|
+
description: 'Context-safe usage audit query. Defaults to aggregated summary, supports precise search by execution_id/search_id/charge_outcome/credit range, and writes large exports to a local JSONL file instead of returning all rows.',
|
|
107
|
+
inputSchema: usageHistorySchema,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'credits_ledger',
|
|
111
|
+
description: 'Context-safe final credits ledger query. Defaults to aggregated summary, supports precise search by entry type/direction/credit range, and writes large exports to a local JSONL file instead of returning all rows.',
|
|
112
|
+
inputSchema: creditsLedgerSchema,
|
|
113
|
+
},
|
|
114
|
+
// Deprecated aliases (backward compatibility)
|
|
115
|
+
{
|
|
116
|
+
name: 'search_tools',
|
|
117
|
+
description: '[Deprecated: use "discover" instead] Search for available tools based on natural language queries.',
|
|
83
118
|
inputSchema: searchToolsSchema,
|
|
84
119
|
},
|
|
85
120
|
{
|
|
86
121
|
name: 'get_tools_by_ids',
|
|
87
|
-
description: 'Get descriptions of tools based on their tool IDs.
|
|
88
|
-
'Useful for retrieving detailed information about specific tools ' +
|
|
89
|
-
'when you already know their tool_ids from previous searches.',
|
|
122
|
+
description: '[Deprecated: use "inspect" instead] Get descriptions of tools based on their tool IDs.',
|
|
90
123
|
inputSchema: getToolsByIdsSchema,
|
|
91
124
|
},
|
|
92
125
|
{
|
|
93
126
|
name: 'execute_tool',
|
|
94
|
-
description: 'Execute a specific remote tool with provided parameters.
|
|
95
|
-
'The tool_id and search_id must come from a previous search_tools call. ' +
|
|
96
|
-
'Pass parameters to the tool through params_to_tool as a JSON string.',
|
|
127
|
+
description: '[Deprecated: use "call" instead] Execute a specific remote tool with provided parameters.',
|
|
97
128
|
inputSchema: executeToolSchema,
|
|
98
129
|
},
|
|
99
130
|
],
|
|
100
131
|
};
|
|
101
132
|
});
|
|
133
|
+
// Deprecated tool name aliases → canonical names
|
|
134
|
+
const DEPRECATED_ALIASES = {
|
|
135
|
+
search_tools: 'discover',
|
|
136
|
+
get_tools_by_ids: 'inspect',
|
|
137
|
+
execute_tool: 'call',
|
|
138
|
+
};
|
|
102
139
|
/**
|
|
103
140
|
* Handles tool execution requests.
|
|
104
141
|
* Routes to the appropriate handler based on tool name.
|
|
142
|
+
* Deprecated aliases emit a warning to stderr.
|
|
105
143
|
*/
|
|
106
144
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
107
|
-
const { name, arguments: args } = request.params;
|
|
145
|
+
const { name: rawName, arguments: args } = request.params;
|
|
146
|
+
// Resolve deprecated aliases
|
|
147
|
+
let name = rawName;
|
|
148
|
+
if (DEPRECATED_ALIASES[rawName]) {
|
|
149
|
+
name = DEPRECATED_ALIASES[rawName];
|
|
150
|
+
process.stderr.write(`[qveris] Deprecated: "${rawName}" → use "${name}" instead\n`);
|
|
151
|
+
}
|
|
108
152
|
try {
|
|
109
|
-
if (name === '
|
|
153
|
+
if (name === 'discover') {
|
|
110
154
|
const input = (args ?? {});
|
|
111
155
|
// Validate required fields
|
|
112
156
|
if (!input.query || typeof input.query !== 'string') {
|
|
@@ -133,7 +177,7 @@ async function main() {
|
|
|
133
177
|
],
|
|
134
178
|
};
|
|
135
179
|
}
|
|
136
|
-
if (name === '
|
|
180
|
+
if (name === 'inspect') {
|
|
137
181
|
const input = (args ?? {});
|
|
138
182
|
// Validate required fields
|
|
139
183
|
if (!input.tool_ids || !Array.isArray(input.tool_ids) || input.tool_ids.length === 0) {
|
|
@@ -160,7 +204,7 @@ async function main() {
|
|
|
160
204
|
],
|
|
161
205
|
};
|
|
162
206
|
}
|
|
163
|
-
if (name === '
|
|
207
|
+
if (name === 'call') {
|
|
164
208
|
const input = (args ?? {});
|
|
165
209
|
// Validate required fields
|
|
166
210
|
const missingFields = [];
|
|
@@ -177,7 +221,7 @@ async function main() {
|
|
|
177
221
|
type: 'text',
|
|
178
222
|
text: JSON.stringify({
|
|
179
223
|
error: `Missing required parameters: ${missingFields.join(', ')}`,
|
|
180
|
-
hint: 'tool_id and search_id must come from a previous
|
|
224
|
+
hint: 'tool_id and search_id must come from a previous discover call',
|
|
181
225
|
}),
|
|
182
226
|
},
|
|
183
227
|
],
|
|
@@ -194,14 +238,38 @@ async function main() {
|
|
|
194
238
|
],
|
|
195
239
|
};
|
|
196
240
|
}
|
|
241
|
+
if (name === 'usage_history') {
|
|
242
|
+
const input = (args ?? {});
|
|
243
|
+
const result = await executeUsageHistory(client, input);
|
|
244
|
+
return {
|
|
245
|
+
content: [
|
|
246
|
+
{
|
|
247
|
+
type: 'text',
|
|
248
|
+
text: JSON.stringify(result, null, 2),
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (name === 'credits_ledger') {
|
|
254
|
+
const input = (args ?? {});
|
|
255
|
+
const result = await executeCreditsLedger(client, input);
|
|
256
|
+
return {
|
|
257
|
+
content: [
|
|
258
|
+
{
|
|
259
|
+
type: 'text',
|
|
260
|
+
text: JSON.stringify(result, null, 2),
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
};
|
|
264
|
+
}
|
|
197
265
|
// Unknown tool
|
|
198
266
|
return {
|
|
199
267
|
content: [
|
|
200
268
|
{
|
|
201
269
|
type: 'text',
|
|
202
270
|
text: JSON.stringify({
|
|
203
|
-
error: `Unknown tool: ${
|
|
204
|
-
available_tools: ['
|
|
271
|
+
error: `Unknown tool: ${rawName}`,
|
|
272
|
+
available_tools: ['discover', 'inspect', 'call', 'usage_history', 'credits_ledger'],
|
|
205
273
|
}),
|
|
206
274
|
},
|
|
207
275
|
],
|
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,oCAAoC,CAAC;AAC5C,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAgB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GAEnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GAEnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,mBAAmB,EACnB,oBAAoB,GAErB,MAAM,uBAAuB,CAAC;
|
|
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,oCAAoC,CAAC;AAC5C,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAgB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GAEnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GAEnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,mBAAmB,EACnB,oBA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AS,CAAC,CAAC;IAEhC,8DAA8D;IAC9D,OAAO,CAAC,KAAK,CAAC,sBAAsB,cAAc,UAAU,CAAC,CAAC;IAC9D,OAAO,CAAC,KAAK,CAAC,eAAe,gBAAgB,EAAE,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,QAAQ,IAAI,KAAK;QACjB,SAAS,IAAI,KAAK,CACnB,CAAC;AACJ,CAAC;AAED,iBAAiB;AACjB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ApiEnvelope, CreditsLedgerItem, CreditsLedgerResponse, UsageEventItem, UsageEventsResponse } from '../types.js';
|
|
2
|
+
export declare const DEFAULT_DETAIL_LIMIT = 10;
|
|
3
|
+
export declare const MAX_DETAIL_LIMIT = 50;
|
|
4
|
+
export declare const DEFAULT_PAGE_SIZE = 500;
|
|
5
|
+
export declare const MAX_SUMMARY_ROWS = 5000;
|
|
6
|
+
export declare const MAX_SEARCH_SCAN_ROWS = 2000;
|
|
7
|
+
export declare const MAX_EXPORT_ROWS = 50000;
|
|
8
|
+
export type AuditMode = 'summary' | 'search' | 'export_file';
|
|
9
|
+
export type Bucket = 'hour' | 'day' | 'week';
|
|
10
|
+
export interface CommonAuditInput {
|
|
11
|
+
mode?: AuditMode | 'export-file';
|
|
12
|
+
start_date?: string;
|
|
13
|
+
end_date?: string;
|
|
14
|
+
bucket?: Bucket;
|
|
15
|
+
min_credits?: number;
|
|
16
|
+
max_credits?: number;
|
|
17
|
+
limit?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface UsageFilterInput extends CommonAuditInput {
|
|
20
|
+
execution_id?: string;
|
|
21
|
+
search_id?: string;
|
|
22
|
+
event_type?: string;
|
|
23
|
+
kind?: string;
|
|
24
|
+
success?: boolean;
|
|
25
|
+
charge_outcome?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface LedgerFilterInput extends CommonAuditInput {
|
|
28
|
+
entry_type?: string;
|
|
29
|
+
direction?: 'consume' | 'grant' | 'any';
|
|
30
|
+
}
|
|
31
|
+
export declare function unwrapEnvelope<T>(response: ApiEnvelope<T> | T): T;
|
|
32
|
+
export declare function normalizeMode(mode: CommonAuditInput['mode']): AuditMode;
|
|
33
|
+
export declare function clampLimit(limit?: number): number;
|
|
34
|
+
export declare function resolveDateRange(input: CommonAuditInput): {
|
|
35
|
+
start_date: string;
|
|
36
|
+
end_date: string;
|
|
37
|
+
};
|
|
38
|
+
export declare function chooseBucket(input: CommonAuditInput): Bucket;
|
|
39
|
+
export declare function getUsageItems(response: UsageEventsResponse): UsageEventItem[];
|
|
40
|
+
export declare function getLedgerItems(response: CreditsLedgerResponse): CreditsLedgerItem[];
|
|
41
|
+
export declare function usageAmount(row: UsageEventItem): number;
|
|
42
|
+
export declare function ledgerAmount(row: CreditsLedgerItem): number;
|
|
43
|
+
export declare function matchesUsage(row: UsageEventItem, input: UsageFilterInput): boolean;
|
|
44
|
+
export declare function matchesLedger(row: CreditsLedgerItem, input: LedgerFilterInput): boolean;
|
|
45
|
+
export declare function pickUsage(row: UsageEventItem): Record<string, unknown>;
|
|
46
|
+
export declare function pickLedger(row: CreditsLedgerItem): Record<string, unknown>;
|
|
47
|
+
export declare function summarizeUsage(rows: UsageEventItem[], input: UsageFilterInput, scannedRecords: number, total: number | undefined, truncated: boolean): Record<string, unknown>;
|
|
48
|
+
export declare function summarizeUsageFromServer(serverSummary: Record<string, unknown>, input: UsageFilterInput, scannedRecords: number, total: number | undefined): Record<string, unknown>;
|
|
49
|
+
export declare function summarizeLedger(rows: CreditsLedgerItem[], input: LedgerFilterInput, scannedRecords: number, total: number | undefined, truncated: boolean): Record<string, unknown>;
|
|
50
|
+
export declare function summarizeLedgerFromServer(serverSummary: Record<string, unknown>, input: LedgerFilterInput, scannedRecords: number, total: number | undefined): Record<string, unknown>;
|
|
51
|
+
export declare function writeJsonlExport(kind: string, rows: unknown[], metadata: Record<string, unknown>): Record<string, unknown>;
|
|
52
|
+
//# sourceMappingURL=audit-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-utils.d.ts","sourceRoot":"","sources":["../../src/tools/audit-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,eAAO,MAAM,oBAAoB,OAAO,CAAC;AACzC,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,CAAC;AAC7D,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,YAAY,CAAC,EAAE,MAAM,CAAC;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