From 504b76c233792413fa6fc03c1260063418656de2 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sat, 11 Jan 2025 21:07:56 +0400 Subject: [PATCH 1/5] Adding mcptools --- package.json | 2 + provider/modelcontextprotocoltools/.gitignore | 5 + provider/modelcontextprotocoltools/README.md | 55 +++++ provider/modelcontextprotocoltools/index.ts | 194 ++++++++++++++++++ .../modelcontextprotocoltools/package.json | 44 ++++ .../modelcontextprotocoltools/tsconfig.json | 11 + 6 files changed, 311 insertions(+) create mode 100644 provider/modelcontextprotocoltools/.gitignore create mode 100644 provider/modelcontextprotocoltools/README.md create mode 100644 provider/modelcontextprotocoltools/index.ts create mode 100644 provider/modelcontextprotocoltools/package.json create mode 100644 provider/modelcontextprotocoltools/tsconfig.json diff --git a/package.json b/package.json index 008f3d46..b72d0895 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,8 @@ "ts-node": "^10.9.2", "typescript": "^5.4.5", "vite": "^5.2.11", + "json-schema-to-zod": "^0.1.5", + "@apidevtools/json-schema-ref-parser": "^11.7.3", "vitest": "^1.6.0" }, "stylelint": { diff --git a/provider/modelcontextprotocoltools/.gitignore b/provider/modelcontextprotocoltools/.gitignore new file mode 100644 index 00000000..3d4b0ca5 --- /dev/null +++ b/provider/modelcontextprotocoltools/.gitignore @@ -0,0 +1,5 @@ +index.test.ts +package-lock.json +dist/ +vitest.config.ts +vitest.config.t \ No newline at end of file diff --git a/provider/modelcontextprotocoltools/README.md b/provider/modelcontextprotocoltools/README.md new file mode 100644 index 00000000..c132c1f4 --- /dev/null +++ b/provider/modelcontextprotocoltools/README.md @@ -0,0 +1,55 @@ +# MCP proxy for OpenCtx + +This is a context provider for [OpenCtx](https://openctx.org) that fetches contents from a [MCP](https://modelcontextprotocol.io) provider for use as context. + +Currently, only MCP over stdio is supported (HTTP is not yet supported). + +## Development + +1. Clone the [modelcontextprotocol/servers](https://github.com/modelcontextprotocol/servers) repository. Follow the instructions there to build the example providers. This should generate output files of the form `build/${example_name}/index.js`. +1. Run `pnpm watch` in this directory. +1. Add the following to your VS Code settings: + ```json + "openctx.providers": { + // ...other providers... + "https://openctx.org/npm/@openctx/provider-modelcontextprotocol": { + "nodeCommand": "node", + "mcp.provider.uri": "file:///path/to/servers/root/build/everything/index.js", + } + } + ``` +1. Reload the VS Code window. You should see `servers/everything` in the `@`-mention dropdown. + +To hook up to the Postgres MCP provider, use: + +```json +"openctx.providers": { + // ...other providers... + "https://openctx.org/npm/@openctx/provider-modelcontextprotocol": { + "nodeCommand": "node", + "mcp.provider.uri": "file:///path/to/servers/root/build/postgres/index.js", + "mcp.provider.args": [ + "postgresql://sourcegraph:sourcegraph@localhost:5432/sourcegraph" + ] + } +} +``` + +## More MCP Servers + +The following MCP servers are available in the [modelcontextprotocol/servers](https://github.com/modelcontextprotocol/servers) repository: + +- [Brave Search](https://github.com/modelcontextprotocol/servers/tree/main/src/brave-search) - Search the Brave search API +- [Postgres](https://github.com/modelcontextprotocol/servers/tree/main/src/postgres) - Connect to your Postgres databases to query schema information and write optimized SQL +- [Filesystem](https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem) - Access files on your local machine +- [Everything](https://github.com/modelcontextprotocol/servers/tree/main/src/everything) - A demo server showing MCP capabilities +- [Google Drive](https://github.com/modelcontextprotocol/servers/tree/main/src/gdrive) - Search and access your Google Drive documents +- [Google Maps](https://github.com/modelcontextprotocol/servers/tree/main/src/google-maps) - Get directions and information about places +- [Memo](https://github.com/modelcontextprotocol/servers/tree/main/src/memo) - Access your Memo notes +- [Git](https://github.com/modelcontextprotocol/servers/tree/main/src/git) - Get git history and commit information +- [Puppeteer](https://github.com/modelcontextprotocol/servers/tree/main/src/puppeteer) - Control headless Chrome for web automation +- [SQLite](https://github.com/modelcontextprotocol/servers/tree/main/src/sqlite) - Query SQLite databases + +## Creating your own MCP server + +See the [MCP docs](https://modelcontextprotocol.io) for how to create your own MCP servers. \ No newline at end of file diff --git a/provider/modelcontextprotocoltools/index.ts b/provider/modelcontextprotocoltools/index.ts new file mode 100644 index 00000000..7c41db08 --- /dev/null +++ b/provider/modelcontextprotocoltools/index.ts @@ -0,0 +1,194 @@ +import { basename } from 'node:path' +import { Client } from '@modelcontextprotocol/sdk/client/index.js' +import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js' +import { + CallToolResultSchema, + +} from '@modelcontextprotocol/sdk/types.js' +import type { + Item, + ItemsParams, + ItemsResult, + Mention, + MentionsParams, + MentionsResult, + MetaParams, + MetaResult, + Provider, + ProviderSettings, +} from '@openctx/provider' +const Ajv = require('ajv') + +async function createClient( + nodeCommand: string, + mcpProviderFile: string, + mcpProviderArgs: string[], +): Promise { + const client = new Client( + { + name: 'mcp-tool', + version: '0.0.1', + }, + { + capabilities: { + experimental: {}, + sampling: {}, + roots: {}, + }, + }, + ) + const transport = new StdioClientTransport({ + command: nodeCommand, + args: [mcpProviderFile, ...mcpProviderArgs], + }) + await client.connect(transport) + return client +} + +class MCPToolsProxy implements Provider { + private mcpClient?: Promise + private toolSchemas: Map = new Map() + private ajv = new Ajv() + + // Gets the Metadata for the MCP Tools Provider + async meta(_params: MetaParams, settings: ProviderSettings): Promise { + const nodeCommand: string = (settings.nodeCommand as string) ?? 'node' + const mcpProviderUri = settings['mcp.provider.uri'] as string + if (!mcpProviderUri) { + this.mcpClient = undefined + return { + name: 'undefined MCP provider', + } + } + if (!mcpProviderUri.startsWith('file://')) { + throw new Error('mcp.provider.uri must be a file:// URI') + } + const mcpProviderFile = mcpProviderUri.slice('file://'.length) + const mcpProviderArgsRaw = settings['mcp.provider.args'] + const mcpProviderArgs = Array.isArray(mcpProviderArgsRaw) + ? mcpProviderArgsRaw.map(e => `${e}`) + : [] + this.mcpClient = createClient(nodeCommand, mcpProviderFile, mcpProviderArgs) + const mcpClient = await this.mcpClient + const serverInfo = mcpClient.getServerVersion() + const name = serverInfo?.name ?? basename(mcpProviderFile) + return { + name, + mentions: { + label: name, + }, + } + } + + // Gets Lists All the tools available in the MCP Provider along with their schemas + async mentions?(params: MentionsParams, _settings: ProviderSettings): Promise { + if (!this.mcpClient) { + return [] + } + const mcpClient = await this.mcpClient + const toolsResp = await mcpClient.listTools() + + const { tools } = toolsResp + const mentions: Mention[] = [] + for (const tool of tools) { + // Store the schema in the Map using tool name as key + this.toolSchemas.set(tool.name, JSON.stringify(tool.inputSchema)) + + const r = { + uri: tool.uri, + title: tool.name, + description: tool.description, + data: (tool.inputSchema), + } as Mention + mentions.push(r) + } + + const query = params.query?.trim().toLowerCase() + if (!query) { + return mentions + } + const prefixMatches: Mention[] = [] + const substringMatches: Mention[] = [] + + // Filters the tools based on the query + for (const mention of mentions) { + const title = mention.title.toLowerCase() + if (title.startsWith(query)) { + prefixMatches.push(mention) + } else if (title.includes(query)) { + substringMatches.push(mention) + } + } + + // Combines the prefix and substring matches + return [...prefixMatches, ...substringMatches] + } + + // Retrieves the schema for a tool from the Map using the tool name as key + getToolSchema(toolName: string): any { + return JSON.parse(this.toolSchemas.get(toolName) as string) + } + + // Calls the tool with the provided input and returns the result + async items?(params: ItemsParams, _settings: ProviderSettings): Promise { + if (!this.mcpClient) { + return [] + } + const mcpClient = await this.mcpClient + + const toolName = params.mention?.title + const toolInput = params.mention?.data + + // Validates the tool input against the stored schema + if (toolName && toolInput) { + const schema = this.getToolSchema(toolName) + if (schema) { + const isValid = this.ajv.validate(schema, toolInput) + if (!isValid) { + console.error('Invalid tool input:', this.ajv.errors) + throw new Error(`Invalid input for tool ${toolName}: ${JSON.stringify(this.ajv.errors)}`) + } + } + } + + // Calls the tool with the provided input + const response = await mcpClient.request( + { + method: 'tools/call' as const, + params: { + name: toolName, + arguments: toolInput + }, + }, + CallToolResultSchema, + ) + + const contents = response.content + const items: Item[] = [] + for (const content of contents) { + if (content.text) { + items.push({ + title: (toolName as string) ?? '', + ai: { + content: (content.text as string) ?? '', + }, + }) + } else { + console.log('No text field was present, mimeType was', content.mimeType) + } + } + return items + } + + dispose?(): void { + if (this.mcpClient) { + this.mcpClient.then(c => { + c.close() + }) + } + } +} + + +const proxy = new MCPToolsProxy() +export default proxy diff --git a/provider/modelcontextprotocoltools/package.json b/provider/modelcontextprotocoltools/package.json new file mode 100644 index 00000000..839bf88e --- /dev/null +++ b/provider/modelcontextprotocoltools/package.json @@ -0,0 +1,44 @@ +{ + "name": "@openctx/provider-modelcontextprotocoltools", + "version": "0.0.13", + "description": "Use information from MCP providers", + "license": "Apache-2.0", + "homepage": "https://openctx.org/docs/providers/modelcontextprotocoltools", + "repository": { + "type": "git", + "url": "https://github.com/sourcegraph/openctx", + "directory": "provider/modelcontextprotocoltools" + }, + "type": "module", + "main": "dist/bundle.js", + "types": "dist/index.d.ts", + "files": [ + "dist/bundle.js", + "dist/index.d.ts" + ], + "sideEffects": false, + "scripts": { + "bundle": "tsc --build && esbuild --log-level=error --platform=node --bundle --format=esm --outfile=dist/bundle.js index.ts", + "prepublishOnly": "tsc --build --clean && npm run --silent bundle", + "test": "vitest", + "test:unit": "vitest run", + "watch": "tsc --build --watch & esbuild --log-level=error --platform=node --bundle --format=esm --outfile=dist/bundle.js --watch index.ts" + }, + "dependencies": { + "@apidevtools/json-schema-ref-parser": "^11.7.3", + "@modelcontextprotocol/sdk": "1.0.1", + "@openctx/provider": "workspace:*", + "ajv": "^8.17.1", + "express": "^4.21.1", + "json-schema-to-zod": "^0.1.5", + "zod": "^3.24.1", + "zod-to-json-schema": "^3.24.1" + }, + "pnpm": { + "peerDependencyRules": { + "allowAny": [ + "@apidevtools/json-schema-ref-parser" + ] + } + } +} diff --git a/provider/modelcontextprotocoltools/tsconfig.json b/provider/modelcontextprotocoltools/tsconfig.json new file mode 100644 index 00000000..a1d94187 --- /dev/null +++ b/provider/modelcontextprotocoltools/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../.config/tsconfig.base.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "dist", + "lib": ["ESNext"] + }, + "include": ["*.ts"], + "exclude": ["dist", "vitest.config.ts"], + "references": [{ "path": "../../lib/provider" }] +} From e1ecedfd7c76cfb09f0d27856b2d1b86492a3f14 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sat, 11 Jan 2025 21:09:36 +0400 Subject: [PATCH 2/5] Remvoing Zod stuff --- package.json | 2 -- provider/modelcontextprotocoltools/.gitignore | 2 +- provider/modelcontextprotocoltools/package.json | 5 +---- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index b72d0895..008f3d46 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,6 @@ "ts-node": "^10.9.2", "typescript": "^5.4.5", "vite": "^5.2.11", - "json-schema-to-zod": "^0.1.5", - "@apidevtools/json-schema-ref-parser": "^11.7.3", "vitest": "^1.6.0" }, "stylelint": { diff --git a/provider/modelcontextprotocoltools/.gitignore b/provider/modelcontextprotocoltools/.gitignore index 3d4b0ca5..6a4de93d 100644 --- a/provider/modelcontextprotocoltools/.gitignore +++ b/provider/modelcontextprotocoltools/.gitignore @@ -2,4 +2,4 @@ index.test.ts package-lock.json dist/ vitest.config.ts -vitest.config.t \ No newline at end of file +vitest.config.t diff --git a/provider/modelcontextprotocoltools/package.json b/provider/modelcontextprotocoltools/package.json index 839bf88e..2cf1f38b 100644 --- a/provider/modelcontextprotocoltools/package.json +++ b/provider/modelcontextprotocoltools/package.json @@ -29,10 +29,7 @@ "@modelcontextprotocol/sdk": "1.0.1", "@openctx/provider": "workspace:*", "ajv": "^8.17.1", - "express": "^4.21.1", - "json-schema-to-zod": "^0.1.5", - "zod": "^3.24.1", - "zod-to-json-schema": "^3.24.1" + "express": "^4.21.1" }, "pnpm": { "peerDependencyRules": { From 83a7c16fefb5c362dc9bda83c1b7e3bd26f1a62c Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sat, 11 Jan 2025 21:11:43 +0400 Subject: [PATCH 3/5] Remvoing Zod stuff --- pnpm-lock.yaml | 304 ++++++++++++++++-- provider/modelcontextprotocoltools/index.ts | 21 +- .../modelcontextprotocoltools/package.json | 8 - 3 files changed, 287 insertions(+), 46 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a874611..dda536c4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -649,6 +649,21 @@ importers: specifier: workspace:* version: link:../../lib/provider + provider/modelcontextprotocoltools: + dependencies: + '@modelcontextprotocol/sdk': + specifier: 1.0.1 + version: 1.0.1 + '@openctx/provider': + specifier: workspace:* + version: link:../../lib/provider + ajv: + specifier: ^8.17.1 + version: 8.17.1 + express: + specifier: ^4.21.1 + version: 4.21.2 + provider/notion: dependencies: '@notionhq/client': @@ -4152,6 +4167,14 @@ packages: zod: 3.23.8 dev: false + /@modelcontextprotocol/sdk@1.0.1: + resolution: {integrity: sha512-slLdFaxQJ9AlRg+hw28iiTtGvShAOgOKXcD0F91nUcRYiOMuS9ZBYjcdNZRXW9G5JQ511GRTdUy1zQVZDpJ+4w==} + dependencies: + content-type: 1.0.5 + raw-body: 3.0.0 + zod: 3.23.8 + dev: false + /@ndelangen/get-tarball@3.0.9: resolution: {integrity: sha512-9JKTEik4vq+yGosHYhZ1tiH/3WpUS0Nh0kej4Agndhox8pAdWhEx5knFVRcb/ya9knCRCs1rPxNrSXTDdfVqpA==} dependencies: @@ -5302,7 +5325,7 @@ packages: '@types/promise.allsettled': 1.0.6 '@types/tsscmp': 1.0.2 axios: 1.7.2 - express: 4.18.2 + express: 4.21.2 path-to-regexp: 6.2.1 please-upgrade-node: 3.2.0 promise.allsettled: 1.0.7 @@ -5655,7 +5678,7 @@ packages: ejs: 3.1.9 esbuild: 0.18.20 esbuild-plugin-alias: 0.2.1 - express: 4.18.2 + express: 4.21.2 find-cache-dir: 3.3.2 fs-extra: 11.1.1 process: 0.11.10 @@ -5691,7 +5714,7 @@ packages: '@types/find-cache-dir': 3.2.1 browser-assert: 1.2.1 es-module-lexer: 0.9.3 - express: 4.18.2 + express: 4.21.2 find-cache-dir: 3.3.2 fs-extra: 11.1.1 magic-string: 0.30.1 @@ -5730,7 +5753,7 @@ packages: '@types/find-cache-dir': 3.2.1 browser-assert: 1.2.1 es-module-lexer: 1.5.2 - express: 4.18.2 + express: 4.21.2 find-cache-dir: 3.3.2 fs-extra: 11.1.1 magic-string: 0.30.7 @@ -5789,7 +5812,7 @@ packages: detect-indent: 6.1.0 envinfo: 7.10.0 execa: 5.1.1 - express: 4.18.2 + express: 4.21.2 find-up: 5.0.0 fs-extra: 11.1.1 get-npm-tarball-url: 2.0.3 @@ -5999,7 +6022,7 @@ packages: cli-table3: 0.6.3 compression: 1.7.4 detect-port: 1.5.1 - express: 4.18.2 + express: 4.21.2 fs-extra: 11.1.1 globby: 11.1.0 ip: 2.0.1 @@ -7334,14 +7357,13 @@ packages: indent-string: 4.0.0 dev: true - /ajv@8.12.0: - resolution: {integrity: sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==} + /ajv@8.17.1: + resolution: {integrity: sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==} dependencies: fast-deep-equal: 3.1.3 + fast-uri: 3.0.5 json-schema-traverse: 1.0.0 require-from-string: 2.0.2 - uri-js: 4.4.1 - dev: true /ansi-colors@4.1.1: resolution: {integrity: sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==} @@ -7693,6 +7715,26 @@ packages: unpipe: 1.0.0 transitivePeerDependencies: - supports-color + dev: false + + /body-parser@1.20.3: + resolution: {integrity: sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==} + engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16} + dependencies: + bytes: 3.1.2 + content-type: 1.0.5 + debug: 2.6.9 + depd: 2.0.0 + destroy: 1.2.0 + http-errors: 2.0.0 + iconv-lite: 0.4.24 + on-finished: 2.4.1 + qs: 6.13.0 + raw-body: 2.5.2 + type-is: 1.6.18 + unpipe: 1.0.0 + transitivePeerDependencies: + - supports-color /boolbase@1.0.0: resolution: {integrity: sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==} @@ -7808,6 +7850,13 @@ packages: ylru: 1.3.2 dev: true + /call-bind-apply-helpers@1.0.1: + resolution: {integrity: sha512-BhYE+WDaywFg2TBWYNXAE+8B1ATnThNBqXHP5nQu0jWJdVvY2hvkpyB3qOmtmDePiS5/BDQ8wASEWGMWRG148g==} + engines: {node: '>= 0.4'} + dependencies: + es-errors: 1.3.0 + function-bind: 1.1.2 + /call-bind@1.0.5: resolution: {integrity: sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==} dependencies: @@ -7825,6 +7874,13 @@ packages: get-intrinsic: 1.2.4 set-function-length: 1.2.2 + /call-bound@1.0.3: + resolution: {integrity: sha512-YTd+6wGlNlPxSuri7Y6X8tY2dmm12UMH66RpKMhiX6rsk5wXXnYgbUcOt8kiS31/AjfoTOvCsE+w8nZQLQnzHA==} + engines: {node: '>= 0.4'} + dependencies: + call-bind-apply-helpers: 1.0.1 + get-intrinsic: 1.2.7 + /call-me-maybe@1.0.2: resolution: {integrity: sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ==} dev: true @@ -8253,7 +8309,6 @@ packages: /content-type@1.0.5: resolution: {integrity: sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==} engines: {node: '>= 0.6'} - dev: false /convert-source-map@1.7.0: resolution: {integrity: sha512-4FJkXzKXEDB1snCFZlLP4gpC3JILicCpGbzG9f9G7tGqGCzETQ2hWPrcinA9oU4wtf2biUaEH5065UnMeR33oA==} @@ -8271,6 +8326,11 @@ packages: /cookie@0.5.0: resolution: {integrity: sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==} engines: {node: '>= 0.6'} + dev: false + + /cookie@0.7.1: + resolution: {integrity: sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==} + engines: {node: '>= 0.6'} /cookies@0.8.0: resolution: {integrity: sha512-8aPsApQfebXnuI+537McwYsDtjVxGm8gTIzQI3FDW6t5t/DAhERxtnbEPN/8RX+uZthoz4eCOgloXaE5cYyNow==} @@ -8772,6 +8832,14 @@ packages: engines: {node: '>=12'} dev: true + /dunder-proto@1.0.1: + resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==} + engines: {node: '>= 0.4'} + dependencies: + call-bind-apply-helpers: 1.0.1 + es-errors: 1.3.0 + gopd: 1.2.0 + /duplexify@3.7.1: resolution: {integrity: sha512-07z8uv2wMyS51kKhD1KsdXJg5WQ6t93RneqRxUHnskXVtlYYkLqM0gqStQZ3pj073g687jPCHrqNfCzawLYh5g==} dependencies: @@ -8821,6 +8889,10 @@ packages: resolution: {integrity: sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==} engines: {node: '>= 0.8'} + /encodeurl@2.0.0: + resolution: {integrity: sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==} + engines: {node: '>= 0.8'} + /end-of-stream@1.4.4: resolution: {integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==} dependencies: @@ -8909,6 +8981,10 @@ packages: dependencies: get-intrinsic: 1.2.4 + /es-define-property@1.0.1: + resolution: {integrity: sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==} + engines: {node: '>= 0.4'} + /es-errors@1.3.0: resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} engines: {node: '>= 0.4'} @@ -8948,7 +9024,6 @@ packages: engines: {node: '>= 0.4'} dependencies: es-errors: 1.3.0 - dev: false /es-set-tostringtag@2.0.3: resolution: {integrity: sha512-3T8uNMC3OQTHkFUsFq8r/BwAXLHvU/9O9mE0fBc/MY5iq/8H7ncvO947LmYA6ldWw9Uh8Yhf25zu6n7nML5QWQ==} @@ -9338,6 +9413,45 @@ packages: vary: 1.1.2 transitivePeerDependencies: - supports-color + dev: false + + /express@4.21.2: + resolution: {integrity: sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==} + engines: {node: '>= 0.10.0'} + dependencies: + accepts: 1.3.8 + array-flatten: 1.1.1 + body-parser: 1.20.3 + content-disposition: 0.5.4 + content-type: 1.0.5 + cookie: 0.7.1 + cookie-signature: 1.0.6 + debug: 2.6.9 + depd: 2.0.0 + encodeurl: 2.0.0 + escape-html: 1.0.3 + etag: 1.8.1 + finalhandler: 1.3.1 + fresh: 0.5.2 + http-errors: 2.0.0 + merge-descriptors: 1.0.3 + methods: 1.1.2 + on-finished: 2.4.1 + parseurl: 1.3.3 + path-to-regexp: 0.1.12 + proxy-addr: 2.0.7 + qs: 6.13.0 + range-parser: 1.2.1 + safe-buffer: 5.2.1 + send: 0.19.0 + serve-static: 1.16.2 + setprototypeof: 1.2.0 + statuses: 2.0.1 + type-is: 1.6.18 + utils-merge: 1.0.1 + vary: 1.1.2 + transitivePeerDependencies: + - supports-color /ext@1.7.0: resolution: {integrity: sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==} @@ -9376,7 +9490,6 @@ packages: /fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} - dev: true /fast-fifo@1.3.2: resolution: {integrity: sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==} @@ -9396,6 +9509,9 @@ packages: resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} dev: true + /fast-uri@3.0.5: + resolution: {integrity: sha512-5JnBCWpFlMo0a3ciDy/JckMzzv1U9coZrIhedq+HXxxUfDTAiS0LA8OKVao4G9BxmCVck/jtA5r3KAtRWEyD8Q==} + /fast-xml-parser@4.4.0: resolution: {integrity: sha512-kLY3jFlwIYwBNDojclKsNAC12sfD6NwW74QB2CoNGPvtVxjliYehVunB3HYyNi+n4Tt1dAcgwYvmKF/Z18flqg==} hasBin: true @@ -9468,6 +9584,21 @@ packages: unpipe: 1.0.0 transitivePeerDependencies: - supports-color + dev: false + + /finalhandler@1.3.1: + resolution: {integrity: sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==} + engines: {node: '>= 0.8'} + dependencies: + debug: 2.6.9 + encodeurl: 2.0.0 + escape-html: 1.0.3 + on-finished: 2.4.1 + parseurl: 1.3.3 + statuses: 2.0.1 + unpipe: 1.0.0 + transitivePeerDependencies: + - supports-color /find-cache-dir@2.1.0: resolution: {integrity: sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ==} @@ -9746,6 +9877,21 @@ packages: has-symbols: 1.0.3 hasown: 2.0.2 + /get-intrinsic@1.2.7: + resolution: {integrity: sha512-VW6Pxhsrk0KAOqs3WEd0klDiF/+V7gQOpAvY1jVU/LHmaD/kQO4523aiJuikX/QAKYiW6x8Jh+RJej1almdtCA==} + engines: {node: '>= 0.4'} + dependencies: + call-bind-apply-helpers: 1.0.1 + es-define-property: 1.0.1 + es-errors: 1.3.0 + es-object-atoms: 1.0.0 + function-bind: 1.1.2 + get-proto: 1.0.1 + gopd: 1.2.0 + has-symbols: 1.1.0 + hasown: 2.0.2 + math-intrinsics: 1.1.0 + /get-nonce@1.0.1: resolution: {integrity: sha512-FJhYRoDaiatfEkUK8HKlicmu/3SGFD51q3itKDGoSTysQJBnfOcxU5GxnhE1E6soB76MbT0MBtnKJuXyAx+96Q==} engines: {node: '>=6'} @@ -9760,6 +9906,13 @@ packages: engines: {node: '>=8'} dev: true + /get-proto@1.0.1: + resolution: {integrity: sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==} + engines: {node: '>= 0.4'} + dependencies: + dunder-proto: 1.0.1 + es-object-atoms: 1.0.0 + /get-stdin@8.0.0: resolution: {integrity: sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==} engines: {node: '>=10'} @@ -9972,6 +10125,10 @@ packages: dependencies: get-intrinsic: 1.2.2 + /gopd@1.2.0: + resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==} + engines: {node: '>= 0.4'} + /graceful-fs@4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} dev: true @@ -10052,6 +10209,10 @@ packages: resolution: {integrity: sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==} engines: {node: '>= 0.4'} + /has-symbols@1.1.0: + resolution: {integrity: sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==} + engines: {node: '>= 0.4'} + /has-tostringtag@1.0.0: resolution: {integrity: sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==} engines: {node: '>= 0.4'} @@ -11055,7 +11216,6 @@ packages: /json-schema-traverse@1.0.0: resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==} - dev: true /json-stringify-safe@5.0.1: resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==} @@ -11558,6 +11718,10 @@ packages: hasBin: true dev: false + /math-intrinsics@1.1.0: + resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==} + engines: {node: '>= 0.4'} + /mathml-tag-names@2.1.3: resolution: {integrity: sha512-APMBEanjybaPzUrfqU0IMU5I0AswKMH7k8OTLs0vvV4KZpExkTkY87nR/zpbuTPj+gARop7aGUbl11pnDfW6xg==} dev: true @@ -11739,6 +11903,10 @@ packages: /merge-descriptors@1.0.1: resolution: {integrity: sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==} + dev: false + + /merge-descriptors@1.0.3: + resolution: {integrity: sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==} /merge-stream@2.0.0: resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} @@ -12391,6 +12559,10 @@ packages: resolution: {integrity: sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==} dev: false + /object-inspect@1.13.3: + resolution: {integrity: sha512-kDCGIbxkDSXE3euJZZXzc6to7fCrKHNI/hSRQnRuQ+BWjFNzZwiFF8fj/6o2t2G9/jTj8PSIYTfCLelLZEeRpA==} + engines: {node: '>= 0.4'} + /object-is@1.1.5: resolution: {integrity: sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==} engines: {node: '>= 0.4'} @@ -12717,8 +12889,12 @@ packages: minipass: 7.0.4 dev: true + /path-to-regexp@0.1.12: + resolution: {integrity: sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==} + /path-to-regexp@0.1.7: resolution: {integrity: sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==} + dev: false /path-to-regexp@6.2.1: resolution: {integrity: sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==} @@ -13106,11 +13282,6 @@ packages: pump: 2.0.1 dev: true - /punycode@2.3.0: - resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==} - engines: {node: '>=6'} - dev: true - /puppeteer-core@2.1.1: resolution: {integrity: sha512-n13AWriBMPYxnpbb6bnaY5YoY6rGj8vPLrz6CZF3o0qJNEwlcfJVxBzYZ0NJsQ21UbdJoijPCDrM++SUVEz7+w==} engines: {node: '>=8.16.0'} @@ -13163,6 +13334,7 @@ packages: engines: {node: '>=0.6'} dependencies: side-channel: 1.0.4 + dev: false /qs@6.11.2: resolution: {integrity: sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==} @@ -13170,6 +13342,12 @@ packages: dependencies: side-channel: 1.0.4 + /qs@6.13.0: + resolution: {integrity: sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==} + engines: {node: '>=0.6'} + dependencies: + side-channel: 1.1.0 + /queue-tick@1.0.1: resolution: {integrity: sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag==} dev: true @@ -13201,6 +13379,16 @@ packages: http-errors: 2.0.0 iconv-lite: 0.4.24 unpipe: 1.0.0 + dev: false + + /raw-body@2.5.2: + resolution: {integrity: sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==} + engines: {node: '>= 0.8'} + dependencies: + bytes: 3.1.2 + http-errors: 2.0.0 + iconv-lite: 0.4.24 + unpipe: 1.0.0 /raw-body@3.0.0: resolution: {integrity: sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g==} @@ -13658,7 +13846,6 @@ packages: /require-from-string@2.0.2: resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} engines: {node: '>=0.10.0'} - dev: true /resolve-from@4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} @@ -13890,6 +14077,27 @@ packages: statuses: 2.0.1 transitivePeerDependencies: - supports-color + dev: false + + /send@0.19.0: + resolution: {integrity: sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==} + engines: {node: '>= 0.8.0'} + dependencies: + debug: 2.6.9 + depd: 2.0.0 + destroy: 1.2.0 + encodeurl: 1.0.2 + escape-html: 1.0.3 + etag: 1.8.1 + fresh: 0.5.2 + http-errors: 2.0.0 + mime: 1.6.0 + ms: 2.1.3 + on-finished: 2.4.1 + range-parser: 1.2.1 + statuses: 2.0.1 + transitivePeerDependencies: + - supports-color /serialize-javascript@6.0.0: resolution: {integrity: sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==} @@ -13907,6 +14115,18 @@ packages: send: 0.18.0 transitivePeerDependencies: - supports-color + dev: false + + /serve-static@1.16.2: + resolution: {integrity: sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==} + engines: {node: '>= 0.8.0'} + dependencies: + encodeurl: 2.0.0 + escape-html: 1.0.3 + parseurl: 1.3.3 + send: 0.19.0 + transitivePeerDependencies: + - supports-color /server-destroy@1.0.1: resolution: {integrity: sha512-rb+9B5YBIEzYcD6x2VKidaa+cqYBJQKnU4oe4E3ANwRRN56yk/ua1YCJT1n21NTS8w6CcOclAKNP3PhdCXKYtQ==} @@ -13974,6 +14194,32 @@ packages: resolution: {integrity: sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==} dev: true + /side-channel-list@1.0.0: + resolution: {integrity: sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==} + engines: {node: '>= 0.4'} + dependencies: + es-errors: 1.3.0 + object-inspect: 1.13.3 + + /side-channel-map@1.0.1: + resolution: {integrity: sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==} + engines: {node: '>= 0.4'} + dependencies: + call-bound: 1.0.3 + es-errors: 1.3.0 + get-intrinsic: 1.2.7 + object-inspect: 1.13.3 + + /side-channel-weakmap@1.0.2: + resolution: {integrity: sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==} + engines: {node: '>= 0.4'} + dependencies: + call-bound: 1.0.3 + es-errors: 1.3.0 + get-intrinsic: 1.2.7 + object-inspect: 1.13.3 + side-channel-map: 1.0.1 + /side-channel@1.0.4: resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==} dependencies: @@ -13981,6 +14227,16 @@ packages: get-intrinsic: 1.2.2 object-inspect: 1.12.3 + /side-channel@1.1.0: + resolution: {integrity: sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==} + engines: {node: '>= 0.4'} + dependencies: + es-errors: 1.3.0 + object-inspect: 1.13.3 + side-channel-list: 1.0.0 + side-channel-map: 1.0.1 + side-channel-weakmap: 1.0.2 + /siginfo@2.0.0: resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==} dev: true @@ -14458,7 +14714,7 @@ packages: resolution: {integrity: sha512-Y4X9zqrCftUhMeH2EptSSERdVKt/nEdijTOacGD/97EKjhQ/Qs8RTlEGABSJNNN8lac9kheH+af7yAkEWlgneA==} engines: {node: '>=10.0.0'} dependencies: - ajv: 8.12.0 + ajv: 8.17.1 lodash.truncate: 4.4.2 slice-ansi: 4.0.0 string-width: 4.2.3 @@ -15083,12 +15339,6 @@ packages: picocolors: 1.0.0 dev: true - /uri-js@4.4.1: - resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} - dependencies: - punycode: 2.3.0 - dev: true - /url-join@4.0.1: resolution: {integrity: sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==} dev: true diff --git a/provider/modelcontextprotocoltools/index.ts b/provider/modelcontextprotocoltools/index.ts index 7c41db08..366fd38f 100644 --- a/provider/modelcontextprotocoltools/index.ts +++ b/provider/modelcontextprotocoltools/index.ts @@ -1,10 +1,7 @@ import { basename } from 'node:path' import { Client } from '@modelcontextprotocol/sdk/client/index.js' import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js' -import { - CallToolResultSchema, - -} from '@modelcontextprotocol/sdk/types.js' +import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js' import type { Item, ItemsParams, @@ -19,6 +16,7 @@ import type { } from '@openctx/provider' const Ajv = require('ajv') +// Creates a new MCP client specific to the MCP Tools Provider async function createClient( nodeCommand: string, mcpProviderFile: string, @@ -93,12 +91,12 @@ class MCPToolsProxy implements Provider { for (const tool of tools) { // Store the schema in the Map using tool name as key this.toolSchemas.set(tool.name, JSON.stringify(tool.inputSchema)) - + const r = { uri: tool.uri, title: tool.name, description: tool.description, - data: (tool.inputSchema), + data: tool.inputSchema, } as Mention mentions.push(r) } @@ -146,7 +144,9 @@ class MCPToolsProxy implements Provider { const isValid = this.ajv.validate(schema, toolInput) if (!isValid) { console.error('Invalid tool input:', this.ajv.errors) - throw new Error(`Invalid input for tool ${toolName}: ${JSON.stringify(this.ajv.errors)}`) + throw new Error( + `Invalid input for tool ${toolName}: ${JSON.stringify(this.ajv.errors)}`, + ) } } } @@ -155,14 +155,14 @@ class MCPToolsProxy implements Provider { const response = await mcpClient.request( { method: 'tools/call' as const, - params: { + params: { name: toolName, - arguments: toolInput + arguments: toolInput, }, }, CallToolResultSchema, ) - + const contents = response.content const items: Item[] = [] for (const content of contents) { @@ -189,6 +189,5 @@ class MCPToolsProxy implements Provider { } } - const proxy = new MCPToolsProxy() export default proxy diff --git a/provider/modelcontextprotocoltools/package.json b/provider/modelcontextprotocoltools/package.json index 2cf1f38b..fbc6e425 100644 --- a/provider/modelcontextprotocoltools/package.json +++ b/provider/modelcontextprotocoltools/package.json @@ -25,17 +25,9 @@ "watch": "tsc --build --watch & esbuild --log-level=error --platform=node --bundle --format=esm --outfile=dist/bundle.js --watch index.ts" }, "dependencies": { - "@apidevtools/json-schema-ref-parser": "^11.7.3", "@modelcontextprotocol/sdk": "1.0.1", "@openctx/provider": "workspace:*", "ajv": "^8.17.1", "express": "^4.21.1" - }, - "pnpm": { - "peerDependencyRules": { - "allowAny": [ - "@apidevtools/json-schema-ref-parser" - ] - } } } From 4fbd13022774ba1a347426fb6e929a831c9ddd02 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sun, 12 Jan 2025 17:51:41 +0400 Subject: [PATCH 4/5] chore: update pnpm lockfile for modelcontextprotocoltools dependencies --- provider/modelcontextprotocoltools/README.md | 58 ++++---------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/provider/modelcontextprotocoltools/README.md b/provider/modelcontextprotocoltools/README.md index c132c1f4..70136cef 100644 --- a/provider/modelcontextprotocoltools/README.md +++ b/provider/modelcontextprotocoltools/README.md @@ -1,55 +1,17 @@ -# MCP proxy for OpenCtx +# MCP Tools Provider for OpenCtx (Work in Progress) -This is a context provider for [OpenCtx](https://openctx.org) that fetches contents from a [MCP](https://modelcontextprotocol.io) provider for use as context. +This is a context provider for [OpenCtx](https://openctx.org) that enables access to tools exposed by [MCP](https://modelcontextprotocol.io) providers. This provider specifically handles tool interactions - it does not support MCP resources. Currently, only MCP over stdio is supported (HTTP is not yet supported). -## Development +## What This Provider Does +- Connects to MCP providers to expose their available tools +- Validates tool inputs against their schemas +- Executes tool calls and returns results +- Supports tool discovery and filtering via mentions -1. Clone the [modelcontextprotocol/servers](https://github.com/modelcontextprotocol/servers) repository. Follow the instructions there to build the example providers. This should generate output files of the form `build/${example_name}/index.js`. -1. Run `pnpm watch` in this directory. -1. Add the following to your VS Code settings: - ```json - "openctx.providers": { - // ...other providers... - "https://openctx.org/npm/@openctx/provider-modelcontextprotocol": { - "nodeCommand": "node", - "mcp.provider.uri": "file:///path/to/servers/root/build/everything/index.js", - } - } - ``` -1. Reload the VS Code window. You should see `servers/everything` in the `@`-mention dropdown. +## Creating MCP Tools -To hook up to the Postgres MCP provider, use: +To create tools that can be used with this provider, see the [MCP documentation](https://modelcontextprotocol.io) on implementing tool endpoints in your MCP server. -```json -"openctx.providers": { - // ...other providers... - "https://openctx.org/npm/@openctx/provider-modelcontextprotocol": { - "nodeCommand": "node", - "mcp.provider.uri": "file:///path/to/servers/root/build/postgres/index.js", - "mcp.provider.args": [ - "postgresql://sourcegraph:sourcegraph@localhost:5432/sourcegraph" - ] - } -} -``` - -## More MCP Servers - -The following MCP servers are available in the [modelcontextprotocol/servers](https://github.com/modelcontextprotocol/servers) repository: - -- [Brave Search](https://github.com/modelcontextprotocol/servers/tree/main/src/brave-search) - Search the Brave search API -- [Postgres](https://github.com/modelcontextprotocol/servers/tree/main/src/postgres) - Connect to your Postgres databases to query schema information and write optimized SQL -- [Filesystem](https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem) - Access files on your local machine -- [Everything](https://github.com/modelcontextprotocol/servers/tree/main/src/everything) - A demo server showing MCP capabilities -- [Google Drive](https://github.com/modelcontextprotocol/servers/tree/main/src/gdrive) - Search and access your Google Drive documents -- [Google Maps](https://github.com/modelcontextprotocol/servers/tree/main/src/google-maps) - Get directions and information about places -- [Memo](https://github.com/modelcontextprotocol/servers/tree/main/src/memo) - Access your Memo notes -- [Git](https://github.com/modelcontextprotocol/servers/tree/main/src/git) - Get git history and commit information -- [Puppeteer](https://github.com/modelcontextprotocol/servers/tree/main/src/puppeteer) - Control headless Chrome for web automation -- [SQLite](https://github.com/modelcontextprotocol/servers/tree/main/src/sqlite) - Query SQLite databases - -## Creating your own MCP server - -See the [MCP docs](https://modelcontextprotocol.io) for how to create your own MCP servers. \ No newline at end of file +> Note: This provider is under active development. Additional documentation and features will be added once design decisions are finalized. \ No newline at end of file From 06b06827ae4e092582e3c5030de9ae5f8cac45b8 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sun, 12 Jan 2025 17:52:36 +0400 Subject: [PATCH 5/5] chore: update pnpm lockfile for modelcontextprotocoltools dependencies --- provider/modelcontextprotocoltools/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/modelcontextprotocoltools/README.md b/provider/modelcontextprotocoltools/README.md index 70136cef..6ec1a39d 100644 --- a/provider/modelcontextprotocoltools/README.md +++ b/provider/modelcontextprotocoltools/README.md @@ -14,4 +14,4 @@ Currently, only MCP over stdio is supported (HTTP is not yet supported). To create tools that can be used with this provider, see the [MCP documentation](https://modelcontextprotocol.io) on implementing tool endpoints in your MCP server. -> Note: This provider is under active development. Additional documentation and features will be added once design decisions are finalized. \ No newline at end of file +> Note: This provider documentation is under active development. Additional documentation and features examples will be added once design decisions are finalized.