Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7
refactor(test): replace Bun.serve with MSW + Hono for MCP tests#189
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
82731d67604652dd07c388715f3059ea223d8348fdefb9e1dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,230 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Mock MCP server for testing using Hono's app.request() method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * This creates an MCP-compatible handler that can be used with MSW | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * without starting a real HTTP server. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { Hono as HonoApp } from 'hono'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { http, HttpResponse } from 'msw'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { StreamableHTTPTransport } from '@hono/mcp'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Hono } from 'hono'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { basicAuth } from 'hono/basic-auth'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export interface McpToolDefinition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputSchema: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'object'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| properties?: Record<string, unknown>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required?: string[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| additionalProperties?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export interface MockMcpServerOptions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Tools available per account ID. Use 'default' for tools when no account header is provided. */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountTools: Record<string, readonly McpToolDefinition[]>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Creates an MSW handler for mocking MCP protocol requests. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Uses Hono's app.request() to handle requests without starting a server. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @example | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * ```ts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * import { server } from './mocks/node'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * import { createMcpHandler, defaultMcpTools, accountMcpTools } from './mocks/mcp-server'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * // In your test setup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * server.use( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * createMcpHandler({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * accountTools: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * default: defaultMcpTools, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * 'account-1': accountMcpTools.acc1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+30
to
+46
CopilotAI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *CreatesanMSWhandlerformockingMCPprotocolrequests. | |
| *UsesHono's app.request() to handle requests without starting a server. | |
| * | |
| * @example | |
| *```ts | |
| *import{server}from'./mocks/node'; | |
| *import{createMcpHandler,defaultMcpTools,accountMcpTools}from'./mocks/mcp-server'; | |
| * | |
| *// In your test setup | |
| *server.use( | |
| *createMcpHandler({ | |
| *accountTools: { | |
| *default: defaultMcpTools, | |
| *'account-1': accountMcpTools.acc1, | |
| *}, | |
| *}) | |
| *); | |
| *CreatesaHonoappformockingMCPprotocolrequests. | |
| *ThiscanbeusedinteststohandleMCPrequestswithoutstartingarealHTTPserver. | |
| * | |
| * @example | |
| *```ts | |
| *import{server}from'./mocks/node'; | |
| *import{createMcpApp,defaultMcpTools,accountMcpTools}from'./mocks/mcp-server'; | |
| * | |
| *// In your test setup | |
| *constmcpApp=createMcpApp({ | |
| *accountTools: { | |
| *default: defaultMcpTools, | |
| *'account-1': accountMcpTools.acc1, | |
| *}, | |
| *}); | |
| *// Use mcpApp.fetch(...) in your test or MSW handler |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -6,14 +6,14 @@ catalogMode: strict | ||||
CopilotAI | ||||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
CopilotAIDec 9, 2025
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.
Unused imports detected. The
httpandHttpResponseimports from 'msw' are not used anywhere in this file. They should be removed.