@react-querybuilder/mcp 0.0.0-stage → 8.25.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.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Jake Boone and other contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,94 @@
1
- # Temporary Holding Version
1
+ # @react-querybuilder/mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Local (stdio) [Model Context Protocol](https://modelcontextprotocol.io) server for [React Query Builder](https://react-querybuilder.js.org/). Gives coding agents the library's real query tooling and version-pinned docs.
4
+
5
+ ## Tools
6
+
7
+ | Tool | Purpose |
8
+ | ------------------ | ------------------------------------------------------------------------------------------------------- |
9
+ | `format_query` | RQB query → any `formatQuery` format (SQL, parameterized, MongoDB, CEL, JsonLogic, natural language, …) |
10
+ | `parse_query` | SQL/CEL/MongoDB/JsonLogic/SpEL/JSONata/Cypher/GQL/Gremlin/SPARQL → RQB query |
11
+ | `convert_query` | Parse + format in one step (e.g. SQL → MongoDB); returns the intermediate RQB query too |
12
+ | `validate_query` | Check a query against a `fields` config (shape, IC alternation, operators, value arity/types, …) |
13
+ | `get_query_schema` | JSON Schema for valid queries (`getQueryJsonSchema`) |
14
+ | `search_docs` | Full-text search of the docs (matching this package's version) |
15
+ | `get_doc` | A docs page (or `#anchor` section) as markdown |
16
+
17
+ ORM formats (`drizzle`, `prisma`, `sequelize`, `tanstack_db`) need live ORM objects and aren't available over MCP. `fields` input accepts the JSON-serializable subset of `Field` (no function props such as `validator`).
18
+
19
+ Also provides:
20
+
21
+ - **Resources**: `rqb://docs/{slug}` (every docs page) and `rqb://types/{name}` (key type declarations, e.g. `RuleGroupType`, `FormatQueryOptions`, `QueryBuilderProps`).
22
+ - **Prompts**: `setup_query_builder` (`uiLibrary`, `fields`) and `convert_filter` (`input`, `from`, `to`).
23
+
24
+ ## Configuration
25
+
26
+ Requires Node.js 20+.
27
+
28
+ **Claude Code**
29
+
30
+ ```bash
31
+ claude mcp add rqb -- npx -y @react-querybuilder/mcp
32
+ ```
33
+
34
+ **opencode** (`opencode.json`)
35
+
36
+ ```json
37
+ {
38
+ "$schema": "https://opencode.ai/config.json",
39
+ "mcp": {
40
+ "rqb": {
41
+ "type": "local",
42
+ "command": ["npx", "-y", "@react-querybuilder/mcp"]
43
+ }
44
+ }
45
+ }
46
+ ```
47
+
48
+ **Cursor** (`.cursor/mcp.json`)
49
+
50
+ ```json
51
+ {
52
+ "mcpServers": {
53
+ "rqb": { "command": "npx", "args": ["-y", "@react-querybuilder/mcp"] }
54
+ }
55
+ }
56
+ ```
57
+
58
+ **VS Code** (`.vscode/mcp.json`)
59
+
60
+ ```json
61
+ {
62
+ "servers": {
63
+ "rqb": { "type": "stdio", "command": "npx", "args": ["-y", "@react-querybuilder/mcp"] }
64
+ }
65
+ }
66
+ ```
67
+
68
+ `bunx @react-querybuilder/mcp` also works.
69
+
70
+ ## Programmatic use
71
+
72
+ ```ts
73
+ import { createServer, handleConvertQuery } from '@react-querybuilder/mcp';
74
+
75
+ // Tool handlers are plain async functions
76
+ const result = await handleConvertQuery({ input: 'age > 30', from: 'sql', to: 'mongodb_query' });
77
+
78
+ // Or connect the server to any MCP transport
79
+ const server = createServer();
80
+ ```
81
+
82
+ ## Development
83
+
84
+ ```bash
85
+ bun run build:mcp # builds the docs index (src/generated/, gitignored) + dist
86
+ bun test packages/mcp
87
+ bun run test:mcp # Vitest w/ coverage
88
+ ```
89
+
90
+ Smoke test with the MCP Inspector (after building):
91
+
92
+ ```bash
93
+ bunx @modelcontextprotocol/inspector node packages/mcp/dist/cli.mjs
94
+ ```
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/dist/cli.mjs ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { n as serverName, t as createServer } from "./server-CEaTrVub.mjs";
3
+ import { serveStdio } from "@modelcontextprotocol/server/stdio";
4
+ //#region src/cli.ts
5
+ const handle = serveStdio(createServer);
6
+ console.error(`${serverName} MCP server listening on stdio`);
7
+ for (const signal of ["SIGINT", "SIGTERM"]) process.on(signal, () => void handle.close().then(() => process.exit(0)));
8
+ //#endregion
9
+ export {};
10
+
11
+ //# sourceMappingURL=cli.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { serveStdio } from '@modelcontextprotocol/server/stdio';\nimport { createServer, serverName } from './server';\n\n// stdout is the JSON-RPC channel; log to stderr only\nconst handle = serveStdio(createServer);\nconsole.error(`${serverName} MCP server listening on stdio`);\n\nfor (const signal of ['SIGINT', 'SIGTERM'] as const) {\n process.on(signal, () => void handle.close().then(() => process.exit(0)));\n}\n"],"mappings":";;;;AAKA,MAAM,SAAS,WAAW,YAAY;AACtC,QAAQ,MAAM,GAAG,WAAW,+BAA+B;AAE3D,KAAK,MAAM,UAAU,CAAC,UAAU,SAAS,GACvC,QAAQ,GAAG,cAAc,KAAK,OAAO,MAAM,CAAC,CAAC,WAAW,QAAQ,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1,177 @@
1
+ import { ExportFormat, FormatQueryOptions, GetQueryJsonSchemaOptions } from "@react-querybuilder/core";
2
+ import { McpServer } from "@modelcontextprotocol/server";
3
+ //#region src/types.d.ts
4
+ /** Docs page metadata. */
5
+ interface DocsPage {
6
+ /** Path under `/docs/`, e.g. `utils/export`. */
7
+ slug: string;
8
+ title: string;
9
+ description: string;
10
+ url: string;
11
+ }
12
+ /** Docs chunk: page preamble (empty `heading`) or one `##` section. */
13
+ interface DocsSection {
14
+ /** Index into {@link DocsIndex.pages}. */
15
+ page: number;
16
+ heading: string;
17
+ anchor: string;
18
+ /** Cleaned markdown. */
19
+ text: string;
20
+ }
21
+ /** Build-time docs/types snapshot (`src/generated/docs-index.json`). */
22
+ interface DocsIndex {
23
+ /** RQB version the docs were built from. */
24
+ version: string;
25
+ pages: DocsPage[];
26
+ sections: DocsSection[];
27
+ /** Type name → declaration source (with JSDoc). */
28
+ types: Record<string, string>;
29
+ }
30
+ /** Tool handler result (subset of MCP `CallToolResult`). Type alias (not interface) so it's
31
+ * assignable to the SDK's index-signature result type. */
32
+ type ToolResult = {
33
+ content: {
34
+ type: "text";
35
+ text: string;
36
+ }[];
37
+ structuredContent?: Record<string, unknown>;
38
+ isError?: boolean;
39
+ };
40
+ //#endregion
41
+ //#region src/docs.d.ts
42
+ /** Build-time docs snapshot. */
43
+ export declare const docsIndex: DocsIndex;
44
+ /** Search hit. */
45
+ export interface DocsSearchResult {
46
+ title: string;
47
+ url: string;
48
+ snippet: string;
49
+ score: number;
50
+ }
51
+ export declare const sectionUrl: (s: DocsSection) => string;
52
+ export declare const sectionTitle: (s: DocsSection) => string;
53
+ /** ~`len`-char plain-ish excerpt around the first matched term. */
54
+ export declare const makeSnippet: (text: string, terms: string[], len?: number) => string;
55
+ /** Full-text docs search (BM25+ via MiniSearch; title/heading boosted). */
56
+ export declare const searchDocs: (query: string, limit?: number) => DocsSearchResult[];
57
+ /** Resolves a docs URL/slug (optionally with `#anchor`) to a page index + anchor. */
58
+ export declare const resolveDocRef: (ref: string) => {
59
+ page: DocsPage;
60
+ anchor: string;
61
+ } | undefined;
62
+ /** Full page markdown (title, description, all sections). */
63
+ export declare const getPageMarkdown: (page: DocsPage) => string;
64
+ /** One section's markdown (+ subsections if `##`), or `undefined` for unknown anchor. */
65
+ export declare const getSectionMarkdown: (page: DocsPage, anchor: string) => string | undefined;
66
+ /** Page markdown, or one section's when `anchor` is non-empty. */
67
+ export declare const getDocMarkdown: (page: DocsPage, anchor?: string) => string | undefined;
68
+ //#endregion
69
+ //#region src/formats.d.ts
70
+ /** ORM formats: need live ORM objects (columns, `Op`, etc.); unsupported over JSON. */
71
+ export type OrmFormat = "drizzle" | "prisma" | "sequelize" | "tanstack_db";
72
+ /** `format_query` formats (every {@link ExportFormat} except {@link OrmFormat}s). */
73
+ export type McpExportFormat = Exclude<ExportFormat, OrmFormat>;
74
+ /** `parse_query` source formats. */
75
+ export type McpImportFormat = "sql" | "cel" | "mongodb" | "jsonlogic" | "spel" | "jsonata" | "cypher" | "gql" | "gremlin" | "sparql";
76
+ export declare const ormFormats: readonly OrmFormat[];
77
+ export declare const exportFormats: readonly McpExportFormat[];
78
+ export declare const importFormats: readonly McpImportFormat[];
79
+ //#endregion
80
+ //#region src/handlers.d.ts
81
+ /** JSON-serializable `fields` (array, option groups, or object map). */
82
+ export type FieldsInput = unknown[] | Record<string, unknown>;
83
+ /** JSON-serializable subset of {@link FormatQueryOptions}. */
84
+ export type FormatOptionsInput = Omit<FormatQueryOptions, "format" | "fields" | "validator" | "getOperators" | "getParameters" | "operatorProcessor" | "valueProcessor" | "ruleProcessor" | "ruleGroupProcessor"> & {
85
+ fields?: FieldsInput;
86
+ };
87
+ /** JSON-serializable parser options. */
88
+ export interface ParseOptionsInput {
89
+ fields?: FieldsInput;
90
+ independentCombinators?: boolean;
91
+ listsAsArrays?: boolean;
92
+ generateIDs?: boolean;
93
+ paramPrefix?: string;
94
+ params?: unknown[] | Record<string, unknown>;
95
+ }
96
+ export interface FormatQueryArgs {
97
+ query: unknown;
98
+ format: string;
99
+ options?: FormatOptionsInput;
100
+ }
101
+ export interface ParseQueryArgs {
102
+ input: unknown;
103
+ sourceFormat: string;
104
+ options?: ParseOptionsInput;
105
+ }
106
+ export interface ConvertQueryArgs {
107
+ input: unknown;
108
+ from: string;
109
+ to: string;
110
+ fields?: FieldsInput;
111
+ parseOptions?: ParseOptionsInput;
112
+ formatOptions?: FormatOptionsInput;
113
+ }
114
+ export interface ValidateQueryArgs {
115
+ query: unknown;
116
+ fields: FieldsInput;
117
+ queryType?: "standard" | "ic";
118
+ }
119
+ export interface GetQuerySchemaArgs {
120
+ fields: FieldsInput;
121
+ options?: GetQueryJsonSchemaOptions;
122
+ }
123
+ export interface SearchDocsArgs {
124
+ query: string;
125
+ limit?: number;
126
+ }
127
+ export interface GetDocArgs {
128
+ page: string;
129
+ }
130
+ /** Validation issue reported by `validate_query`. */
131
+ export interface ValidationIssue {
132
+ code: string;
133
+ message: string;
134
+ path: number[];
135
+ }
136
+ export declare const ok: (structured: Record<string, unknown>, text?: string) => ToolResult;
137
+ export declare const fail: (message: string) => ToolResult;
138
+ /** Parses `query` input (object or JSON string). Throws {@link InputError}. */
139
+ export declare const parseQueryInput: (query: unknown) => unknown;
140
+ /** Structural checks `diagnostics` assumes (group `rules` array, rule `field`/`operator`). */
141
+ export declare const checkShape: (q: unknown, path?: number[]) => ValidationIssue[];
142
+ export declare const handleFormatQuery: (args: FormatQueryArgs) => Promise<ToolResult>;
143
+ export declare const handleParseQuery: (args: ParseQueryArgs) => Promise<ToolResult>;
144
+ export declare const handleConvertQuery: (args: ConvertQueryArgs) => Promise<ToolResult>;
145
+ export declare const handleValidateQuery: (args: ValidateQueryArgs) => Promise<ToolResult>;
146
+ export declare const handleGetQuerySchema: (args: GetQuerySchemaArgs) => Promise<ToolResult>;
147
+ export declare const handleSearchDocs: (args: SearchDocsArgs) => Promise<ToolResult>;
148
+ export declare const handleGetDoc: (args: GetDocArgs) => Promise<ToolResult>;
149
+ //#endregion
150
+ //#region src/prompts.d.ts
151
+ /** MCP `GetPromptResult` subset. */
152
+ export type PromptResult = {
153
+ description?: string;
154
+ messages: {
155
+ role: "user";
156
+ content: {
157
+ type: "text";
158
+ text: string;
159
+ };
160
+ }[];
161
+ };
162
+ /** `setup_query_builder` prompt. */
163
+ export declare const setupQueryBuilderPrompt: (uiLibrary?: string, fields?: string) => PromptResult;
164
+ /** `convert_filter` prompt. */
165
+ export declare const convertFilterPrompt: (input: string, from?: string, to?: string) => PromptResult;
166
+ //#endregion
167
+ //#region src/server.d.ts
168
+ /** Server name advertised to clients. */
169
+ export declare const serverName = "react-querybuilder";
170
+ /**
171
+ * Creates the React Query Builder MCP server (tools, resources, prompts). Transport-agnostic;
172
+ * see `cli.ts` for stdio.
173
+ */
174
+ export declare const createServer: () => McpServer;
175
+ //#endregion
176
+ export type { DocsIndex, DocsPage, DocsSection, ToolResult };
177
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export { a as checkShape, r as convertFilterPrompt, t as createServer, y as docsIndex, g as exportFormats, o as fail, b as getDocMarkdown, x as getPageMarkdown, S as getSectionMarkdown, s as handleConvertQuery, c as handleFormatQuery, l as handleGetDoc, u as handleGetQuerySchema, d as handleParseQuery, f as handleSearchDocs, p as handleValidateQuery, _ as importFormats, C as makeSnippet, m as ok, v as ormFormats, h as parseQueryInput, w as resolveDocRef, T as searchDocs, E as sectionTitle, D as sectionUrl, n as serverName, i as setupQueryBuilderPrompt } from "./server-CEaTrVub.mjs";