Skip to content

Commit 51ea577

Browse files
committed
great progress
1 parent b802249 commit 51ea577

File tree

15 files changed

+86
-459
lines changed

15 files changed

+86
-459
lines changed
Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,25 @@
1-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
2-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
31
import { test, expect, inject } from 'vitest'
2+
import { z } from 'zod'
43

54
const mcpServerPort = inject('mcpServerPort')
5+
const mcpServerUrl = `http://localhost:${mcpServerPort}`
66

7-
async function setupClient() {
8-
const client = new Client(
9-
{
10-
name: 'EpicMeTester',
11-
version: '1.0.0',
12-
},
13-
{ capabilities: {} },
14-
)
7+
test(`Missing Authorization header returns 401 with WWW-Authenticate`, async () => {
8+
const response = await fetch(`${mcpServerUrl}/mcp`)
159

16-
const transport = new StreamableHTTPClientTransport(
17-
new URL(`http://localhost:${mcpServerPort}/mcp`),
18-
)
10+
expect(
11+
response.status,
12+
'🚨 Request without Authorization header should return 401 Unauthorized',
13+
).toBe(401)
1914

20-
await client.connect(transport)
15+
const wwwAuthenticate = response.headers.get('WWW-Authenticate')
16+
expect(
17+
wwwAuthenticate,
18+
'🚨 401 response should include WWW-Authenticate header',
19+
).toBeTruthy()
2120

22-
return {
23-
client,
24-
async [Symbol.asyncDispose]() {
25-
await client.transport?.close()
26-
},
27-
}
28-
}
29-
30-
test('listing tools works', async () => {
31-
await using setup = await setupClient()
32-
const { client } = setup
33-
34-
const result = await client.listTools()
35-
expect(result.tools.length).toBeGreaterThan(0)
21+
expect(
22+
wwwAuthenticate,
23+
'🚨 WWW-Authenticate header should specify Bearer realm="EpicMe"',
24+
).toBe('Bearer realm="EpicMe"')
3625
})
Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,25 @@
1-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
2-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
31
import { test, expect, inject } from 'vitest'
2+
import { z } from 'zod'
43

54
const mcpServerPort = inject('mcpServerPort')
5+
const mcpServerUrl = `http://localhost:${mcpServerPort}`
66

7-
async function setupClient() {
8-
const client = new Client(
9-
{
10-
name: 'EpicMeTester',
11-
version: '1.0.0',
12-
},
13-
{ capabilities: {} },
14-
)
7+
test(`Missing Authorization header returns 401 with WWW-Authenticate`, async () => {
8+
const response = await fetch(`${mcpServerUrl}/mcp`)
159

16-
const transport = new StreamableHTTPClientTransport(
17-
new URL(`http://localhost:${mcpServerPort}/mcp`),
18-
)
10+
expect(
11+
response.status,
12+
'🚨 Request without Authorization header should return 401 Unauthorized',
13+
).toBe(401)
1914

20-
await client.connect(transport)
15+
const wwwAuthenticate = response.headers.get('WWW-Authenticate')
16+
expect(
17+
wwwAuthenticate,
18+
'🚨 401 response should include WWW-Authenticate header',
19+
).toBeTruthy()
2120

22-
return {
23-
client,
24-
async [Symbol.asyncDispose]() {
25-
await client.transport?.close()
26-
},
27-
}
28-
}
29-
30-
test('listing tools works', async () => {
31-
await using setup = await setupClient()
32-
const { client } = setup
33-
34-
const result = await client.listTools()
35-
expect(result.tools.length).toBeGreaterThan(0)
21+
expect(
22+
wwwAuthenticate,
23+
'🚨 WWW-Authenticate header should specify Bearer realm="EpicMe"',
24+
).toBe('Bearer realm="EpicMe"')
3625
})
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
1-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
2-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
31
import { test, expect, inject } from 'vitest'
2+
import { z } from 'zod'
43

54
const mcpServerPort = inject('mcpServerPort')
5+
const mcpServerUrl = `http://localhost:${mcpServerPort}`
66

7-
async function setupClient() {
8-
const client = new Client(
9-
{
10-
name: 'EpicMeTester',
11-
version: '1.0.0',
12-
},
13-
{ capabilities: {} },
14-
)
15-
16-
const transport = new StreamableHTTPClientTransport(
17-
new URL(`http://localhost:${mcpServerPort}/mcp`),
18-
)
19-
20-
await client.connect(transport)
21-
22-
return {
23-
client,
24-
async [Symbol.asyncDispose]() {
25-
await client.transport?.close()
26-
},
27-
}
28-
}
29-
30-
test('listing tools works', async () => {
31-
await using setup = await setupClient()
32-
const { client } = setup
33-
34-
const result = await client.listTools()
35-
expect(result.tools.length).toBeGreaterThan(0)
7+
test(`TODO: update this test title to describe the important thing we're working on in this exercise step`, async () => {
8+
// TODO: implement this test
369
})
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
1-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
2-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
31
import { test, expect, inject } from 'vitest'
2+
import { z } from 'zod'
43

54
const mcpServerPort = inject('mcpServerPort')
5+
const mcpServerUrl = `http://localhost:${mcpServerPort}`
66

7-
async function setupClient() {
8-
const client = new Client(
9-
{
10-
name: 'EpicMeTester',
11-
version: '1.0.0',
12-
},
13-
{ capabilities: {} },
14-
)
15-
16-
const transport = new StreamableHTTPClientTransport(
17-
new URL(`http://localhost:${mcpServerPort}/mcp`),
18-
)
19-
20-
await client.connect(transport)
21-
22-
return {
23-
client,
24-
async [Symbol.asyncDispose]() {
25-
await client.transport?.close()
26-
},
27-
}
28-
}
29-
30-
test('listing tools works', async () => {
31-
await using setup = await setupClient()
32-
const { client } = setup
33-
34-
const result = await client.listTools()
35-
expect(result.tools.length).toBeGreaterThan(0)
7+
test(`TODO: update this test title to describe the important thing we're working on in this exercise step`, async () => {
8+
// TODO: implement this test
369
})
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
1-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
2-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
31
import { test, expect, inject } from 'vitest'
2+
import { z } from 'zod'
43

54
const mcpServerPort = inject('mcpServerPort')
5+
const mcpServerUrl = `http://localhost:${mcpServerPort}`
66

7-
async function setupClient() {
8-
const client = new Client(
9-
{
10-
name: 'EpicMeTester',
11-
version: '1.0.0',
12-
},
13-
{ capabilities: {} },
14-
)
15-
16-
const transport = new StreamableHTTPClientTransport(
17-
new URL(`http://localhost:${mcpServerPort}/mcp`),
18-
)
19-
20-
await client.connect(transport)
21-
22-
return {
23-
client,
24-
async [Symbol.asyncDispose]() {
25-
await client.transport?.close()
26-
},
27-
}
28-
}
29-
30-
test('listing tools works', async () => {
31-
await using setup = await setupClient()
32-
const { client } = setup
33-
34-
const result = await client.listTools()
35-
expect(result.tools.length).toBeGreaterThan(0)
7+
test(`TODO: update this test title to describe the important thing we're working on in this exercise step`, async () => {
8+
// TODO: implement this test
369
})
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
1-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
2-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
31
import { test, expect, inject } from 'vitest'
2+
import { z } from 'zod'
43

54
const mcpServerPort = inject('mcpServerPort')
5+
const mcpServerUrl = `http://localhost:${mcpServerPort}`
66

7-
async function setupClient() {
8-
const client = new Client(
9-
{
10-
name: 'EpicMeTester',
11-
version: '1.0.0',
12-
},
13-
{ capabilities: {} },
14-
)
15-
16-
const transport = new StreamableHTTPClientTransport(
17-
new URL(`http://localhost:${mcpServerPort}/mcp`),
18-
)
19-
20-
await client.connect(transport)
21-
22-
return {
23-
client,
24-
async [Symbol.asyncDispose]() {
25-
await client.transport?.close()
26-
},
27-
}
28-
}
29-
30-
test('listing tools works', async () => {
31-
await using setup = await setupClient()
32-
const { client } = setup
33-
34-
const result = await client.listTools()
35-
expect(result.tools.length).toBeGreaterThan(0)
7+
test(`TODO: update this test title to describe the important thing we're working on in this exercise step`, async () => {
8+
// TODO: implement this test
369
})
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
1-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
2-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
31
import { test, expect, inject } from 'vitest'
2+
import { z } from 'zod'
43

54
const mcpServerPort = inject('mcpServerPort')
5+
const mcpServerUrl = `http://localhost:${mcpServerPort}`
66

7-
async function setupClient() {
8-
const client = new Client(
9-
{
10-
name: 'EpicMeTester',
11-
version: '1.0.0',
12-
},
13-
{ capabilities: {} },
14-
)
15-
16-
const transport = new StreamableHTTPClientTransport(
17-
new URL(`http://localhost:${mcpServerPort}/mcp`),
18-
)
19-
20-
await client.connect(transport)
21-
22-
return {
23-
client,
24-
async [Symbol.asyncDispose]() {
25-
await client.transport?.close()
26-
},
27-
}
28-
}
29-
30-
test('listing tools works', async () => {
31-
await using setup = await setupClient()
32-
const { client } = setup
33-
34-
const result = await client.listTools()
35-
expect(result.tools.length).toBeGreaterThan(0)
7+
test(`TODO: update this test title to describe the important thing we're working on in this exercise step`, async () => {
8+
// TODO: implement this test
369
})
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
1-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
2-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
31
import { test, expect, inject } from 'vitest'
2+
import { z } from 'zod'
43

54
const mcpServerPort = inject('mcpServerPort')
5+
const mcpServerUrl = `http://localhost:${mcpServerPort}`
66

7-
async function setupClient() {
8-
const client = new Client(
9-
{
10-
name: 'EpicMeTester',
11-
version: '1.0.0',
12-
},
13-
{ capabilities: {} },
14-
)
15-
16-
const transport = new StreamableHTTPClientTransport(
17-
new URL(`http://localhost:${mcpServerPort}/mcp`),
18-
)
19-
20-
await client.connect(transport)
21-
22-
return {
23-
client,
24-
async [Symbol.asyncDispose]() {
25-
await client.transport?.close()
26-
},
27-
}
28-
}
29-
30-
test('listing tools works', async () => {
31-
await using setup = await setupClient()
32-
const { client } = setup
33-
34-
const result = await client.listTools()
35-
expect(result.tools.length).toBeGreaterThan(0)
7+
test(`TODO: update this test title to describe the important thing we're working on in this exercise step`, async () => {
8+
// TODO: implement this test
369
})
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
1-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
2-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
31
import { test, expect, inject } from 'vitest'
2+
import { z } from 'zod'
43

54
const mcpServerPort = inject('mcpServerPort')
5+
const mcpServerUrl = `http://localhost:${mcpServerPort}`
66

7-
async function setupClient() {
8-
const client = new Client(
9-
{
10-
name: 'EpicMeTester',
11-
version: '1.0.0',
12-
},
13-
{ capabilities: {} },
14-
)
15-
16-
const transport = new StreamableHTTPClientTransport(
17-
new URL(`http://localhost:${mcpServerPort}/mcp`),
18-
)
19-
20-
await client.connect(transport)
21-
22-
return {
23-
client,
24-
async [Symbol.asyncDispose]() {
25-
await client.transport?.close()
26-
},
27-
}
28-
}
29-
30-
test('listing tools works', async () => {
31-
await using setup = await setupClient()
32-
const { client } = setup
33-
34-
const result = await client.listTools()
35-
expect(result.tools.length).toBeGreaterThan(0)
7+
test(`TODO: update this test title to describe the important thing we're working on in this exercise step`, async () => {
8+
// TODO: implement this test
369
})

0 commit comments

Comments
 (0)