@youdotcom-oss/mcp 2.0.3 → 2.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@youdotcom-oss/mcp",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "You.com API Model Context Protocol Server - For programmatic API access, use @youdotcom-oss/api",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -56,13 +56,13 @@
56
56
  },
57
57
  "mcpName": "io.github.youdotcom-oss/mcp",
58
58
  "dependencies": {
59
- "@youdotcom-oss/api": "0.2.2",
59
+ "@youdotcom-oss/api": "0.3.1",
60
60
  "zod": "^4.3.6",
61
61
  "@hono/mcp": "^0.2.3",
62
62
  "@modelcontextprotocol/sdk": "^1.25.3",
63
63
  "hono": "^4.11.7"
64
64
  },
65
65
  "devDependencies": {
66
- "@modelcontextprotocol/inspector": "0.19.0"
66
+ "@modelcontextprotocol/inspector": "0.20.0"
67
67
  }
68
68
  }
package/src/http.ts CHANGED
@@ -17,19 +17,20 @@ const extractBearerToken = (authHeader: string | null): string | null => {
17
17
  const handleMcpRequest = async (c: Context) => {
18
18
  const authHeader = c.req.header('Authorization')
19
19
 
20
- if (!authHeader) {
21
- c.status(401)
22
- c.header('Content-Type', 'text/plain')
23
- return c.text('Unauthorized: Authorization header required')
24
- }
20
+ let YDC_API_KEY: string | undefined
21
+
22
+ if (authHeader) {
23
+ const token = extractBearerToken(authHeader)
25
24
 
26
- const YDC_API_KEY = extractBearerToken(authHeader)
25
+ if (!token) {
26
+ c.status(401)
27
+ c.header('Content-Type', 'text/plain')
28
+ return c.text('Unauthorized: Invalid Bearer token format')
29
+ }
27
30
 
28
- if (!YDC_API_KEY) {
29
- c.status(401)
30
- c.header('Content-Type', 'text/plain')
31
- return c.text('Unauthorized: Bearer token required')
31
+ YDC_API_KEY = token
32
32
  }
33
+
33
34
  const mcp = getMCpServer()
34
35
  const getUserAgent = useGetClientVersion(mcp)
35
36
 
@@ -76,23 +76,39 @@ describe('HTTP Server Endpoints', () => {
76
76
  expect(typeof data.version).toBe('string')
77
77
  })
78
78
 
79
- test('mcp endpoint requires authorization header', async () => {
79
+ test('mcp endpoint allows requests without authorization (free tier)', async () => {
80
80
  const response = await fetch(`${baseUrl}/mcp`, {
81
81
  method: 'POST',
82
82
  headers: {
83
83
  'Content-Type': 'application/json',
84
+ Accept: 'application/json, text/event-stream',
84
85
  },
85
- body: JSON.stringify({}),
86
+ body: JSON.stringify({
87
+ jsonrpc: '2.0',
88
+ method: 'initialize',
89
+ id: 1,
90
+ params: {
91
+ protocolVersion: '2024-11-05',
92
+ capabilities: {},
93
+ clientInfo: {
94
+ name: 'test-client',
95
+ version: '1.0.0',
96
+ },
97
+ },
98
+ }),
86
99
  })
87
100
 
88
- expect(response.status).toBe(401)
89
- expect(response.headers.get('content-type')).toContain('text/plain')
101
+ // Should succeed without auth header (free tier)
102
+ expect(response.status).toBe(200)
103
+ expect(response.headers.get('content-type')).toContain('text/event-stream')
90
104
 
91
105
  const text = await response.text()
92
- expect(text).toBe('Unauthorized: Authorization header required')
106
+ expect(text).toContain('data:')
107
+ expect(text).toContain('jsonrpc')
108
+ expect(text).toContain('result')
93
109
  })
94
110
 
95
- test('mcp endpoint requires Bearer token format', async () => {
111
+ test('mcp endpoint requires Bearer token format when auth header provided', async () => {
96
112
  const response = await fetch(`${baseUrl}/mcp`, {
97
113
  method: 'POST',
98
114
  headers: {
@@ -106,7 +122,7 @@ describe('HTTP Server Endpoints', () => {
106
122
  expect(response.headers.get('content-type')).toContain('text/plain')
107
123
 
108
124
  const text = await response.text()
109
- expect(text).toBe('Unauthorized: Bearer token required')
125
+ expect(text).toBe('Unauthorized: Invalid Bearer token format')
110
126
  })
111
127
 
112
128
  test('mcp endpoint accepts valid Bearer token', async () => {
@@ -178,20 +194,35 @@ describe('HTTP Server Endpoints', () => {
178
194
  expect(text).toContain('capabilities')
179
195
  })
180
196
 
181
- test('mcp endpoint with trailing slash requires authorization', async () => {
197
+ test('mcp endpoint with trailing slash allows requests without authorization', async () => {
182
198
  const response = await fetch(`${baseUrl}/mcp/`, {
183
199
  method: 'POST',
184
200
  headers: {
185
201
  'Content-Type': 'application/json',
202
+ Accept: 'application/json, text/event-stream',
186
203
  },
187
- body: JSON.stringify({}),
204
+ body: JSON.stringify({
205
+ jsonrpc: '2.0',
206
+ method: 'initialize',
207
+ id: 1,
208
+ params: {
209
+ protocolVersion: '2024-11-05',
210
+ capabilities: {},
211
+ clientInfo: {
212
+ name: 'test-client',
213
+ version: '1.0.0',
214
+ },
215
+ },
216
+ }),
188
217
  })
189
218
 
190
- expect(response.status).toBe(401)
191
- expect(response.headers.get('content-type')).toContain('text/plain')
219
+ // Should succeed without auth header (free tier)
220
+ expect(response.status).toBe(200)
221
+ expect(response.headers.get('content-type')).toContain('text/event-stream')
192
222
 
193
223
  const text = await response.text()
194
- expect(text).toBe('Unauthorized: Authorization header required')
224
+ expect(text).toContain('data:')
225
+ expect(text).toContain('jsonrpc')
195
226
  })
196
227
  })
197
228