Skip to content

Commit 06abe80

Browse files
committed
Fixing and simplifying New Chat keybindings logic
1 parent d5a4ab6 commit 06abe80

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { describe, expect, test, vi } from 'vitest'
2+
import type { MetaParams, ProviderSettings } from '@openctx/provider'
3+
import proxy from './index.js'
4+
5+
vi.mock('@modelcontextprotocol/sdk/client/index.js', () => ({
6+
Client: vi.fn().mockImplementation(() => ({
7+
connect: vi.fn(),
8+
getServerVersion: vi.fn().mockReturnValue({ name: 'Test MCP Server' }),
9+
request: vi.fn().mockImplementation(async (req) => {
10+
if (req.method === 'resources/list') {
11+
return { resources: [
12+
{ uri: 'test://resource', name: 'Test Resource', description: 'Test Description' }
13+
]}
14+
}
15+
if (req.method === 'resources/read') {
16+
return { contents: [
17+
{ uri: 'test://resource', text: 'Test Content', mimeType: 'text/plain' }
18+
]}
19+
}
20+
}),
21+
setNotificationHandler: vi.fn(),
22+
setRequestHandler: vi.fn(),
23+
close: vi.fn()
24+
}))
25+
}))
26+
27+
vi.mock('@modelcontextprotocol/sdk/client/stdio.js', () => ({
28+
StdioClientTransport: vi.fn()
29+
}))
30+
31+
describe('MCP Provider', () => {
32+
const settings: ProviderSettings = {
33+
'mcp.provider.uri': 'file:///path/to/your/mcp/provider.js',
34+
'nodeCommand': 'node',
35+
'mcp.provider.args': ['--some-arg', 'value']
36+
}
37+
38+
test('meta returns provider info', async () => {
39+
const result = await proxy.meta({} as MetaParams, settings)
40+
expect(result).toMatchObject({
41+
name: expect.any(String),
42+
mentions: {
43+
label: expect.any(String)
44+
}
45+
})
46+
})
47+
48+
test('mentions returns resources', async () => {
49+
const result = await proxy.mentions?.({
50+
query: 'test'
51+
}, settings)
52+
53+
expect(result).toBeDefined()
54+
expect(Array.isArray(result)).toBe(true)
55+
})
56+
57+
test('items returns content', async () => {
58+
const result = await proxy.items?.({
59+
mention: {
60+
uri: 'test://resource',
61+
title: 'Test Resource'
62+
}
63+
}, settings)
64+
65+
expect(result).toBeDefined()
66+
expect(Array.isArray(result)).toBe(true)
67+
})
68+
})

provider/modelcontextprotocol/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class MCPProxy implements Provider {
132132
}
133133

134134
async items?(params: ItemsParams, _settings: ProviderSettings): Promise<ItemsResult> {
135+
console.log('items', params)
135136
if (!params.mention || !this.mcpClient) {
136137
return []
137138
}

provider/modelcontextprotocol/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"bundle": "tsc --build && esbuild --log-level=error --platform=node --bundle --format=esm --outfile=dist/bundle.js index.ts",
2222
"prepublishOnly": "tsc --build --clean && npm run --silent bundle",
2323
"test": "vitest",
24+
"test:unit": "vitest run",
2425
"watch": "tsc --build --watch & esbuild --log-level=error --platform=node --bundle --format=esm --outfile=dist/bundle.js --watch index.ts"
2526
},
2627
"dependencies": {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({})

0 commit comments

Comments
 (0)