@hypequery/mcp 0.1.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/LICENSE +201 -0
- package/README.md +283 -0
- package/dist/bin.d.ts +12 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +72 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/prompts/dataset-guide.d.ts +16 -0
- package/dist/prompts/dataset-guide.d.ts.map +1 -0
- package/dist/prompts/dataset-guide.js +130 -0
- package/dist/server.d.ts +45 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +257 -0
- package/dist/tools/introspect.d.ts +9 -0
- package/dist/tools/introspect.d.ts.map +1 -0
- package/dist/tools/introspect.js +76 -0
- package/dist/tools/list-datasets.d.ts +8 -0
- package/dist/tools/list-datasets.d.ts.map +1 -0
- package/dist/tools/list-datasets.js +32 -0
- package/dist/tools/query-dataset.d.ts +9 -0
- package/dist/tools/query-dataset.d.ts.map +1 -0
- package/dist/tools/query-dataset.js +61 -0
- package/dist/tools/query-metric.d.ts +9 -0
- package/dist/tools/query-metric.d.ts.map +1 -0
- package/dist/tools/query-metric.js +63 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are advised to review the applicable
|
|
150
|
+
documentation for the specific language governing permissions and
|
|
151
|
+
limitations under each license.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 hypequery
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# @hypequery/mcp
|
|
2
|
+
|
|
3
|
+
Model Context Protocol (MCP) server for Hypequery semantic layer. Exposes datasets and metrics to AI agents like Claude Desktop, Cursor, and other MCP-compatible tools.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **MCP Tools**: List datasets, introspect schemas, query metrics and datasets
|
|
8
|
+
- **Natural Language**: AI-friendly prompts and responses
|
|
9
|
+
- **Type-Safe**: Full TypeScript support with the Hypequery semantic layer
|
|
10
|
+
- **ClickHouse Native**: Optimized for ClickHouse analytics workloads
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @hypequery/mcp
|
|
16
|
+
# or
|
|
17
|
+
pnpm add @hypequery/mcp
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### 1. Create an MCP Config File
|
|
23
|
+
|
|
24
|
+
Create `mcp-config.ts`:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { MetricExecutor } from '@hypequery/datasets';
|
|
28
|
+
import { createQueryBuilder } from '@hypequery/clickhouse';
|
|
29
|
+
import { OrdersDataset, CustomersDataset } from './datasets/index.js';
|
|
30
|
+
|
|
31
|
+
const revenue = OrdersDataset.metric('revenue', { measure: 'revenue' });
|
|
32
|
+
const customerCount = CustomersDataset.metric('customerCount', {
|
|
33
|
+
measure: 'customerCount',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Export your datasets
|
|
37
|
+
export const datasets = {
|
|
38
|
+
orders: {
|
|
39
|
+
...OrdersDataset,
|
|
40
|
+
metrics: { revenue },
|
|
41
|
+
},
|
|
42
|
+
customers: {
|
|
43
|
+
...CustomersDataset,
|
|
44
|
+
metrics: { customerCount },
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Export your executor
|
|
49
|
+
const builderFactory = createQueryBuilder({
|
|
50
|
+
host: process.env.CLICKHOUSE_HOST,
|
|
51
|
+
username: process.env.CLICKHOUSE_USER,
|
|
52
|
+
password: process.env.CLICKHOUSE_PASSWORD,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const executor = new MetricExecutor({ builderFactory });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. Run the MCP Server
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npx hypequery-mcp --config ./mcp-config.js
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 3. Configure Claude Desktop
|
|
65
|
+
|
|
66
|
+
Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"mcpServers": {
|
|
71
|
+
"hypequery": {
|
|
72
|
+
"command": "npx",
|
|
73
|
+
"args": ["hypequery-mcp", "--config", "/absolute/path/to/mcp-config.js"]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 4. Use with Claude
|
|
80
|
+
|
|
81
|
+
Now you can ask Claude to query your data:
|
|
82
|
+
|
|
83
|
+
> "Show me revenue by region for the last month"
|
|
84
|
+
|
|
85
|
+
> "What are the top 10 customers by order count?"
|
|
86
|
+
|
|
87
|
+
> "List all available datasets"
|
|
88
|
+
|
|
89
|
+
## Available Tools
|
|
90
|
+
|
|
91
|
+
### `list_datasets`
|
|
92
|
+
|
|
93
|
+
Lists all available datasets with their descriptions.
|
|
94
|
+
|
|
95
|
+
**Example:**
|
|
96
|
+
```typescript
|
|
97
|
+
{
|
|
98
|
+
"name": "list_datasets"
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Response:**
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"datasets": [
|
|
106
|
+
{
|
|
107
|
+
"name": "orders",
|
|
108
|
+
"description": "Customer orders and revenue data",
|
|
109
|
+
"dimensionCount": 5,
|
|
110
|
+
"metricCount": 4
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
"total": 1
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### `get_dataset_schema`
|
|
118
|
+
|
|
119
|
+
Gets the complete schema for a dataset.
|
|
120
|
+
|
|
121
|
+
**Example:**
|
|
122
|
+
```typescript
|
|
123
|
+
{
|
|
124
|
+
"name": "get_dataset_schema",
|
|
125
|
+
"arguments": {
|
|
126
|
+
"dataset": "orders"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Response:**
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"name": "orders",
|
|
135
|
+
"dimensions": {
|
|
136
|
+
"region": { "type": "string", "label": "Region" },
|
|
137
|
+
"status": { "type": "string", "label": "Order Status" }
|
|
138
|
+
},
|
|
139
|
+
"metrics": {
|
|
140
|
+
"revenue": { "type": "sum", "label": "Total Revenue", "format": "currency" }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### `query_metric`
|
|
146
|
+
|
|
147
|
+
Executes a pre-defined metric query.
|
|
148
|
+
|
|
149
|
+
**Example:**
|
|
150
|
+
```typescript
|
|
151
|
+
{
|
|
152
|
+
"name": "query_metric",
|
|
153
|
+
"arguments": {
|
|
154
|
+
"dataset": "orders",
|
|
155
|
+
"metric": "revenue",
|
|
156
|
+
"dimensions": ["region"],
|
|
157
|
+
"filters": [
|
|
158
|
+
{ "field": "status", "operator": "eq", "value": "completed" }
|
|
159
|
+
],
|
|
160
|
+
"grain": "month",
|
|
161
|
+
"orderBy": [
|
|
162
|
+
{ "field": "revenue", "direction": "desc" }
|
|
163
|
+
],
|
|
164
|
+
"limit": 10
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Response:**
|
|
170
|
+
```json
|
|
171
|
+
{
|
|
172
|
+
"data": [
|
|
173
|
+
{ "region": "US", "month": "2024-01", "revenue": 125000 },
|
|
174
|
+
{ "region": "EU", "month": "2024-01", "revenue": 98000 }
|
|
175
|
+
],
|
|
176
|
+
"meta": {
|
|
177
|
+
"sql": "SELECT...",
|
|
178
|
+
"timingMs": 45,
|
|
179
|
+
"rowCount": 2
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### `query_dataset`
|
|
185
|
+
|
|
186
|
+
Executes an ad-hoc dataset query with custom dimensions and metrics.
|
|
187
|
+
|
|
188
|
+
**Example:**
|
|
189
|
+
```typescript
|
|
190
|
+
{
|
|
191
|
+
"name": "query_dataset",
|
|
192
|
+
"arguments": {
|
|
193
|
+
"dataset": "orders",
|
|
194
|
+
"dimensions": ["region", "status"],
|
|
195
|
+
"metrics": ["revenue", "orderCount"],
|
|
196
|
+
"limit": 100
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Programmatic Usage
|
|
202
|
+
|
|
203
|
+
You can also use the MCP server programmatically in your application:
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import { createMCPServer } from '@hypequery/mcp';
|
|
207
|
+
import { MetricExecutor } from '@hypequery/datasets';
|
|
208
|
+
import { datasets } from './datasets/index.js';
|
|
209
|
+
import { queryBuilder } from './db/index.js';
|
|
210
|
+
|
|
211
|
+
const executor = new MetricExecutor({ builderFactory: queryBuilder });
|
|
212
|
+
|
|
213
|
+
const server = await createMCPServer({
|
|
214
|
+
datasets,
|
|
215
|
+
executor,
|
|
216
|
+
name: 'my-analytics-mcp',
|
|
217
|
+
version: '1.0.0',
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// Server is now running via stdio transport
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Filter Operators
|
|
224
|
+
|
|
225
|
+
- `eq`: Equal to
|
|
226
|
+
- `neq`: Not equal to
|
|
227
|
+
- `gt`: Greater than
|
|
228
|
+
- `gte`: Greater than or equal to
|
|
229
|
+
- `lt`: Less than
|
|
230
|
+
- `lte`: Less than or equal to
|
|
231
|
+
- `in`: In list
|
|
232
|
+
- `notIn`: Not in list
|
|
233
|
+
- `between`: Between two values
|
|
234
|
+
- `like`: Pattern match (SQL LIKE)
|
|
235
|
+
|
|
236
|
+
## Time Grains
|
|
237
|
+
|
|
238
|
+
- `day`: Daily aggregation
|
|
239
|
+
- `week`: Weekly aggregation
|
|
240
|
+
- `month`: Monthly aggregation
|
|
241
|
+
- `quarter`: Quarterly aggregation
|
|
242
|
+
- `year`: Yearly aggregation
|
|
243
|
+
|
|
244
|
+
## Prompts
|
|
245
|
+
|
|
246
|
+
The MCP server also exposes a `dataset_guide` prompt that provides natural language guidance for querying datasets.
|
|
247
|
+
|
|
248
|
+
## Environment Variables
|
|
249
|
+
|
|
250
|
+
Your config file can use environment variables for database credentials:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
const queryBuilder = createQueryBuilder({
|
|
254
|
+
host: process.env.CLICKHOUSE_HOST || 'localhost',
|
|
255
|
+
username: process.env.CLICKHOUSE_USER || 'default',
|
|
256
|
+
password: process.env.CLICKHOUSE_PASSWORD,
|
|
257
|
+
database: process.env.CLICKHOUSE_DATABASE || 'default',
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Troubleshooting
|
|
262
|
+
|
|
263
|
+
### MCP server not connecting
|
|
264
|
+
|
|
265
|
+
1. Check that the config file path is absolute, not relative
|
|
266
|
+
2. Ensure the config file exports both `datasets` and `executor`
|
|
267
|
+
3. Check Claude Desktop logs for errors
|
|
268
|
+
|
|
269
|
+
### Queries failing
|
|
270
|
+
|
|
271
|
+
1. Verify your ClickHouse connection is working
|
|
272
|
+
2. Check that dataset definitions match your database schema
|
|
273
|
+
3. Use the `meta.sql` field in responses to debug generated SQL
|
|
274
|
+
|
|
275
|
+
## Related Packages
|
|
276
|
+
|
|
277
|
+
- `@hypequery/datasets` - Semantic layer DSL
|
|
278
|
+
- `@hypequery/clickhouse` - ClickHouse query builder
|
|
279
|
+
- `@hypequery/serve` - HTTP server for analytics endpoints
|
|
280
|
+
|
|
281
|
+
## License
|
|
282
|
+
|
|
283
|
+
Apache-2.0
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* MCP Server CLI
|
|
4
|
+
*
|
|
5
|
+
* This is a standalone executable that starts the MCP server.
|
|
6
|
+
* Users can configure it by creating a config file that exports datasets and executor.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* npx hypequery-mcp --config ./mcp-config.js
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=bin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA;;;;;;;;GAQG"}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* MCP Server CLI
|
|
4
|
+
*
|
|
5
|
+
* This is a standalone executable that starts the MCP server.
|
|
6
|
+
* Users can configure it by creating a config file that exports datasets and executor.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* npx hypequery-mcp --config ./mcp-config.js
|
|
10
|
+
*/
|
|
11
|
+
import { createMCPServer } from './server.js';
|
|
12
|
+
import { pathToFileURL } from 'url';
|
|
13
|
+
import { resolve } from 'path';
|
|
14
|
+
import { format } from 'util';
|
|
15
|
+
function routeConsoleOutputToStderr() {
|
|
16
|
+
const write = (...args) => {
|
|
17
|
+
process.stderr.write(`${format(...args)}\n`);
|
|
18
|
+
};
|
|
19
|
+
// MCP stdio transport owns stdout. Keep application and query logs off the
|
|
20
|
+
// protocol stream, including logs emitted while loading the user's config.
|
|
21
|
+
console.log = write;
|
|
22
|
+
console.info = write;
|
|
23
|
+
console.debug = write;
|
|
24
|
+
}
|
|
25
|
+
async function main() {
|
|
26
|
+
routeConsoleOutputToStderr();
|
|
27
|
+
const args = process.argv.slice(2);
|
|
28
|
+
const configIndex = args.indexOf('--config');
|
|
29
|
+
if (configIndex === -1 || !args[configIndex + 1]) {
|
|
30
|
+
console.error('Error: --config flag is required');
|
|
31
|
+
console.error('');
|
|
32
|
+
console.error('Usage: hypequery-mcp --config ./mcp-config.js');
|
|
33
|
+
console.error('');
|
|
34
|
+
console.error('The config file should export { datasets, executor }:');
|
|
35
|
+
console.error('');
|
|
36
|
+
console.error(' export const datasets = { ... };');
|
|
37
|
+
console.error(' export const executor = new MetricExecutor(...);');
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
const configPath = resolve(process.cwd(), args[configIndex + 1]);
|
|
41
|
+
try {
|
|
42
|
+
// Dynamic import of the config file
|
|
43
|
+
const configModule = await import(pathToFileURL(configPath).href);
|
|
44
|
+
const { datasets, executor } = configModule;
|
|
45
|
+
if (!datasets) {
|
|
46
|
+
throw new Error('Config file must export "datasets"');
|
|
47
|
+
}
|
|
48
|
+
if (!executor) {
|
|
49
|
+
throw new Error('Config file must export "executor"');
|
|
50
|
+
}
|
|
51
|
+
// Create and start the MCP server
|
|
52
|
+
await createMCPServer({
|
|
53
|
+
datasets,
|
|
54
|
+
executor,
|
|
55
|
+
name: 'hypequery-mcp-server',
|
|
56
|
+
version: '0.1.0',
|
|
57
|
+
});
|
|
58
|
+
// Keep the process running
|
|
59
|
+
process.on('SIGINT', () => {
|
|
60
|
+
console.error('Shutting down MCP server...');
|
|
61
|
+
process.exit(0);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('Error loading config file:', error);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
main().catch((error) => {
|
|
70
|
+
console.error('Fatal error:', error);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hypequery/mcp
|
|
3
|
+
*
|
|
4
|
+
* Model Context Protocol (MCP) server for Hypequery semantic layer.
|
|
5
|
+
* Exposes datasets and metrics to AI agents via MCP tools.
|
|
6
|
+
*/
|
|
7
|
+
export { HypequeryMCPServer, createMCPServer, type MCPServerConfig } from './server.js';
|
|
8
|
+
export { listDatasetsTool } from './tools/list-datasets.js';
|
|
9
|
+
export { getDatasetSchemaTool } from './tools/introspect.js';
|
|
10
|
+
export { queryMetricTool } from './tools/query-metric.js';
|
|
11
|
+
export { queryDatasetTool } from './tools/query-dataset.js';
|
|
12
|
+
export { datasetGuidePrompt } from './prompts/dataset-guide.js';
|
|
13
|
+
export type { DatasetRegistry, QueryMetricArgs, QueryDatasetArgs, GetDatasetSchemaArgs, MCPToolResponse, DatasetSchema, DimensionSchema, MetricSchema, RelationshipSchema, DatasetListItem, DatasetsListResponse, QueryResultResponse, QueryResultMeta, } from './types.js';
|
|
14
|
+
export { MAX_QUERY_LIMIT, DEFAULT_QUERY_LIMIT } from './types.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE,YAAY,EACV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hypequery/mcp
|
|
3
|
+
*
|
|
4
|
+
* Model Context Protocol (MCP) server for Hypequery semantic layer.
|
|
5
|
+
* Exposes datasets and metrics to AI agents via MCP tools.
|
|
6
|
+
*/
|
|
7
|
+
export { HypequeryMCPServer, createMCPServer } from './server.js';
|
|
8
|
+
export { listDatasetsTool } from './tools/list-datasets.js';
|
|
9
|
+
export { getDatasetSchemaTool } from './tools/introspect.js';
|
|
10
|
+
export { queryMetricTool } from './tools/query-metric.js';
|
|
11
|
+
export { queryDatasetTool } from './tools/query-dataset.js';
|
|
12
|
+
export { datasetGuidePrompt } from './prompts/dataset-guide.js';
|
|
13
|
+
export { MAX_QUERY_LIMIT, DEFAULT_QUERY_LIMIT } from './types.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dataset Guide Prompt
|
|
3
|
+
*
|
|
4
|
+
* Provides natural language guidance for querying datasets.
|
|
5
|
+
*/
|
|
6
|
+
import type { DatasetRegistry } from '../types.js';
|
|
7
|
+
export declare function datasetGuidePrompt(datasets: DatasetRegistry, datasetName?: string): {
|
|
8
|
+
messages: {
|
|
9
|
+
role: "user";
|
|
10
|
+
content: {
|
|
11
|
+
type: "text";
|
|
12
|
+
text: string;
|
|
13
|
+
};
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=dataset-guide.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset-guide.d.ts","sourceRoot":"","sources":["../../src/prompts/dataset-guide.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,eAAe,EAAE,WAAW,CAAC,EAAE,MAAM;;;;;;;;EAmIjF"}
|