-
Notifications
You must be signed in to change notification settings - Fork 5
refactor(toolsets): flatten directory structure and clean up tests #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d88a2bb
refactor(toolsets): flatten directory structure into single module
ryoppippi fa743ea
test(mcp-client): add dedicated unit tests for MCP client factory
ryoppippi 30e072f
test: remove meaningless initialisation tests
ryoppippi c7bb4d7
test(tool): consolidate duplicated test blocks
ryoppippi 5c8afbe
refactor(src): flatten module structure by moving files to root src d…
ryoppippi 7854a56
test(tool): consolidate test files into single tool.test.ts
ryoppippi 8342a23
remove vitest imports from test files
ryoppippi 55a56ad
refactor(schema): flatten schemas directory structure
ryoppippi 7365e0b
merge: integrate main branch with flattened structure
ryoppippi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /** | ||
| * MCP client factory tests. | ||
| * Tests the createMCPClient function for creating MCP protocol clients. | ||
| */ | ||
| import { Client } from '@modelcontextprotocol/sdk/client/index.js'; | ||
| import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; | ||
| import { createMCPClient } from './mcp-client'; | ||
|
|
||
| test('createMCPClient creates client with required options', async () => { | ||
| const mcpClient = await createMCPClient({ | ||
| baseUrl: 'https://api.example.com/mcp', | ||
| }); | ||
|
|
||
| expect(mcpClient.client).toBeInstanceOf(Client); | ||
| expect(mcpClient.transport).toBeInstanceOf(StreamableHTTPClientTransport); | ||
| expect(typeof mcpClient[Symbol.asyncDispose]).toBe('function'); | ||
| }); | ||
|
|
||
| test('createMCPClient creates client with custom headers', async () => { | ||
| const mcpClient = await createMCPClient({ | ||
| baseUrl: 'https://api.example.com/mcp', | ||
| headers: { | ||
| Authorization: 'Bearer test-token', | ||
| 'x-custom-header': 'custom-value', | ||
| }, | ||
| }); | ||
|
|
||
| expect(mcpClient.client).toBeInstanceOf(Client); | ||
| expect(mcpClient.transport).toBeInstanceOf(StreamableHTTPClientTransport); | ||
| }); | ||
|
|
||
| test('createMCPClient provides asyncDispose for cleanup', async () => { | ||
| const mcpClient = await createMCPClient({ | ||
| baseUrl: 'https://api.example.com/mcp', | ||
| }); | ||
|
|
||
| // Spy on close methods | ||
| const clientCloseSpy = vi.spyOn(mcpClient.client, 'close').mockResolvedValue(undefined); | ||
| const transportCloseSpy = vi.spyOn(mcpClient.transport, 'close').mockResolvedValue(undefined); | ||
|
|
||
| // Call asyncDispose | ||
| await mcpClient[Symbol.asyncDispose](); | ||
|
|
||
| expect(clientCloseSpy).toHaveBeenCalledOnce(); | ||
| expect(transportCloseSpy).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| test('createMCPClient can connect and list tools from MCP server', async () => { | ||
| await using mcpClient = await createMCPClient({ | ||
| baseUrl: 'https://api.stackone-dev.com/mcp', | ||
| headers: { | ||
| Authorization: `Basic ${Buffer.from('test-key:').toString('base64')}`, | ||
| 'x-account-id': 'test-account', | ||
| }, | ||
| }); | ||
|
|
||
| await mcpClient.client.connect(mcpClient.transport); | ||
| const result = await mcpClient.client.listTools(); | ||
|
|
||
| expect(result.tools).toBeDefined(); | ||
| expect(Array.isArray(result.tools)).toBe(true); | ||
| expect(result.tools.length).toBeGreaterThan(0); | ||
|
|
||
| const tool = result.tools[0]; | ||
| expect(tool.name).toBe('dummy_action'); | ||
| expect(tool.description).toBe('Dummy tool'); | ||
| expect(tool.inputSchema).toBeDefined(); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: This test makes real network calls to an external server without mocking, making it flaky and inconsistent with other tests in the project that use MSW. Consider mocking the MCP server using MSW's
server.use()pattern as done intoolsets.test.ts.Prompt for AI agents