Skip to content

Commit 731e6b2

Browse files
committed
Fix CLI tool filtering options and cache instructions fetch
- Pass mcpOptions from CLI to both stdio and HTTP transports - Update launchStdioServer to accept mcpOptions parameter - Update newServer in HTTP transport to accept and forward mcpOptions - Cache getInstructions() result to avoid fetching on every HTTP request
1 parent 6818c49 commit 731e6b2

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

packages/mcp-server/src/http.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import { parseAuthHeaders } from './headers';
1111

1212
const newServer = async ({
1313
clientOptions,
14+
mcpOptions,
1415
req,
1516
res,
1617
}: {
1718
clientOptions: ClientOptions;
19+
mcpOptions: McpOptions;
1820
req: express.Request;
1921
res: express.Response;
2022
}): Promise<McpServer | null> => {
@@ -28,6 +30,7 @@ const newServer = async ({
2830
...clientOptions,
2931
...authOptions,
3032
},
33+
mcpOptions,
3134
});
3235
} catch (error) {
3336
res.status(401).json({

packages/mcp-server/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function main() {
1818

1919
switch (options.transport) {
2020
case 'stdio':
21-
await launchStdioServer();
21+
await launchStdioServer({ mcpOptions: options });
2222
break;
2323
case 'http':
2424
await launchStreamableHTTPServer({

packages/mcp-server/src/server.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import { HandlerFunction, McpTool } from './types';
1717
export { McpOptions } from './options';
1818
export { ClientOptions } from 'dedalus-labs';
1919

20+
let cachedInstructions: string | undefined;
21+
2022
async function getInstructions() {
23+
if (cachedInstructions !== undefined) {
24+
return cachedInstructions;
25+
}
26+
2127
// This API key is optional; providing it allows the server to fetch instructions for unreleased versions.
2228
const stainlessAPIKey = readEnv('STAINLESS_API_KEY');
2329
const response = await fetch(
@@ -50,6 +56,7 @@ async function getInstructions() {
5056
${instructions}
5157
`;
5258

59+
cachedInstructions = instructions;
5360
return instructions;
5461
}
5562

packages/mcp-server/src/stdio.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
2+
import { McpOptions } from './options';
23
import { initMcpServer, newMcpServer } from './server';
34

4-
export const launchStdioServer = async () => {
5+
export const launchStdioServer = async (params: { mcpOptions: McpOptions }) => {
56
const server = await newMcpServer();
67

7-
await initMcpServer({ server });
8+
await initMcpServer({ server, mcpOptions: params.mcpOptions });
89

910
const transport = new StdioServerTransport();
1011
await server.connect(transport);

0 commit comments

Comments
 (0)