@regle/mcp-server 1.14.7-beta.4 → 1.14.7
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/regle-mcp-server.js +145 -133
- package/package.json +1 -1
package/dist/regle-mcp-server.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
+
import { createHash } from "crypto";
|
|
6
|
+
import { hostname, userInfo } from "os";
|
|
5
7
|
import { PostHog } from "posthog-node";
|
|
6
8
|
|
|
7
9
|
var docs_data_default = {
|
|
@@ -1664,7 +1666,7 @@ function searchApi(query) {
|
|
|
1664
1666
|
return results;
|
|
1665
1667
|
}
|
|
1666
1668
|
|
|
1667
|
-
var version = "1.14.7
|
|
1669
|
+
var version = "1.14.7";
|
|
1668
1670
|
|
|
1669
1671
|
let posthogClient = null;
|
|
1670
1672
|
posthogClient = new PostHog("phc_kqgJoylCpKkGkkRGxb4MyN2mViehoQcUFEGwVkk4l8E", {
|
|
@@ -1672,86 +1674,29 @@ posthogClient = new PostHog("phc_kqgJoylCpKkGkkRGxb4MyN2mViehoQcUFEGwVkk4l8E", {
|
|
|
1672
1674
|
flushAt: 1,
|
|
1673
1675
|
flushInterval: 0
|
|
1674
1676
|
});
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
+
/**
|
|
1678
|
+
* Get an anonymous hash to differentiate users without storing identifiable info
|
|
1679
|
+
*/
|
|
1680
|
+
function getMachineFingerprint() {
|
|
1681
|
+
const raw = [hostname(), userInfo().username].join("-");
|
|
1682
|
+
return createHash("sha256").update(raw).digest("hex").slice(0, 16);
|
|
1677
1683
|
}
|
|
1678
1684
|
function getBaseProperties(clientInfo) {
|
|
1679
1685
|
return {
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
regle_mcp_server_version: version
|
|
1686
|
+
clientName: clientInfo.clientName,
|
|
1687
|
+
regleMcpServerVersion: version
|
|
1683
1688
|
};
|
|
1684
1689
|
}
|
|
1685
|
-
function
|
|
1686
|
-
if (!posthogClient) return;
|
|
1687
|
-
posthogClient.capture({
|
|
1688
|
-
distinctId: getDistinctId(params.clientName),
|
|
1689
|
-
event: "mcp_server_connected",
|
|
1690
|
-
properties: {
|
|
1691
|
-
...getBaseProperties(params),
|
|
1692
|
-
protocol_version: params.protocolVersion
|
|
1693
|
-
}
|
|
1694
|
-
});
|
|
1695
|
-
}
|
|
1696
|
-
function trackToolCall(params) {
|
|
1690
|
+
function captureEvent(event, clientInfo, inputArgs) {
|
|
1697
1691
|
if (!posthogClient) return;
|
|
1692
|
+
const { success, ...rest } = inputArgs ?? {};
|
|
1698
1693
|
posthogClient.capture({
|
|
1699
|
-
distinctId:
|
|
1700
|
-
event
|
|
1694
|
+
distinctId: getMachineFingerprint(),
|
|
1695
|
+
event,
|
|
1701
1696
|
properties: {
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
...params.errorMessage && { error_message: params.errorMessage }
|
|
1706
|
-
}
|
|
1707
|
-
});
|
|
1708
|
-
}
|
|
1709
|
-
function trackSearchQuery(params) {
|
|
1710
|
-
if (!posthogClient) return;
|
|
1711
|
-
posthogClient.capture({
|
|
1712
|
-
distinctId: getDistinctId(params.clientName),
|
|
1713
|
-
event: "mcp_search_query",
|
|
1714
|
-
properties: {
|
|
1715
|
-
...getBaseProperties(params),
|
|
1716
|
-
query: params.query,
|
|
1717
|
-
result_count: params.resultCount,
|
|
1718
|
-
tool_name: params.toolName
|
|
1719
|
-
}
|
|
1720
|
-
});
|
|
1721
|
-
}
|
|
1722
|
-
function trackDocAccessed(params) {
|
|
1723
|
-
if (!posthogClient) return;
|
|
1724
|
-
posthogClient.capture({
|
|
1725
|
-
distinctId: getDistinctId(params.clientName),
|
|
1726
|
-
event: "mcp_doc_accessed",
|
|
1727
|
-
properties: {
|
|
1728
|
-
...getBaseProperties(params),
|
|
1729
|
-
doc_id: params.docId,
|
|
1730
|
-
doc_category: params.docCategory
|
|
1731
|
-
}
|
|
1732
|
-
});
|
|
1733
|
-
}
|
|
1734
|
-
function trackRuleLookup(params) {
|
|
1735
|
-
if (!posthogClient) return;
|
|
1736
|
-
posthogClient.capture({
|
|
1737
|
-
distinctId: getDistinctId(params.clientName),
|
|
1738
|
-
event: "mcp_rule_lookup",
|
|
1739
|
-
properties: {
|
|
1740
|
-
...getBaseProperties(params),
|
|
1741
|
-
rule_name: params.ruleName,
|
|
1742
|
-
found: params.found
|
|
1743
|
-
}
|
|
1744
|
-
});
|
|
1745
|
-
}
|
|
1746
|
-
function trackHelperLookup(params) {
|
|
1747
|
-
if (!posthogClient) return;
|
|
1748
|
-
posthogClient.capture({
|
|
1749
|
-
distinctId: getDistinctId(params.clientName),
|
|
1750
|
-
event: "mcp_helper_lookup",
|
|
1751
|
-
properties: {
|
|
1752
|
-
...getBaseProperties(params),
|
|
1753
|
-
helper_name: params.helperName,
|
|
1754
|
-
found: params.found
|
|
1697
|
+
success,
|
|
1698
|
+
...getBaseProperties(clientInfo),
|
|
1699
|
+
...rest && { inputArgs: rest }
|
|
1755
1700
|
}
|
|
1756
1701
|
});
|
|
1757
1702
|
}
|
|
@@ -1792,20 +1737,10 @@ function registerTrackedTool(name, config, handler) {
|
|
|
1792
1737
|
server.registerTool(name, config, async (args) => {
|
|
1793
1738
|
const clientInfo = getClientInfo();
|
|
1794
1739
|
try {
|
|
1795
|
-
|
|
1796
|
-
const isError = "isError" in result && result.isError === true;
|
|
1797
|
-
trackToolCall({
|
|
1798
|
-
toolName: name,
|
|
1799
|
-
success: !isError,
|
|
1800
|
-
...clientInfo,
|
|
1801
|
-
...isError && { errorMessage: JSON.stringify(result.content) }
|
|
1802
|
-
});
|
|
1803
|
-
return result;
|
|
1740
|
+
return await handler(args, clientInfo);
|
|
1804
1741
|
} catch (error) {
|
|
1805
|
-
|
|
1806
|
-
toolName: name,
|
|
1742
|
+
captureEvent(name, clientInfo, {
|
|
1807
1743
|
success: false,
|
|
1808
|
-
...clientInfo,
|
|
1809
1744
|
errorMessage: error instanceof Error ? error.message : String(error)
|
|
1810
1745
|
});
|
|
1811
1746
|
return Promise.reject(error);
|
|
@@ -1832,12 +1767,22 @@ registerTrackedTool("regle-get-documentation", {
|
|
|
1832
1767
|
inputSchema: z.object({ id: z.string().describe("The documentation page ID (e.g., \"core-concepts-rules-built-in-rules\")") })
|
|
1833
1768
|
}, async ({ id }, clientInfo) => {
|
|
1834
1769
|
const doc = getDocById(id);
|
|
1835
|
-
if (!doc)
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1770
|
+
if (!doc) {
|
|
1771
|
+
const availableIds = docs.map((d) => d.id);
|
|
1772
|
+
captureEvent("regle-get-documentation", clientInfo, {
|
|
1773
|
+
toolName: "regle-get-documentation",
|
|
1774
|
+
success: false,
|
|
1775
|
+
errorMessage: "Documentation page not found",
|
|
1776
|
+
requestedId: id,
|
|
1777
|
+
availableIds
|
|
1778
|
+
});
|
|
1779
|
+
return errorResponse("Documentation page not found", {
|
|
1780
|
+
requestedId: id,
|
|
1781
|
+
availableIds
|
|
1782
|
+
});
|
|
1783
|
+
}
|
|
1784
|
+
captureEvent("regle-get-documentation", clientInfo, {
|
|
1785
|
+
success: true,
|
|
1841
1786
|
docId: doc.id,
|
|
1842
1787
|
docCategory: doc.category
|
|
1843
1788
|
});
|
|
@@ -1854,9 +1799,15 @@ registerTrackedTool("regle-get-usage-guide", {
|
|
|
1854
1799
|
inputSchema: z.object({})
|
|
1855
1800
|
}, async (_args, clientInfo) => {
|
|
1856
1801
|
const doc = getDocById("core-concepts-index");
|
|
1857
|
-
if (!doc)
|
|
1858
|
-
|
|
1859
|
-
|
|
1802
|
+
if (!doc) {
|
|
1803
|
+
captureEvent("regle-get-usage-guide", clientInfo, {
|
|
1804
|
+
success: false,
|
|
1805
|
+
errorMessage: "useRegle guide not found"
|
|
1806
|
+
});
|
|
1807
|
+
return errorResponse("useRegle guide not found");
|
|
1808
|
+
}
|
|
1809
|
+
captureEvent("regle-get-usage-guide", clientInfo, {
|
|
1810
|
+
success: true,
|
|
1860
1811
|
docId: doc.id,
|
|
1861
1812
|
docCategory: doc.category
|
|
1862
1813
|
});
|
|
@@ -1872,9 +1823,15 @@ registerTrackedTool("regle-get-vuelidate-migration-guide", {
|
|
|
1872
1823
|
inputSchema: z.object({})
|
|
1873
1824
|
}, async (_args, clientInfo) => {
|
|
1874
1825
|
const doc = getDocById("introduction-migrate-from-vuelidate");
|
|
1875
|
-
if (!doc)
|
|
1876
|
-
|
|
1877
|
-
|
|
1826
|
+
if (!doc) {
|
|
1827
|
+
captureEvent("regle-get-vuelidate-migration-guide", clientInfo, {
|
|
1828
|
+
success: false,
|
|
1829
|
+
errorMessage: "Vuelidate migration guide not found"
|
|
1830
|
+
});
|
|
1831
|
+
return errorResponse("Vuelidate migration guide not found");
|
|
1832
|
+
}
|
|
1833
|
+
captureEvent("regle-get-vuelidate-migration-guide", clientInfo, {
|
|
1834
|
+
success: true,
|
|
1878
1835
|
docId: doc.id,
|
|
1879
1836
|
docCategory: doc.category
|
|
1880
1837
|
});
|
|
@@ -1894,16 +1851,27 @@ registerTrackedTool("regle-search-documentation", {
|
|
|
1894
1851
|
})
|
|
1895
1852
|
}, async ({ query, limit }, clientInfo) => {
|
|
1896
1853
|
const results = searchDocs(query).slice(0, limit);
|
|
1897
|
-
|
|
1898
|
-
|
|
1854
|
+
if (results.length === 0) {
|
|
1855
|
+
captureEvent("regle-search-documentation", clientInfo, {
|
|
1856
|
+
success: false,
|
|
1857
|
+
errorMessage: "No results found",
|
|
1858
|
+
query,
|
|
1859
|
+
resultCount: 0,
|
|
1860
|
+
results: [],
|
|
1861
|
+
suggestions: categories
|
|
1862
|
+
});
|
|
1863
|
+
return jsonResponse({
|
|
1864
|
+
query,
|
|
1865
|
+
resultCount: 0,
|
|
1866
|
+
results: [],
|
|
1867
|
+
suggestions: categories
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
captureEvent("regle-search-documentation", clientInfo, {
|
|
1871
|
+
success: true,
|
|
1899
1872
|
query,
|
|
1900
1873
|
resultCount: results.length,
|
|
1901
|
-
|
|
1902
|
-
});
|
|
1903
|
-
if (results.length === 0) return jsonResponse({
|
|
1904
|
-
query,
|
|
1905
|
-
resultCount: 0,
|
|
1906
|
-
results: [],
|
|
1874
|
+
results: results.map((doc) => doc.id),
|
|
1907
1875
|
suggestions: categories
|
|
1908
1876
|
});
|
|
1909
1877
|
const formattedResults = results.map((doc) => ({
|
|
@@ -1950,15 +1918,18 @@ registerTrackedTool("regle-get-rule-reference", {
|
|
|
1950
1918
|
inputSchema: z.object({ name: z.string().describe("The rule name (e.g., \"required\", \"email\", \"minLength\")") })
|
|
1951
1919
|
}, async ({ name }, clientInfo) => {
|
|
1952
1920
|
const rule = getApiByName(name);
|
|
1953
|
-
trackRuleLookup({
|
|
1954
|
-
...clientInfo,
|
|
1955
|
-
ruleName: name,
|
|
1956
|
-
found: !!rule
|
|
1957
|
-
});
|
|
1958
1921
|
if (!rule) {
|
|
1959
1922
|
const allRules = getRulesFromDocs();
|
|
1923
|
+
captureEvent("regle-get-rule-reference", clientInfo, {
|
|
1924
|
+
success: false,
|
|
1925
|
+
errorMessage: `Rule "${name}" not found`
|
|
1926
|
+
});
|
|
1960
1927
|
return errorResponse(`Rule "${name}" not found`, { availableRules: allRules.map((r) => r.name) });
|
|
1961
1928
|
}
|
|
1929
|
+
captureEvent("regle-get-rule-reference", clientInfo, {
|
|
1930
|
+
success: true,
|
|
1931
|
+
ruleName: name
|
|
1932
|
+
});
|
|
1962
1933
|
return jsonResponse({
|
|
1963
1934
|
name: rule.name,
|
|
1964
1935
|
description: rule.description,
|
|
@@ -1972,9 +1943,15 @@ registerTrackedTool("regle-list-validation-properties", {
|
|
|
1972
1943
|
inputSchema: z.object({})
|
|
1973
1944
|
}, async (_args, clientInfo) => {
|
|
1974
1945
|
const doc = getDocById("core-concepts-validation-properties");
|
|
1975
|
-
if (!doc)
|
|
1976
|
-
|
|
1977
|
-
|
|
1946
|
+
if (!doc) {
|
|
1947
|
+
captureEvent("regle-list-validation-properties", clientInfo, {
|
|
1948
|
+
success: false,
|
|
1949
|
+
errorMessage: "Validation properties documentation not found"
|
|
1950
|
+
});
|
|
1951
|
+
return errorResponse("Validation properties documentation not found");
|
|
1952
|
+
}
|
|
1953
|
+
captureEvent("regle-list-validation-properties", clientInfo, {
|
|
1954
|
+
success: true,
|
|
1978
1955
|
docId: doc.id,
|
|
1979
1956
|
docCategory: doc.category
|
|
1980
1957
|
});
|
|
@@ -1988,9 +1965,16 @@ registerTrackedTool("regle-list-validation-properties", {
|
|
|
1988
1965
|
registerTrackedTool("regle-list-helpers", {
|
|
1989
1966
|
title: "Get a reference of all validation helper utilities available in Regle",
|
|
1990
1967
|
inputSchema: z.object({})
|
|
1991
|
-
}, async (_args,
|
|
1968
|
+
}, async (_args, clientInfo) => {
|
|
1992
1969
|
const helpers = getHelpersFromDocs();
|
|
1993
|
-
if (helpers.length === 0)
|
|
1970
|
+
if (helpers.length === 0) {
|
|
1971
|
+
captureEvent("regle-list-helpers", clientInfo, {
|
|
1972
|
+
success: false,
|
|
1973
|
+
docId: "core-concepts-rules-validations-helpers",
|
|
1974
|
+
docCategory: "core-concepts"
|
|
1975
|
+
});
|
|
1976
|
+
return errorResponse("Validation helpers documentation not found");
|
|
1977
|
+
}
|
|
1994
1978
|
const guards = helpers.filter((h) => h.category === "guard");
|
|
1995
1979
|
const operations = helpers.filter((h) => h.category === "operation");
|
|
1996
1980
|
const coerces = helpers.filter((h) => h.category === "coerce");
|
|
@@ -1998,6 +1982,11 @@ registerTrackedTool("regle-list-helpers", {
|
|
|
1998
1982
|
name: h.name,
|
|
1999
1983
|
description: h.description
|
|
2000
1984
|
}));
|
|
1985
|
+
captureEvent("regle-list-helpers", clientInfo, {
|
|
1986
|
+
success: true,
|
|
1987
|
+
docId: "core-concepts-rules-validations-helpers",
|
|
1988
|
+
docCategory: "core-concepts"
|
|
1989
|
+
});
|
|
2001
1990
|
return jsonResponse({
|
|
2002
1991
|
title: "Validation Helpers",
|
|
2003
1992
|
package: "@regle/rules",
|
|
@@ -2036,15 +2025,19 @@ registerTrackedTool("regle-get-helper-reference", {
|
|
|
2036
2025
|
inputSchema: z.object({ name: z.string().describe("The helper name (e.g., \"isFilled\", \"getSize\", \"toNumber\")") })
|
|
2037
2026
|
}, async ({ name }, clientInfo) => {
|
|
2038
2027
|
const helper = getApiByName(name);
|
|
2039
|
-
trackHelperLookup({
|
|
2040
|
-
...clientInfo,
|
|
2041
|
-
helperName: name,
|
|
2042
|
-
found: !!helper
|
|
2043
|
-
});
|
|
2044
2028
|
if (!helper) {
|
|
2045
2029
|
const allHelpers = getHelpersFromDocs();
|
|
2030
|
+
captureEvent("regle-get-helper-reference", clientInfo, {
|
|
2031
|
+
success: false,
|
|
2032
|
+
errorMessage: `Helper "${name}" not found`,
|
|
2033
|
+
availableHelpers: allHelpers.map((h) => h.name)
|
|
2034
|
+
});
|
|
2046
2035
|
return errorResponse(`Helper "${name}" not found`, { availableHelpers: allHelpers.map((h) => h.name) });
|
|
2047
2036
|
}
|
|
2037
|
+
captureEvent("regle-get-helper-reference", clientInfo, {
|
|
2038
|
+
success: true,
|
|
2039
|
+
helperName: name
|
|
2040
|
+
});
|
|
2048
2041
|
return jsonResponse({
|
|
2049
2042
|
name: helper.name,
|
|
2050
2043
|
description: helper.description,
|
|
@@ -2078,8 +2071,20 @@ registerTrackedTool("regle-get-api-reference", {
|
|
|
2078
2071
|
}
|
|
2079
2072
|
if (search) {
|
|
2080
2073
|
const results = searchApi(search);
|
|
2081
|
-
|
|
2082
|
-
|
|
2074
|
+
if (results.length === 0) {
|
|
2075
|
+
captureEvent("regle-get-api-reference", clientInfo, {
|
|
2076
|
+
success: false,
|
|
2077
|
+
errorMessage: "No results found",
|
|
2078
|
+
query: search,
|
|
2079
|
+
resultCount: 0
|
|
2080
|
+
});
|
|
2081
|
+
return errorResponse(`No results found`, {
|
|
2082
|
+
availablePackages: apiPackages,
|
|
2083
|
+
availableExports: results.map((r) => r.name)
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
captureEvent("mcp_search_query", clientInfo, {
|
|
2087
|
+
success: true,
|
|
2083
2088
|
query: search,
|
|
2084
2089
|
resultCount: results.length,
|
|
2085
2090
|
toolName: "regle-get-api-reference"
|
|
@@ -2097,7 +2102,14 @@ registerTrackedTool("regle-get-api-reference", {
|
|
|
2097
2102
|
}
|
|
2098
2103
|
if (packageName) {
|
|
2099
2104
|
const apis = getApiByPackage(packageName);
|
|
2100
|
-
if (apis.length === 0)
|
|
2105
|
+
if (apis.length === 0) {
|
|
2106
|
+
captureEvent("regle-get-api-reference", clientInfo, {
|
|
2107
|
+
success: false,
|
|
2108
|
+
errorMessage: `Package "${packageName}" not found or has no exports`,
|
|
2109
|
+
availablePackages: apiPackages
|
|
2110
|
+
});
|
|
2111
|
+
return errorResponse(`Package "${packageName}" not found or has no exports`, { availablePackages: apiPackages });
|
|
2112
|
+
}
|
|
2101
2113
|
return jsonResponse({
|
|
2102
2114
|
package: packageName,
|
|
2103
2115
|
exportCount: apis.length,
|
|
@@ -2110,24 +2122,24 @@ registerTrackedTool("regle-get-api-reference", {
|
|
|
2110
2122
|
}))
|
|
2111
2123
|
});
|
|
2112
2124
|
}
|
|
2125
|
+
const packageSummary = apiPackages.map((pkg) => ({
|
|
2126
|
+
package: pkg,
|
|
2127
|
+
exportCount: getApiByPackage(pkg).length
|
|
2128
|
+
}));
|
|
2129
|
+
captureEvent("regle-get-api-reference", clientInfo, {
|
|
2130
|
+
success: true,
|
|
2131
|
+
packageName,
|
|
2132
|
+
packageSummary
|
|
2133
|
+
});
|
|
2113
2134
|
return jsonResponse({
|
|
2114
2135
|
message: "Available Regle API packages",
|
|
2115
|
-
packages:
|
|
2116
|
-
package: pkg,
|
|
2117
|
-
exportCount: getApiByPackage(pkg).length
|
|
2118
|
-
})),
|
|
2136
|
+
packages: packageSummary,
|
|
2119
2137
|
usage: "Use \"package\" to list exports, \"name\" to get specific export details, or \"search\" to find exports"
|
|
2120
2138
|
});
|
|
2121
2139
|
});
|
|
2122
2140
|
async function main() {
|
|
2123
2141
|
const transport = new StdioServerTransport();
|
|
2124
2142
|
await server.connect(transport);
|
|
2125
|
-
const clientInfo = server.server.getClientVersion();
|
|
2126
|
-
trackServerConnected({
|
|
2127
|
-
clientName: clientInfo?.name,
|
|
2128
|
-
clientVersion: clientInfo?.version
|
|
2129
|
-
});
|
|
2130
|
-
console.error("Regle MCP Server running on stdio");
|
|
2131
2143
|
}
|
|
2132
2144
|
async function gracefulShutdown() {
|
|
2133
2145
|
await shutdown();
|