chore: remove dead code and fix HTTP port-conflict startup (#351)
* chore: remove dead code and fix HTTP port-conflict startup - drop unused helpers, constants, schemas, and duplicated types - exit non-zero when the HTTP port is already in use - add stdio and port-conflict tests - clean dist on build, add serve:http, fix inspector:http for Inspector v2 * test: harden port-conflict test; drop unreachable listen guard - pin the child's host so BRAVE_MCP_HOST cannot bypass the conflict - bound the exit wait and reject spawn errors - remove the address() guard; 'listening' does not fire on a failed bind
This commit is contained in:
1 parent
2cf96460c1
commit
50cb919200
21 files changed
+191
-252
No files matched your search
@@ -5,27 +5,25 @@ import createMcpServer from '../server.js';
|
||||
|
||||
/**
|
||||
* Connects a real SDK Client to a fresh McpServer over an in-memory transport
|
||||
* pair, so tests exercise the actual registerTool/callTool wiring instead of
|
||||
* invoking a tool's `execute` function directly.
|
||||
* pair, exercising the real registerTool/callTool wiring.
|
||||
*
|
||||
* Tear down with `client.close()`; it cascades to the server.
|
||||
*/
|
||||
export async function connectTestClient(): Promise<{
|
||||
client: Client;
|
||||
close: () => Promise<void>;
|
||||
}> {
|
||||
export async function connectTestClient(): Promise<Client> {
|
||||
const mcpServer = createMcpServer();
|
||||
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
||||
const client = new Client({ name: 'test-client', version: '0.0.0' });
|
||||
|
||||
await Promise.all([mcpServer.connect(serverTransport), client.connect(clientTransport)]);
|
||||
|
||||
return { client, close: () => client.close() };
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces global.fetch with a stub that resolves requests via `handler`,
|
||||
* keyed on the request's pathname. Returns a restore function.
|
||||
*/
|
||||
export function stubFetch(handler: (url: URL) => unknown): () => void {
|
||||
function stubFetch(handler: (url: URL) => unknown): () => void {
|
||||
const originalFetch = globalThis.fetch;
|
||||
|
||||
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
||||
@@ -54,17 +52,16 @@ export function stubFetch(handler: (url: URL) => unknown): () => void {
|
||||
*/
|
||||
export function useTestClient(responder: (url: URL) => unknown): () => Client {
|
||||
let client: Client;
|
||||
let close: () => Promise<void>;
|
||||
let restoreFetch: () => void;
|
||||
|
||||
before(async () => {
|
||||
restoreFetch = stubFetch(responder);
|
||||
({ client, close } = await connectTestClient());
|
||||
client = await connectTestClient();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
restoreFetch();
|
||||
await close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
return () => client;
|
||||
|
||||
Reference in new issue
Block a user