@youdotcom-oss/mcp 3.2.3 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -240
- package/bin/stdio.js +4877 -18044
- package/package.json +7 -12
- package/server.json +11 -4
- package/src/contents/contents.schemas.ts +0 -30
- package/src/contents/contents.utils.ts +0 -85
- package/src/contents/register-contents-tool.ts +0 -93
- package/src/contents/tests/contents.utils.spec.ts +0 -123
- package/src/get-mcp-server.ts +0 -17
- package/src/main.ts +0 -8
- package/src/research/register-research-tool.ts +0 -69
- package/src/research/research.schemas.ts +0 -19
- package/src/research/research.utils.ts +0 -30
- package/src/research/tests/research.utils.spec.ts +0 -128
- package/src/search/register-search-tool.ts +0 -88
- package/src/search/search.schemas.ts +0 -53
- package/src/search/search.utils.ts +0 -83
- package/src/search/tests/register-search-tool.spec.ts +0 -123
- package/src/search/tests/search.utils.spec.ts +0 -291
- package/src/shared/format-search-results-text.ts +0 -69
- package/src/shared/get-logger.ts +0 -19
- package/src/shared/tests/format-search-results-text.spec.ts +0 -95
- package/src/shared/tests/shared.utils.spec.ts +0 -160
- package/src/shared/use-client-version.ts +0 -21
- package/src/stdio-server.ts +0 -24
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import type { SearchResponse } from '@youdotcom-oss/api'
|
|
3
|
-
import { formatSearchResults } from '../search.utils.ts'
|
|
4
|
-
|
|
5
|
-
describe('formatSearchResults', () => {
|
|
6
|
-
test('formats web results correctly', () => {
|
|
7
|
-
const mockResponse: SearchResponse = {
|
|
8
|
-
results: {
|
|
9
|
-
web: [
|
|
10
|
-
{
|
|
11
|
-
url: 'https://example.com',
|
|
12
|
-
title: 'Test Title',
|
|
13
|
-
description: 'Test description',
|
|
14
|
-
snippets: ['snippet 1', 'snippet 2'],
|
|
15
|
-
page_age: '2023-01-01T00:00:00',
|
|
16
|
-
authors: ['Author Name'],
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
news: [],
|
|
20
|
-
},
|
|
21
|
-
metadata: {
|
|
22
|
-
search_uuid: 'test-uuid',
|
|
23
|
-
query: 'test query',
|
|
24
|
-
latency: 0.1,
|
|
25
|
-
},
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const result = formatSearchResults(mockResponse)
|
|
29
|
-
|
|
30
|
-
expect(result).toHaveProperty('content')
|
|
31
|
-
expect(result).toHaveProperty('structuredContent')
|
|
32
|
-
expect(result).toHaveProperty('fullResponse')
|
|
33
|
-
expect(Array.isArray(result.content)).toBe(true)
|
|
34
|
-
expect(result.content[0]).toHaveProperty('type', 'text')
|
|
35
|
-
expect(result.content[0]).toHaveProperty('text')
|
|
36
|
-
expect(result.content[0]?.text).toContain('WEB RESULTS:')
|
|
37
|
-
expect(result.content[0]?.text).toContain('Test Title')
|
|
38
|
-
// URL and page_age should be in text content
|
|
39
|
-
expect(result.content[0]?.text).toContain('URL: https://example.com')
|
|
40
|
-
expect(result.content[0]?.text).toContain('Published: 2023-01-01T00:00:00')
|
|
41
|
-
expect(result.structuredContent).toHaveProperty('resultCounts')
|
|
42
|
-
expect(result.structuredContent.resultCounts).toHaveProperty('web', 1)
|
|
43
|
-
expect(result.structuredContent.resultCounts).toHaveProperty('news', 0)
|
|
44
|
-
expect(result.structuredContent.resultCounts).toHaveProperty('total', 1)
|
|
45
|
-
// All fields should be in structuredContent.results
|
|
46
|
-
expect(result.structuredContent).toHaveProperty('results')
|
|
47
|
-
expect(result.structuredContent.results?.web).toBeDefined()
|
|
48
|
-
expect(result.structuredContent.results?.web?.length).toBe(1)
|
|
49
|
-
expect(result.structuredContent.results?.web?.[0]).toMatchObject({
|
|
50
|
-
url: 'https://example.com',
|
|
51
|
-
title: 'Test Title',
|
|
52
|
-
page_age: '2023-01-01T00:00:00',
|
|
53
|
-
snippets: ['snippet 1', 'snippet 2'],
|
|
54
|
-
})
|
|
55
|
-
expect(result.fullResponse).toBe(mockResponse)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test('formats news results correctly', () => {
|
|
59
|
-
const mockResponse: SearchResponse = {
|
|
60
|
-
results: {
|
|
61
|
-
web: [],
|
|
62
|
-
news: [
|
|
63
|
-
{
|
|
64
|
-
title: 'News Title',
|
|
65
|
-
description: 'News description',
|
|
66
|
-
page_age: '2023-01-01T00:00:00',
|
|
67
|
-
url: 'https://news.com/article',
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
metadata: {
|
|
72
|
-
search_uuid: 'test-uuid',
|
|
73
|
-
query: 'test query',
|
|
74
|
-
latency: 0.1,
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const result = formatSearchResults(mockResponse)
|
|
79
|
-
|
|
80
|
-
expect(result.content[0]?.text).toContain('NEWS RESULTS:')
|
|
81
|
-
expect(result.content[0]?.text).toContain('News Title')
|
|
82
|
-
expect(result.content[0]?.text).toContain('Published: 2023-01-01T00:00:00')
|
|
83
|
-
// URL and Description should be in text content (routed through formatSearchResultsText)
|
|
84
|
-
expect(result.content[0]?.text).toContain('URL: https://news.com/article')
|
|
85
|
-
expect(result.content[0]?.text).toContain('Description: News description')
|
|
86
|
-
expect(result.structuredContent).toHaveProperty('resultCounts')
|
|
87
|
-
expect(result.structuredContent.resultCounts).toHaveProperty('web', 0)
|
|
88
|
-
expect(result.structuredContent.resultCounts).toHaveProperty('news', 1)
|
|
89
|
-
expect(result.structuredContent.resultCounts).toHaveProperty('total', 1)
|
|
90
|
-
// All fields should be in structuredContent.results
|
|
91
|
-
expect(result.structuredContent).toHaveProperty('results')
|
|
92
|
-
expect(result.structuredContent.results?.news).toBeDefined()
|
|
93
|
-
expect(result.structuredContent.results?.news?.length).toBe(1)
|
|
94
|
-
expect(result.structuredContent.results?.news?.[0]).toMatchObject({
|
|
95
|
-
url: 'https://news.com/article',
|
|
96
|
-
title: 'News Title',
|
|
97
|
-
page_age: '2023-01-01T00:00:00',
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
test('formats both web and news results', () => {
|
|
102
|
-
const mockResponse: SearchResponse = {
|
|
103
|
-
results: {
|
|
104
|
-
web: [
|
|
105
|
-
{
|
|
106
|
-
url: 'https://web.com',
|
|
107
|
-
title: 'Web Title',
|
|
108
|
-
description: 'Web description',
|
|
109
|
-
snippets: ['web snippet'],
|
|
110
|
-
page_age: '2023-01-01T00:00:00',
|
|
111
|
-
authors: ['Web Author'],
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
news: [
|
|
115
|
-
{
|
|
116
|
-
title: 'News Title',
|
|
117
|
-
description: 'News description',
|
|
118
|
-
page_age: '2023-01-01T00:00:00',
|
|
119
|
-
url: 'https://news.com/article',
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
},
|
|
123
|
-
metadata: {
|
|
124
|
-
search_uuid: 'test-uuid',
|
|
125
|
-
query: 'test query',
|
|
126
|
-
latency: 0.1,
|
|
127
|
-
},
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const result = formatSearchResults(mockResponse)
|
|
131
|
-
|
|
132
|
-
expect(result.content[0]?.text).toContain('WEB RESULTS:')
|
|
133
|
-
expect(result.content[0]?.text).toContain('NEWS RESULTS:')
|
|
134
|
-
expect(result.content[0]?.text).toContain(`=${'='.repeat(49)}`)
|
|
135
|
-
// URLs should be in text content
|
|
136
|
-
expect(result.content[0]?.text).toContain('URL: https://web.com')
|
|
137
|
-
expect(result.content[0]?.text).toContain('URL: https://news.com/article')
|
|
138
|
-
expect(result.structuredContent.resultCounts).toHaveProperty('web', 1)
|
|
139
|
-
expect(result.structuredContent.resultCounts).toHaveProperty('news', 1)
|
|
140
|
-
expect(result.structuredContent.resultCounts).toHaveProperty('total', 2)
|
|
141
|
-
// All fields should be in structuredContent.results
|
|
142
|
-
expect(result.structuredContent).toHaveProperty('results')
|
|
143
|
-
expect(result.structuredContent.results?.web).toBeDefined()
|
|
144
|
-
expect(result.structuredContent.results?.news).toBeDefined()
|
|
145
|
-
expect(result.structuredContent.results?.web?.length).toBe(1)
|
|
146
|
-
expect(result.structuredContent.results?.news?.length).toBe(1)
|
|
147
|
-
expect(result.structuredContent.results?.web?.[0]).toMatchObject({
|
|
148
|
-
url: 'https://web.com',
|
|
149
|
-
title: 'Web Title',
|
|
150
|
-
page_age: '2023-01-01T00:00:00',
|
|
151
|
-
snippets: ['web snippet'],
|
|
152
|
-
})
|
|
153
|
-
expect(result.structuredContent.results?.news?.[0]).toMatchObject({
|
|
154
|
-
url: 'https://news.com/article',
|
|
155
|
-
title: 'News Title',
|
|
156
|
-
page_age: '2023-01-01T00:00:00',
|
|
157
|
-
})
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
test('includes contents in structuredContent and text indicator when livecrawl returns page content', () => {
|
|
161
|
-
const mockResponse: SearchResponse = {
|
|
162
|
-
results: {
|
|
163
|
-
web: [
|
|
164
|
-
{
|
|
165
|
-
url: 'https://example.com',
|
|
166
|
-
title: 'Livecrawl Title',
|
|
167
|
-
description: 'A page with content',
|
|
168
|
-
snippets: ['snippet'],
|
|
169
|
-
page_age: '2023-01-01T00:00:00',
|
|
170
|
-
authors: [],
|
|
171
|
-
contents: {
|
|
172
|
-
markdown: 'Full page content in markdown format.',
|
|
173
|
-
html: '<p>Full page content in HTML format.</p>',
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
news: [],
|
|
178
|
-
},
|
|
179
|
-
metadata: {
|
|
180
|
-
search_uuid: 'test-uuid',
|
|
181
|
-
query: 'livecrawl test',
|
|
182
|
-
latency: 0.5,
|
|
183
|
-
},
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const result = formatSearchResults(mockResponse)
|
|
187
|
-
|
|
188
|
-
// Text content should include the contents indicator
|
|
189
|
-
expect(result.content[0]?.text).toContain('Page content available:')
|
|
190
|
-
expect(result.content[0]?.text).toContain('chars (markdown)')
|
|
191
|
-
expect(result.content[0]?.text).toContain('chars (html)')
|
|
192
|
-
|
|
193
|
-
// structuredContent should include contents
|
|
194
|
-
expect(result.structuredContent.results?.web?.[0]).toMatchObject({
|
|
195
|
-
url: 'https://example.com',
|
|
196
|
-
title: 'Livecrawl Title',
|
|
197
|
-
contents: {
|
|
198
|
-
markdown: 'Full page content in markdown format.',
|
|
199
|
-
html: '<p>Full page content in HTML format.</p>',
|
|
200
|
-
},
|
|
201
|
-
})
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
test('omits contents when not present in response', () => {
|
|
205
|
-
const mockResponse: SearchResponse = {
|
|
206
|
-
results: {
|
|
207
|
-
web: [
|
|
208
|
-
{
|
|
209
|
-
url: 'https://example.com',
|
|
210
|
-
title: 'No Content',
|
|
211
|
-
description: 'A page without livecrawl',
|
|
212
|
-
snippets: ['snippet'],
|
|
213
|
-
},
|
|
214
|
-
],
|
|
215
|
-
news: [],
|
|
216
|
-
},
|
|
217
|
-
metadata: {
|
|
218
|
-
search_uuid: 'test-uuid',
|
|
219
|
-
query: 'test',
|
|
220
|
-
latency: 0.1,
|
|
221
|
-
},
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const result = formatSearchResults(mockResponse)
|
|
225
|
-
|
|
226
|
-
expect(result.content[0]?.text).not.toContain('Page content available:')
|
|
227
|
-
expect(result.structuredContent.results?.web?.[0]?.contents).toBeUndefined()
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
test('includes contents indicator for news results with livecrawl', () => {
|
|
231
|
-
const mockResponse: SearchResponse = {
|
|
232
|
-
results: {
|
|
233
|
-
web: [],
|
|
234
|
-
news: [
|
|
235
|
-
{
|
|
236
|
-
title: 'News with Content',
|
|
237
|
-
description: 'Breaking news',
|
|
238
|
-
page_age: '2023-01-01T00:00:00',
|
|
239
|
-
url: 'https://news.com/article',
|
|
240
|
-
contents: {
|
|
241
|
-
markdown: 'Full news article content in markdown.',
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
|
-
],
|
|
245
|
-
},
|
|
246
|
-
metadata: {
|
|
247
|
-
search_uuid: 'test-uuid',
|
|
248
|
-
query: 'news livecrawl test',
|
|
249
|
-
latency: 0.4,
|
|
250
|
-
},
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const result = formatSearchResults(mockResponse)
|
|
254
|
-
|
|
255
|
-
// Text content should include the contents indicator for news too
|
|
256
|
-
expect(result.content[0]?.text).toContain('Page content available:')
|
|
257
|
-
expect(result.content[0]?.text).toContain('chars (markdown)')
|
|
258
|
-
|
|
259
|
-
// structuredContent should include contents for news
|
|
260
|
-
expect(result.structuredContent.results?.news?.[0]).toMatchObject({
|
|
261
|
-
url: 'https://news.com/article',
|
|
262
|
-
title: 'News with Content',
|
|
263
|
-
contents: { markdown: 'Full news article content in markdown.' },
|
|
264
|
-
})
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
test('includes snippets in structuredContent for web results', () => {
|
|
268
|
-
const mockResponse: SearchResponse = {
|
|
269
|
-
results: {
|
|
270
|
-
web: [
|
|
271
|
-
{
|
|
272
|
-
url: 'https://example.com',
|
|
273
|
-
title: 'With Snippets',
|
|
274
|
-
description: 'Has snippets',
|
|
275
|
-
snippets: ['first snippet', 'second snippet'],
|
|
276
|
-
},
|
|
277
|
-
],
|
|
278
|
-
news: [],
|
|
279
|
-
},
|
|
280
|
-
metadata: {
|
|
281
|
-
search_uuid: 'test-uuid',
|
|
282
|
-
query: 'test',
|
|
283
|
-
latency: 0.1,
|
|
284
|
-
},
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const result = formatSearchResults(mockResponse)
|
|
288
|
-
|
|
289
|
-
expect(result.structuredContent.results?.web?.[0]?.snippets).toEqual(['first snippet', 'second snippet'])
|
|
290
|
-
})
|
|
291
|
-
})
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic search result type for Search API results
|
|
3
|
-
* Used by search.utils.ts
|
|
4
|
-
*/
|
|
5
|
-
type GenericSearchResult = {
|
|
6
|
-
url: string
|
|
7
|
-
title: string
|
|
8
|
-
description?: string
|
|
9
|
-
snippet?: string
|
|
10
|
-
snippets?: string[]
|
|
11
|
-
page_age?: string
|
|
12
|
-
contents?: { html?: string; markdown?: string }
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Format a character count with locale-aware number formatting
|
|
17
|
-
*/
|
|
18
|
-
const formatCharCount = (count: number): string => count.toLocaleString()
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Format array of search results into display text
|
|
22
|
-
* Used by search result formatting
|
|
23
|
-
* @param results - Array of search results to format
|
|
24
|
-
*/
|
|
25
|
-
export const formatSearchResultsText = (results: GenericSearchResult[]): string => {
|
|
26
|
-
return results
|
|
27
|
-
.map((result) => {
|
|
28
|
-
const parts: string[] = [`Title: ${result.title}`]
|
|
29
|
-
|
|
30
|
-
// Add URL
|
|
31
|
-
parts.push(`URL: ${result.url}`)
|
|
32
|
-
|
|
33
|
-
// Add page age if present
|
|
34
|
-
if (result.page_age) {
|
|
35
|
-
parts.push(`Published: ${result.page_age}`)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Add description if present (from Search API)
|
|
39
|
-
if (result.description) {
|
|
40
|
-
parts.push(`Description: ${result.description}`)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Handle snippets array (from Search API)
|
|
44
|
-
if (result.snippets && result.snippets.length > 0) {
|
|
45
|
-
parts.push(`Snippets:\n- ${result.snippets.join('\n- ')}`)
|
|
46
|
-
}
|
|
47
|
-
// Handle single snippet
|
|
48
|
-
else if (result.snippet) {
|
|
49
|
-
parts.push(`Snippet: ${result.snippet}`)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Add contents indicator if livecrawl returned page content
|
|
53
|
-
if (result.contents) {
|
|
54
|
-
const formats: string[] = []
|
|
55
|
-
if (result.contents.markdown) {
|
|
56
|
-
formats.push(`${formatCharCount(result.contents.markdown.length)} chars (markdown)`)
|
|
57
|
-
}
|
|
58
|
-
if (result.contents.html) {
|
|
59
|
-
formats.push(`${formatCharCount(result.contents.html.length)} chars (html)`)
|
|
60
|
-
}
|
|
61
|
-
if (formats.length > 0) {
|
|
62
|
-
parts.push(`Page content available: ${formats.join(', ')}`)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return parts.join('\n')
|
|
67
|
-
})
|
|
68
|
-
.join('\n\n')
|
|
69
|
-
}
|
package/src/shared/get-logger.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { LoggingMessageNotification, ServerNotification } from '@modelcontextprotocol/sdk/types.js'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a logger that routes notifications through the request's SSE stream
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* Uses `extra.sendNotification` from the tool callback, which attaches `relatedRequestId`
|
|
8
|
-
* so the transport routes the message to the POST SSE stream (not the standalone GET stream).
|
|
9
|
-
*
|
|
10
|
-
* @param sendNotification - From the tool callback's `extra` parameter
|
|
11
|
-
* @returns Async function that sends logging notifications
|
|
12
|
-
*
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export const getLogger =
|
|
16
|
-
(sendNotification: (notification: ServerNotification) => Promise<void>) =>
|
|
17
|
-
async (params: LoggingMessageNotification['params']) => {
|
|
18
|
-
await sendNotification({ method: 'notifications/message', params })
|
|
19
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { formatSearchResultsText } from '../format-search-results-text.ts'
|
|
3
|
-
|
|
4
|
-
describe('formatSearchResultsText', () => {
|
|
5
|
-
test('formats basic search results with title and URL', () => {
|
|
6
|
-
const result = formatSearchResultsText([{ url: 'https://example.com', title: 'Test' }])
|
|
7
|
-
|
|
8
|
-
expect(result).toContain('Title: Test')
|
|
9
|
-
expect(result).toContain('URL: https://example.com')
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
test('includes page_age when present', () => {
|
|
13
|
-
const result = formatSearchResultsText([{ url: 'https://example.com', title: 'Test', page_age: '2023-01-01' }])
|
|
14
|
-
|
|
15
|
-
expect(result).toContain('Published: 2023-01-01')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test('includes description when present', () => {
|
|
19
|
-
const result = formatSearchResultsText([
|
|
20
|
-
{ url: 'https://example.com', title: 'Test', description: 'A description' },
|
|
21
|
-
])
|
|
22
|
-
|
|
23
|
-
expect(result).toContain('Description: A description')
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
test('includes snippets array when present', () => {
|
|
27
|
-
const result = formatSearchResultsText([{ url: 'https://example.com', title: 'Test', snippets: ['one', 'two'] }])
|
|
28
|
-
|
|
29
|
-
expect(result).toContain('Snippets:')
|
|
30
|
-
expect(result).toContain('- one')
|
|
31
|
-
expect(result).toContain('- two')
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('includes single snippet when present', () => {
|
|
35
|
-
const result = formatSearchResultsText([{ url: 'https://example.com', title: 'Test', snippet: 'a snippet' }])
|
|
36
|
-
|
|
37
|
-
expect(result).toContain('Snippet: a snippet')
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
test('formats multiple results with separator', () => {
|
|
41
|
-
const result = formatSearchResultsText([
|
|
42
|
-
{ url: 'https://a.com', title: 'A' },
|
|
43
|
-
{ url: 'https://b.com', title: 'B' },
|
|
44
|
-
])
|
|
45
|
-
|
|
46
|
-
expect(result).toContain('Title: A')
|
|
47
|
-
expect(result).toContain('Title: B')
|
|
48
|
-
expect(result).toContain('\n\n')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('handles empty results array', () => {
|
|
52
|
-
const result = formatSearchResultsText([])
|
|
53
|
-
|
|
54
|
-
expect(result).toBe('')
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('includes contents indicator when markdown content is present', () => {
|
|
58
|
-
const result = formatSearchResultsText([
|
|
59
|
-
{
|
|
60
|
-
url: 'https://example.com',
|
|
61
|
-
title: 'Test',
|
|
62
|
-
contents: { markdown: 'A'.repeat(4523) },
|
|
63
|
-
},
|
|
64
|
-
])
|
|
65
|
-
|
|
66
|
-
expect(result).toContain('Page content available:')
|
|
67
|
-
expect(result).toContain('4,523 chars (markdown)')
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
test('includes contents indicator for both markdown and html', () => {
|
|
71
|
-
const result = formatSearchResultsText([
|
|
72
|
-
{
|
|
73
|
-
url: 'https://example.com',
|
|
74
|
-
title: 'Test',
|
|
75
|
-
contents: { markdown: 'markdown content', html: '<p>html content</p>' },
|
|
76
|
-
},
|
|
77
|
-
])
|
|
78
|
-
|
|
79
|
-
expect(result).toContain('Page content available:')
|
|
80
|
-
expect(result).toContain('chars (markdown)')
|
|
81
|
-
expect(result).toContain('chars (html)')
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
test('omits contents indicator when contents object has no content', () => {
|
|
85
|
-
const result = formatSearchResultsText([{ url: 'https://example.com', title: 'Test', contents: {} }])
|
|
86
|
-
|
|
87
|
-
expect(result).not.toContain('Page content available:')
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('omits contents indicator when contents is not present', () => {
|
|
91
|
-
const result = formatSearchResultsText([{ url: 'https://example.com', title: 'Test' }])
|
|
92
|
-
|
|
93
|
-
expect(result).not.toContain('Page content available:')
|
|
94
|
-
})
|
|
95
|
-
})
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
3
|
-
import { useGetClientVersion } from '../use-client-version.ts'
|
|
4
|
-
|
|
5
|
-
describe('useGetClientVersion', () => {
|
|
6
|
-
test('returns formatted string with all fields present', () => {
|
|
7
|
-
const mockMcp = {
|
|
8
|
-
server: {
|
|
9
|
-
getClientVersion: () => ({
|
|
10
|
-
name: 'test-client',
|
|
11
|
-
version: '1.0.0',
|
|
12
|
-
title: 'Test Client',
|
|
13
|
-
websiteUrl: 'https://example.com',
|
|
14
|
-
}),
|
|
15
|
-
},
|
|
16
|
-
} as unknown as McpServer
|
|
17
|
-
|
|
18
|
-
const getUserAgent = useGetClientVersion(mockMcp)
|
|
19
|
-
const result = getUserAgent()
|
|
20
|
-
|
|
21
|
-
expect(result).toMatch(
|
|
22
|
-
/^MCP\/[\d.]+(-[\w.]+)? \(You\.com; test-client; 1\.0\.0; Test Client; https:\/\/example\.com\)$/,
|
|
23
|
-
)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
test('returns formatted string with name and version only', () => {
|
|
27
|
-
const mockMcp = {
|
|
28
|
-
server: {
|
|
29
|
-
getClientVersion: () => ({
|
|
30
|
-
name: 'test-client',
|
|
31
|
-
version: '1.0.0',
|
|
32
|
-
}),
|
|
33
|
-
},
|
|
34
|
-
} as unknown as McpServer
|
|
35
|
-
|
|
36
|
-
const getUserAgent = useGetClientVersion(mockMcp)
|
|
37
|
-
const result = getUserAgent()
|
|
38
|
-
|
|
39
|
-
expect(result).toMatch(/^MCP\/[\d.]+(-[\w.]+)? \(You\.com; test-client; 1\.0\.0\)$/)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
test('returns UNKNOWN when no client version available', () => {
|
|
43
|
-
const mockMcp = {
|
|
44
|
-
server: {
|
|
45
|
-
getClientVersion: () => null,
|
|
46
|
-
},
|
|
47
|
-
} as unknown as McpServer
|
|
48
|
-
|
|
49
|
-
const getUserAgent = useGetClientVersion(mockMcp)
|
|
50
|
-
const result = getUserAgent()
|
|
51
|
-
|
|
52
|
-
expect(result).toMatch(/^MCP\/[\d.]+(-[\w.]+)? \(You\.com; UNKNOWN\)$/)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
test('returns UNKNOWN when getClientVersion returns undefined', () => {
|
|
56
|
-
const mockMcp = {
|
|
57
|
-
server: {
|
|
58
|
-
getClientVersion: () => undefined,
|
|
59
|
-
},
|
|
60
|
-
} as unknown as McpServer
|
|
61
|
-
|
|
62
|
-
const getUserAgent = useGetClientVersion(mockMcp)
|
|
63
|
-
const result = getUserAgent()
|
|
64
|
-
|
|
65
|
-
expect(result).toMatch(/^MCP\/[\d.]+(-[\w.]+)? \(You\.com; UNKNOWN\)$/)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
test('filters out empty strings from fields', () => {
|
|
69
|
-
const mockMcp = {
|
|
70
|
-
server: {
|
|
71
|
-
getClientVersion: () => ({
|
|
72
|
-
name: 'test-client',
|
|
73
|
-
version: '1.0.0',
|
|
74
|
-
title: '', // Empty string should be filtered out
|
|
75
|
-
websiteUrl: 'https://example.com',
|
|
76
|
-
}),
|
|
77
|
-
},
|
|
78
|
-
} as unknown as McpServer
|
|
79
|
-
|
|
80
|
-
const getUserAgent = useGetClientVersion(mockMcp)
|
|
81
|
-
const result = getUserAgent()
|
|
82
|
-
|
|
83
|
-
expect(result).toMatch(/^MCP\/[\d.]+(-[\w.]+)? \(You\.com; test-client; 1\.0\.0; https:\/\/example\.com\)$/)
|
|
84
|
-
expect(result).not.toContain(';;') // No double semicolons
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
test('filters out null values from fields', () => {
|
|
88
|
-
const mockMcp = {
|
|
89
|
-
server: {
|
|
90
|
-
getClientVersion: () => ({
|
|
91
|
-
name: 'test-client',
|
|
92
|
-
version: '1.0.0',
|
|
93
|
-
title: null, // Null should be filtered out
|
|
94
|
-
websiteUrl: 'https://example.com',
|
|
95
|
-
}),
|
|
96
|
-
},
|
|
97
|
-
} as unknown as McpServer
|
|
98
|
-
|
|
99
|
-
const getUserAgent = useGetClientVersion(mockMcp)
|
|
100
|
-
const result = getUserAgent()
|
|
101
|
-
|
|
102
|
-
expect(result).toMatch(/^MCP\/[\d.]+(-[\w.]+)? \(You\.com; test-client; 1\.0\.0; https:\/\/example\.com\)$/)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
test('handles partial fields - name, version, and title only', () => {
|
|
106
|
-
const mockMcp = {
|
|
107
|
-
server: {
|
|
108
|
-
getClientVersion: () => ({
|
|
109
|
-
name: 'Claude Desktop',
|
|
110
|
-
version: '0.7.6',
|
|
111
|
-
title: 'Claude Desktop App',
|
|
112
|
-
}),
|
|
113
|
-
},
|
|
114
|
-
} as unknown as McpServer
|
|
115
|
-
|
|
116
|
-
const getUserAgent = useGetClientVersion(mockMcp)
|
|
117
|
-
const result = getUserAgent()
|
|
118
|
-
|
|
119
|
-
expect(result).toMatch(/^MCP\/[\d.]+(-[\w.]+)? \(You\.com; Claude Desktop; 0\.7\.6; Claude Desktop App\)$/)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
test('handles Claude Desktop client info format', () => {
|
|
123
|
-
const mockMcp = {
|
|
124
|
-
server: {
|
|
125
|
-
getClientVersion: () => ({
|
|
126
|
-
name: 'Claude Desktop',
|
|
127
|
-
version: '0.7.6',
|
|
128
|
-
}),
|
|
129
|
-
},
|
|
130
|
-
} as unknown as McpServer
|
|
131
|
-
|
|
132
|
-
const getUserAgent = useGetClientVersion(mockMcp)
|
|
133
|
-
const result = getUserAgent()
|
|
134
|
-
|
|
135
|
-
expect(result).toMatch(/^MCP\/[\d.]+(-[\w.]+)? \(You\.com; Claude Desktop; 0\.7\.6\)$/)
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
test('returns a function that can be called multiple times', () => {
|
|
139
|
-
const mockMcp = {
|
|
140
|
-
server: {
|
|
141
|
-
getClientVersion: () => ({
|
|
142
|
-
name: 'test-client',
|
|
143
|
-
version: '1.0.0',
|
|
144
|
-
}),
|
|
145
|
-
},
|
|
146
|
-
} as unknown as McpServer
|
|
147
|
-
|
|
148
|
-
const getUserAgent = useGetClientVersion(mockMcp)
|
|
149
|
-
|
|
150
|
-
// Call multiple times to ensure consistent results
|
|
151
|
-
const result1 = getUserAgent()
|
|
152
|
-
const result2 = getUserAgent()
|
|
153
|
-
const result3 = getUserAgent()
|
|
154
|
-
|
|
155
|
-
const pattern = /^MCP\/[\d.]+(-[\w.]+)? \(You\.com; test-client; 1\.0\.0\)$/
|
|
156
|
-
expect(result1).toMatch(pattern)
|
|
157
|
-
expect(result2).toMatch(pattern)
|
|
158
|
-
expect(result3).toMatch(pattern)
|
|
159
|
-
})
|
|
160
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
-
import packageJson from '../../package.json' with { type: 'json' }
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates User-Agent string for API requests
|
|
6
|
-
* Used by search and contents API calls
|
|
7
|
-
*/
|
|
8
|
-
const setUserAgent = (client: string) => `MCP/${packageJson.version} (You.com; ${client})`
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get's function that returns a formatted client version information into a string
|
|
12
|
-
* Used by stdio.ts and http.ts for logging/debugging
|
|
13
|
-
*/
|
|
14
|
-
export const useGetClientVersion = (mcp: McpServer) => () => {
|
|
15
|
-
const clientVersion = mcp.server.getClientVersion()
|
|
16
|
-
if (clientVersion) {
|
|
17
|
-
const { name, version, title, websiteUrl } = clientVersion
|
|
18
|
-
return setUserAgent([name, version, title, websiteUrl].filter(Boolean).join('; '))
|
|
19
|
-
}
|
|
20
|
-
return setUserAgent('UNKNOWN')
|
|
21
|
-
}
|
package/src/stdio-server.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
3
|
-
import { registerContentsTool } from './contents/register-contents-tool.ts'
|
|
4
|
-
import { getMcpServer } from './get-mcp-server.ts'
|
|
5
|
-
import { registerResearchTool } from './research/register-research-tool.ts'
|
|
6
|
-
import { registerSearchTool } from './search/register-search-tool.ts'
|
|
7
|
-
import { useGetClientVersion } from './shared/use-client-version.ts'
|
|
8
|
-
|
|
9
|
-
const YDC_API_KEY = process.env.YDC_API_KEY || undefined
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
const mcp = getMcpServer()
|
|
13
|
-
const getUserAgent = useGetClientVersion(mcp)
|
|
14
|
-
|
|
15
|
-
registerSearchTool({ mcp, YDC_API_KEY, getUserAgent })
|
|
16
|
-
registerContentsTool({ mcp, YDC_API_KEY, getUserAgent })
|
|
17
|
-
registerResearchTool({ mcp, YDC_API_KEY, getUserAgent })
|
|
18
|
-
|
|
19
|
-
const transport = new StdioServerTransport()
|
|
20
|
-
await mcp.connect(transport)
|
|
21
|
-
} catch (error) {
|
|
22
|
-
process.stderr.write(`Failed to start MCP server: ${error}\n`)
|
|
23
|
-
process.exit(1)
|
|
24
|
-
}
|