Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "toolception",
"version": "0.5.0",
"version": "0.5.1",
"private": false,
"type": "module",
"main": "dist/index.js",
Expand Down
5 changes: 5 additions & 0 deletions src/server/createMcpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export async function createMcpServer(options: CreateMcpServerOptions) {
: mode === "DYNAMIC",
});

// In STATIC mode, wait for initialization to complete before starting
if (mode === "STATIC") {
await orchestrator.ensureReady();
}

const transport = new FastifyTransport(
orchestrator.getManager(),
() => {
Expand Down
46 changes: 46 additions & 0 deletions tests/createMcpServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,50 @@ describe("createMcpServer", () => {
// No additional registrations should have occurred on the shared server
expect(base.calls.filter((n) => n === "core.ping").length).toBe(1);
});

it("ensures tools are ready immediately in STATIC mode (waits for async module loaders)", async () => {
const f = makeFakeServerFactory();
let moduleLoaderStarted = false;
let moduleLoaderCompleted = false;

const staticCatalog = {
testset: {
name: "Test Toolset",
description: "Test tools with async loading",
modules: ["testset"],
},
} as any;

await createMcpServer({
catalog: staticCatalog,
moduleLoaders: {
testset: async () => {
moduleLoaderStarted = true;
// Simulate async loading delay
await new Promise((r) => setTimeout(r, 100));
moduleLoaderCompleted = true;
return [
{
name: "test_tool",
description: "A test tool",
inputSchema: { type: "object", properties: {} },
handler: async () => ({
content: [{ type: "text", text: "test" }],
}),
},
];
},
},
startup: { mode: "STATIC", toolsets: ["testset"] },
createServer: f.createServer,
});

// After createMcpServer returns, the module loader should have completed
expect(moduleLoaderStarted).toBe(true);
expect(moduleLoaderCompleted).toBe(true);

// Tools should be registered on the server
const base = f.created[0];
expect(base.calls.filter((n) => n === "testset.test_tool").length).toBe(1);
});
});