From e2f816b6c1ec8ac3c4ad35dfbc89b9cd6983428a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 21 Nov 2025 17:44:15 -0600 Subject: [PATCH] Add MCP support --- package-lock.json | 667 +++++++++++++++++++++++- package.json | 1 + src/components/AISettingsProvider.tsx | 26 +- src/components/MCPServersSection.tsx | 210 ++++++++ src/components/ModelSelector.test.tsx | 15 +- src/components/Shakespeare/ChatPane.tsx | 38 +- src/contexts/AISettingsContext.ts | 12 + src/hooks/useAIProjectId.test.ts | 26 +- src/hooks/useMCPServerStatus.ts | 45 ++ src/hooks/useMCPTools.ts | 39 ++ src/lib/MCPClient.ts | 163 ++++++ src/lib/configUtils.test.ts | 7 +- src/lib/configUtils.ts | 16 +- src/lib/tools/MCPTool.ts | 48 ++ src/locales/en.json | 18 + src/pages/AISettings.tsx | 4 + 16 files changed, 1306 insertions(+), 29 deletions(-) create mode 100644 src/components/MCPServersSection.tsx create mode 100644 src/hooks/useMCPServerStatus.ts create mode 100644 src/hooks/useMCPTools.ts create mode 100644 src/lib/MCPClient.ts create mode 100644 src/lib/tools/MCPTool.ts diff --git a/package-lock.json b/package-lock.json index 3cb66e79..5e235ccb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@getalby/sdk": "^6.0.1", "@hookform/resolvers": "^3.9.0", "@isomorphic-git/lightning-fs": "^4.6.2", + "@modelcontextprotocol/sdk": "^1.22.0", "@mozilla/readability": "^0.6.0", "@nostrify/nostrify": "^0.47.1", "@nostrify/react": "^0.2.17", @@ -2866,6 +2867,60 @@ "integrity": "sha512-Y28PR25bHXUg88kCV7nivXrP2Nj2RueZ3/l/jdx6J9f8J4nsEGcgX0Qe6lt7Pa+J79+kPiJU3LguR6O/6zrLOw==", "license": "BSD-2-Clause" }, + "node_modules/@modelcontextprotocol/sdk": { + "version": "1.22.0", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.22.0.tgz", + "integrity": "sha512-VUpl106XVTCpDmTBil2ehgJZjhyLY2QZikzF8NvTXtLRF1CvO5iEE2UNZdVIUer35vFOwMKYeUGbjJtvPWan3g==", + "license": "MIT", + "dependencies": { + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1", + "content-type": "^1.0.5", + "cors": "^2.8.5", + "cross-spawn": "^7.0.5", + "eventsource": "^3.0.2", + "eventsource-parser": "^3.0.0", + "express": "^5.0.1", + "express-rate-limit": "^7.5.0", + "pkce-challenge": "^5.0.0", + "raw-body": "^3.0.0", + "zod": "^3.23.8", + "zod-to-json-schema": "^3.24.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@cfworker/json-schema": "^4.1.1" + }, + "peerDependenciesMeta": { + "@cfworker/json-schema": { + "optional": true + } + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/ajv": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, "node_modules/@mozilla/readability": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/@mozilla/readability/-/readability-0.6.0.tgz", @@ -6103,6 +6158,19 @@ "integrity": "sha512-RYTOHHdWipFUliRFMCS4X2Yn2X8M87V/OpSqWzKKOGhzqyUxzyVmhHDH9sAvG+ZuQf/TAOFsLCpMw09I1ufUnA==", "license": "MIT" }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/acorn": { "version": "8.15.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", @@ -6152,6 +6220,45 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/ajv-formats/node_modules/ajv": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats/node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, "node_modules/ansi-regex": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", @@ -6500,6 +6607,26 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/body-parser": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.0.tgz", + "integrity": "sha512-02qvAaxv8tp7fBa/mw1ga98OGm+eCbqzJOKoRt70sLmfEEi+jyBYVTDGfCL/k06/4EMk/z01gCe7HoCH/f2LTg==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.0", + "http-errors": "^2.0.0", + "iconv-lite": "^0.6.3", + "on-finished": "^2.4.1", + "qs": "^6.14.0", + "raw-body": "^3.0.0", + "type-is": "^2.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/boolean": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/boolean/-/boolean-3.2.0.tgz", @@ -6607,6 +6734,15 @@ "dev": true, "license": "MIT" }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/cac": { "version": "6.7.14", "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", @@ -7034,6 +7170,28 @@ "integrity": "sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w==", "license": "MIT" }, + "node_modules/content-disposition": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.1.tgz", + "integrity": "sha512-oIXISMynqSqm241k6kcQ5UwttDILMK4BiurCfGEREw6+X9jkkpEe5T9FZaApyLGGOnFuyMWZpdolTXMtvEJ08Q==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/convert-source-map": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", @@ -7041,6 +7199,24 @@ "dev": true, "license": "MIT" }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, "node_modules/core-js-compat": { "version": "3.46.0", "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.46.0.tgz", @@ -7061,6 +7237,19 @@ "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", "license": "MIT" }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/crc-32": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz", @@ -7484,6 +7673,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/dequal": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", @@ -7582,6 +7780,12 @@ "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", "license": "MIT" }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, "node_modules/ejs": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", @@ -7658,6 +7862,15 @@ "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", "license": "MIT" }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/end-of-stream": { "version": "1.4.5", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", @@ -7908,6 +8121,12 @@ "node": ">=6" } }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, "node_modules/escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", @@ -8141,12 +8360,42 @@ "node": ">=0.10.0" } }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", "license": "MIT" }, + "node_modules/eventsource": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz", + "integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==", + "license": "MIT", + "dependencies": { + "eventsource-parser": "^3.0.1" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/eventsource-parser": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.6.tgz", + "integrity": "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/expect-type": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.2.1.tgz", @@ -8157,6 +8406,63 @@ "node": ">=12.0.0" } }, + "node_modules/express": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz", + "integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.0", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express-rate-limit": { + "version": "7.5.1", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-7.5.1.tgz", + "integrity": "sha512-7iN8iPMDzOMHPUYllBEsQdWVB6fPDMPqwjBaFrgr4Jgr/+okjvzAy+UHlYYL/Vs0OsOrMkwS6PJDkFlJwoxUnw==", + "license": "MIT", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/express-rate-limit" + }, + "peerDependencies": { + "express": ">= 4.11" + } + }, "node_modules/extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", @@ -8200,7 +8506,6 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true, "license": "MIT" }, "node_modules/fast-equals": { @@ -8264,7 +8569,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz", "integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==", - "dev": true, "funding": [ { "type": "github", @@ -8354,6 +8658,23 @@ "node": ">=8" } }, + "node_modules/finalhandler": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.0.tgz", + "integrity": "sha512-/t88Ty3d5JWQbWYgaOGCCYfXRwV1+be02WqYYlL6h0lEiUAMPM8o8qKGO01YIkOHzka2up08wvgYD0mDiI+q3Q==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -8423,6 +8744,15 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/fraction.js": { "version": "4.3.7", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz", @@ -8437,6 +8767,15 @@ "url": "https://github.com/sponsors/rawify" } }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/fs-extra": { "version": "9.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", @@ -9213,6 +9552,26 @@ "dev": true, "license": "BSD-2-Clause" }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/http-proxy-agent": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", @@ -9290,7 +9649,6 @@ "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "dev": true, "license": "MIT", "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" @@ -9436,6 +9794,15 @@ "node": ">=12" } }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/is-array-buffer": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.5.tgz", @@ -9744,6 +10111,12 @@ "dev": true, "license": "MIT" }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, "node_modules/is-regex": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.2.1.tgz", @@ -10903,6 +11276,27 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -11522,6 +11916,31 @@ "node": ">=16" } }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/mimic-response": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", @@ -11638,6 +12057,15 @@ "dev": true, "license": "MIT" }, + "node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/node-releases": { "version": "2.0.26", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.26.tgz", @@ -11769,7 +12197,6 @@ "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -11809,6 +12236,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -11980,6 +12419,15 @@ "url": "https://github.com/inikulin/parse5?sponsor=1" } }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/path-browserify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", @@ -12036,6 +12484,16 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/path-to-regexp": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.3.0.tgz", + "integrity": "sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/pathe": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", @@ -12095,6 +12553,15 @@ "node": ">= 6" } }, + "node_modules/pkce-challenge": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.0.tgz", + "integrity": "sha512-ueGLflrrnvwB3xuo/uGob5pd5FN7l0MsLf0Z87o/UQmRtwjvfylfc9MurIxRAWywCYTgrvpXBcqjV4OfCYGCIQ==", + "license": "MIT", + "engines": { + "node": ">=16.20.0" + } + }, "node_modules/pkg-types": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-1.3.1.tgz", @@ -12405,6 +12872,19 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/pump": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.3.tgz", @@ -12443,6 +12923,21 @@ "node": ">=10.13.0" } }, + "node_modules/qs": { + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz", + "integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -12486,6 +12981,46 @@ "safe-buffer": "^5.1.0" } }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/raw-body/node_modules/iconv-lite": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.0.tgz", + "integrity": "sha512-cf6L2Ds3h57VVmkZe+Pn+5APsT7FpqJtEhhieDCvrE2MK5Qk9MyffgQyuxQTm6BChfeZNtcOLHp9IcWRVcIcBQ==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/react": { "version": "18.3.1", "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", @@ -13075,7 +13610,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -13206,6 +13740,22 @@ "fsevents": "~2.3.2" } }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/rrweb-cssom": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.8.0.tgz", @@ -13315,7 +13865,6 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true, "license": "MIT" }, "node_modules/saxes": { @@ -13374,6 +13923,28 @@ "license": "MIT", "optional": true }, + "node_modules/send": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.0.tgz", + "integrity": "sha512-uaW0WwXKpL9blXE2o0bRhoL2EGXIrZxQ2ZQ4mgcfoBxdFmQold+qWsD2jLrfZ0trjKL6vOw0j//eAwcALFjKSw==", + "license": "MIT", + "dependencies": { + "debug": "^4.3.5", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "mime-types": "^3.0.1", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/serialize-error": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-7.0.1.tgz", @@ -13415,6 +13986,21 @@ "randombytes": "^2.1.0" } }, + "node_modules/serve-static": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz", + "integrity": "sha512-61g9pCh0Vnh7IutZjtLGGpTA355+OPn2TyDv/6ivP2h/AdAVX9azsoxmg2/M6nZeQZNYBEwIcsne1mJd9oQItQ==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", @@ -13475,6 +14061,12 @@ "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==", "license": "MIT" }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, "node_modules/sha.js": { "version": "2.4.12", "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.12.tgz", @@ -13536,7 +14128,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -13556,7 +14147,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -13573,7 +14163,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", - "dev": true, "license": "MIT", "dependencies": { "call-bound": "^1.0.2", @@ -13592,7 +14181,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", - "dev": true, "license": "MIT", "dependencies": { "call-bound": "^1.0.2", @@ -13785,6 +14373,15 @@ "dev": true, "license": "MIT" }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/std-env": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.9.0.tgz", @@ -14509,6 +15106,15 @@ "node": ">=8.0" } }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, "node_modules/tough-cookie": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.2.tgz", @@ -14615,6 +15221,20 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/type-is": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", + "integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==", + "license": "MIT", + "dependencies": { + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/typed-array-buffer": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/typed-array-buffer/-/typed-array-buffer-1.0.3.tgz", @@ -14955,6 +15575,15 @@ "node": ">= 10.0.0" } }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/unplugin": { "version": "2.3.5", "resolved": "https://registry.npmjs.org/unplugin/-/unplugin-2.3.5.tgz", @@ -15124,6 +15753,15 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "license": "MIT" }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/vaul": { "version": "0.9.9", "resolved": "https://registry.npmjs.org/vaul/-/vaul-0.9.9.tgz", @@ -16360,6 +16998,15 @@ "url": "https://github.com/sponsors/colinhacks" } }, + "node_modules/zod-to-json-schema": { + "version": "3.25.0", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.25.0.tgz", + "integrity": "sha512-HvWtU2UG41LALjajJrML6uQejQhNJx+JBO9IflpSja4R03iNWfKXrj6W2h7ljuLyc1nKS+9yDyL/9tD1U/yBnQ==", + "license": "ISC", + "peerDependencies": { + "zod": "^3.25 || ^4" + } + }, "node_modules/zwitch": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", diff --git a/package.json b/package.json index 33dbadbf..c9c28cda 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@getalby/sdk": "^6.0.1", "@hookform/resolvers": "^3.9.0", "@isomorphic-git/lightning-fs": "^4.6.2", + "@modelcontextprotocol/sdk": "^1.22.0", "@mozilla/readability": "^0.6.0", "@nostrify/nostrify": "^0.47.1", "@nostrify/react": "^0.2.17", diff --git a/src/components/AISettingsProvider.tsx b/src/components/AISettingsProvider.tsx index b808b098..3fe99666 100644 --- a/src/components/AISettingsProvider.tsx +++ b/src/components/AISettingsProvider.tsx @@ -1,6 +1,6 @@ import { useQueryClient } from '@tanstack/react-query'; import { ReactNode, useState, useEffect } from 'react'; -import { AISettingsContext, type AISettings, type AIProvider, type AISettingsContextType } from '@/contexts/AISettingsContext'; +import { AISettingsContext, type AISettings, type AIProvider, type MCPServer, type AISettingsContextType } from '@/contexts/AISettingsContext'; import { useFS } from '@/hooks/useFS'; import { useFSPaths } from '@/hooks/useFSPaths'; import { readAISettings, writeAISettings } from '@/lib/configUtils'; @@ -12,6 +12,7 @@ interface AISettingsProviderProps { const DEFAULT_SETTINGS: AISettings = { providers: [], recentlyUsedModels: [], + mcpServers: {}, }; export function AISettingsProvider({ children }: AISettingsProviderProps) { @@ -128,6 +129,27 @@ export function AISettingsProvider({ children }: AISettingsProviderProps) { }); }; + const setMCPServer = (name: string, server: MCPServer) => { + setSettings(prev => ({ + ...prev, + mcpServers: { + ...(prev.mcpServers || {}), + [name]: server, + }, + })); + }; + + const removeMCPServer = (name: string) => { + setSettings(prev => { + const newMCPServers = { ...(prev.mcpServers || {}) }; + delete newMCPServers[name]; + return { + ...prev, + mcpServers: newMCPServers, + }; + }); + }; + const isConfigured = settings.providers.length > 0; const contextValue: AISettingsContextType = { @@ -137,6 +159,8 @@ export function AISettingsProvider({ children }: AISettingsProviderProps) { removeProvider, setProviders, addRecentlyUsedModel, + setMCPServer, + removeMCPServer, isConfigured, }; diff --git a/src/components/MCPServersSection.tsx b/src/components/MCPServersSection.tsx new file mode 100644 index 00000000..1d93e6da --- /dev/null +++ b/src/components/MCPServersSection.tsx @@ -0,0 +1,210 @@ +import { useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { Server, Trash2, Check } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; +import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; +import { useAISettings } from '@/hooks/useAISettings'; +import { useToast } from '@/hooks/useToast'; +import { useMCPServerStatus } from '@/hooks/useMCPServerStatus'; +import type { MCPServer } from '@/contexts/AISettingsContext'; +import { cn } from '@/lib/utils'; + +function MCPConnectionStatus({ server }: { server: MCPServer }) { + const status = useMCPServerStatus(server); + + return ( +
+
+ + {status} + +
+ ); +} + +export function MCPServersSection() { + const { t } = useTranslation(); + const { settings, setMCPServer, removeMCPServer } = useAISettings(); + const { toast } = useToast(); + const [serverName, setServerName] = useState(''); + const [serverUrl, setServerUrl] = useState(''); + const [serverType] = useState<'streamable-http'>('streamable-http'); // Only streamable-http is supported + + const mcpServers = settings.mcpServers || {}; + const serverEntries = Object.entries(mcpServers); + + const handleAddServer = () => { + if (!serverName.trim() || !serverUrl.trim()) return; + + if (mcpServers[serverName.trim()]) { + toast({ + title: t('error'), + description: t('mcpServerAddFailed'), + variant: 'destructive', + }); + return; + } + + const newServer: MCPServer = { + type: serverType, + url: serverUrl.trim(), + }; + + setMCPServer(serverName.trim(), newServer); + + toast({ + title: t('mcpServerAdded'), + description: t('mcpServerAddedDescription', { name: serverName.trim() }), + }); + + setServerName(''); + setServerUrl(''); + }; + + const handleRemoveServer = (name: string) => { + removeMCPServer(name); + + toast({ + title: t('mcpServerDeleted'), + description: t('mcpServerDeletedDescription', { name }), + }); + }; + + return ( +
+
+

{t('mcpServers')}

+
+ +

+ {t('mcpServersDescription')} +

+ + {/* Configured MCP Servers */} + {serverEntries.length > 0 && ( + + {serverEntries.map(([name, server]) => ( + + +
+ + {name} + +
+
+ +
+
+ + +
+
+ + setMCPServer(name, { ...server, url: e.target.value })} + placeholder="https://example.com/mcp" + /> +
+ +
+
+
+ ))} +
+ )} + + {/* Add New MCP Server */} + + + +
{t('addMcpServer')}
+
+ +
+

+ {t('mcpServerDescription')} +

+
+ + setServerName(e.target.value)} + /> +
+
+ + +

+ Only Streamable HTTP transport is currently supported +

+
+
+ + setServerUrl(e.target.value)} + /> +
+ + {mcpServers[serverName.trim()] && ( +

+ A server with this name already exists +

+ )} +
+
+
+
+ + {serverEntries.length === 0 && ( +

+ {t('noMcpServersConfigured')} +

+ )} +
+ ); +} diff --git a/src/components/ModelSelector.test.tsx b/src/components/ModelSelector.test.tsx index 880afd98..d02c993c 100644 --- a/src/components/ModelSelector.test.tsx +++ b/src/components/ModelSelector.test.tsx @@ -42,14 +42,15 @@ describe('ModelSelector', () => { vi.clearAllMocks(); mockUseAISettings.mockReturnValue({ - settings: { providers: [], recentlyUsedModels: [] }, + settings: { providers: [], recentlyUsedModels: [], mcpServers: {} }, addRecentlyUsedModel: mockAddRecentlyUsedModel, isConfigured: true, updateSettings: vi.fn(), removeProvider: vi.fn(), setProvider: vi.fn(), setProviders: vi.fn(), - + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); mockUseProviderModels.mockReturnValue({ @@ -87,6 +88,8 @@ describe('ModelSelector', () => { removeProvider: vi.fn(), setProvider: vi.fn(), setProviders: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); @@ -140,6 +143,8 @@ describe('ModelSelector', () => { removeProvider: vi.fn(), setProvider: vi.fn(), setProviders: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); @@ -189,6 +194,8 @@ describe('ModelSelector', () => { removeProvider: vi.fn(), setProvider: vi.fn(), setProviders: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); @@ -233,13 +240,15 @@ describe('ModelSelector', () => { }); mockUseAISettings.mockReturnValue({ - settings: { providers: [], recentlyUsedModels: [] }, // No recently used models + settings: { providers: [], recentlyUsedModels: [], mcpServers: {} }, // No recently used models addRecentlyUsedModel: mockAddRecentlyUsedModel, isConfigured: true, updateSettings: vi.fn(), removeProvider: vi.fn(), setProvider: vi.fn(), setProviders: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 72fe5752..b3fdeb4b 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -14,6 +14,7 @@ import { useAppContext } from '@/hooks/useAppContext'; import { useAIChat } from '@/hooks/useAIChat'; import { useProviderModels } from '@/hooks/useProviderModels'; import { useSessionManager } from '@/hooks/useSessionManager'; +import { useMCPTools } from '@/hooks/useMCPTools'; import { AIMessageItem } from '@/components/AIMessageItem'; import { TextEditorViewTool } from '@/lib/tools/TextEditorViewTool'; import { TextEditorWriteTool } from '@/lib/tools/TextEditorWriteTool'; @@ -35,6 +36,7 @@ import { ShellTool } from '@/lib/tools/ShellTool'; import { TypecheckTool } from '@/lib/tools/TypecheckTool'; import { ReadConsoleMessagesTool } from '@/lib/tools/ReadConsoleMessagesTool'; import { SkillTool } from '@/lib/tools/SkillTool'; +import { createMCPTools } from '@/lib/tools/MCPTool'; import { ProjectPreviewConsoleError } from '@/lib/consoleMessages'; import { toolToOpenAI } from '@/lib/tools/openai-adapter'; import { Tool } from '@/lib/tools/Tool'; @@ -148,8 +150,12 @@ export const ChatPane = forwardRef(({ sessionManager.emit('fileChanged', projectId, filePath); }, [sessionManager, projectId]); - const customTools = useMemo(() => { - const baseTools = { + // Fetch MCP tools + const { tools: mcpOpenAITools, clients: mcpClients } = useMCPTools(); + + // Separate built-in tools from MCP tools for clarity + const builtInTools = useMemo(() => { + const tools: Record> = { git_commit: new GitCommitTool(fs, cwd, git), text_editor_view: new TextEditorViewTool(fs, cwd, { projectsPath }), text_editor_write: new TextEditorWriteTool(fs, cwd, { projectsPath, tmpPath, onFileChanged: handleFileChanged }), @@ -173,23 +179,35 @@ export const ChatPane = forwardRef(({ // Add deploy tool only if user is logged in if (user && user.signer) { - return { - ...baseTools, - deploy_project: new DeployProjectTool(fs, cwd, user.signer, projectId), - }; + tools.deploy_project = new DeployProjectTool(fs, cwd, user.signer, projectId); } - return baseTools; + return tools; }, [fs, git, cwd, user, projectId, projectsPath, tmpPath, pluginsPath, config.corsProxy, handleFileChanged]); - // Convert tools to OpenAI format + // MCP tools wrapped for execution + const mcpToolWrappers = useMemo(() => createMCPTools(mcpClients), [mcpClients]); + + // Combined tool executors (for SessionManager to call) + const customTools = useMemo(() => ({ + ...builtInTools, + ...mcpToolWrappers, + }), [builtInTools, mcpToolWrappers]); + + // Convert tools to OpenAI format for AI provider const tools = useMemo(() => { const result: Record = {}; - for (const [name, tool] of Object.entries(customTools)) { + + // Convert built-in tools to OpenAI format + for (const [name, tool] of Object.entries(builtInTools)) { result[name] = toolToOpenAI(name, tool as Tool); } + + // Add MCP tools (already in OpenAI format from useMCPTools) + Object.assign(result, mcpOpenAITools); + return result; - }, [customTools]); + }, [builtInTools, mcpOpenAITools]); // Keep-alive functionality to prevent tab throttling during AI processing const { updateMetadata } = useKeepAlive({ diff --git a/src/contexts/AISettingsContext.ts b/src/contexts/AISettingsContext.ts index 85d5d7cd..7fa69eb4 100644 --- a/src/contexts/AISettingsContext.ts +++ b/src/contexts/AISettingsContext.ts @@ -8,9 +8,19 @@ export interface AIProvider { proxy?: boolean; } +export interface MCPServer { + type: 'streamable-http'; + url: string; +} + +export interface MCPServers { + [key: string]: MCPServer; +} + export interface AISettings { providers: AIProvider[]; recentlyUsedModels: string[]; + mcpServers?: MCPServers; } export interface AISettingsContextType { @@ -20,6 +30,8 @@ export interface AISettingsContextType { removeProvider: (id: string) => void; setProviders: (providers: AIProvider[]) => void; addRecentlyUsedModel: (modelId: string) => void; + setMCPServer: (name: string, server: MCPServer) => void; + removeMCPServer: (name: string) => void; isConfigured: boolean; } diff --git a/src/hooks/useAIProjectId.test.ts b/src/hooks/useAIProjectId.test.ts index 26026962..11a2bb82 100644 --- a/src/hooks/useAIProjectId.test.ts +++ b/src/hooks/useAIProjectId.test.ts @@ -93,13 +93,15 @@ describe('useAIProjectId', () => { it('should return not configured when AI settings are not configured', () => { mockUseAISettings.mockReturnValue({ - settings: { providers: [], recentlyUsedModels: [] }, + settings: { providers: [], recentlyUsedModels: [], mcpServers: {} }, isConfigured: false, updateSettings: vi.fn(), setProvider: vi.fn(), removeProvider: vi.fn(), setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); const { result } = renderHook(() => useAIProjectId()); @@ -110,7 +112,7 @@ describe('useAIProjectId', () => { it('should throw error when trying to generate ID without configuration', async () => { mockUseAISettings.mockReturnValue({ - settings: { providers: [], recentlyUsedModels: [] }, + settings: { providers: [], recentlyUsedModels: [], mcpServers: {} }, isConfigured: false, updateSettings: vi.fn(), setProvider: vi.fn(), @@ -118,6 +120,8 @@ describe('useAIProjectId', () => { setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); const { result } = renderHook(() => useAIProjectId()); @@ -142,6 +146,8 @@ describe('useAIProjectId', () => { setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); const { result } = renderHook(() => useAIProjectId()); @@ -166,6 +172,8 @@ describe('useAIProjectId', () => { setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); const { result } = renderHook(() => useAIProjectId()); @@ -189,6 +197,8 @@ describe('useAIProjectId', () => { setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); const { result } = renderHook(() => useAIProjectId()); @@ -221,6 +231,8 @@ describe('useAIProjectId', () => { setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); // Mock AI response - returns a project name that already exists @@ -274,6 +286,8 @@ describe('useAIProjectId', () => { setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); // Mock AI to return a project name that already exists @@ -329,6 +343,8 @@ describe('useAIProjectId', () => { setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); // Mock AI to return a very long project name (over 50 characters) @@ -379,6 +395,8 @@ describe('useAIProjectId', () => { setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); // Mock AI to return an invalid project name (doesn't match regex) @@ -429,6 +447,8 @@ describe('useAIProjectId', () => { setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); // Mock AI to return a project name that already exists @@ -486,6 +506,8 @@ describe('useAIProjectId', () => { setProviders: vi.fn(), addRecentlyUsedModel: vi.fn(), + setMCPServer: vi.fn(), + removeMCPServer: vi.fn(), }); const { result } = renderHook(() => useAIProjectId()); diff --git a/src/hooks/useMCPServerStatus.ts b/src/hooks/useMCPServerStatus.ts new file mode 100644 index 00000000..c8d11f02 --- /dev/null +++ b/src/hooks/useMCPServerStatus.ts @@ -0,0 +1,45 @@ +import { useEffect, useState } from 'react'; +import { MCPClient } from '@/lib/MCPClient'; +import type { MCPServer } from '@/contexts/AISettingsContext'; + +/** + * Hook to check the connection status of an MCP server. + * Returns 'connected', 'offline', or 'checking'. + */ +export function useMCPServerStatus(server: MCPServer): 'connected' | 'offline' | 'checking' { + const [status, setStatus] = useState<'connected' | 'offline' | 'checking'>('checking'); + + useEffect(() => { + let cancelled = false; + + async function checkConnection() { + setStatus('checking'); + + try { + const client = new MCPClient(server); + await client.connect(); + + // Try to list tools to verify the connection is working + await client.listTools(); + + await client.close(); + + if (!cancelled) { + setStatus('connected'); + } + } catch (error) { + if (!cancelled) { + setStatus('offline'); + } + } + } + + checkConnection(); + + return () => { + cancelled = true; + }; + }, [server.url]); // Re-check when URL changes + + return status; +} diff --git a/src/hooks/useMCPTools.ts b/src/hooks/useMCPTools.ts new file mode 100644 index 00000000..ac3d1fc4 --- /dev/null +++ b/src/hooks/useMCPTools.ts @@ -0,0 +1,39 @@ +import { useQuery } from '@tanstack/react-query'; +import { useAISettings } from './useAISettings'; +import { discoverMCPTools } from '@/lib/MCPClient'; +import type OpenAI from 'openai'; +import type { MCPClient } from '@/lib/MCPClient'; + +interface UseMCPToolsResult { + tools: Record; + clients: Record; + isLoading: boolean; + error: Error | null; +} + +/** + * Hook to discover and manage MCP tools from configured servers. + */ +export function useMCPTools(): UseMCPToolsResult { + const { settings } = useAISettings(); + const mcpServers = settings.mcpServers || {}; + + const { data, isLoading, error } = useQuery({ + queryKey: ['mcp-tools', mcpServers], + queryFn: async () => { + if (Object.keys(mcpServers).length === 0) { + return { tools: {}, clients: {} }; + } + return await discoverMCPTools(mcpServers); + }, + staleTime: 5 * 60 * 1000, // Cache for 5 minutes + retry: 1, + }); + + return { + tools: data?.tools || {}, + clients: data?.clients || {}, + isLoading, + error: error as Error | null, + }; +} diff --git a/src/lib/MCPClient.ts b/src/lib/MCPClient.ts new file mode 100644 index 00000000..f8676727 --- /dev/null +++ b/src/lib/MCPClient.ts @@ -0,0 +1,163 @@ +import { Client } from '@modelcontextprotocol/sdk/client/index.js'; +import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; +import type { MCPServer } from '@/contexts/AISettingsContext'; +import type OpenAI from 'openai'; + +/** + * MCP (Model Context Protocol) Client for discovering and executing tools from MCP servers. + * Uses the official @modelcontextprotocol/sdk library. + */ +export class MCPClient { + private client: Client; + private transport: StreamableHTTPClientTransport; + private connected = false; + + constructor(server: MCPServer) { + // Create the client + this.client = new Client({ + name: 'shakespeare', + version: '1.0.0', + }, { + capabilities: {} + }); + + // Create HTTP transport + this.transport = new StreamableHTTPClientTransport(new URL(server.url)); + } + + /** + * Connect to the MCP server. + */ + async connect(): Promise { + if (this.connected) return; + + await this.client.connect(this.transport); + this.connected = true; + } + + /** + * List all available tools from the MCP server. + */ + async listTools(): Promise; + required?: string[]; + }; + }>> { + await this.connect(); + + const result = await this.client.listTools(); + return result.tools; + } + + /** + * Call a tool on the MCP server. + */ + async callTool(name: string, args: Record): Promise { + await this.connect(); + + const result = await this.client.callTool({ + name, + arguments: args, + }); + + const content = Array.isArray(result.content) ? result.content : []; + + if (result.isError) { + const errorText = content + .filter((c): c is { type: 'text'; text: string } => c.type === 'text') + .map(c => c.text) + .join('\n'); + throw new Error(`MCP tool error: ${errorText}`); + } + + // Concatenate all text content from the response + return content + .filter((c): c is { type: 'text'; text: string } => c.type === 'text') + .map(c => c.text) + .join('\n'); + } + + /** + * Close the connection to the MCP server. + */ + async close(): Promise { + if (!this.connected) return; + + await this.client.close(); + this.connected = false; + } + + /** + * Convert MCP tools to OpenAI tool format. + */ + static toOpenAITools(mcpTools: Array<{ + name: string; + description?: string; + inputSchema: { + type: 'object'; + properties?: Record; + required?: string[]; + }; + }>): Record { + const tools: Record = {}; + + for (const tool of mcpTools) { + tools[tool.name] = { + type: 'function', + function: { + name: tool.name, + description: tool.description || '', + parameters: tool.inputSchema as Record, + }, + } as OpenAI.Chat.Completions.ChatCompletionTool; + } + + return tools; + } +} + +/** + * Discover tools from all configured MCP servers. + */ +export async function discoverMCPTools( + mcpServers: Record +): Promise<{ + tools: Record; + clients: Record; +}> { + const allTools: Record = {}; + const clients: Record = {}; + + for (const [serverName, serverConfig] of Object.entries(mcpServers)) { + try { + const client = new MCPClient(serverConfig); + const mcpTools = await client.listTools(); + const openAITools = MCPClient.toOpenAITools(mcpTools); + + // Store tools with server prefix to avoid name collisions + for (const [toolName, tool] of Object.entries(openAITools)) { + const prefixedName = `${serverName}__${toolName}`; + const functionTool = tool as OpenAI.Chat.Completions.ChatCompletionTool & { + function: { name: string; description: string; parameters: Record } + }; + allTools[prefixedName] = { + type: 'function', + function: { + ...functionTool.function, + name: prefixedName, + description: `[${serverName}] ${functionTool.function.description}`, + }, + } as OpenAI.Chat.Completions.ChatCompletionTool; + clients[prefixedName] = client; + } + } catch (error) { + console.error(`Failed to discover tools from MCP server "${serverName}":`, error); + } + } + + return { tools: allTools, clients }; +} diff --git a/src/lib/configUtils.test.ts b/src/lib/configUtils.test.ts index eb6529c1..9e3e5b9f 100644 --- a/src/lib/configUtils.test.ts +++ b/src/lib/configUtils.test.ts @@ -74,7 +74,10 @@ describe('configUtils', () => { const result = await readAISettings(mockFS); expect(mockFS.readFile).toHaveBeenCalledWith('/config/ai.json', 'utf8'); - expect(result).toEqual(sampleAISettings); + expect(result).toEqual({ + ...sampleAISettings, + mcpServers: {}, + }); }); it('should return default settings if file does not exist and no localStorage data', async () => { @@ -86,6 +89,7 @@ describe('configUtils', () => { expect(result).toEqual({ providers: [], recentlyUsedModels: [], + mcpServers: {}, }); }); @@ -98,6 +102,7 @@ describe('configUtils', () => { expect(result).toEqual({ providers: [], recentlyUsedModels: [], + mcpServers: {}, }); }); }); diff --git a/src/lib/configUtils.ts b/src/lib/configUtils.ts index 12ce1b2c..35d32c45 100644 --- a/src/lib/configUtils.ts +++ b/src/lib/configUtils.ts @@ -1,7 +1,7 @@ import z from 'zod'; import { filteredArray } from '@/lib/schema'; import type { JSRuntimeFS } from '@/lib/JSRuntime'; -import type { AIProvider, AISettings } from '@/contexts/AISettingsContext'; +import type { AIProvider, AISettings, MCPServer } from '@/contexts/AISettingsContext'; import type { GitSettings } from '@/contexts/GitSettingsContext'; import type { DeployProvider, DeploySettings } from '@/contexts/DeploySettingsContext'; @@ -42,9 +42,15 @@ const providerModelSchema = z.string().regex( 'Must be in format provider/model (e.g., "openai/gpt-4o")', ); +const mcpServerSchema: z.ZodType = z.object({ + type: z.literal('streamable-http'), + url: z.string().url(), +}); + const aiSettingsSchema = z.object({ providers: filteredArray(aiProviderSchema), recentlyUsedModels: filteredArray(providerModelSchema), + mcpServers: z.record(z.string(), mcpServerSchema).optional(), }); const gitCredentialSchema = z.object({ @@ -130,13 +136,19 @@ export async function readAISettings(fs: JSRuntimeFS, configPath = '/config'): P const defaultSettings: AISettings = { providers: [], recentlyUsedModels: [], + mcpServers: {}, }; try { const aiConfigPath = getAIConfigPath(configPath); const content = await fs.readFile(aiConfigPath, 'utf8'); const data = JSON.parse(content); - return aiSettingsSchema.parse(data); + const parsed = aiSettingsSchema.parse(data); + // Ensure mcpServers exists even if not in parsed data + return { + ...parsed, + mcpServers: parsed.mcpServers || {}, + }; } catch (error) { if (error instanceof z.ZodError) { console.error('AI settings parsing error:', error.errors); diff --git a/src/lib/tools/MCPTool.ts b/src/lib/tools/MCPTool.ts new file mode 100644 index 00000000..8cf3fb37 --- /dev/null +++ b/src/lib/tools/MCPTool.ts @@ -0,0 +1,48 @@ +import type { Tool } from './Tool'; +import type { MCPClient } from '@/lib/MCPClient'; + +/** + * Wrapper for MCP tools to integrate with Shakespeare's tool system. + */ +export class MCPTool implements Tool> { + description: string; + private client: MCPClient; + private originalToolName: string; + + constructor( + description: string, + client: MCPClient, + originalToolName: string + ) { + this.description = description; + this.client = client; + this.originalToolName = originalToolName; + } + + async execute(args: Record): Promise { + return await this.client.callTool(this.originalToolName, args); + } +} + +/** + * Create MCPTool instances from discovered MCP tools. + */ +export function createMCPTools( + clients: Record +): Record> { + const tools: Record> = {}; + + for (const [prefixedName, client] of Object.entries(clients)) { + // Extract original tool name by removing server prefix + const parts = prefixedName.split('__'); + const originalToolName = parts.slice(1).join('__'); + + tools[prefixedName] = new MCPTool( + `MCP tool: ${prefixedName}`, + client, + originalToolName + ); + } + + return tools; +} diff --git a/src/locales/en.json b/src/locales/en.json index 8f88ef58..959cf60f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -478,6 +478,24 @@ "noPluginsConfigured": "No plugins configured. Add a plugin to get started.", "pluginsDirectory": "Plugins Directory", "pluginsDirectoryDescription": "Directory where plugins are stored in the virtual filesystem.", + "mcpServers": "MCP Servers", + "mcpServersDescription": "Connect to Model Context Protocol servers to extend the AI's capabilities with external tools.", + "addMcpServer": "Add MCP Server", + "mcpServerName": "Server Name", + "mcpServerUrl": "Server URL", + "mcpServerType": "Server Type", + "mcpServerTypeStreamableHttp": "Streamable HTTP", + "mcpServerDescription": "MCP servers provide tools that can be discovered and used by the AI assistant.", + "noMcpServersConfigured": "No MCP servers configured. Add a server to get started.", + "mcpServerAdded": "MCP Server Added", + "mcpServerAddedDescription": "MCP server \"{{name}}\" has been added successfully.", + "mcpServerAddFailed": "Failed to Add MCP Server", + "mcpServerDeleted": "MCP Server Deleted", + "mcpServerDeletedDescription": "MCP server \"{{name}}\" has been deleted successfully.", + "mcpServerDeleteFailed": "Failed to Delete MCP Server", + "discoveringTools": "Discovering tools...", + "toolsDiscovered": "{{count}} tool(s) discovered", + "toolDiscoveryFailed": "Failed to discover tools from this server", "filesystemPaths": "Filesystem Paths", "projectsDirectory": "Projects Directory", "projectsDirectoryDescription": "Directory where projects are stored in the virtual filesystem.", diff --git a/src/pages/AISettings.tsx b/src/pages/AISettings.tsx index c36ddaca..63635b3c 100644 --- a/src/pages/AISettings.tsx +++ b/src/pages/AISettings.tsx @@ -36,6 +36,7 @@ import { useNavigate, Link } from 'react-router-dom'; import type { AIProvider } from '@/contexts/AISettingsContext'; import { AI_PROVIDER_PRESETS, type PresetProvider } from '@/lib/aiProviderPresets'; import { ExternalFavicon } from '@/components/ExternalFavicon'; +import { MCPServersSection } from '@/components/MCPServersSection'; import { PluginsSection } from '@/components/PluginsSection'; interface SortableProviderItemProps { @@ -566,6 +567,9 @@ export function AISettings() {
+ {/* MCP Servers Section */} + + {/* Plugins Section */}